Skip to content

Commit 26438f0

Browse files
authored
Update submodule, and use new linter version (#19)
* update submodule to commit 80bf * lint config * fix lint findings
1 parent a6bb459 commit 26438f0

File tree

7 files changed

+57
-54
lines changed

7 files changed

+57
-54
lines changed

.golangci.yaml

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,46 @@
1+
version: "2"
12
run:
2-
timeout: 5m
33
allow-parallel-runners: true
4-
5-
issues:
6-
# don't skip warning about doc comments
7-
# don't exclude the default set of lint
8-
exclude-use-default: false
9-
# restore some of the defaults
10-
# (fill in the rest as needed)
11-
exclude-rules:
12-
- path: "internal/*"
13-
linters:
14-
- dupl
154
linters:
16-
disable-all: true
5+
default: none
176
enable:
7+
- copyloopvar
188
- dupl
199
- errcheck
20-
- copyloopvar
2110
- ginkgolinter
2211
- goconst
2312
- gocyclo
24-
- gofmt
25-
- goimports
26-
- gosimple
2713
- govet
2814
- ineffassign
2915
- misspell
3016
- nakedret
3117
- prealloc
3218
- revive
3319
- staticcheck
34-
- typecheck
3520
- unconvert
3621
- unparam
3722
- unused
38-
39-
linters-settings:
40-
revive:
23+
settings:
24+
revive:
25+
rules:
26+
- name: comment-spacings
27+
exclusions:
28+
generated: lax
4129
rules:
42-
- name: comment-spacings
30+
- linters:
31+
- dupl
32+
path: internal/*
33+
paths:
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
formatters:
38+
enable:
39+
- gofmt
40+
- goimports
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- third_party$
45+
- builtin$
46+
- examples$

Taskfile.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ includes:
1414
REPO_URL: 'https://github.com/openmcp-project/openmcp-operator'
1515
GENERATE_DOCS_INDEX: "true"
1616
CHART_COMPONENTS: "[]"
17-
LINTER_VERSION: "v1.64.4"

hack/common

internal/controllers/provider/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ type ProviderReconciler struct {
4040
}
4141

4242
func (r *ProviderReconciler) ControllerName() string {
43-
return strings.ToLower(r.GroupVersionKind.Kind)
43+
return strings.ToLower(r.Kind)
4444
}
4545

4646
func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.Result, err error) {
@@ -78,7 +78,7 @@ func (r *ProviderReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
7878
// Therefore, the ProviderReconciler watches also jobs. The present method handles the job events and creates a reconcile request.
7979
func (r *ProviderReconciler) HandleJob(_ context.Context, job client.Object) []reconcile.Request {
8080
providerKind, found := job.GetLabels()[install.ProviderKindLabel]
81-
if !found || providerKind != r.GroupVersionKind.Kind {
81+
if !found || providerKind != r.Kind {
8282
return nil
8383
}
8484

internal/controllers/provider/install/installer.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
"github.com/openmcp-project/controller-utils/pkg/logging"
99
"github.com/openmcp-project/controller-utils/pkg/readiness"
10-
. "github.com/openmcp-project/controller-utils/pkg/resources"
10+
"github.com/openmcp-project/controller-utils/pkg/resources"
1111
v1 "k8s.io/api/batch/v1"
1212
core "k8s.io/api/core/v1"
1313
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -38,19 +38,19 @@ func (a *Installer) InstallInitJob(ctx context.Context) (completed bool, err err
3838

3939
values := NewValues(a.Provider, a.DeploymentSpec, a.Environment)
4040

41-
if err := CreateOrUpdateResource(ctx, a.PlatformClient, NewNamespaceMutator(values.Namespace(), nil, nil)); err != nil {
41+
if err := resources.CreateOrUpdateResource(ctx, a.PlatformClient, resources.NewNamespaceMutator(values.Namespace(), nil, nil)); err != nil {
4242
return false, err
4343
}
4444

45-
if err = CreateOrUpdateResource(ctx, a.PlatformClient, newInitServiceAccountMutator(values)); err != nil {
45+
if err = resources.CreateOrUpdateResource(ctx, a.PlatformClient, newInitServiceAccountMutator(values)); err != nil {
4646
return false, err
4747
}
4848

49-
if err = CreateOrUpdateResource(ctx, a.PlatformClient, newInitClusterRoleMutator(values)); err != nil {
49+
if err = resources.CreateOrUpdateResource(ctx, a.PlatformClient, newInitClusterRoleMutator(values)); err != nil {
5050
return false, err
5151
}
5252

53-
if err = CreateOrUpdateResource(ctx, a.PlatformClient, newInitClusterRoleBindingMutator(values)); err != nil {
53+
if err = resources.CreateOrUpdateResource(ctx, a.PlatformClient, newInitClusterRoleBindingMutator(values)); err != nil {
5454
return false, err
5555
}
5656

@@ -61,7 +61,7 @@ func (a *Installer) InstallInitJob(ctx context.Context) (completed bool, err err
6161
})
6262
var job *v1.Job
6363
found := true
64-
job, err = GetResource(ctx, a.PlatformClient, j)
64+
job, err = resources.GetResource(ctx, a.PlatformClient, j)
6565
if err != nil {
6666
if apierrors.IsNotFound(err) {
6767
found = false
@@ -72,7 +72,7 @@ func (a *Installer) InstallInitJob(ctx context.Context) (completed bool, err err
7272

7373
if !found {
7474
// Job does not exist, create it
75-
if err := CreateOrUpdateResource(ctx, a.PlatformClient, j); err != nil {
75+
if err := resources.CreateOrUpdateResource(ctx, a.PlatformClient, j); err != nil {
7676
return false, fmt.Errorf("failed to create job %s/%s: %w", values.Namespace(), a.Provider.GetName(), err)
7777
}
7878
return false, nil
@@ -83,10 +83,10 @@ func (a *Installer) InstallInitJob(ctx context.Context) (completed bool, err err
8383
return false, fmt.Errorf("failed to cleanup job pods %s/%s: %w", values.Namespace(), a.Provider.GetName(), err)
8484
}
8585

86-
if err := DeleteResource(ctx, a.PlatformClient, j); err != nil {
86+
if err := resources.DeleteResource(ctx, a.PlatformClient, j); err != nil {
8787
return false, fmt.Errorf("failed to delete job %s/%s: %w", values.Namespace(), a.Provider.GetName(), err)
8888
}
89-
if err := CreateOrUpdateResource(ctx, a.PlatformClient, j); err != nil {
89+
if err := resources.CreateOrUpdateResource(ctx, a.PlatformClient, j); err != nil {
9090
return false, fmt.Errorf("failed to re-create job %s/%s: %w", values.Namespace(), a.Provider.GetName(), err)
9191
}
9292
return false, nil
@@ -101,15 +101,15 @@ func (a *Installer) InstallProvider(ctx context.Context) error {
101101

102102
values := NewValues(a.Provider, a.DeploymentSpec, a.Environment)
103103

104-
if err := CreateOrUpdateResource(ctx, a.PlatformClient, newProviderServiceAccountMutator(values)); err != nil {
104+
if err := resources.CreateOrUpdateResource(ctx, a.PlatformClient, newProviderServiceAccountMutator(values)); err != nil {
105105
return err
106106
}
107107

108-
if err := CreateOrUpdateResource(ctx, a.PlatformClient, newProviderClusterRoleBindingMutator(values)); err != nil {
108+
if err := resources.CreateOrUpdateResource(ctx, a.PlatformClient, newProviderClusterRoleBindingMutator(values)); err != nil {
109109
return err
110110
}
111111

112-
if err := CreateOrUpdateResource(ctx, a.PlatformClient, newDeploymentMutator(values)); err != nil {
112+
if err := resources.CreateOrUpdateResource(ctx, a.PlatformClient, newDeploymentMutator(values)); err != nil {
113113
return err
114114
}
115115

@@ -119,7 +119,7 @@ func (a *Installer) InstallProvider(ctx context.Context) error {
119119
func (a *Installer) CheckProviderReadiness(ctx context.Context) readiness.CheckResult {
120120
values := NewValues(a.Provider, a.DeploymentSpec, a.Environment)
121121

122-
depl, err := GetResource(ctx, a.PlatformClient, newDeploymentMutator(values))
122+
depl, err := resources.GetResource(ctx, a.PlatformClient, newDeploymentMutator(values))
123123
if err != nil {
124124
return readiness.NewFailedResult(err)
125125
}
@@ -131,31 +131,31 @@ func (a *Installer) UninstallProvider(ctx context.Context) (deleted bool, err er
131131

132132
values := NewValues(a.Provider, a.DeploymentSpec, a.Environment)
133133

134-
if err := DeleteResource(ctx, a.PlatformClient, newDeploymentMutator(values)); err != nil {
134+
if err := resources.DeleteResource(ctx, a.PlatformClient, newDeploymentMutator(values)); err != nil {
135135
return false, err
136136
}
137137

138-
if err := DeleteResource(ctx, a.PlatformClient, newProviderClusterRoleBindingMutator(values)); err != nil {
138+
if err := resources.DeleteResource(ctx, a.PlatformClient, newProviderClusterRoleBindingMutator(values)); err != nil {
139139
return false, err
140140
}
141141

142-
if err := DeleteResource(ctx, a.PlatformClient, newProviderServiceAccountMutator(values)); err != nil {
142+
if err := resources.DeleteResource(ctx, a.PlatformClient, newProviderServiceAccountMutator(values)); err != nil {
143143
return false, err
144144
}
145145

146-
if err := DeleteResource(ctx, a.PlatformClient, newJobMutator(values, a.DeploymentSpec, nil)); err != nil {
146+
if err := resources.DeleteResource(ctx, a.PlatformClient, newJobMutator(values, a.DeploymentSpec, nil)); err != nil {
147147
return false, err
148148
}
149149

150-
if err := DeleteResource(ctx, a.PlatformClient, newInitClusterRoleBindingMutator(values)); err != nil {
150+
if err := resources.DeleteResource(ctx, a.PlatformClient, newInitClusterRoleBindingMutator(values)); err != nil {
151151
return false, err
152152
}
153153

154-
if err := DeleteResource(ctx, a.PlatformClient, newInitClusterRoleMutator(values)); err != nil {
154+
if err := resources.DeleteResource(ctx, a.PlatformClient, newInitClusterRoleMutator(values)); err != nil {
155155
return false, err
156156
}
157157

158-
if err := DeleteResource(ctx, a.PlatformClient, newInitServiceAccountMutator(values)); err != nil {
158+
if err := resources.DeleteResource(ctx, a.PlatformClient, newInitServiceAccountMutator(values)); err != nil {
159159
return false, err
160160
}
161161

@@ -194,7 +194,7 @@ func (a *Installer) isJobFailed(job *v1.Job) bool {
194194
}
195195

196196
func (a *Installer) isGenerationUpToDate(ctx context.Context, job *v1.Job) bool {
197-
genJob := job.ObjectMeta.Annotations[ProviderGenerationLabel]
197+
genJob := job.Annotations[ProviderGenerationLabel]
198198
if genJob == "" {
199199
return false
200200
}

internal/controllers/scheduler/controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func (r *ClusterScheduler) reconcile(ctx context.Context, log logging.Logger, re
8181
log.Info("Resource not found")
8282
return ReconcileResult{}
8383
}
84-
return ReconcileResult{ReconcileError: errutils.WithReason(fmt.Errorf("unable to get resource '%s' from cluster: %w", req.NamespacedName.String(), err), cconst.ReasonPlatformClusterInteractionProblem)}
84+
return ReconcileResult{ReconcileError: errutils.WithReason(fmt.Errorf("unable to get resource '%s' from cluster: %w", req.String(), err), cconst.ReasonPlatformClusterInteractionProblem)}
8585
}
8686

8787
// handle operation annotation
@@ -125,7 +125,7 @@ func (r *ClusterScheduler) handleCreateOrUpdate(ctx context.Context, req reconci
125125
if controllerutil.AddFinalizer(cr, clustersv1alpha1.ClusterRequestFinalizer) {
126126
log.Info("Adding finalizer")
127127
if err := r.PlatformCluster.Client().Patch(ctx, cr, client.MergeFrom(rr.OldObject)); err != nil {
128-
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error patching finalizer on resource '%s': %w", req.NamespacedName.String(), err), cconst.ReasonPlatformClusterInteractionProblem)
128+
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error patching finalizer on resource '%s': %w", req.String(), err), cconst.ReasonPlatformClusterInteractionProblem)
129129
return rr
130130
}
131131
}
@@ -230,7 +230,7 @@ func (r *ClusterScheduler) handleCreateOrUpdate(ctx context.Context, req reconci
230230
// create Cluster resource
231231
if err := r.PlatformCluster.Client().Create(ctx, cluster); err != nil {
232232
if apierrors.IsAlreadyExists(err) {
233-
rr.ReconcileError = errutils.WithReason(fmt.Errorf("Cluster '%s/%s' already exists, this is not supposed to happen", cluster.Namespace, cluster.Name), cconst.ReasonInternalError)
233+
rr.ReconcileError = errutils.WithReason(fmt.Errorf("cluster '%s/%s' already exists, this is not supposed to happen", cluster.Namespace, cluster.Name), cconst.ReasonInternalError)
234234
return rr
235235
}
236236
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error creating cluster '%s/%s': %w", cluster.Namespace, cluster.Name, err), cconst.ReasonPlatformClusterInteractionProblem)
@@ -304,7 +304,7 @@ func (r *ClusterScheduler) handleDelete(ctx context.Context, req reconcile.Reque
304304
if controllerutil.RemoveFinalizer(cr, clustersv1alpha1.ClusterRequestFinalizer) {
305305
log.Info("Removing finalizer")
306306
if err := r.PlatformCluster.Client().Patch(ctx, cr, client.MergeFrom(rr.OldObject)); err != nil {
307-
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error removing finalizer from resource '%s': %w", req.NamespacedName.String(), err), cconst.ReasonPlatformClusterInteractionProblem)
307+
rr.ReconcileError = errutils.WithReason(fmt.Errorf("error removing finalizer from resource '%s': %w", req.String(), err), cconst.ReasonPlatformClusterInteractionProblem)
308308
return rr
309309
}
310310
}

internal/controllers/scheduler/controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ var _ = Describe("Scheduler", func() {
7070
Expect(cluster.Name).To(Equal(req.Status.Cluster.Name))
7171
Expect(cluster.Namespace).To(Equal(clusterNamespace))
7272
Expect(cluster.Name).To(HavePrefix(fmt.Sprintf("%s-", req.Spec.Purpose)))
73-
Expect(cluster.Namespace).To(Equal(sc.Config.PurposeMappings[req.Spec.Purpose].Template.ObjectMeta.Namespace))
73+
Expect(cluster.Namespace).To(Equal(sc.Config.PurposeMappings[req.Spec.Purpose].Template.Namespace))
7474
Expect(cluster.Spec.Tenancy).To(BeEquivalentTo(sc.Config.PurposeMappings[req.Spec.Purpose].Template.Spec.Tenancy))
7575
Expect(cluster.Finalizers).To(ContainElements(req.FinalizerForCluster()))
7676
})
@@ -126,7 +126,7 @@ var _ = Describe("Scheduler", func() {
126126
Expect(cluster.Name).To(Equal(req.Status.Cluster.Name))
127127
Expect(cluster.Namespace).To(Equal(clusterNamespace))
128128
Expect(cluster.Name).To(HavePrefix(fmt.Sprintf("%s-", req.Spec.Purpose)))
129-
Expect(cluster.Namespace).To(Equal(sc.Config.PurposeMappings[req.Spec.Purpose].Template.ObjectMeta.Namespace))
129+
Expect(cluster.Namespace).To(Equal(sc.Config.PurposeMappings[req.Spec.Purpose].Template.Namespace))
130130
Expect(cluster.Spec.Tenancy).To(BeEquivalentTo(sc.Config.PurposeMappings[req.Spec.Purpose].Template.Spec.Tenancy))
131131
Expect(cluster.Finalizers).To(ContainElements(req.FinalizerForCluster()))
132132
})
@@ -238,7 +238,7 @@ var _ = Describe("Scheduler", func() {
238238
Expect(cluster.Name).To(Equal(requests[0].Status.Cluster.Name))
239239
Expect(cluster.Namespace).To(Equal(clusterNamespace))
240240
Expect(cluster.Name).To(Equal(requests[0].Spec.Purpose))
241-
Expect(cluster.Namespace).To(Equal(sc.Config.PurposeMappings[requests[0].Spec.Purpose].Template.ObjectMeta.Namespace))
241+
Expect(cluster.Namespace).To(Equal(sc.Config.PurposeMappings[requests[0].Spec.Purpose].Template.Namespace))
242242
Expect(cluster.Spec.Tenancy).To(BeEquivalentTo(clustersv1alpha1.TENANCY_SHARED))
243243
Expect(cluster.Finalizers).To(ContainElements(requests[0].FinalizerForCluster()))
244244
})

0 commit comments

Comments
 (0)