sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/plugins/common/kustomize/v2/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  #labels:
    59  #- includeSelectors: true
    60  #  pairs:
    61  #    someName: someValue
    62  
    63  resources:
    64  #- ../crd
    65  - ../rbac
    66  - ../manager
    67  # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
    68  # crd/kustomization.yaml
    69  #- ../webhook
    70  # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
    71  #- ../certmanager
    72  # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
    73  #- ../prometheus
    74  
    75  patches:
    76  # Protect the /metrics endpoint by putting it behind auth.
    77  # If you want your controller-manager to expose the /metrics
    78  # endpoint w/o any authn/z, please comment the following line.
    79  - path: manager_auth_proxy_patch.yaml
    80  
    81  {{ if .ComponentConfig -}}
    82  # Mount the controller config file for loading manager configurations
    83  # through a ComponentConfig type
    84  - path: manager_config_patch.yaml
    85  
    86  {{ end -}}
    87  
    88  # [WEBHOOK] To enable webhook, uncomment all the sections with [WEBHOOK] prefix including the one in
    89  # crd/kustomization.yaml
    90  #- path: manager_webhook_patch.yaml
    91  
    92  # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'.
    93  # Uncomment 'CERTMANAGER' sections in crd/kustomization.yaml to enable the CA injection in the admission webhooks.
    94  # 'CERTMANAGER' needs to be enabled to use ca injection
    95  #- path: webhookcainjection_patch.yaml
    96  
    97  # [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER' prefix.
    98  # Uncomment the following replacements to add the cert-manager CA injection annotations
    99  #replacements:
   100  #  - source: # Add cert-manager annotation to ValidatingWebhookConfiguration, MutatingWebhookConfiguration and CRDs
   101  #      kind: Certificate
   102  #      group: cert-manager.io
   103  #      version: v1
   104  #      name: serving-cert # this name should match the one in certificate.yaml
   105  #      fieldPath: .metadata.namespace # namespace of the certificate CR
   106  #    targets:
   107  #      - select:
   108  #          kind: ValidatingWebhookConfiguration
   109  #        fieldPaths:
   110  #          - .metadata.annotations.[cert-manager.io/inject-ca-from]
   111  #        options:
   112  #          delimiter: '/'
   113  #          index: 0
   114  #          create: true
   115  #      - select:
   116  #          kind: MutatingWebhookConfiguration
   117  #        fieldPaths:
   118  #          - .metadata.annotations.[cert-manager.io/inject-ca-from]
   119  #        options:
   120  #          delimiter: '/'
   121  #          index: 0
   122  #          create: true
   123  #      - select:
   124  #          kind: CustomResourceDefinition
   125  #        fieldPaths:
   126  #          - .metadata.annotations.[cert-manager.io/inject-ca-from]
   127  #        options:
   128  #          delimiter: '/'
   129  #          index: 0
   130  #          create: true
   131  #  - source:
   132  #      kind: Certificate
   133  #      group: cert-manager.io
   134  #      version: v1
   135  #      name: serving-cert # this name should match the one in certificate.yaml
   136  #      fieldPath: .metadata.name
   137  #    targets:
   138  #      - select:
   139  #          kind: ValidatingWebhookConfiguration
   140  #        fieldPaths:
   141  #          - .metadata.annotations.[cert-manager.io/inject-ca-from]
   142  #        options:
   143  #          delimiter: '/'
   144  #          index: 1
   145  #          create: true
   146  #      - select:
   147  #          kind: MutatingWebhookConfiguration
   148  #        fieldPaths:
   149  #          - .metadata.annotations.[cert-manager.io/inject-ca-from]
   150  #        options:
   151  #          delimiter: '/'
   152  #          index: 1
   153  #          create: true
   154  #      - select:
   155  #          kind: CustomResourceDefinition
   156  #        fieldPaths:
   157  #          - .metadata.annotations.[cert-manager.io/inject-ca-from]
   158  #        options:
   159  #          delimiter: '/'
   160  #          index: 1
   161  #          create: true
   162  #  - source: # Add cert-manager annotation to the webhook Service
   163  #      kind: Service
   164  #      version: v1
   165  #      name: webhook-service
   166  #      fieldPath: .metadata.name # namespace of the service
   167  #    targets:
   168  #      - select:
   169  #          kind: Certificate
   170  #          group: cert-manager.io
   171  #          version: v1
   172  #        fieldPaths:
   173  #          - .spec.dnsNames.0
   174  #          - .spec.dnsNames.1
   175  #        options:
   176  #          delimiter: '.'
   177  #          index: 0
   178  #          create: true
   179  #  - source:
   180  #      kind: Service
   181  #      version: v1
   182  #      name: webhook-service
   183  #      fieldPath: .metadata.namespace # namespace of the service
   184  #    targets:
   185  #      - select:
   186  #          kind: Certificate
   187  #          group: cert-manager.io
   188  #          version: v1
   189  #        fieldPaths:
   190  #          - .spec.dnsNames.0
   191  #          - .spec.dnsNames.1
   192  #        options:
   193  #          delimiter: '.'
   194  #          index: 1
   195  #          create: true
   196  `