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 <[email protected]>
  • Loading branch information
andreaskaris committed Sep 22, 2023
1 parent 2097c2a commit 9dbdfde
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 11 deletions.
26 changes: 20 additions & 6 deletions api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,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()
Expand Down Expand Up @@ -528,13 +528,16 @@ 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
}
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
}
Expand Down Expand Up @@ -563,8 +566,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()
Expand Down Expand Up @@ -652,13 +655,24 @@ 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
}
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
}
Expand Down
7 changes: 7 additions & 0 deletions api/v1/sriovnetwork_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 loglevel of the SRIOV device plugin - either of panic, error, warning, info, debug. Defaults to
// error 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 crio 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 @@ -37,6 +37,12 @@ spec:
{{- end -}}
{{- if .StateConfigured -}}
"link_state":"{{.SriovCniState}}",
{{- end -}}
{{- if .LogLevelConfigured -}}
"loglevel":"{{.LogLevel}}",
{{- end -}}
{{- if .LogFileConfigured -}}
"logfile":"{{.LogFile}}",
{{- end -}}
{{.SriovCniIpam}}
}
Expand Down
17 changes: 17 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,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 crio
logs.
type: string
loglevel:
description: LogLevel sets the loglevel of the SRIOV device plugin
- either of panic, error, warning, info, debug. Defaults to error
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
22 changes: 20 additions & 2 deletions controllers/sriovnetwork_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,20 @@ 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",
func(cr sriovnetworkv1.SriovNetwork) {
var err error
expect := generateExpectedNetConfig(&cr)

By("Create the SriovNetwork Custom Resource")
By(fmt.Sprintf("Create the SriovNetwork Custom Resource %v", cr))
// get global framework variables
err = k8sClient.Create(goctx.TODO(), &cr)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 crio
logs.
type: string
loglevel:
description: LogLevel sets the loglevel of the SRIOV device plugin
- either of panic, error, warning, info, debug. Defaults to error
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
2 changes: 1 addition & 1 deletion doc/ovs-hw-offload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion doc/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion doc/vdpa.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 9dbdfde

Please sign in to comment.