From 35ed8902ae90d21db6873c78f0533a077b2cd416 Mon Sep 17 00:00:00 2001 From: Sushmitha Ravikumar <58063229+sushrk@users.noreply.github.com> Date: Mon, 18 Mar 2024 17:25:22 -0700 Subject: [PATCH] fix:update cluster tag name in CNINode (#386) --- controllers/crds/cninode_controller.go | 12 +++++------- pkg/config/type.go | 1 + pkg/k8s/wrapper.go | 2 +- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/controllers/crds/cninode_controller.go b/controllers/crds/cninode_controller.go index a67d08d2..ac1cb1bd 100644 --- a/controllers/crds/cninode_controller.go +++ b/controllers/crds/cninode_controller.go @@ -15,7 +15,6 @@ package crds import ( "context" - "fmt" "time" "github.com/aws/amazon-vpc-resource-controller-k8s/apis/vpcresources/v1alpha1" @@ -94,15 +93,14 @@ func (r *CNINodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct if cniNode.GetDeletionTimestamp().IsZero() { // Add cluster name tag if it does not exist - clusterNameTagKey := fmt.Sprintf(config.ClusterNameTagKeyFormat, r.ClusterName) - val, ok := cniNode.Spec.Tags[clusterNameTagKey] - if !ok || val != config.ClusterNameTagValue { + val, ok := cniNode.Spec.Tags[config.CNINodeClusterNameKey] + if !ok || val != r.ClusterName { cniNodeCopy := cniNode.DeepCopy() if len(cniNodeCopy.Spec.Tags) != 0 { - cniNodeCopy.Spec.Tags[clusterNameTagKey] = config.ClusterNameTagValue + cniNodeCopy.Spec.Tags[config.CNINodeClusterNameKey] = r.ClusterName } else { cniNodeCopy.Spec.Tags = map[string]string{ - clusterNameTagKey: config.ClusterNameTagValue, + config.CNINodeClusterNameKey: r.ClusterName, } } return ctrl.Result{}, r.Client.Patch(ctx, cniNodeCopy, client.MergeFromWithOptions(cniNode, client.MergeFromWithOptimisticLock{})) @@ -181,7 +179,7 @@ func (r *CNINodeReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct recreateCNINodeErrCount.Inc() // raise event on node publish warning that CNINode is deleted and could not be recreated by controller utils.SendNodeEventWithNodeName(r.K8sAPI, node.Name, utils.CNINodeCreateFailed, - fmt.Sprint("CNINode was deleted and failed to be recreated by the vpc-resource-controller"), v1.EventTypeWarning, r.Log) + "CNINode was deleted and failed to be recreated by the vpc-resource-controller", v1.EventTypeWarning, r.Log) // return nil as deleted and we cannot recreate the object now return ctrl.Result{}, nil } diff --git a/pkg/config/type.go b/pkg/config/type.go index a0c271cb..894b57b8 100644 --- a/pkg/config/type.go +++ b/pkg/config/type.go @@ -68,6 +68,7 @@ const ( NetworkInterfaceOwnerTagValue = "eks-vpc-resource-controller" NetworkInterfaceOwnerVPCCNITagValue = "amazon-vpc-cni" NetworkInterfaceNodenameKey = "node.k8s.amazonaws.com/nodename" + CNINodeClusterNameKey = "cluster.k8s.amazonaws.com/name" ) const ( diff --git a/pkg/k8s/wrapper.go b/pkg/k8s/wrapper.go index 90e8355f..fdb7c57d 100644 --- a/pkg/k8s/wrapper.go +++ b/pkg/k8s/wrapper.go @@ -253,7 +253,7 @@ func (k *k8sWrapper) CreateCNINode(node *v1.Node, clusterName string) error { }, Spec: rcv1alpha1.CNINodeSpec{ Tags: map[string]string{ - fmt.Sprintf(config.ClusterNameTagKeyFormat, clusterName): config.ClusterNameTagValue, + fmt.Sprintf(config.CNINodeClusterNameKey): clusterName, }, }, }