Skip to content

Commit 7fd267b

Browse files
committed
fix linting issues
1 parent e0141ae commit 7fd267b

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

internal/controllers/scheduler/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func (r *ClusterScheduler) handleCreateOrUpdate(ctx context.Context, req reconci
179179

180180
// if no cluster was found, check if there is an existing cluster that qualifies for the request
181181
// skip this check for preemptive requests with purposes with exclusive tenancy, as they will always result in a new cluster
182-
if !(cDef.IsExclusive() && cr.Spec.Preemptive) {
182+
if !(cDef.IsExclusive() && cr.Spec.Preemptive) { //nolint:staticcheck // QF1001
183183
cluster, rerr = r.pickFittingCluster(ctx, cr, clusters, cDef)
184184
if rerr != nil {
185185
rr.ReconcileError = rerr
@@ -363,7 +363,7 @@ func (r *ClusterScheduler) fetchRelevantClusters(ctx context.Context, cr *cluste
363363
if a == nil || b == nil {
364364
return 0 // cannot compare nil clusters, should not happen
365365
}
366-
return a.CreationTimestamp.Time.Compare(b.CreationTimestamp.Time)
366+
return a.CreationTimestamp.Compare(b.CreationTimestamp.Time)
367367
})
368368

369369
return clusters, nil

internal/controllers/scheduler/controller_test.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import (
2929

3030
var scheme = install.InstallOperatorAPIs(runtime.NewScheme())
3131

32+
const (
33+
exclusiveString = "exclusive"
34+
sharedTwiceString = "shared-twice"
35+
sharedUnlimitedString = "shared-unlimited"
36+
)
37+
3238
// defaultTestSetup initializes a new environment for testing the scheduler controller.
3339
// Expected folder structure is a 'config.yaml' file next to a folder named 'cluster' containing the manifests.
3440
func defaultTestSetup(testDirPathSegments ...string) (*scheduler.ClusterScheduler, *testutils.Environment) {
@@ -50,7 +56,7 @@ func defaultTestSetup(testDirPathSegments ...string) (*scheduler.ClusterSchedule
5056
if !ok {
5157
panic(fmt.Errorf("indexer function for type %T's spec.preemptive field received object of type %T, this should never happen", clustersv1alpha1.ClusterRequest{}, obj))
5258
}
53-
return []string{string(strconv.FormatBool(c.Spec.Preemptive))}
59+
return []string{strconv.FormatBool(c.Spec.Preemptive)}
5460
}).
5561
Build()
5662
sc, ok := env.Reconciler().(*scheduler.ClusterScheduler)
@@ -63,15 +69,15 @@ var _ = Describe("Scheduler", func() {
6369
Context("Scope: Namespaced", func() {
6470

6571
It("should create a new exclusive cluster if no cluster exists", func() {
66-
clusterNamespace := "exclusive"
72+
clusterNamespace := exclusiveString
6773
sc, env := defaultTestSetup("testdata", "test-01")
6874
Expect(env.Client().DeleteAllOf(env.Ctx, &clustersv1alpha1.Cluster{}, client.InNamespace(clusterNamespace))).To(Succeed())
6975
existingClusters := &clustersv1alpha1.ClusterList{}
7076
Expect(env.Client().List(env.Ctx, existingClusters, client.InNamespace(clusterNamespace))).To(Succeed())
7177
Expect(existingClusters.Items).To(BeEmpty())
7278

7379
req := &clustersv1alpha1.ClusterRequest{}
74-
Expect(env.Client().Get(env.Ctx, ctrlutils.ObjectKey("exclusive", "foo"), req)).To(Succeed())
80+
Expect(env.Client().Get(env.Ctx, ctrlutils.ObjectKey(exclusiveString, "foo"), req)).To(Succeed())
7581
Expect(req.Status.Cluster).To(BeNil())
7682

7783
env.ShouldReconcile(testutils.RequestFromObject(req))
@@ -90,14 +96,14 @@ var _ = Describe("Scheduler", func() {
9096
})
9197

9298
It("should create a new exclusive cluster if a cluster exists", func() {
93-
clusterNamespace := "exclusive"
99+
clusterNamespace := exclusiveString
94100
sc, env := defaultTestSetup("testdata", "test-01")
95101
existingClusters := &clustersv1alpha1.ClusterList{}
96102
Expect(env.Client().List(env.Ctx, existingClusters, client.InNamespace(clusterNamespace))).To(Succeed())
97103
oldCount := len(existingClusters.Items)
98104

99105
req := &clustersv1alpha1.ClusterRequest{}
100-
Expect(env.Client().Get(env.Ctx, ctrlutils.ObjectKey("exclusive", "foo"), req)).To(Succeed())
106+
Expect(env.Client().Get(env.Ctx, ctrlutils.ObjectKey(exclusiveString, "foo"), req)).To(Succeed())
101107
Expect(req.Status.Cluster).To(BeNil())
102108

103109
env.ShouldReconcile(testutils.RequestFromObject(req))
@@ -119,7 +125,7 @@ var _ = Describe("Scheduler", func() {
119125
})
120126

121127
It("should create a new shared cluster if no cluster exists", func() {
122-
clusterNamespace := "shared-twice"
128+
clusterNamespace := sharedTwiceString
123129
sc, env := defaultTestSetup("testdata", "test-01")
124130
Expect(env.Client().DeleteAllOf(env.Ctx, &clustersv1alpha1.Cluster{}, client.InNamespace(clusterNamespace))).To(Succeed())
125131
existingClusters := &clustersv1alpha1.ClusterList{}
@@ -146,7 +152,7 @@ var _ = Describe("Scheduler", func() {
146152
})
147153

148154
It("should share a shared cluster if it still has capacity and create a new one otherwise", func() {
149-
clusterNamespace := "shared-twice"
155+
clusterNamespace := sharedTwiceString
150156
sc, env := defaultTestSetup("testdata", "test-01")
151157
existingClusters := &clustersv1alpha1.ClusterList{}
152158
Expect(env.Client().List(env.Ctx, existingClusters, client.InNamespace(clusterNamespace))).To(Succeed())
@@ -226,7 +232,7 @@ var _ = Describe("Scheduler", func() {
226232
})
227233

228234
It("should only create a new cluster if none exists for unlimitedly shared clusters", func() {
229-
clusterNamespace := "shared-unlimited"
235+
clusterNamespace := sharedUnlimitedString
230236
sc, env := defaultTestSetup("testdata", "test-01")
231237
reqCount := 20
232238
requests := make([]*clustersv1alpha1.ClusterRequest, reqCount)
@@ -235,7 +241,7 @@ var _ = Describe("Scheduler", func() {
235241
requests[i].SetName(fmt.Sprintf("req-%d", i))
236242
requests[i].SetNamespace("foo")
237243
requests[i].SetUID(uuid.NewUUID())
238-
requests[i].Spec.Purpose = "shared-unlimited"
244+
requests[i].Spec.Purpose = sharedUnlimitedString
239245
Expect(env.Client().Create(env.Ctx, requests[i])).To(Succeed())
240246
env.ShouldReconcile(testutils.RequestFromObject(requests[i]))
241247
}
@@ -261,7 +267,7 @@ var _ = Describe("Scheduler", func() {
261267
_, env := defaultTestSetup("testdata", "test-02")
262268

263269
req := &clustersv1alpha1.ClusterRequest{}
264-
Expect(env.Client().Get(env.Ctx, ctrlutils.ObjectKey("exclusive", "foo"), req)).To(Succeed())
270+
Expect(env.Client().Get(env.Ctx, ctrlutils.ObjectKey(exclusiveString, "foo"), req)).To(Succeed())
265271
Expect(req.Status.Cluster).To(BeNil())
266272

267273
env.ShouldReconcile(testutils.RequestFromObject(req))
@@ -466,7 +472,7 @@ var _ = Describe("Scheduler", func() {
466472

467473
c := &clustersv1alpha1.Cluster{}
468474
c.SetName("shared-1")
469-
c.SetNamespace("shared-twice")
475+
c.SetNamespace(sharedTwiceString)
470476
Expect(env.Client().Get(env.Ctx, client.ObjectKeyFromObject(c), c)).To(Succeed())
471477

472478
cr := &clustersv1alpha1.ClusterRequest{}
@@ -500,7 +506,7 @@ var _ = Describe("Scheduler", func() {
500506
Context("Preemptive ClusterRequests", func() {
501507

502508
It("should create a new exclusive cluster if no cluster exists", func() {
503-
clusterNamespace := "exclusive"
509+
clusterNamespace := exclusiveString
504510
sc, env := defaultTestSetup("testdata", "test-01")
505511
Expect(env.Client().DeleteAllOf(env.Ctx, &clustersv1alpha1.Cluster{}, client.InNamespace(clusterNamespace))).To(Succeed())
506512
existingClusters := &clustersv1alpha1.ClusterList{}
@@ -526,7 +532,7 @@ var _ = Describe("Scheduler", func() {
526532
})
527533

528534
It("should create a new exclusive cluster if a cluster exists", func() {
529-
clusterNamespace := "exclusive"
535+
clusterNamespace := exclusiveString
530536
sc, env := defaultTestSetup("testdata", "test-01")
531537
existingClusters := &clustersv1alpha1.ClusterList{}
532538
Expect(env.Client().List(env.Ctx, existingClusters, client.InNamespace(clusterNamespace))).To(Succeed())
@@ -553,7 +559,7 @@ var _ = Describe("Scheduler", func() {
553559
})
554560

555561
It("should create a new shared cluster if no cluster exists", func() {
556-
clusterNamespace := "shared-twice"
562+
clusterNamespace := sharedTwiceString
557563
sc, env := defaultTestSetup("testdata", "test-01")
558564
Expect(env.Client().DeleteAllOf(env.Ctx, &clustersv1alpha1.Cluster{}, client.InNamespace(clusterNamespace))).To(Succeed())
559565
existingClusters := &clustersv1alpha1.ClusterList{}
@@ -579,7 +585,7 @@ var _ = Describe("Scheduler", func() {
579585
})
580586

581587
It("should share a shared cluster if it still has capacity and create a new one otherwise", func() {
582-
clusterNamespace := "shared-twice"
588+
clusterNamespace := sharedTwiceString
583589
sc, env := defaultTestSetup("testdata", "test-01")
584590
existingClusters := &clustersv1alpha1.ClusterList{}
585591
Expect(env.Client().List(env.Ctx, existingClusters, client.InNamespace(clusterNamespace))).To(Succeed())
@@ -650,7 +656,7 @@ var _ = Describe("Scheduler", func() {
650656
})
651657

652658
It("should evict preemptive requests to make space for regular ones", func() {
653-
clusterNamespace := "shared-twice"
659+
clusterNamespace := sharedTwiceString
654660
sc, env := defaultTestSetup("testdata", "test-01")
655661
existingClusters := &clustersv1alpha1.ClusterList{}
656662
Expect(env.Client().List(env.Ctx, existingClusters, client.InNamespace(clusterNamespace))).To(Succeed())
@@ -757,7 +763,7 @@ var _ = Describe("Scheduler", func() {
757763
})
758764

759765
It("should only create a single unlimitedly shared cluster and not remove its preemptive request finalizers", func() {
760-
clusterNamespace := "shared-unlimited"
766+
clusterNamespace := sharedUnlimitedString
761767
sc, env := defaultTestSetup("testdata", "test-01")
762768
reqCount := 20
763769
prequests := make([]*clustersv1alpha1.ClusterRequest, reqCount)
@@ -766,7 +772,7 @@ var _ = Describe("Scheduler", func() {
766772
prequests[i].SetName(fmt.Sprintf("reqp-%d", i))
767773
prequests[i].SetNamespace("foo")
768774
prequests[i].SetUID(uuid.NewUUID())
769-
prequests[i].Spec.Purpose = "shared-unlimited"
775+
prequests[i].Spec.Purpose = sharedUnlimitedString
770776
prequests[i].Spec.Preemptive = true
771777
Expect(env.Client().Create(env.Ctx, prequests[i])).To(Succeed())
772778
env.ShouldReconcile(testutils.RequestFromObject(prequests[i]))
@@ -787,7 +793,7 @@ var _ = Describe("Scheduler", func() {
787793
requests[i].SetName(fmt.Sprintf("req-%d", i))
788794
requests[i].SetNamespace("foo")
789795
requests[i].SetUID(uuid.NewUUID())
790-
requests[i].Spec.Purpose = "shared-unlimited"
796+
requests[i].Spec.Purpose = sharedUnlimitedString
791797
Expect(env.Client().Create(env.Ctx, requests[i])).To(Succeed())
792798
env.ShouldReconcile(testutils.RequestFromObject(requests[i]))
793799
}

lib/clusteraccess/clusteraccess_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ var _ = Describe("ClusterAccessReconciler", func() {
219219
env.ShouldReconcile(request, "reconcilerImpl should not return an error")
220220

221221
// cast to ClusterAccessReconciler to access the reconcilerImpl methods
222-
reconciler, ok := env.Reconciler().(clusteraccess.Reconciler) // nolint:staticcheck
222+
reconciler, ok := env.Reconciler().(clusteraccess.Reconciler) //nolint:staticcheck
223223
Expect(ok).To(BeTrue(), "reconcilerImpl should be of type ClusterAccessReconciler")
224224

225225
mcpCluster, err := reconciler.MCPCluster(env.Ctx, request)

0 commit comments

Comments
 (0)