Skip to content

Commit

Permalink
fix: use existing eni label if set
Browse files Browse the repository at this point in the history
Signed-off-by: Jonah Back <[email protected]>
  • Loading branch information
backjo committed Aug 28, 2021
1 parent beee06a commit 55f8965
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
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 {
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

0 comments on commit 55f8965

Please sign in to comment.