Skip to content

Commit

Permalink
Add AllMuticast mode support
Browse files Browse the repository at this point in the history
The sriov cni has a new option to enable allmulticast mode on the VF.
These changes allows users to enable this mode via the SriovNetwork object.

Signed-off-by: Marcelo Guerrero <[email protected]>
  • Loading branch information
mlguerrero12 committed Jun 20, 2023
1 parent 109c2c2 commit 9d4ba88
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 2 deletions.
10 changes: 10 additions & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,16 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) {
data.Data["TrustConfigured"] = false
}

data.Data["AllMulticastConfigured"] = true
switch cr.Spec.AllMulticast {
case SriovCniStateOn:
data.Data["SriovCniAllMulticast"] = SriovCniStateOn
case SriovCniStateOff:
data.Data["SriovCniAllMulticast"] = SriovCniStateOff
default:
data.Data["AllMulticastConfigured"] = false
}

data.Data["StateConfigured"] = true
switch cr.Spec.LinkState {
case SriovCniStateEnable:
Expand Down
3 changes: 3 additions & 0 deletions api/v1/sriovnetwork_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ type SriovNetworkSpec struct {
// VF trust mode (on|off)
// +kubebuilder:validation:Enum={"on","off"}
Trust string `json:"trust,omitempty"`
// AllMulticast mode (on|off)
// +kubebuilder:validation:Enum={"on","off"}
AllMulticast string `json:"allMulticast,omitempty"`
// VF link state (enable|disable|auto)
// +kubebuilder:validation:Enum={"auto","enable","disable"}
LinkState string `json:"linkState,omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions bindata/manifests/cni-config/sriov-cni-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ spec:
{{- if .TrustConfigured -}}
"trust":"{{.SriovCniTrust}}",
{{- end -}}
{{- if .AllMulticastConfigured -}}
"all_multicast":"{{.SriovCniAllMulticast}}",
{{- end -}}
{{- if .VlanQoSConfigured -}}
"vlanQoS":{{.SriovCniVlanQoS}},
{{- end -}}
Expand Down
4 changes: 4 additions & 0 deletions bindata/manifests/operator-webhook/003-webhook.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,7 @@ webhooks:
apiGroups: ["sriovnetwork.openshift.io"]
apiVersions: ["v1"]
resources: ["sriovnetworknodepolicies"]
- operations: [ "CREATE", "UPDATE" ]
apiGroups: [ "sriovnetwork.openshift.io" ]
apiVersions: [ "v1" ]
resources: [ "sriovnetworks" ]
6 changes: 6 additions & 0 deletions config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ spec:
spec:
description: SriovNetworkSpec defines the desired state of SriovNetwork
properties:
allMulticast:
description: AllMulticast mode (on|off)
enum:
- "on"
- "off"
type: string
capabilities:
description: 'Capabilities to be configured for this network. Capabilities
supported: (mac|ips), e.g. ''{"mac": true}'''
Expand Down
12 changes: 10 additions & 2 deletions controllers/sriovnetwork_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var _ = Describe("SriovNetwork Controller", func() {
ResourceName: "resource_1",
IPAM: `{"type":"host-local","subnet":"10.56.217.0/24","rangeStart":"10.56.217.171","rangeEnd":"10.56.217.181","routes":[{"dst":"0.0.0.0/0"}],"gateway":"10.56.217.1"}`,
Trust: on,
AllMulticast: on,
},
"test-4": {
ResourceName: "resource_1",
Expand Down Expand Up @@ -90,7 +91,7 @@ var _ = Describe("SriovNetwork Controller", func() {
Entry("with vlan flag", sriovnets["test-0"]),
Entry("with networkNamespace flag", sriovnets["test-1"]),
Entry("with SpoofChk flag on", sriovnets["test-2"]),
Entry("with Trust flag on", sriovnets["test-3"]),
Entry("with Trust and AllMulticast on", sriovnets["test-3"]),
)

newSpecs := map[string]sriovnetworkv1.SriovNetworkSpec{
Expand Down Expand Up @@ -220,6 +221,7 @@ var _ = Describe("SriovNetwork Controller", func() {
func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string {
spoofchk := ""
trust := ""
allMulticast := ""
ipam := emptyCurls

if cr.Spec.Trust == sriovnetworkv1.SriovCniStateOn {
Expand All @@ -228,6 +230,12 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string {
trust = `"trust":"off",`
}

if cr.Spec.AllMulticast == sriovnetworkv1.SriovCniStateOn {
trust = `"all_multicast":"on",`
} else if cr.Spec.AllMulticast == sriovnetworkv1.SriovCniStateOff {
trust = `"all_multicast":"off",`
}

if cr.Spec.SpoofChk == sriovnetworkv1.SriovCniStateOn {
spoofchk = `"spoofchk":"on",`
} else if cr.Spec.SpoofChk == sriovnetworkv1.SriovCniStateOff {
Expand All @@ -241,7 +249,7 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string {
}
vlanQoS := cr.Spec.VlanQoS

configStr, err := formatJSON(fmt.Sprintf(`{ "cniVersion":"0.3.1", "name":"%s","type":"sriov","vlan":%d,%s%s%s"vlanQoS":%d,"ipam":%s }`, cr.GetName(), cr.Spec.Vlan, spoofchk, trust, state, vlanQoS, ipam))
configStr, err := formatJSON(fmt.Sprintf(`{ "cniVersion":"0.3.1", "name":"%s","type":"sriov","vlan":%d,%s%s%s"vlanQoS":%d,%s"ipam":%s }`, cr.GetName(), cr.Spec.Vlan, spoofchk, trust, allMulticast, vlanQoS, state, ipam))
if err != nil {
panic(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ spec:
spec:
description: SriovNetworkSpec defines the desired state of SriovNetwork
properties:
allMulticast:
description: AllMulticast mode (on|off)
enum:
- "on"
- "off"
type: string
capabilities:
description: 'Capabilities to be configured for this network. Capabilities
supported: (mac|ips), e.g. ''{"mac": true}'''
Expand Down
13 changes: 13 additions & 0 deletions pkg/webhook/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,19 @@ func validateSriovOperatorConfig(cr *sriovnetworkv1.SriovOperatorConfig, operati
return false, warnings, fmt.Errorf("only default SriovOperatorConfig is used")
}

func validateSriovNetwork(cr *sriovnetworkv1.SriovNetwork, operation v1.Operation) (bool, []string, error) {
glog.V(2).Infof("validateSriovNetwork: %v", cr)
var warnings []string

if operation == v1.Create || operation == v1.Update {
if cr.Spec.AllMulticast == sriovnetworkv1.SriovCniStateOn && cr.Spec.Trust != sriovnetworkv1.SriovCniStateOn {
return false, warnings, fmt.Errorf("trust must be enabled in order to set allMulticast on")
}
}

return true, warnings, nil
}

func validateSriovNetworkNodePolicy(cr *sriovnetworkv1.SriovNetworkNodePolicy, operation v1.Operation) (bool, []string, error) {
glog.V(2).Infof("validateSriovNetworkNodePolicy: %v", cr)
var warnings []string
Expand Down
34 changes: 34 additions & 0 deletions pkg/webhook/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,40 @@ func TestValidateSriovOperatorConfigWithDefaultOperatorConfig(t *testing.T) {
g.Expect(ok).To(Equal(true))
}

func TestValidateSriovNetworkAllMulticast(t *testing.T) {
var err error
var ok bool

network := &SriovNetwork{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: SriovNetworkSpec{
AllMulticast: "on",
Trust: "on",
},
}

g := NewGomegaWithT(t)
ok, _, err = validateSriovNetwork(network, "CREATE")
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ok).To(Equal(true))

ok, _, err = validateSriovNetwork(network, "UPDATE")
g.Expect(err).NotTo(HaveOccurred())
g.Expect(ok).To(Equal(true))

network.Spec.Trust = "off"

ok, _, err = validateSriovNetwork(network, "CREATE")
g.Expect(err).To(HaveOccurred())
g.Expect(ok).To(Equal(false))

ok, _, err = validateSriovNetwork(network, "UPDATE")
g.Expect(err).To(HaveOccurred())
g.Expect(ok).To(Equal(false))
}

func TestValidateSriovNetworkNodePolicyWithDefaultPolicy(t *testing.T) {
var err error
var ok bool
Expand Down
14 changes: 14 additions & 0 deletions pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ func ValidateCustomResource(ar v1.AdmissionReview) *v1.AdmissionResponse {
Reason: metav1.StatusReason(err.Error()),
}
}
case "SriovNetwork":
network := sriovnetworkv1.SriovNetwork{}

err = json.Unmarshal(raw, &network)
if err != nil {
glog.Error(err)
return toV1AdmissionResponse(err)
}

if reviewResponse.Allowed, reviewResponse.Warnings, err = validateSriovNetwork(&network, ar.Request.Operation); err != nil {
reviewResponse.Result = &metav1.Status{
Reason: metav1.StatusReason(err.Error()),
}
}
case "SriovOperatorConfig":
config := sriovnetworkv1.SriovOperatorConfig{}

Expand Down

0 comments on commit 9d4ba88

Please sign in to comment.