sigs.k8s.io/kubebuilder/v3@v3.14.0/pkg/machinery/mixins.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 machinery 18 19 import ( 20 "sigs.k8s.io/kubebuilder/v3/pkg/model/resource" 21 ) 22 23 // PathMixin provides file builders with a path field 24 type PathMixin struct { 25 // Path is the of the file 26 Path string 27 } 28 29 // GetPath implements Builder 30 func (t *PathMixin) GetPath() string { 31 return t.Path 32 } 33 34 // IfExistsActionMixin provides file builders with a if-exists-action field 35 type IfExistsActionMixin struct { 36 // IfExistsAction determines what to do if the file exists 37 IfExistsAction IfExistsAction 38 } 39 40 // GetIfExistsAction implements Builder 41 func (t *IfExistsActionMixin) GetIfExistsAction() IfExistsAction { 42 return t.IfExistsAction 43 } 44 45 // TemplateMixin is the mixin that should be embedded in Template builders 46 type TemplateMixin struct { 47 PathMixin 48 IfExistsActionMixin 49 50 // TemplateBody is the template body to execute 51 TemplateBody string 52 parseDelimLeft string 53 parseDelimRight string 54 } 55 56 // GetBody implements Template 57 func (t *TemplateMixin) GetBody() string { 58 return t.TemplateBody 59 } 60 61 // SetDelim implements Template 62 func (t *TemplateMixin) SetDelim(left, right string) { 63 t.parseDelimLeft = left 64 t.parseDelimRight = right 65 } 66 67 // GetDelim implements Template 68 func (t *TemplateMixin) GetDelim() (string, string) { 69 return t.parseDelimLeft, t.parseDelimRight 70 } 71 72 // InserterMixin is the mixin that should be embedded in Inserter builders 73 type InserterMixin struct { 74 PathMixin 75 } 76 77 // GetIfExistsAction implements Builder 78 func (t *InserterMixin) GetIfExistsAction() IfExistsAction { 79 // Inserter builders always need to overwrite previous files 80 return OverwriteFile 81 } 82 83 // DomainMixin provides templates with a injectable domain field 84 type DomainMixin struct { 85 // Domain is the domain for the APIs 86 Domain string 87 } 88 89 // InjectDomain implements HasDomain 90 func (m *DomainMixin) InjectDomain(domain string) { 91 if m.Domain == "" { 92 m.Domain = domain 93 } 94 } 95 96 // RepositoryMixin provides templates with a injectable repository field 97 type RepositoryMixin struct { 98 // Repo is the go project package path 99 Repo string 100 } 101 102 // InjectRepository implements HasRepository 103 func (m *RepositoryMixin) InjectRepository(repository string) { 104 if m.Repo == "" { 105 m.Repo = repository 106 } 107 } 108 109 // ProjectNameMixin provides templates with an injectable project name field. 110 type ProjectNameMixin struct { 111 ProjectName string 112 } 113 114 // InjectProjectName implements HasProjectName. 115 func (m *ProjectNameMixin) InjectProjectName(projectName string) { 116 if m.ProjectName == "" { 117 m.ProjectName = projectName 118 } 119 } 120 121 // MultiGroupMixin provides templates with a injectable multi-group flag field 122 type MultiGroupMixin struct { 123 // MultiGroup is the multi-group flag 124 MultiGroup bool 125 } 126 127 // InjectMultiGroup implements HasMultiGroup 128 func (m *MultiGroupMixin) InjectMultiGroup(flag bool) { 129 m.MultiGroup = flag 130 } 131 132 // Deprecated: The ComponentConfig has been deprecated in the Controller-Runtime since its version 0.15.0. 133 // Fur further information see: https://github.com/kubernetes-sigs/controller-runtime/issues/895 134 // Moreover, it has undergone breaking changes and is no longer functioning as intended. 135 // As a result, Kubebuilder, which heavily relies on the Controller Runtime, has also deprecated this feature, 136 // no longer guaranteeing its functionality from version 3.11.0 onwards. 137 // 138 // Please, be aware that it will force Kubebuilder remove this option soon in future release. 139 // 140 // ComponentConfigMixin provides templates with a injectable component-config flag field 141 type ComponentConfigMixin struct { 142 // ComponentConfig is the component-config flag 143 ComponentConfig bool 144 } 145 146 // InjectComponentConfig implements HasComponentConfig 147 func (m *ComponentConfigMixin) InjectComponentConfig(flag bool) { 148 m.ComponentConfig = flag 149 } 150 151 // BoilerplateMixin provides templates with a injectable boilerplate field 152 type BoilerplateMixin struct { 153 // Boilerplate is the contents of a Boilerplate go header file 154 Boilerplate string 155 } 156 157 // InjectBoilerplate implements HasBoilerplate 158 func (m *BoilerplateMixin) InjectBoilerplate(boilerplate string) { 159 if m.Boilerplate == "" { 160 m.Boilerplate = boilerplate 161 } 162 } 163 164 // ResourceMixin provides templates with a injectable resource field 165 type ResourceMixin struct { 166 Resource *resource.Resource 167 } 168 169 // InjectResource implements HasResource 170 func (m *ResourceMixin) InjectResource(res *resource.Resource) { 171 if m.Resource == nil { 172 m.Resource = res 173 } 174 }