Skip to content

Commit

Permalink
fix:update cluster tag name in CNINode (aws#386)
Browse files Browse the repository at this point in the history
  • Loading branch information
sushrk committed Apr 30, 2024
1 parent cf1c49b commit 35ed890
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
12 changes: 5 additions & 7 deletions controllers/crds/cninode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package crds

import (
"context"
"fmt"
"time"

"github.com/aws/amazon-vpc-resource-controller-k8s/apis/vpcresources/v1alpha1"
Expand Down Expand Up @@ -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{}))
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/config/type.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion pkg/k8s/wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down

0 comments on commit 35ed890

Please sign in to comment.