Skip to content

Commit 6a676b1

Browse files
authored
Merge pull request #1987 from Adirio/go-fmt-templates
🌱 Go fmt templates
2 parents 63904d2 + fed6174 commit 6a676b1

File tree

11 files changed

+38
-45
lines changed

11 files changed

+38
-45
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ type {{ .Resource.Kind }}Status struct {
8787
8888
//+kubebuilder:object:root=true
8989
//+kubebuilder:subresource:status
90-
{{ if not .Resource.API.Namespaced }} //+kubebuilder:resource:scope=Cluster {{ end }}
90+
{{- if not .Resource.API.Namespaced }}
91+
//+kubebuilder:resource:scope=Cluster
92+
{{- end }}
9193
9294
// {{ .Resource.Kind }} is the Schema for the {{ .Resource.Plural }} API
9395
type {{ .Resource.Kind }} struct {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ import (
8080
// {{ .Resource.Kind }}Reconciler reconciles a {{ .Resource.Kind }} object
8181
type {{ .Resource.Kind }}Reconciler struct {
8282
client.Client
83-
Log logr.Logger
83+
Log logr.Logger
8484
Scheme *runtime.Scheme
8585
}
8686

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@ func (f *Controller) SetTemplateDefaults() error {
6464
//nolint:lll
6565
const controllerTemplate = `{{ .Boilerplate }}
6666
67-
{{if and .MultiGroup .Resource.Group }}
68-
package {{ .Resource.PackageName }}
69-
{{else}}
70-
package controllers
71-
{{end}}
67+
package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ else }}controllers{{ end }}
7268
7369
import (
7470
"context"
@@ -84,7 +80,7 @@ import (
8480
// {{ .Resource.Kind }}Reconciler reconciles a {{ .Resource.Kind }} object
8581
type {{ .Resource.Kind }}Reconciler struct {
8682
client.Client
87-
Log logr.Logger
83+
Log logr.Logger
8884
Scheme *runtime.Scheme
8985
}
9086

plugins/addon/controller.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ const controllerTemplate = `{{ .Boilerplate }}
3535
package controllers
3636
3737
import (
38+
"github.com/go-logr/logr"
39+
"k8s.io/apimachinery/pkg/runtime"
40+
ctrl "sigs.k8s.io/controller-runtime"
41+
"sigs.k8s.io/controller-runtime/pkg/client"
3842
"sigs.k8s.io/controller-runtime/pkg/controller"
3943
"sigs.k8s.io/controller-runtime/pkg/handler"
4044
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -43,11 +47,6 @@ import (
4347
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/status"
4448
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
4549
46-
"github.com/go-logr/logr"
47-
"k8s.io/apimachinery/pkg/runtime"
48-
ctrl "sigs.k8s.io/controller-runtime"
49-
"sigs.k8s.io/controller-runtime/pkg/client"
50-
5150
api "{{ .Resource.Path }}"
5251
)
5352
@@ -56,7 +55,7 @@ var _ reconcile.Reconciler = &{{ .Resource.Kind }}Reconciler{}
5655
// {{ .Resource.Kind }}Reconciler reconciles a {{ .Resource.Kind }} object
5756
type {{ .Resource.Kind }}Reconciler struct {
5857
client.Client
59-
Log logr.Logger
58+
Log logr.Logger
6059
Scheme *runtime.Scheme
6160
6261
declarative.Reconciler

plugins/addon/type.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ type {{ .Resource.Kind }}Status struct {
7676
7777
//+kubebuilder:object:root=true
7878
//+kubebuilder:subresource:status
79-
{{ if not .Resource.API.Namespaced }} //+kubebuilder:resource:scope=Cluster {{ end }}
79+
{{- if not .Resource.API.Namespaced }}
80+
//+kubebuilder:resource:scope=Cluster
81+
{{- end }}
8082
8183
// {{.Resource.Kind}} is the Schema for the {{ .Resource.Plural }} API
8284
type {{ .Resource.Kind }} struct {

testdata/project-v2-addon/controllers/admiral_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"github.com/go-logr/logr"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
ctrl "sigs.k8s.io/controller-runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
2024
"sigs.k8s.io/controller-runtime/pkg/controller"
2125
"sigs.k8s.io/controller-runtime/pkg/handler"
2226
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -25,11 +29,6 @@ import (
2529
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/status"
2630
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
2731

28-
"github.com/go-logr/logr"
29-
"k8s.io/apimachinery/pkg/runtime"
30-
ctrl "sigs.k8s.io/controller-runtime"
31-
"sigs.k8s.io/controller-runtime/pkg/client"
32-
3332
api "sigs.k8s.io/kubebuilder/testdata/project-v2-addon/api/v1"
3433
)
3534

testdata/project-v2-addon/controllers/captain_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"github.com/go-logr/logr"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
ctrl "sigs.k8s.io/controller-runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
2024
"sigs.k8s.io/controller-runtime/pkg/controller"
2125
"sigs.k8s.io/controller-runtime/pkg/handler"
2226
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -25,11 +29,6 @@ import (
2529
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/status"
2630
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
2731

28-
"github.com/go-logr/logr"
29-
"k8s.io/apimachinery/pkg/runtime"
30-
ctrl "sigs.k8s.io/controller-runtime"
31-
"sigs.k8s.io/controller-runtime/pkg/client"
32-
3332
api "sigs.k8s.io/kubebuilder/testdata/project-v2-addon/api/v1"
3433
)
3534

testdata/project-v2-addon/controllers/firstmate_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"github.com/go-logr/logr"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
ctrl "sigs.k8s.io/controller-runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
2024
"sigs.k8s.io/controller-runtime/pkg/controller"
2125
"sigs.k8s.io/controller-runtime/pkg/handler"
2226
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -25,11 +29,6 @@ import (
2529
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/status"
2630
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
2731

28-
"github.com/go-logr/logr"
29-
"k8s.io/apimachinery/pkg/runtime"
30-
ctrl "sigs.k8s.io/controller-runtime"
31-
"sigs.k8s.io/controller-runtime/pkg/client"
32-
3332
api "sigs.k8s.io/kubebuilder/testdata/project-v2-addon/api/v1"
3433
)
3534

testdata/project-v3-addon/controllers/admiral_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"github.com/go-logr/logr"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
ctrl "sigs.k8s.io/controller-runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
2024
"sigs.k8s.io/controller-runtime/pkg/controller"
2125
"sigs.k8s.io/controller-runtime/pkg/handler"
2226
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -25,11 +29,6 @@ import (
2529
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/status"
2630
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
2731

28-
"github.com/go-logr/logr"
29-
"k8s.io/apimachinery/pkg/runtime"
30-
ctrl "sigs.k8s.io/controller-runtime"
31-
"sigs.k8s.io/controller-runtime/pkg/client"
32-
3332
api "sigs.k8s.io/kubebuilder/testdata/project-v3-addon/api/v1"
3433
)
3534

testdata/project-v3-addon/controllers/captain_controller.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ limitations under the License.
1717
package controllers
1818

1919
import (
20+
"github.com/go-logr/logr"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
ctrl "sigs.k8s.io/controller-runtime"
23+
"sigs.k8s.io/controller-runtime/pkg/client"
2024
"sigs.k8s.io/controller-runtime/pkg/controller"
2125
"sigs.k8s.io/controller-runtime/pkg/handler"
2226
"sigs.k8s.io/controller-runtime/pkg/reconcile"
@@ -25,11 +29,6 @@ import (
2529
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/status"
2630
"sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/declarative"
2731

28-
"github.com/go-logr/logr"
29-
"k8s.io/apimachinery/pkg/runtime"
30-
ctrl "sigs.k8s.io/controller-runtime"
31-
"sigs.k8s.io/controller-runtime/pkg/client"
32-
3332
api "sigs.k8s.io/kubebuilder/testdata/project-v3-addon/api/v1"
3433
)
3534

0 commit comments

Comments
 (0)