Skip to content

Commit 6ce9be5

Browse files
committed
(feat) add necessary changes to support applyconfiguration gen
1 parent c169977 commit 6ce9be5

File tree

4 files changed

+62
-4
lines changed

4 files changed

+62
-4
lines changed

pkg/plugins/golang/v4/scaffolds/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ func (s *apiScaffolder) Scaffold() error {
100100
if err := scaffold.Execute(
101101
&api.Types{Force: s.force},
102102
&api.Group{},
103+
&api.Doc{},
103104
); err != nil {
104105
return fmt.Errorf("error scaffolding APIs: %w", err)
105106
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2022 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 api
18+
19+
import (
20+
log "log/slog"
21+
"path/filepath"
22+
23+
"sigs.k8s.io/kubebuilder/v4/pkg/machinery"
24+
)
25+
26+
var _ machinery.Template = &Doc{}
27+
28+
// Doc scaffolds the doc file that defines the groupName
29+
type Doc struct {
30+
machinery.TemplateMixin
31+
machinery.MultiGroupMixin
32+
machinery.BoilerplateMixin
33+
machinery.ResourceMixin
34+
}
35+
36+
// SetTemplateDefaults implements machinery.Template
37+
func (f *Doc) SetTemplateDefaults() error {
38+
if f.Path == "" {
39+
f.Path = filepath.Join("api", "%[version]", "doc.go")
40+
}
41+
42+
f.Path = f.Resource.Replacer().Replace(f.Path)
43+
log.Info(f.Path)
44+
f.TemplateBody = docTemplate
45+
46+
return nil
47+
}
48+
49+
//nolint:lll
50+
const docTemplate = `{{ .Boilerplate }}
51+
52+
// Package {{ .Resource.Version }} contains API Schema definitions for the {{ .Resource.Group }} {{ .Resource.Version }} API group.
53+
// +groupName={{ .Resource.QualifiedGroup }}
54+
package {{ .Resource.Version }}
55+
`

pkg/plugins/golang/v4/scaffolds/internal/templates/api/group.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ const groupTemplate = `{{ .Boilerplate }}
5555
5656
// Package {{ .Resource.Version }} contains API Schema definitions for the {{ .Resource.Group }} {{ .Resource.Version }} API group.
5757
// +kubebuilder:object:generate=true
58-
// +groupName={{ .Resource.QualifiedGroup }}
5958
package {{ .Resource.Version }}
6059
6160
import (
@@ -64,11 +63,11 @@ import (
6463
)
6564
6665
var (
67-
// GroupVersion is group version used to register these objects.
68-
GroupVersion = schema.GroupVersion{Group: "{{ .Resource.QualifiedGroup }}", Version: "{{ .Resource.Version }}"}
66+
// SchemeGroupVersion is group version used to register these objects.
67+
SchemeGroupVersion = schema.GroupVersion{Group: "{{ .Resource.QualifiedGroup }}", Version: "{{ .Resource.Version }}"}
6968
7069
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
71-
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
70+
SchemeBuilder = &scheme.Builder{GroupVersion: SchemeGroupVersion}
7271
7372
// AddToScheme adds the types in this group-version to the given scheme.
7473
AddToScheme = SchemeBuilder.AddToScheme

pkg/plugins/golang/v4/scaffolds/internal/templates/api/types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func (f *Types) SetTemplateDefaults() error {
6464
//nolint:lll
6565
const typesTemplate = `{{ .Boilerplate }}
6666
67+
// +kubebuilder:ac:generate=true
6768
package {{ .Resource.Version }}
6869
6970
import (
@@ -116,6 +117,8 @@ type {{ .Resource.Kind }}Status struct {
116117
// +kubebuilder:resource:scope=Cluster
117118
{{- else if not .Resource.IsRegularPlural }}
118119
// +kubebuilder:resource:path={{ .Resource.Plural }}
120+
{{- else }}
121+
// +kubebuilder:resource
119122
{{- end }}
120123
121124
// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API

0 commit comments

Comments
 (0)