github.com/joelanford/operator-sdk@v0.8.2/internal/pkg/scaffold/ansible/main.go (about) 1 // Copyright 2019 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 // Main - main source file for ansible operator 24 type Main struct { 25 StaticInput 26 } 27 28 func (m *Main) GetInput() (input.Input, error) { 29 if m.Path == "" { 30 m.Path = filepath.Join("cmd", "manager", "main.go") 31 } 32 m.TemplateBody = mainTmpl 33 return m.Input, nil 34 } 35 36 const mainTmpl = `package main 37 38 import ( 39 "os" 40 41 // Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.) 42 _ "k8s.io/client-go/plugin/pkg/client/auth" 43 44 aoflags "github.com/operator-framework/operator-sdk/pkg/ansible/flags" 45 "github.com/operator-framework/operator-sdk/pkg/ansible" 46 "github.com/operator-framework/operator-sdk/pkg/log/zap" 47 48 "github.com/spf13/pflag" 49 logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" 50 ) 51 52 func main() { 53 aflags := aoflags.AddTo(pflag.CommandLine) 54 pflag.Parse() 55 logf.SetLogger(zap.Logger()) 56 57 if err := ansible.Run(aflags); err != nil { 58 logf.Log.WithName("cmd").Error(err, "") 59 os.Exit(1) 60 } 61 } 62 `