Skip to content

Commit

Permalink
Merge pull request #365 from SchSeba/systemd
Browse files Browse the repository at this point in the history
Implementation for new systemd configuration method
  • Loading branch information
e0ne authored Jul 5, 2023
2 parents 4ddfd02 + 4e0b661 commit 680654f
Show file tree
Hide file tree
Showing 48 changed files with 3,243 additions and 287 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ vet:
generate: controller-gen
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

mock-generate: gomock
go generate ./...

CONTROLLER_GEN = $(BIN_DIR)/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
$(call go-install-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/[email protected])
Expand All @@ -150,6 +153,10 @@ ENVTEST = $(BIN_DIR)/setup-envtest
envtest: ## Download envtest-setup locally if necessary.
$(call go-install-tool,$(ENVTEST),sigs.k8s.io/controller-runtime/tools/setup-envtest@latest)

GOMOCK = $(shell pwd)/bin/mockgen
gomock:
$(call go-get-tool,$(GOMOCK),github.com/golang/mock/[email protected])

# go-install-tool will 'go install' any package $2 and install it to $1.
define go-install-tool
@[ -f $(1) ] || { \
Expand Down
14 changes: 13 additions & 1 deletion api/v1/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ const (
SupportedNicIDConfigmap = "supported-nic-ids"
)

type ConfigurationModeType string

const (
DaemonConfigurationMode ConfigurationModeType = "daemon"
SystemdConfigurationMode ConfigurationModeType = "systemd"
)

func (e NetFilterType) String() string {
switch e {
case OpenstackNetworkID:
Expand All @@ -66,7 +73,7 @@ func (e NetFilterType) String() string {
}
}

func InitNicIDMap(client kubernetes.Interface, namespace string) error {
func InitNicIDMapFromConfigMap(client kubernetes.Interface, namespace string) error {
cm, err := client.CoreV1().ConfigMaps(namespace).Get(
context.Background(),
SupportedNicIDConfigmap,
Expand All @@ -79,9 +86,14 @@ func InitNicIDMap(client kubernetes.Interface, namespace string) error {
for _, v := range cm.Data {
NicIDMap = append(NicIDMap, v)
}

return nil
}

func InitNicIDMapFromList(idList []string) {
NicIDMap = append(NicIDMap, idList...)
}

func IsSupportedVendor(vendorID string) bool {
for _, n := range NicIDMap {
ids := strings.Split(n, " ")
Expand Down
4 changes: 4 additions & 0 deletions api/v1/sriovoperatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ type SriovOperatorConfigSpec struct {
DisableDrain bool `json:"disableDrain,omitempty"`
// Flag to enable OVS hardware offload. Set to 'true' to provision switchdev-configuration.service and enable OpenvSwitch hw-offload on nodes.
EnableOvsOffload bool `json:"enableOvsOffload,omitempty"`
// Flag to enable the sriov-network-config-daemon to use a systemd service to configure SR-IOV devices on boot
// Default mode: daemon
// +kubebuilder:validation:Enum=daemon;systemd
ConfigurationMode ConfigurationModeType `json:"configurationMode,omitempty"`
}

// SriovOperatorConfigStatus defines the observed state of SriovOperatorConfig
Expand Down
75 changes: 52 additions & 23 deletions bindata/manifests/daemon/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ spec:
hostPID: true
nodeSelector:
kubernetes.io/os: linux
node-role.kubernetes.io/worker:
node-role.kubernetes.io/worker: ""
tolerations:
- operator: Exists
serviceAccountName: sriov-network-config-daemon
Expand All @@ -37,6 +37,54 @@ spec:
- name: {{ . }}
{{- end }}
{{- end }}
initContainers:
- name: sriov-cni
image: {{.SRIOVCNIImage}}
command:
- /bin/sh
- -c
- cp /usr/bin/sriov /host/opt/cni/bin/
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
- name: sriov-infiniband-cni
image: {{.SRIOVInfiniBandCNIImage}}
command:
- /bin/sh
- -c
- cp /usr/bin/ib-sriov /host/opt/cni/bin/
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
{{- if .UsedSystemdMode}}
- name: sriov-service-copy
image: {{.Image}}
command:
- /bin/bash
- -c
- mkdir -p /host/var/lib/sriov/ && cp /usr/bin/sriov-network-config-daemon /host/var/lib/sriov/sriov-network-config-daemon && chcon -t bin_t /host/var/lib/sriov/sriov-network-config-daemon | true # Allow systemd to run the file, use pipe true to not failed if the system doesn't have selinux or apparmor enabled
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: host
mountPath: /host
{{- end }}
containers:
- name: sriov-network-config-daemon
image: {{.Image}}
Expand All @@ -46,6 +94,9 @@ spec:
privileged: true
args:
- "start"
{{- if .UsedSystemdMode}}
- --use-systemd-service
{{- end }}
env:
- name: NODE_NAME
valueFrom:
Expand All @@ -70,28 +121,6 @@ spec:
preStop:
exec:
command: ["/bindata/scripts/clean-k8s-services.sh"]
- name: sriov-cni
image: {{.SRIOVCNIImage}}
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
- name: sriov-infiniband-cni
image: {{.SRIOVInfiniBandCNIImage}}
securityContext:
privileged: true
resources:
requests:
cpu: 10m
memory: 10Mi
volumeMounts:
- name: cnibin
mountPath: /host/opt/cni/bin
volumes:
- name: host
hostPath:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contents: |
[Unit]
Description=Configures SRIOV NIC
Wants=network-pre.target
Before=network-pre.target
[Service]
Type=oneshot
ExecStart=/var/lib/sriov/sriov-network-config-daemon service
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target
enabled: true
name: sriov-config.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
apiVersion: machineconfiguration.openshift.io/v1
kind: MachineConfig
metadata:
labels:
machineconfiguration.openshift.io/role: worker
name: sriov-config-service
spec:
config:
ignition:
version: 3.2.0
systemd:
units:
- contents: |
[Unit]
Description=Configures SRIOV NIC
# Removal of this file signals firstboot completion
ConditionPathExists=!/etc/ignition-machine-config-encapsulated.json
# This service is used to configure the SR-IOV VFs on NICs
Wants=network-pre.target
Before=network-pre.target
[Service]
Type=oneshot
ExecStart=/var/lib/sriov/sriov-network-config-daemon service -v {{ .LogLevel }}
StandardOutput=journal+console
[Install]
WantedBy=multi-user.target
enabled: true
name: "sriov-config.service"
75 changes: 0 additions & 75 deletions bindata/scripts/enable-rdma.sh

This file was deleted.

16 changes: 0 additions & 16 deletions bindata/scripts/load-kmod.sh

This file was deleted.

15 changes: 15 additions & 0 deletions cmd/sriov-network-config-daemon/main.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
/*
Copyright 2023.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package main

import (
Expand Down
Loading

0 comments on commit 680654f

Please sign in to comment.