github.com/joelanford/operator-sdk@v0.8.2/internal/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/internal/pkg/scaffold"
    21  	"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
    22  )
    23  
    24  const DeployOperatorFile = "operator.yaml"
    25  
    26  type DeployOperator struct {
    27  	input.Input
    28  }
    29  
    30  // GetInput - gets the input
    31  func (d *DeployOperator) GetInput() (input.Input, error) {
    32  	if d.Path == "" {
    33  		d.Path = filepath.Join(scaffold.DeployDir, DeployOperatorFile)
    34  	}
    35  	d.TemplateBody = deployOperatorAnsibleTmpl
    36  	d.Delims = AnsibleDelims
    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: ansible
    58            command:
    59            - /usr/local/bin/ao-logs
    60            - /tmp/ansible-operator/runner
    61            - stdout
    62            # Replace this with the built image name
    63            image: "{{ REPLACE_IMAGE }}"
    64            imagePullPolicy: "{{ pull_policy|default('Always') }}"
    65            volumeMounts:
    66            - mountPath: /tmp/ansible-operator/runner
    67              name: runner
    68              readOnly: true
    69          - name: operator
    70            # Replace this with the built image name
    71            image: "{{ REPLACE_IMAGE }}"
    72            imagePullPolicy: "{{ pull_policy|default('Always') }}"
    73            volumeMounts:
    74            - mountPath: /tmp/ansible-operator/runner
    75              name: runner
    76            env:
    77              - name: WATCH_NAMESPACE
    78                valueFrom:
    79                  fieldRef:
    80                    fieldPath: metadata.namespace
    81              - name: POD_NAME
    82                valueFrom:
    83                  fieldRef:
    84                    fieldPath: metadata.name
    85              - name: OPERATOR_NAME
    86                value: "[[.ProjectName]]"
    87        volumes:
    88          - name: runner
    89            emptyDir: {}
    90  `