sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/common/kustomize/v1/scaffolds/internal/templates/config/kdefault/kustomization.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 kdefault
    18  
    19  import (
    20  	"path/filepath"
    21  
    22  	"sigs.k8s.io/kubebuilder/v3/pkg/machinery"
    23  )
    24  
    25  var _ machinery.Template = &Kustomization{}
    26  
    27  // Kustomization scaffolds a file that defines the kustomization scheme for the default overlay folder
    28  type Kustomization struct {
    29  	machinery.TemplateMixin
    30  	machinery.ProjectNameMixin
    31  	machinery.ComponentConfigMixin
    32  }
    33  
    34  // SetTemplateDefaults implements file.Template
    35  func (f *Kustomization) SetTemplateDefaults() error {
    36  	if f.Path == "" {
    37  		f.Path = filepath.Join("config", "default", "kustomization.yaml")
    38  	}
    39  
    40  	f.TemplateBody = kustomizeTemplate
    41  
    42  	f.IfExistsAction = machinery.Error
    43  
    44  	return nil
    45  }
    46  
    47  const kustomizeTemplate = `# Adds namespace to all resources.
    48  namespace: {{ .ProjectName }}-system
    49  
    50  # Value of this field is prepended to the
    51  # names of all resources, e.g. a deployment named
    52  # "wordpress" becomes "alices-wordpress".
    53  # Note that it should also match with the prefix (text before '-') of the namespace
    54  # field above.
    55  namePrefix: {{ .ProjectName }}-
    56  
    57  # Labels to add to all resources and selectors.
    58  #commonLabels:
    59  #  someName: someValue
    60  
    61  bases:
    62  - ../crd
    63  - ../rbac
    64  - ../manager
    65  # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
    66  # crd/kustomization.yaml
    67  #- ../webhook
    68  # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
    69  #- ../certmanager
    70  # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
    71  #- ../prometheus
    72  
    73  patchesStrategicMerge:
    74  # Protect the /metrics endpoint by putting it behind auth.
    75  # If you want your controller-manager to expose the /metrics
    76  # endpoint w/o any authn/z, please comment the following line.
    77  - manager_auth_proxy_patch.yaml
    78  
    79  {{ if .ComponentConfig }}
    80  # Mount the controller config file for loading manager configurations
    81  # through a ComponentConfig type
    82  - manager_config_patch.yaml{{ end }}
    83  
    84  # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
    85  # crd/kustomization.yaml
    86  #- manager_webhook_patch.yaml
    87  
    88  # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
    89  # Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
    90  # 'CERTMANAGER' needs to be enabled to use ca injection
    91  #- webhookcainjection_patch.yaml
    92  
    93  # the following config is for teaching kustomize how to do var substitution
    94  vars:
    95  # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
    96  #- name: CERTIFICATE_NAMESPACE # namespace of the certificate CR
    97  #  objref:
    98  #    kind: Certificate
    99  #    group: cert-manager.io
   100  #    version: v1
   101  #    name: serving-cert # this name should match the one in certificate.yaml
   102  #  fieldref:
   103  #    fieldpath: metadata.namespace
   104  #- name: CERTIFICATE_NAME
   105  #  objref:
   106  #    kind: Certificate
   107  #    group: cert-manager.io
   108  #    version: v1
   109  #    name: serving-cert # this name should match the one in certificate.yaml
   110  #- name: SERVICE_NAMESPACE # namespace of the service
   111  #  objref:
   112  #    kind: Service
   113  #    version: v1
   114  #    name: webhook-service
   115  #  fieldref:
   116  #    fieldpath: metadata.namespace
   117  #- name: SERVICE_NAME
   118  #  objref:
   119  #    kind: Service
   120  #    version: v1
   121  #    name: webhook-service
   122  `