sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/common/kustomize/v1/scaffolds/internal/templates/config/manager/config.go (about)

     1  /*
     2  Copyright 2020 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package manager
    18  
    19  import (
    20  	"path/filepath"
    21  
    22  	"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
    23  )
    24  
    25  var _ machinery.Template = &Config{}
    26  
    27  // Config scaffolds a file that defines the namespace and the manager deployment
    28  type Config struct {
    29  	machinery.TemplateMixin
    30  	machinery.ComponentConfigMixin
    31  	machinery.ProjectNameMixin
    32  
    33  	// Image is controller manager image name
    34  	Image string
    35  }
    36  
    37  // SetTemplateDefaults implements file.Template
    38  func (f *Config) SetTemplateDefaults() error {
    39  	if f.Path == "" {
    40  		f.Path = filepath.Join("config", "manager", "manager.yaml")
    41  	}
    42  
    43  	f.TemplateBody = configTemplate
    44  
    45  	return nil
    46  }
    47  
    48  const configTemplate = `apiVersion: v1
    49  kind: Namespace
    50  metadata:
    51    labels:
    52      control-plane: controller-manager
    53      app.kubernetes.io/name: namespace
    54      app.kubernetes.io/instance: system
    55      app.kubernetes.io/component: manager
    56      app.kubernetes.io/created-by: {{ .ProjectName }}
    57      app.kubernetes.io/part-of: {{ .ProjectName }}
    58      app.kubernetes.io/managed-by: kustomize
    59    name: system
    60  ---
    61  apiVersion: apps/v1
    62  kind: Deployment
    63  metadata:
    64    name: controller-manager
    65    namespace: system
    66    labels:
    67      control-plane: controller-manager
    68      app.kubernetes.io/name: deployment
    69      app.kubernetes.io/instance: controller-manager
    70      app.kubernetes.io/component: manager
    71      app.kubernetes.io/created-by: {{ .ProjectName }}
    72      app.kubernetes.io/part-of: {{ .ProjectName }}
    73      app.kubernetes.io/managed-by: kustomize
    74  spec:
    75    selector:
    76      matchLabels:
    77        control-plane: controller-manager
    78    replicas: 1
    79    template:
    80      metadata:
    81        annotations:
    82          kubectl.kubernetes.io/default-container: manager
    83        labels:
    84          control-plane: controller-manager
    85      spec:
    86        # TODO(user): Uncomment the following code to configure the nodeAffinity expression
    87        # according to the platforms which are supported by your solution.
    88        # It is considered best practice to support multiple architectures. You can
    89        # build your manager image using the makefile target docker-buildx.
    90        # affinity:
    91        #   nodeAffinity:
    92        #     requiredDuringSchedulingIgnoredDuringExecution:
    93        #       nodeSelectorTerms:
    94        #         - matchExpressions:
    95        #           - key: kubernetes.io/arch
    96        #             operator: In
    97        #             values:
    98        #               - amd64
    99        #               - arm64
   100        #               - ppc64le
   101        #               - s390x
   102        #           - key: kubernetes.io/os
   103        #             operator: In
   104        #             values:
   105        #               - linux
   106        securityContext:
   107          runAsNonRoot: true
   108          # TODO(user): For common cases that do not require escalating privileges
   109          # it is recommended to ensure that all your Pods/Containers are restrictive.
   110          # More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
   111          # Please uncomment the following code if your project does NOT have to work on old Kubernetes
   112          # versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
   113          # seccompProfile:
   114          #   type: RuntimeDefault
   115        containers:
   116        - command:
   117          - /manager
   118  {{- if not .ComponentConfig }}
   119          args:
   120          - --leader-elect
   121  {{- end }}
   122          image: {{ .Image }}
   123          name: manager
   124          securityContext:
   125            allowPrivilegeEscalation: false
   126            capabilities:
   127              drop:
   128                - "ALL"
   129          livenessProbe:
   130            httpGet:
   131              path: /healthz
   132              port: 8081
   133            initialDelaySeconds: 15
   134            periodSeconds: 20
   135          readinessProbe:
   136            httpGet:
   137              path: /readyz
   138              port: 8081
   139            initialDelaySeconds: 5
   140            periodSeconds: 10
   141          # TODO(user): Configure the resources accordingly based on the project requirements.
   142          # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
   143          resources:
   144            limits:
   145              cpu: 500m
   146              memory: 128Mi
   147            requests:
   148              cpu: 10m
   149              memory: 64Mi
   150        serviceAccountName: controller-manager
   151        terminationGracePeriodSeconds: 10
   152  `