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