github.com/jmrodri/operator-sdk@v0.5.0/pkg/scaffold/ansible/deploy_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 ansible
    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  const DeployOperatorFile = "operator.yaml"
    25  
    26  type DeployOperator struct {
    27  	input.Input
    28  	IsClusterScoped bool
    29  }
    30  
    31  // GetInput - gets the input
    32  func (d *DeployOperator) GetInput() (input.Input, error) {
    33  	if d.Path == "" {
    34  		d.Path = filepath.Join(scaffold.DeployDir, DeployOperatorFile)
    35  	}
    36  	d.TemplateBody = deployOperatorAnsibleTmpl
    37  
    38  	return d.Input, nil
    39  }
    40  
    41  const deployOperatorAnsibleTmpl = `apiVersion: apps/v1
    42  kind: Deployment
    43  metadata:
    44    name: {{.ProjectName}}
    45  spec:
    46    replicas: 1
    47    selector:
    48      matchLabels:
    49        name: {{.ProjectName}}
    50    template:
    51      metadata:
    52        labels:
    53          name: {{.ProjectName}}
    54      spec:
    55        serviceAccountName: {{.ProjectName}}
    56        containers:
    57          - name: {{.ProjectName}}
    58            # Replace this with the built image name
    59            image: "{{ "{{ REPLACE_IMAGE }}" }}"
    60            imagePullPolicy: "{{ "{{ pull_policy|default('Always') }}"}}"
    61            env:
    62              - name: WATCH_NAMESPACE
    63                {{- if .IsClusterScoped }}
    64                value: ""
    65                {{- else }}
    66                valueFrom:
    67                  fieldRef:
    68                    fieldPath: metadata.namespace
    69                {{- end}}
    70              - name: POD_NAME
    71                valueFrom:
    72                  fieldRef:
    73                    fieldPath: metadata.name
    74              - name: OPERATOR_NAME
    75                value: "{{.ProjectName}}"
    76  `