Skip to content

Commit

Permalink
Support logLevel and logFile for SR-IOV plugin
Browse files Browse the repository at this point in the history
The SR-IOV device plugin now supports the configuration of logLevel
and logFile. Expose these settings through the API.

Signed-off-by: Andreas Karis <ak.karis@gmail.com>
  • Loading branch information
andreaskaris committed Oct 19, 2023
1 parent e1f6fd9 commit c090283
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 2 deletions.
15 changes: 15 additions & 0 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -659,6 +663,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
Expand Down
8 changes: 8 additions & 0 deletions api/v1/sriovnetwork_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions bindata/manifests/cni-config/sriov-cni-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ spec:
{{- end -}}
{{- if .StateConfigured -}}
"link_state":"{{.SriovCniState}}",
{{- end -}}
{{- if .LogLevelConfigured -}}
"logLevel":"{{.LogLevel}}",
{{- end -}}
{{- if .LogFileConfigured -}}
"logFile":"{{.LogFile}}",
{{- end -}}
{{.SriovCniIpam}}
}
Expand Down
18 changes: 18 additions & 0 deletions config/crd/bases/sriovnetwork.openshift.io_sriovnetworks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
20 changes: 18 additions & 2 deletions controllers/sriovnetwork_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -274,6 +281,8 @@ func generateExpectedNetConfig(cr *sriovnetworkv1.SriovNetwork) string {
spoofchk := ""
trust := ""
vlanProto := ""
logLevel := ""
logFile := ""
ipam := emptyCurls

if cr.Spec.Trust == sriovnetworkv1.SriovCniStateOn {
Expand All @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit c090283

Please sign in to comment.