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

Respect existing eniConfig label if set on node. #1596

Merged
merged 5 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 8 additions & 2 deletions pkg/eniconfig/eniconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const (
defaultEniConfigAnnotationDef = "k8s.amazonaws.com/eniConfig"
defaultEniConfigLabelDef = "k8s.amazonaws.com/eniConfig"
eniConfigDefault = "default"
eniConfigLabel = "vpc.amazonaws.com/eniConfig"

// when "ENI_CONFIG_LABEL_DEF is defined, ENIConfigController will use that label key to
// search if is setting value for eniConfigLabelDef
Expand Down Expand Up @@ -135,8 +136,13 @@ func GetNodeSpecificENIConfigName(ctx context.Context, k8sClient client.Client)
eniConfigName = val
if val != eniConfigDefault {
labels := node.GetLabels()
labels["vpc.amazonaws.com/eniConfig"] = eniConfigName
node.SetLabels(labels)
if labels[eniConfigLabel] == "" {
//Only set if the label is not already set.
labels[eniConfigLabel] = eniConfigName
node.SetLabels(labels)
} else {
jayanthvn marked this conversation as resolved.
Show resolved Hide resolved
return labels[eniConfigLabel], nil
}
}

return eniConfigName, nil
Expand Down
24 changes: 24 additions & 0 deletions pkg/eniconfig/eniconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ func TestMyENIConfig(t *testing.T) {
},
}

testENIConfigCustom := &v1alpha1.ENIConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "custom",
},
Spec: v1alpha1.ENIConfigSpec{
SecurityGroups: []string{"SG1"},
Subnet: "SB1",
},
}

type env struct {
nodes []*corev1.Node
eniconfigs []*v1alpha1.ENIConfig
Expand Down Expand Up @@ -167,6 +177,20 @@ func TestMyENIConfig(t *testing.T) {
want: &testENIConfigAZ1.Spec,
wantErr: nil,
},
{
name: "Matching ENIConfig available - Using label",
env: env{
nodes: []*corev1.Node{testNode},
eniconfigs: []*v1alpha1.ENIConfig{testENIConfigAZ1, testENIConfigCustom},
Labels: map[string]string{
"vpc.amazonaws.com/eniConfig": "custom",
"failure-domain.beta.kubernetes.io/zone": "az2",
},
eniConfigLabelKey: "failure-domain.beta.kubernetes.io/zone",
},
want: &testENIConfigCustom.Spec,
wantErr: nil,
},
{
name: "No Matching ENIConfig available - Using Custom Label Key exposed via ENI_CONFIG_ANNOTATION_DEF",
env: env{
Expand Down