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 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
16 changes: 12 additions & 4 deletions pkg/eniconfig/eniconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ const (
defaultEniConfigAnnotationDef = "k8s.amazonaws.com/eniConfig"
defaultEniConfigLabelDef = "k8s.amazonaws.com/eniConfig"
eniConfigDefault = "default"
eniConfigLabel = "vpc.amazonaws.com/eniConfig"

// when this is defined, it is to be treated as the source of truth for the eniconfig.
// it is meant to be used for out-of-band mananagement of the eniConfig - i.e. on the kubelet or elsewhere
externalEniConfigLabel = "vpc.amazonaws.com/externalEniConfig"

// 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 @@ -123,12 +128,15 @@ func GetNodeSpecificENIConfigName(ctx context.Context, k8sClient client.Client)
return eniConfigName, err
}

//Derive ENIConfig Name from either Node Annotations or Labels
val, ok := node.GetAnnotations()[getEniConfigAnnotationDef()]
//Derive ENIConfig Name from either externally managed label, Node Annotations or Labels
val, ok := node.GetLabels()[externalEniConfigLabel]
if !ok {
val, ok = node.GetLabels()[getEniConfigLabelDef()]
val, ok = node.GetAnnotations()[getEniConfigAnnotationDef()]
if !ok {
val = eniConfigDefault
val, ok = node.GetLabels()[getEniConfigLabelDef()]
if !ok {
val = eniConfigDefault
}
}
}

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 external label",
env: env{
nodes: []*corev1.Node{testNode},
eniconfigs: []*v1alpha1.ENIConfig{testENIConfigAZ1, testENIConfigCustom},
Labels: map[string]string{
"vpc.amazonaws.com/externalEniConfig": "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