Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:update cluster tag name in CNINode #386

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading