github.com/theishshah/operator-sdk@v0.6.0/pkg/scaffold/helm/operator.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 helm 16 17 import ( 18 "path/filepath" 19 20 "github.com/operator-framework/operator-sdk/pkg/scaffold" 21 "github.com/operator-framework/operator-sdk/pkg/scaffold/input" 22 ) 23 24 // Operator specifies the Helm operator.yaml manifest scaffold 25 type Operator struct { 26 input.Input 27 28 IsClusterScoped bool 29 } 30 31 // GetInput gets the scaffold execution input 32 func (s *Operator) GetInput() (input.Input, error) { 33 if s.Path == "" { 34 s.Path = filepath.Join(scaffold.DeployDir, scaffold.OperatorYamlFile) 35 } 36 s.TemplateBody = operatorTemplate 37 return s.Input, nil 38 } 39 40 const operatorTemplate = `apiVersion: apps/v1 41 kind: Deployment 42 metadata: 43 name: {{.ProjectName}} 44 spec: 45 replicas: 1 46 selector: 47 matchLabels: 48 name: {{.ProjectName}} 49 template: 50 metadata: 51 labels: 52 name: {{.ProjectName}} 53 spec: 54 serviceAccountName: {{.ProjectName}} 55 containers: 56 - name: {{.ProjectName}} 57 # Replace this with the built image name 58 image: REPLACE_IMAGE 59 imagePullPolicy: Always 60 env: 61 - name: WATCH_NAMESPACE 62 {{- if .IsClusterScoped }} 63 value: "" 64 {{- else }} 65 valueFrom: 66 fieldRef: 67 fieldPath: metadata.namespace 68 {{- end}} 69 - name: POD_NAME 70 valueFrom: 71 fieldRef: 72 fieldPath: metadata.name 73 - name: OPERATOR_NAME 74 value: "{{.ProjectName}}" 75 `