From d3788a1cc16ff93e1715b0486c6ef1b8010e4e5d Mon Sep 17 00:00:00 2001 From: Andreas Karis Date: Fri, 22 Sep 2023 18:44:07 +0200 Subject: [PATCH] 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 | 14 +++++++++++++ api/v1/sriovnetwork_types.go | 7 +++++++ .../cni-config/sriov-cni-config.yaml | 6 ++++++ ...iovnetwork.openshift.io_sriovnetworks.yaml | 17 ++++++++++++++++ controllers/sriovnetwork_controller_test.go | 20 ++++++++++++++++++- ...iovnetwork.openshift.io_sriovnetworks.yaml | 17 ++++++++++++++++ 6 files changed, 80 insertions(+), 1 deletion(-) diff --git a/api/v1/helper.go b/api/v1/helper.go index 5bd845607..95f15e904 100644 --- a/api/v1/helper.go +++ b/api/v1/helper.go @@ -528,6 +528,9 @@ func (cr *SriovIBNetwork) RenderNetAttDef() (*uns.Unstructured, error) { data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig } + data.Data["LogLevelConfigured"] = false + data.Data["LogFileConfigured"] = false + objs, err := render.RenderDir(ManifestsPath, &data) if err != nil { return nil, err @@ -652,6 +655,17 @@ func (cr *SriovNetwork) RenderNetAttDef() (*uns.Unstructured, error) { data.Data["MetaPlugins"] = cr.Spec.MetaPluginsConfig } + data.Data["LogLevelConfigured"] = false + if cr.Spec.LogLevel != "" { + data.Data["LogLevelConfigured"] = true + data.Data["LogLevel"] = cr.Spec.LogLevel + } + data.Data["LogFileConfigured"] = false + if cr.Spec.LogFile != "" { + data.Data["LogFileConfigured"] = true + 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 eac7238d8..f9166f8b7 100644 --- a/api/v1/sriovnetwork_types.go +++ b/api/v1/sriovnetwork_types.go @@ -60,6 +60,13 @@ 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 device plugin - either of panic, error, warning, info, debug. Defaults + // to info if left blank. + // +kubebuilder:validation:Enum={"panic", "error","warning","info","debug",""} + LogLevel string `json:"logLevel,omitempty"` + // LogFile sets the log file of the SRIOV device 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 cac67c65c..6cae7703f 100644 --- a/bindata/manifests/cni-config/sriov-cni-config.yaml +++ b/bindata/manifests/cni-config/sriov-cni-config.yaml @@ -37,6 +37,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 17cdcb7ce..698588ef9 100644 --- a/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml +++ b/config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml @@ -49,6 +49,23 @@ spec: - enable - disable type: string + logFile: + description: LogFile sets the log file of the SRIOV device plugin + logs. If unset (default), this will log to stderr and thus to multuls + and container runtime logs. + type: string + logLevel: + description: LogLevel sets the log level of the SRIOV device 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 e4123135e..45b07104c 100644 --- a/controllers/sriovnetwork_controller_test.go +++ b/controllers/sriovnetwork_controller_test.go @@ -55,6 +55,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", @@ -93,6 +99,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{ @@ -291,7 +298,18 @@ 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)) + var logLevel string + if cr.Spec.LogLevel != "" { + logLevel = fmt.Sprintf(`"logLevel":"%s",`, cr.Spec.LogLevel) + } + var logFile string + 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%s"vlanQoS":%d,%s%s"ipam":%s }`, + cr.GetName(), cr.Spec.Vlan, spoofchk, trust, state, vlanQoS, 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 17cdcb7ce..698588ef9 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,23 @@ spec: - enable - disable type: string + logFile: + description: LogFile sets the log file of the SRIOV device plugin + logs. If unset (default), this will log to stderr and thus to multuls + and container runtime logs. + type: string + logLevel: + description: LogLevel sets the log level of the SRIOV device 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)