Skip to content

Commit bd5b718

Browse files
committed
Remove spaces from machine-readable comments (v3 only)
Signed-off-by: Adrian Orive <[email protected]>
1 parent 503ba3b commit bd5b718

File tree

144 files changed

+388
-383
lines changed

Some content is hidden

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

144 files changed

+388
-383
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
// When adding additional file extensions, update also the NewMarkerFor documentation and error
3231
}
3332

@@ -53,6 +52,12 @@ func (m Marker) String() string {
5352
return m.comment + prefix + m.value
5453
}
5554

55+
// EqualsLine compares a marker with a string representation to check if they are the same marker
56+
func (m Marker) EqualsLine(line string) bool {
57+
line = strings.TrimSpace(strings.TrimPrefix(line, m.comment))
58+
return line == prefix + m.value
59+
}
60+
5661
// CodeFragments represents a set of code fragments
5762
// A code fragment is a piece of code provided as a Go string, it may have multiple lines
5863
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
@@ -78,9 +78,9 @@ type {{ .Resource.Kind }}Status struct {
7878
// Important: Run "make" to regenerate code after modifying this file
7979
}
8080
81-
// +kubebuilder:object:root=true
82-
// +kubebuilder:subresource:status
83-
{{ if not .Resource.Namespaced }} // +kubebuilder:resource:scope=Cluster {{ end }}
81+
//+kubebuilder:object:root=true
82+
//+kubebuilder:subresource:status
83+
{{ if not .Resource.Namespaced }} //+kubebuilder:resource:scope=Cluster {{ end }}
8484
8585
// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API
8686
type {{ .Resource.Kind }} struct {
@@ -91,7 +91,7 @@ type {{ .Resource.Kind }} struct {
9191
Status {{ .Resource.Kind }}Status ` + "`" + `json:"status,omitempty"` + "`" + `
9292
}
9393
94-
// +kubebuilder:object:root=true
94+
//+kubebuilder:object:root=true
9595
9696
// {{ .Resource.Kind }}List contains a list of {{ .Resource.Kind }}
9797
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
@@ -79,8 +79,8 @@ type {{ .Resource.Kind }}Reconciler struct {
7979
Scheme *runtime.Scheme
8080
}
8181
82-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
83-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
82+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }},verbs=get;list;watch;create;update;patch;delete
83+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/status,verbs=get;update;patch
8484
8585
func (r *{{ .Resource.Kind }}Reconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
8686
_ = 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
@@ -82,9 +82,9 @@ type {{ .Resource.Kind }}Status struct {
8282
// Important: Run "make" to regenerate code after modifying this file
8383
}
8484
85-
// +kubebuilder:object:root=true
86-
// +kubebuilder:subresource:status
87-
{{ if not .Resource.Namespaced }} // +kubebuilder:resource:scope=Cluster {{ end }}
85+
//+kubebuilder:object:root=true
86+
//+kubebuilder:subresource:status
87+
{{ if not .Resource.Namespaced }} //+kubebuilder:resource:scope=Cluster {{ end }}
8888
8989
// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API
9090
type {{ .Resource.Kind }} struct {
@@ -95,7 +95,7 @@ type {{ .Resource.Kind }} struct {
9595
Status {{ .Resource.Kind }}Status ` + "`" + `json:"status,omitempty"` + "`" + `
9696
}
9797
98-
// +kubebuilder:object:root=true
98+
//+kubebuilder:object:root=true
9999
100100
// {{ .Resource.Kind }}List contains a list of {{ .Resource.Kind }}
101101
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
@@ -111,7 +111,7 @@ func (r *{{ .Resource.Kind }}) SetupWebhookWithManager(mgr ctrl.Manager) error {
111111
// TODO(estroz): update admissionReviewVersions to include v1 when controller-runtime supports that version.
112112
//nolint:lll
113113
defaultingWebhookTemplate = `
114-
// +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}
114+
//+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}
115115
116116
var _ webhook.Defaulter = &{{ .Resource.Kind }}{}
117117
@@ -127,7 +127,7 @@ func (r *{{ .Resource.Kind }}) Default() {
127127
//nolint:lll
128128
validatingWebhookTemplate = `
129129
// TODO(user): change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
130-
// +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}
130+
//+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}
131131
132132
var _ webhook.Validator = &{{ .Resource.Kind }}{}
133133

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,9 @@ 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
90-
// +kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/finalizers,verbs=update
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
90+
//+kubebuilder:rbac:groups={{ .Resource.Domain }},resources={{ .Resource.Plural }}/finalizers,verbs=update
9191
9292
// Reconcile is part of the main kubernetes reconciliation loop which aims to
9393
// move the current state of the cluster closer to the desired state.

pkg/plugins/internal/machinery/scaffold.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func insertStrings(content string, codeFragmentsMap file.CodeFragmentsMap) ([]by
343343
line := scanner.Text()
344344

345345
for marker, codeFragments := range codeFragmentsMap {
346-
if strings.TrimSpace(line) == strings.TrimSpace(marker.String()) {
346+
if marker.EqualsLine(line) {
347347
for _, codeFragment := range codeFragments {
348348
_, _ = out.WriteString(codeFragment) // bytes.Buffer.WriteString always returns nil errors
349349
}

0 commit comments

Comments
 (0)