github.com/joelanford/operator-sdk@v0.8.2/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 m.Delims = AnsibleDelims 36 37 return m.Input, nil 38 } 39 40 const moleculeDefaultPrepareAnsibleTmpl = `--- 41 - name: Prepare 42 hosts: k8s 43 gather_facts: no 44 vars: 45 kubeconfig: "{{ lookup('env', 'KUBECONFIG') }}" 46 tasks: 47 - name: delete the kubeconfig if present 48 file: 49 path: '{{ kubeconfig }}' 50 state: absent 51 delegate_to: localhost 52 53 - name: Fetch the kubeconfig 54 fetch: 55 dest: '{{ kubeconfig }}' 56 flat: yes 57 src: /root/.kube/config 58 59 - name: Change the kubeconfig port to the proper value 60 replace: 61 regexp: 8443 62 replace: "{{ lookup('env', 'KIND_PORT') }}" 63 path: '{{ kubeconfig }}' 64 delegate_to: localhost 65 66 - name: Wait for the Kubernetes API to become available (this could take a minute) 67 uri: 68 url: "https://localhost:8443/apis" 69 status_code: 200 70 validate_certs: no 71 register: result 72 until: (result.status|default(-1)) == 200 73 retries: 60 74 delay: 5 75 `