Skip to content

Commit d698795

Browse files
authored
fix(ci): Fix kube-api-linter install (kubeflow#3023)
Signed-off-by: Antonin Stefanutti <antonin@stefanutti.fr>
1 parent ba66ef0 commit d698795

8 files changed

Lines changed: 70 additions & 72 deletions

File tree

.golangci.yaml

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
# golangci-lint configuration file
22
# see: https://golangci-lint.run/usage/configuration/
33

4-
# Settings of specific linters
5-
linters-settings:
6-
gci:
7-
sections:
8-
- standard # Standard section: captures all standard packages.
9-
- default # Default section: contains all imports that could not be matched to another section type.
10-
- prefix(github.com/kubeflow/trainer/v2) # Custom section: groups all imports with the specified Prefix.
11-
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
12-
- dot # Dot section: contains all dot imports.
13-
skip-generated: true # Skip generated files.
4+
version: "2"
145

15-
# Settings for enabling and disabling linters
16-
linters:
6+
run:
7+
go: "1.24"
8+
allow-parallel-runners: true
9+
10+
issues:
11+
max-same-issues: 0
12+
13+
formatters:
1714
enable:
1815
- gci
16+
settings:
17+
gci:
18+
sections:
19+
- standard # Standard section: captures all standard packages.
20+
- default # Default section: contains all imports that could not be matched to another section type.
21+
- prefix(github.com/kubeflow/trainer) # Custom section: groups all imports with the specified Prefix.
22+
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
23+
- dot # Dot section: contains all dot imports.

Makefile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ KIND ?= $(LOCALBIN)/kind
4040
HELM ?= $(LOCALBIN)/helm
4141
HELM_DOCS ?= $(LOCALBIN)/helm-docs
4242
YQ ?= $(LOCALBIN)/yq
43+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
4344
GOLANGCI_LINT_KAL ?= $(LOCALBIN)/golangci-lint-kube-api-linter
4445

4546
##@ General
@@ -82,13 +83,9 @@ kind: ## Download Kind binary if required.
8283
helm: ## Download helm locally if required.
8384
GOBIN=$(LOCALBIN) go install helm.sh/helm/v3/cmd/helm@$(HELM_VERSION)
8485

85-
GOLANGCI_LINT=$(shell which golangci-lint)
86-
.PHONY: golangci-lint
87-
golangci-lint-install: ## Run golangci-lint to verify Go files.
88-
ifeq ($(GOLANGCI_LINT),)
89-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(shell go env GOPATH)/bin v1.64.8
90-
$(info golangci-lint has been installed)
91-
endif
86+
.PHONY: golangci-lint-install
87+
golangci-lint-install: ## Download golangci-lint locally if required.
88+
@GOBIN=$(LOCALBIN) go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.7.1
9289

9390
.PHONY: golangci-lint-kal
9491
golangci-lint-kal: ## Build golangci-lint-kal from custom configuration.
@@ -165,7 +162,7 @@ vet: ## Run go vet against the code.
165162

166163
.PHONY: golangci-lint
167164
golangci-lint: golangci-lint-install golangci-lint-kal ## Run golangci-lint to verify Go files.
168-
golangci-lint run --timeout 5m --go 1.24 ./...
165+
$(GOLANGCI_LINT) run --timeout 5m ./...
169166
$(GOLANGCI_LINT_KAL) run -v --config $(PROJECT_DIR)/.golangci-kal.yml
170167

171168
# Instructions to run tests.

hack/swagger/main.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ func main() {
8989
}
9090

9191
func swaggify(name string) string {
92-
name = strings.Replace(name, "github.com/kubeflow/trainer/v2/pkg/apis/", "", -1)
93-
name = strings.Replace(name, "sigs.k8s.io/jobset/api/", "", -1)
94-
name = strings.Replace(name, "volcano.sh/apis/pkg/apis/", "", -1)
95-
name = strings.Replace(name, "k8s.io", "io.k8s", -1)
96-
name = strings.Replace(name, "/", ".", -1)
92+
name = strings.ReplaceAll(name, "github.com/kubeflow/trainer/v2/pkg/apis/", "")
93+
name = strings.ReplaceAll(name, "sigs.k8s.io/jobset/api/", "")
94+
name = strings.ReplaceAll(name, "volcano.sh/apis/pkg/apis/", "")
95+
name = strings.ReplaceAll(name, "k8s.io", "io.k8s")
96+
name = strings.ReplaceAll(name, "/", ".")
9797
return name
9898
}

pkg/runtime/framework/plugins/coscheduling/coscheduling.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ import (
4545
trainer "github.com/kubeflow/trainer/v2/pkg/apis/trainer/v1alpha1"
4646
"github.com/kubeflow/trainer/v2/pkg/runtime"
4747
"github.com/kubeflow/trainer/v2/pkg/runtime/framework"
48-
index "github.com/kubeflow/trainer/v2/pkg/runtime/indexer"
49-
runtimeindexer "github.com/kubeflow/trainer/v2/pkg/runtime/indexer"
48+
"github.com/kubeflow/trainer/v2/pkg/runtime/indexer"
5049
)
5150

5251
type CoScheduling struct {
@@ -173,26 +172,26 @@ func (h *PodGroupRuntimeClassHandler) Generic(context.Context, event.TypedGeneri
173172

174173
func (h *PodGroupRuntimeClassHandler) queueSuspendedTrainJobs(ctx context.Context, runtimeClass *nodev1.RuntimeClass, q workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
175174
var trainingRuntimes trainer.TrainingRuntimeList
176-
if err := h.client.List(ctx, &trainingRuntimes, client.MatchingFields{index.TrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
175+
if err := h.client.List(ctx, &trainingRuntimes, client.MatchingFields{indexer.TrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
177176
return err
178177
}
179178
var clusterTrainingRuntimes trainer.ClusterTrainingRuntimeList
180-
if err := h.client.List(ctx, &clusterTrainingRuntimes, client.MatchingFields{index.ClusterTrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
179+
if err := h.client.List(ctx, &clusterTrainingRuntimes, client.MatchingFields{indexer.ClusterTrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
181180
return err
182181
}
183182

184183
var trainJobs []trainer.TrainJob
185184
for _, trainingRuntime := range trainingRuntimes.Items {
186185
var trainJobsWithTrainingRuntime trainer.TrainJobList
187-
err := h.client.List(ctx, &trainJobsWithTrainingRuntime, client.MatchingFields{runtimeindexer.TrainJobRuntimeRefKey: trainingRuntime.Name})
186+
err := h.client.List(ctx, &trainJobsWithTrainingRuntime, client.MatchingFields{indexer.TrainJobRuntimeRefKey: trainingRuntime.Name})
188187
if err != nil {
189188
return err
190189
}
191190
trainJobs = append(trainJobs, trainJobsWithTrainingRuntime.Items...)
192191
}
193192
for _, clusterTrainingRuntime := range clusterTrainingRuntimes.Items {
194193
var trainJobsWithClTrainingRuntime trainer.TrainJobList
195-
err := h.client.List(ctx, &trainJobsWithClTrainingRuntime, client.MatchingFields{runtimeindexer.TrainJobClusterRuntimeRefKey: clusterTrainingRuntime.Name})
194+
err := h.client.List(ctx, &trainJobsWithClTrainingRuntime, client.MatchingFields{indexer.TrainJobClusterRuntimeRefKey: clusterTrainingRuntime.Name})
196195
if err != nil {
197196
return err
198197
}

pkg/runtime/framework/plugins/volcano/volcano.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ import (
5151
trainer "github.com/kubeflow/trainer/v2/pkg/apis/trainer/v1alpha1"
5252
"github.com/kubeflow/trainer/v2/pkg/runtime"
5353
"github.com/kubeflow/trainer/v2/pkg/runtime/framework"
54-
index "github.com/kubeflow/trainer/v2/pkg/runtime/indexer"
55-
runtimeindexer "github.com/kubeflow/trainer/v2/pkg/runtime/indexer"
54+
"github.com/kubeflow/trainer/v2/pkg/runtime/indexer"
5655
)
5756

5857
type Volcano struct {
@@ -246,26 +245,26 @@ func (h *PodGroupRuntimeClassHandler) Generic(context.Context, event.TypedGeneri
246245

247246
func (h *PodGroupRuntimeClassHandler) queueSuspendedTrainJobs(ctx context.Context, runtimeClass *nodev1.RuntimeClass, q workqueue.TypedRateLimitingInterface[reconcile.Request]) error {
248247
var trainingRuntimes trainer.TrainingRuntimeList
249-
if err := h.client.List(ctx, &trainingRuntimes, client.MatchingFields{index.TrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
248+
if err := h.client.List(ctx, &trainingRuntimes, client.MatchingFields{indexer.TrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
250249
return err
251250
}
252251
var clusterTrainingRuntimes trainer.ClusterTrainingRuntimeList
253-
if err := h.client.List(ctx, &clusterTrainingRuntimes, client.MatchingFields{index.ClusterTrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
252+
if err := h.client.List(ctx, &clusterTrainingRuntimes, client.MatchingFields{indexer.ClusterTrainingRuntimeContainerRuntimeClassKey: runtimeClass.Name}); err != nil {
254253
return err
255254
}
256255

257256
var trainJobs []trainer.TrainJob
258257
for _, trainingRuntime := range trainingRuntimes.Items {
259258
var trainJobsWithTrainingRuntime trainer.TrainJobList
260-
err := h.client.List(ctx, &trainJobsWithTrainingRuntime, client.MatchingFields{runtimeindexer.TrainJobRuntimeRefKey: trainingRuntime.Name})
259+
err := h.client.List(ctx, &trainJobsWithTrainingRuntime, client.MatchingFields{indexer.TrainJobRuntimeRefKey: trainingRuntime.Name})
261260
if err != nil {
262261
return err
263262
}
264263
trainJobs = append(trainJobs, trainJobsWithTrainingRuntime.Items...)
265264
}
266265
for _, clusterTrainingRuntime := range clusterTrainingRuntimes.Items {
267266
var trainJobsWithClTrainingRuntime trainer.TrainJobList
268-
err := h.client.List(ctx, &trainJobsWithClTrainingRuntime, client.MatchingFields{runtimeindexer.TrainJobClusterRuntimeRefKey: clusterTrainingRuntime.Name})
267+
err := h.client.List(ctx, &trainJobsWithClTrainingRuntime, client.MatchingFields{indexer.TrainJobClusterRuntimeRefKey: clusterTrainingRuntime.Name})
269268
if err != nil {
270269
return err
271270
}

pkg/util/testing/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func (b *builderIndexer) IndexField(_ context.Context, obj client.Object, field
5656
if obj == nil || field == "" || extractValue == nil {
5757
return fmt.Errorf("error from test indexer")
5858
}
59-
b.ClientBuilder = b.ClientBuilder.WithIndex(obj, field, extractValue)
59+
b.ClientBuilder = b.WithIndex(obj, field, extractValue)
6060
return nil
6161
}
6262

pkg/util/testing/compare.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,11 @@ var (
4646
)
4747

4848
func MPISecretDataComparer(a, b map[string][]byte) bool {
49-
isKeysEqual := true
50-
if (a != nil && b != nil) &&
51-
((len(a[constants.MPISSHPublicKey]) > 0) != (len(b[constants.MPISSHPublicKey]) > 0) ||
52-
(len(a[corev1.SSHAuthPrivateKey]) > 0) != (len(b[corev1.SSHAuthPrivateKey]) > 0)) {
53-
isKeysEqual = false
54-
}
55-
return isKeysEqual && cmp.Equal(a, b, cmpopts.IgnoreMapEntries(func(k string, _ []byte) bool {
49+
areKeysEqual := (a == nil || b != nil) ||
50+
((len(a[constants.MPISSHPublicKey]) > 0) == (len(b[constants.MPISSHPublicKey]) > 0) &&
51+
(len(a[corev1.SSHAuthPrivateKey]) > 0) == (len(b[corev1.SSHAuthPrivateKey]) > 0))
52+
53+
return areKeysEqual && cmp.Equal(a, b, cmpopts.IgnoreMapEntries(func(k string, _ []byte) bool {
5654
return k == constants.MPISSHPublicKey || k == corev1.SSHAuthPrivateKey
5755
}))
5856
}

pkg/util/testing/wrapper.go

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -520,18 +520,18 @@ func (j *JobSetWrapper) PodPriorityClassName(value string) *JobSetWrapper {
520520
}
521521

522522
func (j *JobSetWrapper) Label(key, value string) *JobSetWrapper {
523-
if j.ObjectMeta.Labels == nil {
524-
j.ObjectMeta.Labels = make(map[string]string, 1)
523+
if j.Labels == nil {
524+
j.Labels = make(map[string]string, 1)
525525
}
526-
j.ObjectMeta.Labels[key] = value
526+
j.Labels[key] = value
527527
return j
528528
}
529529

530530
func (j *JobSetWrapper) Annotation(key, value string) *JobSetWrapper {
531-
if j.ObjectMeta.Annotations == nil {
532-
j.ObjectMeta.Annotations = make(map[string]string, 1)
531+
if j.Annotations == nil {
532+
j.Annotations = make(map[string]string, 1)
533533
}
534-
j.ObjectMeta.Annotations[key] = value
534+
j.Annotations[key] = value
535535
return j
536536
}
537537

@@ -665,10 +665,10 @@ func (t *TrainJobTrainerWrapper) NumProcPerNode(numProcPerNode intstr.IntOrStrin
665665
}
666666

667667
func (t *TrainJobTrainerWrapper) Container(image string, command []string, args []string, resRequests corev1.ResourceList) *TrainJobTrainerWrapper {
668-
t.Trainer.Image = &image
669-
t.Trainer.Command = command
670-
t.Trainer.Args = args
671-
t.Trainer.ResourcesPerNode = &corev1.ResourceRequirements{
668+
t.Image = &image
669+
t.Command = command
670+
t.Args = args
671+
t.ResourcesPerNode = &corev1.ResourceRequirements{
672672
Requests: resRequests,
673673
}
674674
return t
@@ -694,12 +694,12 @@ func MakeTrainJobInitializerWrapper() *TrainJobInitializerWrapper {
694694
}
695695

696696
func (t *TrainJobInitializerWrapper) DatasetInitializer(datasetInitializer *trainer.DatasetInitializer) *TrainJobInitializerWrapper {
697-
t.Initializer.Dataset = datasetInitializer
697+
t.Dataset = datasetInitializer
698698
return t
699699
}
700700

701701
func (t *TrainJobInitializerWrapper) ModelInitializer(modelInitializer *trainer.ModelInitializer) *TrainJobInitializerWrapper {
702-
t.Initializer.Model = modelInitializer
702+
t.Model = modelInitializer
703703
return t
704704
}
705705

@@ -901,18 +901,18 @@ func MakeTrainingRuntimeWrapper(namespace, name string) *TrainingRuntimeWrapper
901901
}
902902

903903
func (r *TrainingRuntimeWrapper) Label(key, value string) *TrainingRuntimeWrapper {
904-
if r.ObjectMeta.Labels == nil {
905-
r.ObjectMeta.Labels = make(map[string]string, 1)
904+
if r.Labels == nil {
905+
r.Labels = make(map[string]string, 1)
906906
}
907-
r.ObjectMeta.Labels[key] = value
907+
r.Labels[key] = value
908908
return r
909909
}
910910

911911
func (r *TrainingRuntimeWrapper) Annotation(key, value string) *TrainingRuntimeWrapper {
912-
if r.ObjectMeta.Annotations == nil {
913-
r.ObjectMeta.Annotations = make(map[string]string, 1)
912+
if r.Annotations == nil {
913+
r.Annotations = make(map[string]string, 1)
914914
}
915-
r.ObjectMeta.Annotations[key] = value
915+
r.Annotations[key] = value
916916
return r
917917
}
918918

@@ -1289,17 +1289,17 @@ func MakeSchedulerPluginsPodGroup(namespace, name string) *SchedulerPluginsPodGr
12891289
}
12901290

12911291
func (p *SchedulerPluginsPodGroupWrapper) MinMember(members int32) *SchedulerPluginsPodGroupWrapper {
1292-
p.PodGroup.Spec.MinMember = members
1292+
p.Spec.MinMember = members
12931293
return p
12941294
}
12951295

12961296
func (p *SchedulerPluginsPodGroupWrapper) MinResources(resources corev1.ResourceList) *SchedulerPluginsPodGroupWrapper {
1297-
p.PodGroup.Spec.MinResources = resources
1297+
p.Spec.MinResources = resources
12981298
return p
12991299
}
13001300

13011301
func (p *SchedulerPluginsPodGroupWrapper) SchedulingTimeout(timeout int32) *SchedulerPluginsPodGroupWrapper {
1302-
p.PodGroup.Spec.ScheduleTimeoutSeconds = &timeout
1302+
p.Spec.ScheduleTimeoutSeconds = &timeout
13031303
return p
13041304
}
13051305

@@ -1339,27 +1339,27 @@ func MakeVolcanoPodGroup(namespace, name string) *VolcanoPodGroupWrapper {
13391339
}
13401340

13411341
func (p *VolcanoPodGroupWrapper) MinMember(members int32) *VolcanoPodGroupWrapper {
1342-
p.PodGroup.Spec.MinMember = members
1342+
p.Spec.MinMember = members
13431343
return p
13441344
}
13451345

13461346
func (p *VolcanoPodGroupWrapper) MinResources(resources *corev1.ResourceList) *VolcanoPodGroupWrapper {
1347-
p.PodGroup.Spec.MinResources = resources
1347+
p.Spec.MinResources = resources
13481348
return p
13491349
}
13501350

13511351
func (p *VolcanoPodGroupWrapper) Queue(queue string) *VolcanoPodGroupWrapper {
1352-
p.PodGroup.Spec.Queue = queue
1352+
p.Spec.Queue = queue
13531353
return p
13541354
}
13551355

13561356
func (p *VolcanoPodGroupWrapper) PriorityClassName(pc string) *VolcanoPodGroupWrapper {
1357-
p.PodGroup.Spec.PriorityClassName = pc
1357+
p.Spec.PriorityClassName = pc
13581358
return p
13591359
}
13601360

13611361
func (p *VolcanoPodGroupWrapper) NetworkTopology(mode volcanov1beta1.NetworkTopologyMode, highestTier int) *VolcanoPodGroupWrapper {
1362-
p.PodGroup.Spec.NetworkTopology = &volcanov1beta1.NetworkTopologySpec{
1362+
p.Spec.NetworkTopology = &volcanov1beta1.NetworkTopologySpec{
13631363
Mode: mode,
13641364
HighestTierAllowed: &highestTier,
13651365
}
@@ -1374,7 +1374,7 @@ func (p *VolcanoPodGroupWrapper) ControllerReference(gvk schema.GroupVersionKind
13741374
UID: types.UID(uid),
13751375
},
13761376
}, gvk)
1377-
p.PodGroup.OwnerReferences = append(p.PodGroup.OwnerReferences, owner)
1377+
p.OwnerReferences = append(p.OwnerReferences, owner)
13781378
return p
13791379
}
13801380

0 commit comments

Comments
 (0)