From e1f6fd9f273fd5dc938be8c32b11101eab39245b Mon Sep 17 00:00:00 2001 From: Andreas Karis Date: Fri, 22 Sep 2023 18:43:57 +0200 Subject: [PATCH 1/2] Fix typo NetworkAttachementDefinition Signed-off-by: Andreas Karis --- api/v1/helper.go | 12 ++++++------ doc/ovs-hw-offload.md | 2 +- doc/quickstart.md | 2 +- doc/vdpa.md | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/api/v1/helper.go b/api/v1/helper.go index 614fa4520..735252044 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -483,8 +483,8 @@ func (s *SriovNetworkNodeState) GetDriverByPciAddress(addr string) string { // RenderNetAttDef renders a net-att-def for ib-sriov CNI func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) { - logger := log.WithName("renderNetAttDef") - logger.Info("Start to render IB SRIOV CNI NetworkAttachementDefinition") + logger := log.WithName("RenderNetAttDef") + logger.Info("Start to render IB SRIOV CNI NetworkAttachmentDefinition") // render RawCNIConfig manifests data := render.MakeRenderData() @@ -535,7 +535,7 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) { } for _, obj := range objs { raw, _ := json.Marshal(obj) - logger.Info("render NetworkAttachementDefinition output", "raw", string(raw)) + logger.Info("render NetworkAttachmentDefinition output", "raw", string(raw)) } return objs[0], nil } @@ -564,8 +564,8 @@ func (cr *SriovIBNetwork) DeleteNetAttDef(c client.Client) error { // RenderNetAttDef renders a net-att-def for sriov CNI func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) { - logger := log.WithName("renderNetAttDef") - logger.Info("Start to render SRIOV CNI NetworkAttachementDefinition") + logger := log.WithName("RenderNetAttDef") + logger.Info("Start to render SRIOV CNI NetworkAttachmentDefinition") // render RawCNIConfig manifests data := render.MakeRenderData() @@ -665,7 +665,7 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) { } for _, obj := range objs { raw, _ := json.Marshal(obj) - logger.Info("render NetworkAttachementDefinition output", "raw", string(raw)) + logger.Info("render NetworkAttachmentDefinition output", "raw", string(raw)) } return objs[0], nil } diff --git a/doc/ovs-hw-offload.md b/doc/ovs-hw-offload.md index b9be9d836..1c2115239 100644 --- a/doc/ovs-hw-offload.md +++ b/doc/ovs-hw-offload.md @@ -48,7 +48,7 @@ spec: linkType: eth ``` -### Create NetworkAttachementDefinition CRD with OVS CNI config +### Create NetworkAttachmentDefinition CRD with OVS CNI config ```yaml apiVersion: "k8s.cni.cncf.io/v1" diff --git a/doc/quickstart.md b/doc/quickstart.md index a3c5d3ead..bd28a33dd 100644 --- a/doc/quickstart.md +++ b/doc/quickstart.md @@ -218,7 +218,7 @@ $ kubectl get no -o json | jq -r '[.items[] | {name:.metadata.name, allocable:.s ] ``` -Now you can create a SriovNetwork CR which refer to the 'resourceName' defined in SriovNetworkNodePolicy. Then a NetworkAttachementDefinition CR will be generated by operator with the same name and namespace. +Now you can create a SriovNetwork CR which refer to the 'resourceName' defined in SriovNetworkNodePolicy. Then a NetworkAttachmentDefinition CR will be generated by operator with the same name and namespace. Here is an example: diff --git a/doc/vdpa.md b/doc/vdpa.md index cbb422081..e15356b84 100644 --- a/doc/vdpa.md +++ b/doc/vdpa.md @@ -49,7 +49,7 @@ spec: vdpaType: virtio ``` -### Create NetworkAttachementDefinition CRD with OVN-K CNI config +### Create NetworkAttachmentDefinition CRD with OVN-K CNI config ```yaml apiVersion: "k8s.cni.cncf.io/v1" From 3a69bf8560b757ba09aa6054614da5bf3070a032 Mon Sep 17 00:00:00 2001 From: Andreas Karis Date: Fri, 22 Sep 2023 18:44:07 +0200 Subject: [PATCH 2/2] Support logLevel and logFile for SR-IOV plugin The SR-IOV device plugin now supports the configuration of logLevel and logFile. Expose these settings through the API. Signed-off-by: Andreas Karis --- api/v1/helper.go | 9 +++++++++ api/v1/sriovnetwork_types.go | 8 ++++++++ .../cni-config/sriov-cni-config.yaml | 6 ++++++ ...iovnetwork.openshift.io_sriovnetworks.yaml | 18 +++++++++++++++++ controllers/sriovnetwork_controller_test.go | 20 +++++++++++++++++-- ...iovnetwork.openshift.io_sriovnetworks.yaml | 18 +++++++++++++++++ 6 files changed, 77 insertions(+), 2 deletions(-) diff --git a/api/v1/helper.go b/api/v1/helper.go index 735252044..68e77c66a 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -529,6 +529,10 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) { data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig } + // logLevel and logFile are currently not supports by the ip-sriov-cni -> hardcode them to false. + data.Data["LogLevelConfigured"] = false + data.Data["LogFileConfigured"] = false + objs, err := render.RenderDir(ManifestsPath, &data) if err != nil { return nil, err @@ -659,6 +663,11 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) { data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig } + data.Data["LogLevelConfigured"] = (cr.Spec.LogLevel != "") + data.Data["LogLevel"] = cr.Spec.LogLevel + data.Data["LogFileConfigured"] = (cr.Spec.LogFile != "") + data.Data["LogFile"] = cr.Spec.LogFile + objs, err := render.RenderDir(ManifestsPath, &data) if err != nil { return nil, err diff --git a/api/v1/sriovnetwork_types.go b/api/v1/sriovnetwork_types.go index 40da9fc01..8104bf50e 100644 --- a/api/v1/sriovnetwork_types.go +++ b/api/v1/sriovnetwork_types.go @@ -63,6 +63,14 @@ type SriovNetworkSpec struct { // MetaPluginsConfig configuration to be used in order to chain metaplugins to the sriov interface returned // by the operator. MetaPluginsConfig string `json:"metaPlugins,omitempty"` + // LogLevel sets the log level of the SRIOV CNI plugin - either of panic, error, warning, info, debug. Defaults + // to info if left blank. + // +kubebuilder:validation:Enum={"panic", "error","warning","info","debug",""} + // +kubebuilder:default:= "info" + LogLevel string `json:"logLevel,omitempty"` + // LogFile sets the log file of the SRIOV CNI plugin logs. If unset (default), this will log to stderr and thus + // to multus and container runtime logs. + LogFile string `json:"logFile,omitempty"` } // SriovNetworkStatus defines the observed state of SriovNetwork diff --git a/bindata/manifests/cni-config/sriov-cni-config.yaml b/bindata/manifests/cni-config/sriov-cni-config.yaml index 322dfaa05..6e917e528 100644 --- a/bindata/manifests/cni-config/sriov-cni-config.yaml +++ b/bindata/manifests/cni-config/sriov-cni-config.yaml @@ -40,6 +40,12 @@ spec: {{- end -}} {{- if .StateConfigured -}} "link_state":"{{.SriovCniState}}", +{{- end -}} +{{- if .LogLevelConfigured -}} + "logLevel":"{{.LogLevel}}", +{{- end -}} +{{- if .LogFileConfigured -}} + "logFile":"{{.LogFile}}", {{- end -}} {{.SriovCniIpam}} } diff --git a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml index f8e48de40..15e1bfd3f 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml @@ -49,6 +49,24 @@ spec: - enable - disable type: string + logFile: + description: LogFile sets the log file of the SRIOV CNI plugin logs. + If unset (default), this will log to stderr and thus to multus and + container runtime logs. + type: string + logLevel: + default: info + description: LogLevel sets the log level of the SRIOV CNI plugin - + either of panic, error, warning, info, debug. Defaults to info if + left blank. + enum: + - panic + - error + - warning + - info + - debug + - "" + type: string maxTxRate: description: Maximum tx rate, in Mbps, for the VF. Defaults to 0 (no rate limiting) diff --git a/controllers/sriovnetwork_controller_test.go b/controllers/sriovnetwork_controller_test.go index 38fe69e00..f4eb42020 100644 --- a/controllers/sriovnetwork_controller_test.go +++ b/controllers/sriovnetwork_controller_test.go @@ -57,6 +57,12 @@ 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"}`, }, + "test-5": { + 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"}`, + LogLevel: "debug", + LogFile: "/tmp/tmpfile", + }, } sriovnets := util.GenerateSriovNetworkCRs(testNamespace, specs) DescribeTable("should be possible to create/delete net-att-def", @@ -95,6 +101,7 @@ var _ = Describe("SriovNetwork Controller", func() { 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 LogLevel and LogFile", sriovnets["test-5"]), ) newSpecs := map[string]sriovnetworkv1.SriovNetworkSpec{ @@ -274,6 +281,8 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string { spoofchk := "" trust := "" vlanProto := "" + logLevel := `"logLevel":"info",` + logFile := "" ipam := emptyCurls if cr.Spec.Trust == sriovnetworkv1.SriovCniStateOn { @@ -298,9 +307,16 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string { if cr.Spec.VlanProto != "" { vlanProto = fmt.Sprintf(`"vlanProto": "%s",`, cr.Spec.VlanProto) } + if cr.Spec.LogLevel != "" { + logLevel = fmt.Sprintf(`"logLevel":"%s",`, cr.Spec.LogLevel) + } + if cr.Spec.LogFile != "" { + logFile = fmt.Sprintf(`"logFile":"%s",`, cr.Spec.LogFile) + } - configStr, err := formatJSON(fmt.Sprintf(`{ "cniVersion":"0.3.1", "name":"%s","type":"sriov","vlan":%d,%s%s"vlanQoS":%d,%s%s"ipam":%s }`, - cr.GetName(), cr.Spec.Vlan, spoofchk, trust, vlanQoS, vlanProto, state, ipam)) + configStr, err := formatJSON(fmt.Sprintf( + `{ "cniVersion":"0.3.1", "name":"%s","type":"sriov","vlan":%d,%s%s"vlanQoS":%d,%s%s%s%s"ipam":%s }`, + cr.GetName(), cr.Spec.Vlan, spoofchk, trust, vlanQoS, vlanProto, state, logLevel, logFile, ipam)) if err != nil { panic(err) } diff --git a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml index f8e48de40..15e1bfd3f 100644 --- a/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml +++ b/deployment/sriov-network-operator/crds/sriovnetwork.openshift.io_sriovnetworks.yaml @@ -49,6 +49,24 @@ spec: - enable - disable type: string + logFile: + description: LogFile sets the log file of the SRIOV CNI plugin logs. + If unset (default), this will log to stderr and thus to multus and + container runtime logs. + type: string + logLevel: + default: info + description: LogLevel sets the log level of the SRIOV CNI plugin - + either of panic, error, warning, info, debug. Defaults to info if + left blank. + enum: + - panic + - error + - warning + - info + - debug + - "" + type: string maxTxRate: description: Maximum tx rate, in Mbps, for the VF. Defaults to 0 (no rate limiting)