Skip to content

Commit

Permalink
Address comments
Browse files Browse the repository at this point in the history
* use "cni.exclusive=false" by default
* only check if the annotation is set, do not expect an actual
  boolean value
* s/AnnotationCniExclusive/AnnotationCNIExclusive
  • Loading branch information
petrutlucian94 committed Nov 26, 2024
1 parent c3c6449 commit 7449524
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 23 deletions.
4 changes: 1 addition & 3 deletions src/k8s/pkg/k8sd/features/cilium/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,7 @@ func internalConfig(annotations types.Annotations) (config, error) {
c.vlanBPFBypass = vlanTags
}

if v, ok := annotations.Get(apiv1_annotations.AnnotationCniExclusive); ok {
c.cniExclusive = v == "true"
} else {
if _, ok := annotations.Get(apiv1_annotations.AnnotationCNIExclusive); ok {
c.cniExclusive = true
}

Expand Down
15 changes: 4 additions & 11 deletions src/k8s/pkg/k8sd/features/cilium/internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestInternalConfig(t *testing.T) {
devices: "",
directRoutingDevice: "",
vlanBPFBypass: nil,
cniExclusive: true,
cniExclusive: false,
},
expectError: false,
},
Expand All @@ -31,20 +31,19 @@ func TestInternalConfig(t *testing.T) {
apiv1_annotations.AnnotationDevices: "eth+ lxdbr+",
apiv1_annotations.AnnotationDirectRoutingDevice: "eth0",
apiv1_annotations.AnnotationVLANBPFBypass: "1,2,3",
apiv1_annotations.AnnotationCniExclusive: "false",
apiv1_annotations.AnnotationCNIExclusive: "false",
},
expectedConfig: config{
devices: "eth+ lxdbr+",
directRoutingDevice: "eth0",
vlanBPFBypass: []int{1, 2, 3},
cniExclusive: false,
},
expectError: false,
},
{
name: "Cilum exclusive CNI",
annotations: map[string]string{
apiv1_annotations.AnnotationCniExclusive: "true",
apiv1_annotations.AnnotationCNIExclusive: "true",
},
expectedConfig: config{
devices: "",
Expand All @@ -61,7 +60,6 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
vlanBPFBypass: []int{1},
cniExclusive: true,
},
expectError: false,
},
Expand All @@ -72,7 +70,6 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
vlanBPFBypass: []int{1, 2, 3, 4, 5},
cniExclusive: true,
},
expectError: false,
},
Expand All @@ -83,7 +80,6 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
vlanBPFBypass: []int{0},
cniExclusive: true,
},
expectError: false,
},
Expand Down Expand Up @@ -115,7 +111,6 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
vlanBPFBypass: []int{1, 2, 3},
cniExclusive: true,
},
expectError: false,
},
Expand All @@ -126,7 +121,6 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
vlanBPFBypass: []int{1, 2, 3, 4, 5},
cniExclusive: true,
},
expectError: false,
},
Expand All @@ -140,7 +134,7 @@ func TestInternalConfig(t *testing.T) {
{
name: "Nil annotations",
annotations: nil,
expectedConfig: config{cniExclusive: true},
expectedConfig: config{},
expectError: false,
},
{
Expand All @@ -150,7 +144,6 @@ func TestInternalConfig(t *testing.T) {
},
expectedConfig: config{
vlanBPFBypass: []int{1, 2, 3},
cniExclusive: true,
},
expectError: false,
},
Expand Down
14 changes: 5 additions & 9 deletions src/k8s/pkg/k8sd/features/cilium/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func TestNetworkEnabled(t *testing.T) {
validateNetworkValues(g, callArgs.Values, network, snapM)
})

t.Run("cniExclusiveDisabled", func(t *testing.T) {
t.Run("CNIExclusive", func(t *testing.T) {
g := NewWithT(t)

helmM := &helmmock.Mock{}
Expand All @@ -203,7 +203,7 @@ func TestNetworkEnabled(t *testing.T) {
testAnnotations := types.Annotations{
apiv1_annotations.AnnotationDevices: "eth+ lxdbr+",
apiv1_annotations.AnnotationDirectRoutingDevice: "eth0",
apiv1_annotations.AnnotationCniExclusive: "false",
apiv1_annotations.AnnotationCNIExclusive: "true",
}
status, err := ApplyNetwork(context.Background(), snapM, "127.0.0.1", apiserver, network, testAnnotations)

Expand All @@ -218,7 +218,7 @@ func TestNetworkEnabled(t *testing.T) {
g.Expect(callArgs.State).To(Equal(helm.StatePresent))

cniValues := callArgs.Values["cni"].(map[string]interface{})
g.Expect(cniValues["exclusive"]).To(BeFalse())
g.Expect(cniValues["exclusive"]).To(BeTrue())
})
}

Expand Down Expand Up @@ -435,11 +435,7 @@ func validateNetworkValues(g Gomega, values map[string]any, network types.Networ
g.Expect(values["nodePort"].(map[string]any)["directRoutingDevice"]).To(Equal(directRoutingDevice))
}

cniExclusiveStr, exists := annotations.Get(apiv1_annotations.AnnotationCniExclusive)
_, exists = annotations.Get(apiv1_annotations.AnnotationCNIExclusive)
cniValues := values["cni"].(map[string]interface{})
if exists {
g.Expect(cniValues["exclusive"]).To(Equal(cniExclusiveStr == "true"))
} else {
g.Expect(cniValues["exclusive"]).To(BeTrue())
}
g.Expect(cniValues["exclusive"]).To(Equal(exists))
}

0 comments on commit 7449524

Please sign in to comment.