github.com/fabianvf/ocp-release-operator-sdk@v0.0.0-20190426141702-57620ee2f090/internal/pkg/scaffold/ansible/molecule_default_prepare.go (about) 1 // Copyright 2018 The Operator-SDK Authors 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package ansible 16 17 import ( 18 "path/filepath" 19 20 "github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input" 21 ) 22 23 const MoleculeDefaultPrepareFile = "prepare.yml" 24 25 type MoleculeDefaultPrepare struct { 26 input.Input 27 } 28 29 // GetInput - gets the input 30 func (m *MoleculeDefaultPrepare) GetInput() (input.Input, error) { 31 if m.Path == "" { 32 m.Path = filepath.Join(MoleculeDefaultDir, MoleculeDefaultPrepareFile) 33 } 34 m.TemplateBody = moleculeDefaultPrepareAnsibleTmpl 35 36 return m.Input, nil 37 } 38 39 const moleculeDefaultPrepareAnsibleTmpl = `--- 40 - name: Prepare 41 hosts: k8s 42 gather_facts: no 43 vars: 44 kubeconfig: "{{"{{ lookup('env', 'KUBECONFIG') }}"}}" 45 tasks: 46 - name: delete the kubeconfig if present 47 file: 48 path: '{{"{{ kubeconfig }}"}}' 49 state: absent 50 delegate_to: localhost 51 52 - name: Fetch the kubeconfig 53 fetch: 54 dest: '{{ "{{ kubeconfig }}" }}' 55 flat: yes 56 src: /root/.kube/config 57 58 - name: Change the kubeconfig port to the proper value 59 replace: 60 regexp: 8443 61 replace: "{{"{{ lookup('env', 'KIND_PORT') }}"}}" 62 path: '{{ "{{ kubeconfig }}" }}' 63 delegate_to: localhost 64 65 - name: Wait for the Kubernetes API to become available (this could take a minute) 66 uri: 67 url: "https://localhost:8443/apis" 68 status_code: 200 69 validate_certs: no 70 register: result 71 until: (result.status|default(-1)) == 200 72 retries: 60 73 delay: 5 74 `