github.com/fabianvf/ocp-release-operator-sdk@v0.0.0-20190426141702-57620ee2f090/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  	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: 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                {{- if .IsClusterScoped }}
    79                value: ""
    80                {{- else }}
    81                valueFrom:
    82                  fieldRef:
    83                    fieldPath: metadata.namespace
    84                {{- end}}
    85              - name: POD_NAME
    86                valueFrom:
    87                  fieldRef:
    88                    fieldPath: metadata.name
    89              - name: OPERATOR_NAME
    90                value: "{{.ProjectName}}"
    91        volumes:
    92          - name: runner
    93            emptyDir: {}
    94  `