fix(lint): resolve all golangci-lint findings

Migrate the lint config to the v2 format.
Replace the deprecated scheme.Builder with runtime.NewSchemeBuilder.
Handle Close errors in the worker and replace repeated strings with constants.
Remove unused parameters and use switch statements where the linter asks.
This commit is contained in:
2026-10-02 10:37:06 +01:00
parent c87d3eb56e
commit 2fdce1bf21
12 changed files with 149 additions and 120 deletions
+5
View File
@@ -29,6 +29,11 @@ const (
// STORAGE DEFINITIONS
STORAGE_S3 = "S3"
STORAGE_FILE = "FILE"
FIELD_EXPORT_NAME = "spec.exportName"
DEFAULT_IMAGE_TAG = "latest"
LABEL_APP = "app"
EXPORTER_CONTAINER = "exporter"
)
type Container struct {
+3 -3
View File
@@ -59,7 +59,7 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
Namespace: params.Namespace,
OwnerReferences: params.OwnerReferences,
Labels: map[string]string{
"app": "image-export",
LABEL_APP: "image-export",
},
Annotations: params.Annotations,
},
@@ -69,7 +69,7 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app": "image-export",
LABEL_APP: "image-export",
},
Annotations: params.Annotations,
},
@@ -80,7 +80,7 @@ func CreateJob[T any](params JobParams, setupFunc func(T) []string) *batchv1.Job
Volumes: volumes,
Containers: []corev1.Container{
{
Name: "exporter",
Name: EXPORTER_CONTAINER,
Image: params.Image,
TTY: true,
Command: []string{},
+10 -10
View File
@@ -204,18 +204,18 @@ func (s *JobsTestSuite) TestCreateJob() {
require.NotNil(s.T(), job, "Job should not be nil")
// Verify job metadata
assert.Equal(s.T(), tc.expectJobName, job.ObjectMeta.Name)
assert.Equal(s.T(), tc.expectNamespace, job.ObjectMeta.Namespace)
assert.Equal(s.T(), tc.expectJobName, job.Name)
assert.Equal(s.T(), tc.expectNamespace, job.Namespace)
// Verify labels
assert.Equal(s.T(), "image-export", job.ObjectMeta.Labels["app"])
assert.Equal(s.T(), "image-export", job.Spec.Template.ObjectMeta.Labels["app"])
assert.Equal(s.T(), "image-export", job.Labels["app"])
assert.Equal(s.T(), "image-export", job.Spec.Template.Labels["app"])
// Verify annotations if expected
if tc.expectAnnotations != nil {
for k, v := range tc.expectAnnotations {
assert.Equal(s.T(), v, job.ObjectMeta.Annotations[k])
assert.Equal(s.T(), v, job.Spec.Template.ObjectMeta.Annotations[k])
assert.Equal(s.T(), v, job.Annotations[k])
assert.Equal(s.T(), v, job.Spec.Template.Annotations[k])
}
}
@@ -268,9 +268,9 @@ func (s *JobsTestSuite) TestCreateJobWithOwnerReferences() {
job := CreateJob(params, func(raczylocomv1.ClusterImageExport) []string { return nil })
require.Len(s.T(), job.ObjectMeta.OwnerReferences, 1)
assert.Equal(s.T(), "ClusterImage", job.ObjectMeta.OwnerReferences[0].Kind)
assert.Equal(s.T(), "test-image", job.ObjectMeta.OwnerReferences[0].Name)
require.Len(s.T(), job.OwnerReferences, 1)
assert.Equal(s.T(), "ClusterImage", job.OwnerReferences[0].Kind)
assert.Equal(s.T(), "test-image", job.OwnerReferences[0].Name)
}
// TestCreateJobCommands tests command concatenation
@@ -525,7 +525,7 @@ func (s *JobsTestSuite) TestSecretVolumeMounting() {
// Verify volumes are created
require.Len(s.T(), podSpec.Volumes, 3)
for i, vol := range podSpec.Volumes {
assert.Equal(s.T(), secrets[i].Name, vol.VolumeSource.Secret.SecretName)
assert.Equal(s.T(), secrets[i].Name, vol.Secret.SecretName)
assert.Contains(s.T(), vol.Name, "secret-")
}
+3 -3
View File
@@ -84,7 +84,7 @@ func ProcessContainerName(containerName string) (Container, error) {
}
if cnt.Sha == "" && cnt.Tag == "" {
cnt.Tag = "latest"
cnt.Tag = DEFAULT_IMAGE_TAG
}
if cnt.Image == "" {
@@ -109,7 +109,7 @@ func processContainers(ctx context.Context, resource K8sResource, namespace stri
}
for _, container := range podSpec.EphemeralContainers {
if err := processContainer(ctx, container.EphemeralContainerCommon.Image, namespace, containersList); err != nil {
if err := processContainer(ctx, container.Image, namespace, containersList); err != nil {
return err
}
}
@@ -211,7 +211,7 @@ func SetupIndexers(mgr manager.Manager) error {
Jitter: 0.1,
Steps: 5,
}, func() (bool, error) {
err := mgr.GetFieldIndexer().IndexField(context.Background(), &raczylocomv1.ClusterImage{}, "spec.exportName", func(rawObj client.Object) []string {
err := mgr.GetFieldIndexer().IndexField(context.Background(), &raczylocomv1.ClusterImage{}, FIELD_EXPORT_NAME, func(rawObj client.Object) []string {
clusterImage := rawObj.(*raczylocomv1.ClusterImage)
return []string{clusterImage.Spec.ExportName}
})