Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementation for new systemd configuration method #365

Merged
merged 8 commits into from
Jul 5, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ spec:
type: string
description: NodeSelector selects the nodes to be configured
type: object
configurationMode:
description: Flag to enable the sriov-network-config-daemon to use
a systemd mode instead of the regular method
enum:
- daemon
- systemd
type: string
disableDrain:
description: Flag to disable nodes drain during debugging
type: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ spec:
type: string
description: NodeSelector selects the nodes to be configured
type: object
configurationMode:
description: Flag to enable the sriov-network-config-daemon to use
a systemd mode instead of the regular method
enum:
- daemon
- systemd
type: string
disableDrain:
description: Flag to disable nodes drain during debugging
type: boolean
Expand Down
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func main() {
var metricsAddr string
var enableLeaderElection bool
var probeAddr string

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this change is not needed

flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
Expand All @@ -82,6 +83,7 @@ func main() {
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))

restConfig := ctrl.GetConfigOrDie()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this change is not needed

kubeClient, err := client.New(restConfig, client.Options{Scheme: scheme})
if err != nil {
setupLog.Error(err, "couldn't create client")
Expand Down Expand Up @@ -210,7 +212,7 @@ func main() {
func initNicIDMap() error {
namespace := os.Getenv("NAMESPACE")
kubeclient := kubernetes.NewForConfigOrDie(ctrl.GetConfigOrDie())
if err := sriovnetworkv1.InitNicIDMap(kubeclient, namespace); err != nil {
if err := sriovnetworkv1.InitNicIDMapFromConfigMap(kubeclient, namespace); err != nil {
return err
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
var namespace = os.Getenv("NAMESPACE")

func RetriveSupportedNics() error {
if err := sriovnetworkv1.InitNicIDMap(kubeclient, namespace); err != nil {
if err := sriovnetworkv1.InitNicIDMapFromConfigMap(kubeclient, namespace); err != nil {
return err
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion test/conformance/tests/test_sriov_operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/pod"
)

var waitingTime time.Duration = 20 * time.Minute
var waitingTime = 20 * time.Minute
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: this change is not needed

var sriovNetworkName = "test-sriovnetwork"
var snoTimeoutMultiplier time.Duration = 0

Expand Down
2 changes: 1 addition & 1 deletion test/util/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func DiscoverSriov(clients *testclient.ClientSet, operatorNamespace string) (*En
return nil, fmt.Errorf("failed to find matching node states %v", err)
}

err = sriovv1.InitNicIDMap(kubernetes.NewForConfigOrDie(clients.Config), operatorNamespace)
err = sriovv1.InitNicIDMapFromConfigMap(kubernetes.NewForConfigOrDie(clients.Config), operatorNamespace)
if err != nil {
return nil, fmt.Errorf("failed to InitNicIdMap %v", err)
}
Expand Down