Skip to content

Commit 7245d41

Browse files
authored
Merge pull request #1868 from Adirio/machine-readable-markers
✨ Remove spaces from machine-readable comments
2 parents a4d0a3a + 9ee7a30 commit 7245d41

File tree

148 files changed

+398
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+398
-395
lines changed

pkg/model/file/marker.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,14 @@ package file
1919
import (
2020
"fmt"
2121
"path/filepath"
22+
"strings"
2223
)
2324

2425
const prefix = "+kubebuilder:scaffold:"
2526

2627
var commentsByExt = map[string]string{
27-
// TODO(v3): machine-readable comments should not have spaces by Go convention. However,
28-
// this is a backwards incompatible change, and thus should be done for next project version.
29-
".go": "// ",
30-
".yaml": "# ",
28+
".go": "//",
29+
".yaml": "#",
3130
".yml": "#",
3231
// When adding additional file extensions, update also the NewMarkerFor documentation and error
3332
}
@@ -54,6 +53,12 @@ func (m Marker) String() string {
5453
return m.comment + prefix + m.value
5554
}
5655

56+
// EqualsLine compares a marker with a string representation to check if they are the same marker
57+
func (m Marker) EqualsLine(line string) bool {
58+
line = strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(line), m.comment))
59+
return line == prefix+m.value
60+
}
61+
5762
// CodeFragments represents a set of code fragments
5863
// A code fragment is a piece of code provided as a Go string, it may have multiple lines
5964
type CodeFragments []string

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ func (f *Group) SetTemplateDefaults() error {
5252
const groupTemplate = `{{ .Boilerplate }}
5353
5454
// Package {{ .Resource.Version }} contains API Schema definitions for the {{ .Resource.Group }} {{ .Resource.Version }} API group
55-
// +kubebuilder:object:generate=true
56-
// +groupName={{ .Resource.Domain }}
55+
//+kubebuilder:object:generate=true
56+
//+groupName={{ .Resource.Domain }}
5757
package {{ .Resource.Version }}
5858
5959
import (

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ type {{ .Resource.Kind }}Status struct {
8585
// Important: Run "make" to regenerate code after modifying this file
8686
}
8787
88-
// +kubebuilder:object:root=true
89-
// +kubebuilder:subresource:status
90-
{{ if not .Resource.Namespaced }} // +kubebuilder:resource:scope=Cluster {{ end }}
88+
//+kubebuilder:object:root=true
89+
//+kubebuilder:subresource:status
90+
{{ if not .Resource.Namespaced }} //+kubebuilder:resource:scope=Cluster {{ end }}
9191
9292
// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API
9393
type {{ .Resource.Kind }} struct {
@@ -98,7 +98,7 @@ type {{ .Resource.Kind }} struct {
9898
Status {{ .Resource.Kind }}Status ` + "`" + `json:"status,omitempty"` + "`" + `
9999
}
100100
101-
// +kubebuilder:object:root=true
101+
//+kubebuilder:object:root=true
102102
103103
// {{ .Resource.Kind }}List contains a list of {{ .Resource.Kind }}
104104
type {{ .Resource.Kind }}List struct {

pkg/plugins/golang/v2/scaffolds/internal/templates/api/webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (r *{{ .Resource.Kind }}) SetupWebhookWithManager(mgr ctrl.Manager) error {
100100

101101
//nolint:lll
102102
defaultingWebhookTemplate = `
103-
// +kubebuilder:webhook:path=/mutate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=true,failurePolicy=fail,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=m{{ lower .Resource.Kind }}.kb.io
103+
//+kubebuilder:webhook:path=/mutate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=true,failurePolicy=fail,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=m{{ lower .Resource.Kind }}.kb.io
104104
105105
var _ webhook.Defaulter = &{{ .Resource.Kind }}{}
106106
@@ -114,7 +114,7 @@ func (r *{{ .Resource.Kind }}) Default() {
114114
//nolint:lll
115115
validatingWebhookTemplate = `
116116
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
117-
// +kubebuilder:webhook:verbs=create;update,path=/validate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=false,failurePolicy=fail,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},versions={{ .Resource.Version }},name=v{{ lower .Resource.Kind }}.kb.io
117+
//+kubebuilder:webhook:verbs=create;update,path=/validate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=false,failurePolicy=fail,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},versions={{ .Resource.Version }},name=v{{ lower .Resource.Kind }}.kb.io
118118
119119
var _ webhook.Validator = &{{ .Resource.Kind }}{}
120120

pkg/plugins/golang/v2/scaffolds/internal/templates/controllers/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,8 @@ type {{ .Resource.Kind }}Reconciler struct {
8585
Scheme *runtime.Scheme
8686
}
8787
88-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
89-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
88+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
89+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
9090
9191
func (r *{{ .Resource.Kind }}Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
9292
_ = context.Background()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ func (f *Group) SetTemplateDefaults() error {
5656
const groupTemplate = `{{ .Boilerplate }}
5757
5858
// Package {{ .Resource.Version }} contains API Schema definitions for the {{ .Resource.Group }} {{ .Resource.Version }} API group
59-
// +kubebuilder:object:generate=true
60-
// +groupName={{ .Resource.Domain }}
59+
//+kubebuilder:object:generate=true
60+
//+groupName={{ .Resource.Domain }}
6161
package {{ .Resource.Version }}
6262
6363
import (

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ type {{ .Resource.Kind }}Status struct {
8989
// Important: Run "make" to regenerate code after modifying this file
9090
}
9191
92-
// +kubebuilder:object:root=true
93-
// +kubebuilder:subresource:status
94-
{{ if not .Resource.Namespaced }} // +kubebuilder:resource:scope=Cluster {{ end }}
92+
//+kubebuilder:object:root=true
93+
//+kubebuilder:subresource:status
94+
{{ if not .Resource.Namespaced }} //+kubebuilder:resource:scope=Cluster {{ end }}
9595
9696
// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API
9797
type {{ .Resource.Kind }} struct {
@@ -102,7 +102,7 @@ type {{ .Resource.Kind }} struct {
102102
Status {{ .Resource.Kind }}Status ` + "`" + `json:"status,omitempty"` + "`" + `
103103
}
104104
105-
// +kubebuilder:object:root=true
105+
//+kubebuilder:object:root=true
106106
107107
// {{ .Resource.Kind }}List contains a list of {{ .Resource.Kind }}
108108
type {{ .Resource.Kind }}List struct {

pkg/plugins/golang/v3/scaffolds/internal/templates/api/webhook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func (r *{{ .Resource.Kind }}) SetupWebhookWithManager(mgr ctrl.Manager) error {
117117
// TODO(estroz): update admissionReviewVersions to include v1 when controller-runtime supports that version.
118118
//nolint:lll
119119
defaultingWebhookTemplate = `
120-
// +kubebuilder:webhook:{{ if ne .WebhookVersion "v1" }}webhookVersions={{"{"}}{{ .WebhookVersion }}{{"}"}},{{ end }}path=/mutate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=true,failurePolicy=fail,sideEffects=None,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=m{{ lower .Resource.Kind }}.kb.io,admissionReviewVersions={v1,v1beta1}
120+
//+kubebuilder:webhook:{{ if ne .WebhookVersion "v1" }}webhookVersions={{"{"}}{{ .WebhookVersion }}{{"}"}},{{ end }}path=/mutate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=true,failurePolicy=fail,sideEffects=None,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=m{{ lower .Resource.Kind }}.kb.io,admissionReviewVersions={v1,v1beta1}
121121
122122
var _ webhook.Defaulter = &{{ .Resource.Kind }}{}
123123
@@ -133,7 +133,7 @@ func (r *{{ .Resource.Kind }}) Default() {
133133
//nolint:lll
134134
validatingWebhookTemplate = `
135135
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
136-
// +kubebuilder:webhook:{{ if ne .WebhookVersion "v1" }}webhookVersions={{"{"}}{{ .WebhookVersion }}{{"}"}},{{ end }}path=/validate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=false,failurePolicy=fail,sideEffects=None,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=v{{ lower .Resource.Kind }}.kb.io,admissionReviewVersions={v1,v1beta1}
136+
//+kubebuilder:webhook:{{ if ne .WebhookVersion "v1" }}webhookVersions={{"{"}}{{ .WebhookVersion }}{{"}"}},{{ end }}path=/validate-{{ .GroupDomainWithDash }}-{{ .Resource.Version }}-{{ lower .Resource.Kind }},mutating=false,failurePolicy=fail,sideEffects=None,groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=create;update,versions={{ .Resource.Version }},name=v{{ lower .Resource.Kind }}.kb.io,admissionReviewVersions={v1,v1beta1}
137137
138138
var _ webhook.Validator = &{{ .Resource.Kind }}{}
139139

pkg/plugins/golang/v3/scaffolds/internal/templates/api/webhook_suitetest.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,7 @@ func (f *WebhookSuite) GetCodeFragments() file.CodeFragmentsMap {
114114
return fragments
115115
}
116116

117-
const (
118-
webhookTestSuiteTemplate = `{{ .Boilerplate }}
117+
const webhookTestSuiteTemplate = `{{ .Boilerplate }}
119118
120119
package {{ .Resource.Version }}
121120
@@ -225,4 +224,3 @@ var _ = AfterSuite(func() {
225224
Expect(err).NotTo(HaveOccurred())
226225
})
227226
`
228-
)

pkg/plugins/golang/v3/scaffolds/internal/templates/controllers/controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ type {{ .Resource.Kind }}Reconciler struct {
9191
Scheme *runtime.Scheme
9292
}
9393
94-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
95-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
96-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/finalizers,verbs=update
94+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
95+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
96+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/finalizers,verbs=update
9797
9898
// Reconcile is part of the main kubernetes reconciliation loop which aims to
9999
// move the current state of the cluster closer to the desired state.

0 commit comments

Comments
 (0)