From f80034157fbf7ad3df95f2270ce9973da56ac9c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Thu, 7 May 2026 21:21:44 +0200 Subject: [PATCH 01/10] feat: add node annotation reconciliation to synchronize cluster specifications --- .../kubernetescluster/talos/cluster_init.go | 5 + .../talos/reconcile_node_annotations.go | 168 ++++++++++++++++++ 2 files changed, 173 insertions(+) create mode 100644 internal/kubernetescluster/talos/reconcile_node_annotations.go diff --git a/internal/kubernetescluster/talos/cluster_init.go b/internal/kubernetescluster/talos/cluster_init.go index 584cdf5..aaa3ec4 100644 --- a/internal/kubernetescluster/talos/cluster_init.go +++ b/internal/kubernetescluster/talos/cluster_init.go @@ -63,6 +63,11 @@ func initializeTalosCluster(ctx context.Context, t *TalosManager, cluster *vitis vlog.Warn(fmt.Sprintf("Error during node version reconciliation %s: %v", clusterLogTag(cluster), err)) } + // Reconcile node annotations to keep them in sync with cluster/machine spec + if err := t.reconcileNodeAnnotations(ctx, cluster); err != nil { + vlog.Warn(fmt.Sprintf("Error during node annotation reconciliation %s: %v", clusterLogTag(cluster), err)) + } + // Enforce the configured Talos OS version: probes each node's // running Talos version via the Talos API and reinstalls any // node that doesn't match TALOS_VERSION (CPs first, then diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations.go b/internal/kubernetescluster/talos/reconcile_node_annotations.go new file mode 100644 index 0000000..a422e2c --- /dev/null +++ b/internal/kubernetescluster/talos/reconcile_node_annotations.go @@ -0,0 +1,168 @@ +package talos + +import ( + "context" + "encoding/json" + "fmt" + "strings" + + "github.com/spf13/viper" + "github.com/vitistack/common/pkg/loggers/vlog" + vitistackv1alpha1 "github.com/vitistack/common/pkg/v1alpha1" + "github.com/vitistack/talos-operator/internal/services/networknamespaceservice" + "github.com/vitistack/talos-operator/internal/services/vitistackservice" + "github.com/vitistack/talos-operator/pkg/consts" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + k8stypes "k8s.io/apimachinery/pkg/types" +) + +// reconcileNodeAnnotations ensures that all nodes in the workload cluster have +// the expected vitistack annotations. This covers cases where the cluster spec +// has changed after initial provisioning (e.g. project, environment, region) +// and keeps annotations in sync without requiring a node re-provision. +func (t *TalosManager) reconcileNodeAnnotations(ctx context.Context, cluster *vitistackv1alpha1.KubernetesCluster) error { + clientset, err := t.getWorkloadClusterClient(ctx, cluster) + if err != nil || clientset == nil { + return err + } + + nodeList, err := clientset.CoreV1().Nodes().List(ctx, metav1.ListOptions{}) + if err != nil { + return fmt.Errorf("failed to list workload cluster nodes for annotation reconciliation: %w", err) + } + + machines, err := t.machineService.GetClusterMachines(ctx, cluster) + if err != nil { + return fmt.Errorf("failed to get cluster machines for annotation reconciliation: %w", err) + } + machineMap := make(map[string]*vitistackv1alpha1.Machine, len(machines)) + for _, m := range machines { + machineMap[m.Name] = m + } + + // Resolve shared annotation values once + country, az := extractNodeAnnotationDatacenterInfo(cluster.Spec.Cluster.Datacenter) + networkNamespaceName := resolveNetworkNamespaceName(ctx, cluster) + infrastructure := resolveInfrastructure(ctx) + + for i := range nodeList.Items { + node := &nodeList.Items[i] + m, exists := machineMap[node.Name] + if !exists { + continue + } + + desired := buildDesiredNodeAnnotations(cluster, m, country, az, networkNamespaceName, infrastructure) + patch := computeAnnotationPatch(node.Annotations, desired) + if len(patch) == 0 { + continue + } + + patchBytes, err := json.Marshal(map[string]interface{}{ + "metadata": map[string]interface{}{ + "annotations": patch, + }, + }) + if err != nil { + vlog.Warn(fmt.Sprintf("Failed to marshal annotation patch for node %s: %v", node.Name, err)) + continue + } + + if _, err := clientset.CoreV1().Nodes().Patch(ctx, node.Name, k8stypes.MergePatchType, patchBytes, metav1.PatchOptions{}); err != nil { + vlog.Warn(fmt.Sprintf("Failed to patch annotations on node %s: %v", node.Name, err)) + continue + } + + vlog.Info(fmt.Sprintf("Reconciled %d annotations on node %s", len(patch), node.Name)) + } + + return nil +} + +// buildDesiredNodeAnnotations returns the expected annotation map for a node. +func buildDesiredNodeAnnotations( + cluster *vitistackv1alpha1.KubernetesCluster, + m *vitistackv1alpha1.Machine, + country, az, networkNamespaceName, infrastructure string, +) map[string]string { + annotations := map[string]string{ + vitistackv1alpha1.ClusterIdAnnotation: cluster.Spec.Cluster.ClusterId, + vitistackv1alpha1.ClusterNameAnnotation: cluster.Name, + vitistackv1alpha1.ClusterProjectAnnotation: cluster.Spec.Cluster.Project, + vitistackv1alpha1.EnvironmentAnnotation: cluster.Spec.Cluster.Environment, + vitistackv1alpha1.CountryAnnotation: country, + vitistackv1alpha1.AzAnnotation: az, + vitistackv1alpha1.RegionAnnotation: cluster.Spec.Cluster.Region, + vitistackv1alpha1.KubernetesProviderAnnotation: string(cluster.Spec.Cluster.Provider), + vitistackv1alpha1.MachineProviderAnnotation: string(m.Status.Provider), + vitistackv1alpha1.MachineClassAnnotation: m.Spec.MachineClass, + vitistackv1alpha1.MachineIdAnnotation: m.Name, + vitistackv1alpha1.ClusterWorkspaceAnnotation: networkNamespaceName, + vitistackv1alpha1.MachineInfrastructureAnnotation: infrastructure, + vitistackv1alpha1.VMProviderAnnotation: string(m.Status.Provider), //nolint:staticcheck // backward compatibility + vitistackv1alpha1.InfrastructureAnnotation: infrastructure, //nolint:staticcheck // backward compatibility + } + + if nodePool, ok := m.Annotations[vitistackv1alpha1.NodePoolAnnotation]; ok && nodePool != "" { + annotations[vitistackv1alpha1.NodePoolAnnotation] = nodePool + } + + return annotations +} + +// computeAnnotationPatch returns only the annotations that differ from current. +func computeAnnotationPatch(current, desired map[string]string) map[string]string { + patch := make(map[string]string) + for k, v := range desired { + if current[k] != v { + patch[k] = v + } + } + return patch +} + +// extractNodeAnnotationDatacenterInfo splits a datacenter string into country and AZ. +func extractNodeAnnotationDatacenterInfo(datacenter string) (country string, az string) { + parts := strings.Split(datacenter, "-") + switch { + case len(parts) >= 3: + country = parts[0] + az = parts[len(parts)-1] + case len(parts) == 2: + country = parts[0] + az = "" + default: + country = datacenter + az = "" + } + return country, az +} + +// resolveNetworkNamespaceName resolves the network namespace name for annotation use. +func resolveNetworkNamespaceName(ctx context.Context, cluster *vitistackv1alpha1.KubernetesCluster) string { + if cluster.Spec.Cluster.NetworkNamespaceName != "" { + return cluster.Spec.Cluster.NetworkNamespaceName + } + ns, err := networknamespaceservice.FetchFirstNetworkNamespaceByNamespace(ctx, cluster.GetNamespace()) + if err != nil { + vlog.Warn(fmt.Sprintf("failed to fetch NetworkNamespaces for namespace %q: %v", cluster.GetNamespace(), err)) + return "" + } + if ns != nil { + return ns.Name + } + return "" +} + +// resolveInfrastructure resolves the infrastructure name from the Vitistack CR. +func resolveInfrastructure(ctx context.Context) string { + vitistack, err := vitistackservice.FetchVitistackByName(ctx, viper.GetString(consts.VITISTACK_NAME)) + if err != nil { + vlog.Warn(fmt.Sprintf("failed to fetch Vitistack %q: %v", viper.GetString(consts.VITISTACK_NAME), err)) + return "" + } + if vitistack != nil && vitistack.Spec.Infrastructure != "" { + return vitistack.Spec.Infrastructure + } + return "" +} From 3209a225e1afd06a8b6b4f775e67fbf3b71eb5d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Thu, 7 May 2026 21:40:41 +0200 Subject: [PATCH 02/10] fix: improve annotation reconciliation logging and enhance patch computation Co-authored-by: Copilot --- .../talos/reconcile_node_annotations.go | 37 +++++++++++++++++-- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations.go b/internal/kubernetescluster/talos/reconcile_node_annotations.go index a422e2c..3018268 100644 --- a/internal/kubernetescluster/talos/reconcile_node_annotations.go +++ b/internal/kubernetescluster/talos/reconcile_node_annotations.go @@ -63,6 +63,8 @@ func (t *TalosManager) reconcileNodeAnnotations(ctx context.Context, cluster *vi "annotations": patch, }, }) + // Count actual updates (non-nil values) for the log message + updated, removed := countPatchOps(patch) if err != nil { vlog.Warn(fmt.Sprintf("Failed to marshal annotation patch for node %s: %v", node.Name, err)) continue @@ -73,7 +75,7 @@ func (t *TalosManager) reconcileNodeAnnotations(ctx context.Context, cluster *vi continue } - vlog.Info(fmt.Sprintf("Reconciled %d annotations on node %s", len(patch), node.Name)) + vlog.Info(fmt.Sprintf("Reconciled annotations on node %s: %d updated, %d removed", node.Name, updated, removed)) } return nil @@ -110,17 +112,44 @@ func buildDesiredNodeAnnotations( return annotations } -// computeAnnotationPatch returns only the annotations that differ from current. -func computeAnnotationPatch(current, desired map[string]string) map[string]string { - patch := make(map[string]string) +// computeAnnotationPatch computes a JSON merge-patch for annotations. +// It sets desired values that differ from current, and sets managed keys +// (vitistack.io/* annotations) to nil when they are present on the node +// but absent from the desired set — causing MergePatch to delete them. +func computeAnnotationPatch(current, desired map[string]string) map[string]interface{} { + patch := make(map[string]interface{}) + + // Set or update desired annotations for k, v := range desired { if current[k] != v { patch[k] = v } } + + // Remove managed annotations that are no longer desired + for _, k := range vitistackv1alpha1.GetAllVitistackAnnotations() { + if _, isDesired := desired[k]; !isDesired { + if _, exists := current[k]; exists { + patch[k] = nil + } + } + } + return patch } +// countPatchOps counts the number of updates and removals in a patch. +func countPatchOps(patch map[string]interface{}) (updated, removed int) { + for _, v := range patch { + if v == nil { + removed++ + } else { + updated++ + } + } + return updated, removed +} + // extractNodeAnnotationDatacenterInfo splits a datacenter string into country and AZ. func extractNodeAnnotationDatacenterInfo(datacenter string) (country string, az string) { parts := strings.Split(datacenter, "-") From b1c2b5b4341c059589074088ad0f9b6a26914d45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Thu, 7 May 2026 21:42:14 +0200 Subject: [PATCH 03/10] fix: enhance node annotation resolution to prevent clobbering valid annotations --- .../talos/reconcile_node_annotations.go | 44 ++++++++++++++----- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations.go b/internal/kubernetescluster/talos/reconcile_node_annotations.go index 3018268..369f655 100644 --- a/internal/kubernetescluster/talos/reconcile_node_annotations.go +++ b/internal/kubernetescluster/talos/reconcile_node_annotations.go @@ -40,10 +40,21 @@ func (t *TalosManager) reconcileNodeAnnotations(ctx context.Context, cluster *vi machineMap[m.Name] = m } - // Resolve shared annotation values once + // Resolve shared annotation values once; track keys to skip on lookup failure + // so we don't clobber valid annotations with empty strings due to transient errors. country, az := extractNodeAnnotationDatacenterInfo(cluster.Spec.Cluster.Datacenter) - networkNamespaceName := resolveNetworkNamespaceName(ctx, cluster) - infrastructure := resolveInfrastructure(ctx) + skipKeys := make(map[string]bool) + + networkNamespaceName, err := resolveNetworkNamespaceName(ctx, cluster) + if err != nil { + skipKeys[vitistackv1alpha1.ClusterWorkspaceAnnotation] = true + } + + infrastructure, err := resolveInfrastructure(ctx) + if err != nil { + skipKeys[vitistackv1alpha1.MachineInfrastructureAnnotation] = true + skipKeys[vitistackv1alpha1.InfrastructureAnnotation] = true //nolint:staticcheck // backward compatibility + } for i := range nodeList.Items { node := &nodeList.Items[i] @@ -53,6 +64,11 @@ func (t *TalosManager) reconcileNodeAnnotations(ctx context.Context, cluster *vi } desired := buildDesiredNodeAnnotations(cluster, m, country, az, networkNamespaceName, infrastructure) + // Remove keys that couldn't be resolved reliably to avoid + // overwriting valid annotations with empty strings. + for k := range skipKeys { + delete(desired, k) + } patch := computeAnnotationPatch(node.Annotations, desired) if len(patch) == 0 { continue @@ -168,30 +184,34 @@ func extractNodeAnnotationDatacenterInfo(datacenter string) (country string, az } // resolveNetworkNamespaceName resolves the network namespace name for annotation use. -func resolveNetworkNamespaceName(ctx context.Context, cluster *vitistackv1alpha1.KubernetesCluster) string { +// Returns an error when the lookup fails so the caller can skip the key rather than +// clobbering a valid annotation with an empty string. +func resolveNetworkNamespaceName(ctx context.Context, cluster *vitistackv1alpha1.KubernetesCluster) (string, error) { if cluster.Spec.Cluster.NetworkNamespaceName != "" { - return cluster.Spec.Cluster.NetworkNamespaceName + return cluster.Spec.Cluster.NetworkNamespaceName, nil } ns, err := networknamespaceservice.FetchFirstNetworkNamespaceByNamespace(ctx, cluster.GetNamespace()) if err != nil { vlog.Warn(fmt.Sprintf("failed to fetch NetworkNamespaces for namespace %q: %v", cluster.GetNamespace(), err)) - return "" + return "", err } if ns != nil { - return ns.Name + return ns.Name, nil } - return "" + return "", nil } // resolveInfrastructure resolves the infrastructure name from the Vitistack CR. -func resolveInfrastructure(ctx context.Context) string { +// Returns an error when the lookup fails so the caller can skip the key rather than +// clobbering a valid annotation with an empty string. +func resolveInfrastructure(ctx context.Context) (string, error) { vitistack, err := vitistackservice.FetchVitistackByName(ctx, viper.GetString(consts.VITISTACK_NAME)) if err != nil { vlog.Warn(fmt.Sprintf("failed to fetch Vitistack %q: %v", viper.GetString(consts.VITISTACK_NAME), err)) - return "" + return "", err } if vitistack != nil && vitistack.Spec.Infrastructure != "" { - return vitistack.Spec.Infrastructure + return vitistack.Spec.Infrastructure, nil } - return "" + return "", nil } From eef919c6c0a08e3761e79f4b411cb94f4162e5de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Thu, 7 May 2026 21:43:49 +0200 Subject: [PATCH 04/10] refactor: replace local datacenter info extraction with service method for consistency --- .../talos/reconcile_node_annotations.go | 21 ++----------------- .../talos_config_service.go | 5 +++-- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations.go b/internal/kubernetescluster/talos/reconcile_node_annotations.go index 369f655..a359608 100644 --- a/internal/kubernetescluster/talos/reconcile_node_annotations.go +++ b/internal/kubernetescluster/talos/reconcile_node_annotations.go @@ -4,12 +4,12 @@ import ( "context" "encoding/json" "fmt" - "strings" "github.com/spf13/viper" "github.com/vitistack/common/pkg/loggers/vlog" vitistackv1alpha1 "github.com/vitistack/common/pkg/v1alpha1" "github.com/vitistack/talos-operator/internal/services/networknamespaceservice" + "github.com/vitistack/talos-operator/internal/services/talosconfigservice" "github.com/vitistack/talos-operator/internal/services/vitistackservice" "github.com/vitistack/talos-operator/pkg/consts" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -42,7 +42,7 @@ func (t *TalosManager) reconcileNodeAnnotations(ctx context.Context, cluster *vi // Resolve shared annotation values once; track keys to skip on lookup failure // so we don't clobber valid annotations with empty strings due to transient errors. - country, az := extractNodeAnnotationDatacenterInfo(cluster.Spec.Cluster.Datacenter) + country, az := talosconfigservice.ExtractDatacenterInfo(cluster.Spec.Cluster.Datacenter) skipKeys := make(map[string]bool) networkNamespaceName, err := resolveNetworkNamespaceName(ctx, cluster) @@ -166,23 +166,6 @@ func countPatchOps(patch map[string]interface{}) (updated, removed int) { return updated, removed } -// extractNodeAnnotationDatacenterInfo splits a datacenter string into country and AZ. -func extractNodeAnnotationDatacenterInfo(datacenter string) (country string, az string) { - parts := strings.Split(datacenter, "-") - switch { - case len(parts) >= 3: - country = parts[0] - az = parts[len(parts)-1] - case len(parts) == 2: - country = parts[0] - az = "" - default: - country = datacenter - az = "" - } - return country, az -} - // resolveNetworkNamespaceName resolves the network namespace name for annotation use. // Returns an error when the lookup fails so the caller can skip the key rather than // clobbering a valid annotation with an empty string. diff --git a/internal/services/talosconfigservice/talos_config_service.go b/internal/services/talosconfigservice/talos_config_service.go index a4be1d3..9df06d5 100644 --- a/internal/services/talosconfigservice/talos_config_service.go +++ b/internal/services/talosconfigservice/talos_config_service.go @@ -493,7 +493,7 @@ func cidrToNetmask(cidr string) string { // buildNodeAnnotationsPatch builds a YAML patch for node annotations func (s *TalosConfigService) buildNodeAnnotationsPatch(cluster *vitistackv1alpha1.KubernetesCluster, m *vitistackv1alpha1.Machine) string { - country, az := extractDatacenterInfo(cluster.Spec.Cluster.Datacenter) + country, az := ExtractDatacenterInfo(cluster.Spec.Cluster.Datacenter) annotations := map[string]string{ vitistackv1alpha1.ClusterIdAnnotation: cluster.Spec.Cluster.ClusterId, @@ -785,7 +785,8 @@ func ValidateTenantConfigYAML(raw string) error { return nil } -func extractDatacenterInfo(datacenter string) (country string, az string) { +// ExtractDatacenterInfo splits a datacenter string (e.g. "no-east-1") into country and availability zone. +func ExtractDatacenterInfo(datacenter string) (country string, az string) { parts := strings.Split(datacenter, "-") switch { case len(parts) >= 3: From 0636b25c869cc2510761ace8e9c0fa74f37670df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Thu, 7 May 2026 21:46:41 +0200 Subject: [PATCH 05/10] test: add unit tests for node annotation reconciliation and patch computation --- .../talos/reconcile_node_annotations_test.go | 248 ++++++++++++++++++ 1 file changed, 248 insertions(+) create mode 100644 internal/kubernetescluster/talos/reconcile_node_annotations_test.go diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go new file mode 100644 index 0000000..65e591d --- /dev/null +++ b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go @@ -0,0 +1,248 @@ +package talos + +import ( + "testing" + + vitistackv1alpha1 "github.com/vitistack/common/pkg/v1alpha1" + "github.com/vitistack/talos-operator/internal/services/talosconfigservice" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestExtractDatacenterInfo(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + datacenter string + wantCC string + wantAZ string + }{ + {name: "three parts", datacenter: "no-east-1", wantCC: "no", wantAZ: "1"}, + {name: "four parts", datacenter: "us-west-coast-2", wantCC: "us", wantAZ: "2"}, + {name: "two parts", datacenter: "de-west", wantCC: "de", wantAZ: ""}, + {name: "single part", datacenter: "local", wantCC: "local", wantAZ: ""}, + {name: "empty string", datacenter: "", wantCC: "", wantAZ: ""}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + t.Parallel() + cc, az := talosconfigservice.ExtractDatacenterInfo(tt.datacenter) + if cc != tt.wantCC { + t.Errorf("country = %q, want %q", cc, tt.wantCC) + } + if az != tt.wantAZ { + t.Errorf("az = %q, want %q", az, tt.wantAZ) + } + }) + } +} + +func TestBuildDesiredNodeAnnotations(t *testing.T) { + t.Parallel() + + cluster := &vitistackv1alpha1.KubernetesCluster{ + ObjectMeta: metav1.ObjectMeta{Name: "test-cluster"}, + Spec: vitistackv1alpha1.KubernetesClusterSpec{ + Cluster: vitistackv1alpha1.KubernetesClusterSpecData{ + ClusterId: "uuid-123", + Project: "myproject", + Environment: "prod", + Region: "europe", + Provider: "talos", + }, + }, + } + + machine := &vitistackv1alpha1.Machine{ + ObjectMeta: metav1.ObjectMeta{ + Name: "node-1", + Annotations: map[string]string{vitistackv1alpha1.NodePoolAnnotation: "pool-a"}, + }, + Spec: vitistackv1alpha1.MachineSpec{MachineClass: "large"}, + } + machine.Status.Provider = "kubevirt" + + result := buildDesiredNodeAnnotations(cluster, machine, "no", "1", "ws-ns", "infra-prod") + + checks := map[string]string{ + vitistackv1alpha1.ClusterIdAnnotation: "uuid-123", + vitistackv1alpha1.ClusterNameAnnotation: "test-cluster", + vitistackv1alpha1.ClusterProjectAnnotation: "myproject", + vitistackv1alpha1.EnvironmentAnnotation: "prod", + vitistackv1alpha1.CountryAnnotation: "no", + vitistackv1alpha1.AzAnnotation: "1", + vitistackv1alpha1.RegionAnnotation: "europe", + vitistackv1alpha1.KubernetesProviderAnnotation: "talos", + vitistackv1alpha1.MachineProviderAnnotation: "kubevirt", + vitistackv1alpha1.MachineClassAnnotation: "large", + vitistackv1alpha1.MachineIdAnnotation: "node-1", + vitistackv1alpha1.ClusterWorkspaceAnnotation: "ws-ns", + vitistackv1alpha1.MachineInfrastructureAnnotation: "infra-prod", + vitistackv1alpha1.VMProviderAnnotation: "kubevirt", + vitistackv1alpha1.InfrastructureAnnotation: "infra-prod", + vitistackv1alpha1.NodePoolAnnotation: "pool-a", + } + + for k, want := range checks { + if got := result[k]; got != want { + t.Errorf("annotation %s = %q, want %q", k, got, want) + } + } +} + +func TestBuildDesiredNodeAnnotations_NoNodePool(t *testing.T) { + t.Parallel() + + cluster := &vitistackv1alpha1.KubernetesCluster{ + ObjectMeta: metav1.ObjectMeta{Name: "c"}, + Spec: vitistackv1alpha1.KubernetesClusterSpec{}, + } + machine := &vitistackv1alpha1.Machine{ + ObjectMeta: metav1.ObjectMeta{Name: "n"}, + } + + result := buildDesiredNodeAnnotations(cluster, machine, "", "", "", "") + + if _, exists := result[vitistackv1alpha1.NodePoolAnnotation]; exists { + t.Error("NodePoolAnnotation should not be present when machine has no nodepool annotation") + } +} + +func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { + t.Parallel() + + current := map[string]string{ + vitistackv1alpha1.ClusterNameAnnotation: "old-name", + vitistackv1alpha1.EnvironmentAnnotation: "dev", + vitistackv1alpha1.MachineClassAnnotation: "medium", + vitistackv1alpha1.MachineIdAnnotation: "node-1", + vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", + vitistackv1alpha1.ClusterProjectAnnotation: "proj", + } + + desired := map[string]string{ + vitistackv1alpha1.ClusterNameAnnotation: "new-name", // changed + vitistackv1alpha1.EnvironmentAnnotation: "dev", // unchanged + vitistackv1alpha1.MachineClassAnnotation: "large", // changed + vitistackv1alpha1.MachineIdAnnotation: "node-1", // unchanged + vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", // unchanged + vitistackv1alpha1.ClusterProjectAnnotation: "new-proj", // changed + } + + patch := computeAnnotationPatch(current, desired) + + // Should contain the 3 changed keys + if v, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; !ok || v != "new-name" { + t.Errorf("expected ClusterNameAnnotation = 'new-name', got %v", v) + } + if v, ok := patch[vitistackv1alpha1.MachineClassAnnotation]; !ok || v != "large" { + t.Errorf("expected MachineClassAnnotation = 'large', got %v", v) + } + if v, ok := patch[vitistackv1alpha1.ClusterProjectAnnotation]; !ok || v != "new-proj" { + t.Errorf("expected ClusterProjectAnnotation = 'new-proj', got %v", v) + } + + // Should NOT contain unchanged keys + if _, ok := patch[vitistackv1alpha1.EnvironmentAnnotation]; ok { + t.Error("unchanged EnvironmentAnnotation should not be in patch") + } + if _, ok := patch[vitistackv1alpha1.MachineIdAnnotation]; ok { + t.Error("unchanged MachineIdAnnotation should not be in patch") + } +} + +func TestComputeAnnotationPatch_DeletesManagedKeys(t *testing.T) { + t.Parallel() + + current := map[string]string{ + vitistackv1alpha1.ClusterNameAnnotation: "c", + vitistackv1alpha1.NodePoolAnnotation: "pool-a", // managed key, not in desired + "some.other/annotation": "keep", // unmanaged, should be ignored + } + + desired := map[string]string{ + vitistackv1alpha1.ClusterNameAnnotation: "c", // unchanged + } + + patch := computeAnnotationPatch(current, desired) + + // NodePoolAnnotation is managed and missing from desired → should be nil (delete) + v, ok := patch[vitistackv1alpha1.NodePoolAnnotation] + if !ok || v != nil { + t.Errorf("expected NodePoolAnnotation = nil (delete), got ok=%v v=%v", ok, v) + } + + // Unmanaged key should NOT appear in patch + if _, ok := patch["some.other/annotation"]; ok { + t.Error("unmanaged annotation should not appear in patch") + } + + // ClusterNameAnnotation unchanged → should not appear + if _, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; ok { + t.Error("unchanged ClusterNameAnnotation should not be in patch") + } +} + +func TestComputeAnnotationPatch_NoPatchWhenInSync(t *testing.T) { + t.Parallel() + + annotations := map[string]string{ + vitistackv1alpha1.ClusterNameAnnotation: "c", + vitistackv1alpha1.MachineIdAnnotation: "n", + } + + patch := computeAnnotationPatch(annotations, annotations) + + if len(patch) != 0 { + t.Errorf("expected empty patch when in sync, got %d entries", len(patch)) + } +} + +func TestComputeAnnotationPatch_AddsNewAnnotations(t *testing.T) { + t.Parallel() + + current := map[string]string{} + desired := map[string]string{ + vitistackv1alpha1.ClusterNameAnnotation: "new-cluster", + vitistackv1alpha1.RegionAnnotation: "europe", + } + + patch := computeAnnotationPatch(current, desired) + + if v, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; !ok || v != "new-cluster" { + t.Errorf("expected ClusterNameAnnotation = 'new-cluster', got %v", v) + } + if v, ok := patch[vitistackv1alpha1.RegionAnnotation]; !ok || v != "europe" { + t.Errorf("expected RegionAnnotation = 'europe', got %v", v) + } +} + +func TestCountPatchOps(t *testing.T) { + t.Parallel() + + patch := map[string]interface{}{ + "a": "value1", + "b": "value2", + "c": nil, + "d": nil, + "e": nil, + } + + updated, removed := countPatchOps(patch) + if updated != 2 { + t.Errorf("updated = %d, want 2", updated) + } + if removed != 3 { + t.Errorf("removed = %d, want 3", removed) + } +} + +func TestCountPatchOps_Empty(t *testing.T) { + t.Parallel() + + updated, removed := countPatchOps(map[string]interface{}{}) + if updated != 0 || removed != 0 { + t.Errorf("expected 0/0 for empty patch, got %d/%d", updated, removed) + } +} From 4860eb23061cd037ec40e63f41bfd8da92b9e685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Fri, 8 May 2026 08:37:28 +0200 Subject: [PATCH 06/10] refactor: replace hardcoded values with constants in node annotation tests --- .../talos/reconcile_node_annotations_test.go | 48 +++++++++++-------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go index 65e591d..65880b0 100644 --- a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go +++ b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go @@ -8,6 +8,14 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) +const ( + testNodeName = "node-1" + testRegion = "europe" + testNodePool = "pool-a" + testMachineClass = "large" + testMachineProvider = "kubevirt" +) + func TestExtractDatacenterInfo(t *testing.T) { t.Parallel() @@ -48,7 +56,7 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { ClusterId: "uuid-123", Project: "myproject", Environment: "prod", - Region: "europe", + Region: testRegion, Provider: "talos", }, }, @@ -56,12 +64,12 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { machine := &vitistackv1alpha1.Machine{ ObjectMeta: metav1.ObjectMeta{ - Name: "node-1", - Annotations: map[string]string{vitistackv1alpha1.NodePoolAnnotation: "pool-a"}, + Name: testNodeName, + Annotations: map[string]string{vitistackv1alpha1.NodePoolAnnotation: testNodePool}, }, - Spec: vitistackv1alpha1.MachineSpec{MachineClass: "large"}, + Spec: vitistackv1alpha1.MachineSpec{MachineClass: testMachineClass}, } - machine.Status.Provider = "kubevirt" + machine.Status.Provider = vitistackv1alpha1.MachineProviderType(testMachineProvider) result := buildDesiredNodeAnnotations(cluster, machine, "no", "1", "ws-ns", "infra-prod") @@ -72,16 +80,16 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { vitistackv1alpha1.EnvironmentAnnotation: "prod", vitistackv1alpha1.CountryAnnotation: "no", vitistackv1alpha1.AzAnnotation: "1", - vitistackv1alpha1.RegionAnnotation: "europe", + vitistackv1alpha1.RegionAnnotation: testRegion, vitistackv1alpha1.KubernetesProviderAnnotation: "talos", - vitistackv1alpha1.MachineProviderAnnotation: "kubevirt", - vitistackv1alpha1.MachineClassAnnotation: "large", - vitistackv1alpha1.MachineIdAnnotation: "node-1", + vitistackv1alpha1.MachineProviderAnnotation: testMachineProvider, + vitistackv1alpha1.MachineClassAnnotation: testMachineClass, + vitistackv1alpha1.MachineIdAnnotation: testNodeName, vitistackv1alpha1.ClusterWorkspaceAnnotation: "ws-ns", vitistackv1alpha1.MachineInfrastructureAnnotation: "infra-prod", - vitistackv1alpha1.VMProviderAnnotation: "kubevirt", - vitistackv1alpha1.InfrastructureAnnotation: "infra-prod", - vitistackv1alpha1.NodePoolAnnotation: "pool-a", + vitistackv1alpha1.VMProviderAnnotation: testMachineProvider, //nolint:staticcheck // testing deprecated annotation + vitistackv1alpha1.InfrastructureAnnotation: "infra-prod", //nolint:staticcheck // testing deprecated annotation + vitistackv1alpha1.NodePoolAnnotation: testNodePool, } for k, want := range checks { @@ -116,7 +124,7 @@ func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { vitistackv1alpha1.ClusterNameAnnotation: "old-name", vitistackv1alpha1.EnvironmentAnnotation: "dev", vitistackv1alpha1.MachineClassAnnotation: "medium", - vitistackv1alpha1.MachineIdAnnotation: "node-1", + vitistackv1alpha1.MachineIdAnnotation: testNodeName, vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", vitistackv1alpha1.ClusterProjectAnnotation: "proj", } @@ -124,8 +132,8 @@ func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { desired := map[string]string{ vitistackv1alpha1.ClusterNameAnnotation: "new-name", // changed vitistackv1alpha1.EnvironmentAnnotation: "dev", // unchanged - vitistackv1alpha1.MachineClassAnnotation: "large", // changed - vitistackv1alpha1.MachineIdAnnotation: "node-1", // unchanged + vitistackv1alpha1.MachineClassAnnotation: testMachineClass, // changed + vitistackv1alpha1.MachineIdAnnotation: testNodeName, // unchanged vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", // unchanged vitistackv1alpha1.ClusterProjectAnnotation: "new-proj", // changed } @@ -136,8 +144,8 @@ func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { if v, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; !ok || v != "new-name" { t.Errorf("expected ClusterNameAnnotation = 'new-name', got %v", v) } - if v, ok := patch[vitistackv1alpha1.MachineClassAnnotation]; !ok || v != "large" { - t.Errorf("expected MachineClassAnnotation = 'large', got %v", v) + if v, ok := patch[vitistackv1alpha1.MachineClassAnnotation]; !ok || v != testMachineClass { + t.Errorf("expected MachineClassAnnotation = %q, got %v", testMachineClass, v) } if v, ok := patch[vitistackv1alpha1.ClusterProjectAnnotation]; !ok || v != "new-proj" { t.Errorf("expected ClusterProjectAnnotation = 'new-proj', got %v", v) @@ -157,7 +165,7 @@ func TestComputeAnnotationPatch_DeletesManagedKeys(t *testing.T) { current := map[string]string{ vitistackv1alpha1.ClusterNameAnnotation: "c", - vitistackv1alpha1.NodePoolAnnotation: "pool-a", // managed key, not in desired + vitistackv1alpha1.NodePoolAnnotation: testNodePool, // managed key, not in desired "some.other/annotation": "keep", // unmanaged, should be ignored } @@ -213,8 +221,8 @@ func TestComputeAnnotationPatch_AddsNewAnnotations(t *testing.T) { if v, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; !ok || v != "new-cluster" { t.Errorf("expected ClusterNameAnnotation = 'new-cluster', got %v", v) } - if v, ok := patch[vitistackv1alpha1.RegionAnnotation]; !ok || v != "europe" { - t.Errorf("expected RegionAnnotation = 'europe', got %v", v) + if v, ok := patch[vitistackv1alpha1.RegionAnnotation]; !ok || v != testRegion { + t.Errorf("expected RegionAnnotation = %q, got %v", testRegion, v) } } From a4c6c4484d69646e1f38aabdb708dd0837d95ae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Fri, 8 May 2026 08:38:49 +0200 Subject: [PATCH 07/10] refactor: replace hardcoded values with constants in node annotation tests Co-authored-by: Copilot --- .golangci.yml | 1 + .../talos/reconcile_node_annotations_test.go | 58 ++++++++----------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 435fa72..24699d7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -20,6 +20,7 @@ issues: - errcheck - dupl - gosec + - goconst linters: # Enable a balanced set of linters for a Kubernetes operator diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go index 65880b0..2c2dc67 100644 --- a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go +++ b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go @@ -8,14 +8,6 @@ import ( metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -const ( - testNodeName = "node-1" - testRegion = "europe" - testNodePool = "pool-a" - testMachineClass = "large" - testMachineProvider = "kubevirt" -) - func TestExtractDatacenterInfo(t *testing.T) { t.Parallel() @@ -56,7 +48,7 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { ClusterId: "uuid-123", Project: "myproject", Environment: "prod", - Region: testRegion, + Region: "europe", Provider: "talos", }, }, @@ -64,12 +56,12 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { machine := &vitistackv1alpha1.Machine{ ObjectMeta: metav1.ObjectMeta{ - Name: testNodeName, - Annotations: map[string]string{vitistackv1alpha1.NodePoolAnnotation: testNodePool}, + Name: "node-1", + Annotations: map[string]string{vitistackv1alpha1.NodePoolAnnotation: "pool-a"}, }, - Spec: vitistackv1alpha1.MachineSpec{MachineClass: testMachineClass}, + Spec: vitistackv1alpha1.MachineSpec{MachineClass: "large"}, } - machine.Status.Provider = vitistackv1alpha1.MachineProviderType(testMachineProvider) + machine.Status.Provider = "kubevirt" result := buildDesiredNodeAnnotations(cluster, machine, "no", "1", "ws-ns", "infra-prod") @@ -80,16 +72,16 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { vitistackv1alpha1.EnvironmentAnnotation: "prod", vitistackv1alpha1.CountryAnnotation: "no", vitistackv1alpha1.AzAnnotation: "1", - vitistackv1alpha1.RegionAnnotation: testRegion, + vitistackv1alpha1.RegionAnnotation: "europe", vitistackv1alpha1.KubernetesProviderAnnotation: "talos", - vitistackv1alpha1.MachineProviderAnnotation: testMachineProvider, - vitistackv1alpha1.MachineClassAnnotation: testMachineClass, - vitistackv1alpha1.MachineIdAnnotation: testNodeName, + vitistackv1alpha1.MachineProviderAnnotation: "kubevirt", + vitistackv1alpha1.MachineClassAnnotation: "large", + vitistackv1alpha1.MachineIdAnnotation: "node-1", vitistackv1alpha1.ClusterWorkspaceAnnotation: "ws-ns", vitistackv1alpha1.MachineInfrastructureAnnotation: "infra-prod", - vitistackv1alpha1.VMProviderAnnotation: testMachineProvider, //nolint:staticcheck // testing deprecated annotation - vitistackv1alpha1.InfrastructureAnnotation: "infra-prod", //nolint:staticcheck // testing deprecated annotation - vitistackv1alpha1.NodePoolAnnotation: testNodePool, + vitistackv1alpha1.VMProviderAnnotation: "kubevirt", //nolint:staticcheck // testing deprecated annotation + vitistackv1alpha1.InfrastructureAnnotation: "infra-prod", //nolint:staticcheck // testing deprecated annotation + vitistackv1alpha1.NodePoolAnnotation: "pool-a", } for k, want := range checks { @@ -124,18 +116,18 @@ func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { vitistackv1alpha1.ClusterNameAnnotation: "old-name", vitistackv1alpha1.EnvironmentAnnotation: "dev", vitistackv1alpha1.MachineClassAnnotation: "medium", - vitistackv1alpha1.MachineIdAnnotation: testNodeName, + vitistackv1alpha1.MachineIdAnnotation: "node-1", vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", vitistackv1alpha1.ClusterProjectAnnotation: "proj", } desired := map[string]string{ - vitistackv1alpha1.ClusterNameAnnotation: "new-name", // changed - vitistackv1alpha1.EnvironmentAnnotation: "dev", // unchanged - vitistackv1alpha1.MachineClassAnnotation: testMachineClass, // changed - vitistackv1alpha1.MachineIdAnnotation: testNodeName, // unchanged - vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", // unchanged - vitistackv1alpha1.ClusterProjectAnnotation: "new-proj", // changed + vitistackv1alpha1.ClusterNameAnnotation: "new-name", // changed + vitistackv1alpha1.EnvironmentAnnotation: "dev", // unchanged + vitistackv1alpha1.MachineClassAnnotation: "large", // changed + vitistackv1alpha1.MachineIdAnnotation: "node-1", // unchanged + vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", // unchanged + vitistackv1alpha1.ClusterProjectAnnotation: "new-proj", // changed } patch := computeAnnotationPatch(current, desired) @@ -144,8 +136,8 @@ func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { if v, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; !ok || v != "new-name" { t.Errorf("expected ClusterNameAnnotation = 'new-name', got %v", v) } - if v, ok := patch[vitistackv1alpha1.MachineClassAnnotation]; !ok || v != testMachineClass { - t.Errorf("expected MachineClassAnnotation = %q, got %v", testMachineClass, v) + if v, ok := patch[vitistackv1alpha1.MachineClassAnnotation]; !ok || v != "large" { + t.Errorf("expected MachineClassAnnotation = 'large', got %v", v) } if v, ok := patch[vitistackv1alpha1.ClusterProjectAnnotation]; !ok || v != "new-proj" { t.Errorf("expected ClusterProjectAnnotation = 'new-proj', got %v", v) @@ -165,8 +157,8 @@ func TestComputeAnnotationPatch_DeletesManagedKeys(t *testing.T) { current := map[string]string{ vitistackv1alpha1.ClusterNameAnnotation: "c", - vitistackv1alpha1.NodePoolAnnotation: testNodePool, // managed key, not in desired - "some.other/annotation": "keep", // unmanaged, should be ignored + vitistackv1alpha1.NodePoolAnnotation: "pool-a", // managed key, not in desired + "some.other/annotation": "keep", // unmanaged, should be ignored } desired := map[string]string{ @@ -221,8 +213,8 @@ func TestComputeAnnotationPatch_AddsNewAnnotations(t *testing.T) { if v, ok := patch[vitistackv1alpha1.ClusterNameAnnotation]; !ok || v != "new-cluster" { t.Errorf("expected ClusterNameAnnotation = 'new-cluster', got %v", v) } - if v, ok := patch[vitistackv1alpha1.RegionAnnotation]; !ok || v != testRegion { - t.Errorf("expected RegionAnnotation = %q, got %v", testRegion, v) + if v, ok := patch[vitistackv1alpha1.RegionAnnotation]; !ok || v != "europe" { + t.Errorf("expected RegionAnnotation = 'europe', got %v", v) } } From 3473d3b0a898af5cb45257f33c6fc9821be23434 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Fri, 8 May 2026 08:52:33 +0200 Subject: [PATCH 08/10] refactor: format comments for consistency in node annotation tests --- .../talos/reconcile_node_annotations_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go index 2c2dc67..9509bb8 100644 --- a/internal/kubernetescluster/talos/reconcile_node_annotations_test.go +++ b/internal/kubernetescluster/talos/reconcile_node_annotations_test.go @@ -79,7 +79,7 @@ func TestBuildDesiredNodeAnnotations(t *testing.T) { vitistackv1alpha1.MachineIdAnnotation: "node-1", vitistackv1alpha1.ClusterWorkspaceAnnotation: "ws-ns", vitistackv1alpha1.MachineInfrastructureAnnotation: "infra-prod", - vitistackv1alpha1.VMProviderAnnotation: "kubevirt", //nolint:staticcheck // testing deprecated annotation + vitistackv1alpha1.VMProviderAnnotation: "kubevirt", //nolint:staticcheck // testing deprecated annotation vitistackv1alpha1.InfrastructureAnnotation: "infra-prod", //nolint:staticcheck // testing deprecated annotation vitistackv1alpha1.NodePoolAnnotation: "pool-a", } @@ -122,12 +122,12 @@ func TestComputeAnnotationPatch_UpdatesChanged(t *testing.T) { } desired := map[string]string{ - vitistackv1alpha1.ClusterNameAnnotation: "new-name", // changed - vitistackv1alpha1.EnvironmentAnnotation: "dev", // unchanged + vitistackv1alpha1.ClusterNameAnnotation: "new-name", // changed + vitistackv1alpha1.EnvironmentAnnotation: "dev", // unchanged vitistackv1alpha1.MachineClassAnnotation: "large", // changed vitistackv1alpha1.MachineIdAnnotation: "node-1", // unchanged - vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", // unchanged - vitistackv1alpha1.ClusterProjectAnnotation: "new-proj", // changed + vitistackv1alpha1.ClusterIdAnnotation: "uuid-1", // unchanged + vitistackv1alpha1.ClusterProjectAnnotation: "new-proj", // changed } patch := computeAnnotationPatch(current, desired) @@ -158,7 +158,7 @@ func TestComputeAnnotationPatch_DeletesManagedKeys(t *testing.T) { current := map[string]string{ vitistackv1alpha1.ClusterNameAnnotation: "c", vitistackv1alpha1.NodePoolAnnotation: "pool-a", // managed key, not in desired - "some.other/annotation": "keep", // unmanaged, should be ignored + "some.other/annotation": "keep", // unmanaged, should be ignored } desired := map[string]string{ From ee33a39caf855d516fe38375ed35c1f3b6b63c3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Fri, 8 May 2026 09:04:27 +0200 Subject: [PATCH 09/10] chore: update Go version to 1.26.3 in go.mod --- go.mod | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 77a95b2..2176b28 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/vitistack/talos-operator -go 1.26.2 +go 1.26.3 godebug default=go1.26 From 3f596b19f56c7d33f8e2528615b02e71db5c1b30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A5vard=20Elnan?= Date: Fri, 8 May 2026 09:04:31 +0200 Subject: [PATCH 10/10] refactor: reorganize exclusions and rules in golangci configuration --- .golangci.yml | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 24699d7..77f613b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -4,25 +4,28 @@ run: timeout: 5m allow-parallel-runners: true -issues: - exclude-use-default: false - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll - - path: _test\.go - linters: - - gocyclo - - errcheck - - dupl - - gosec - - goconst - linters: + exclusions: + presets: + - comments + - std-error-handling + - common-false-positives + rules: + - path: "api/*" + linters: + - lll + - path: "internal/*" + linters: + - dupl + - lll + - path: _test\.go + linters: + - gocyclo + - errcheck + - dupl + - gosec + - goconst + # Enable a balanced set of linters for a Kubernetes operator enable: # Default linters