Skip to content

Commit

Permalink
chore: add feature flag for mellanox fw reset
Browse files Browse the repository at this point in the history
To not enable the new feature by default we want to add a feature flag first.

Signed-off-by: Tobias Giese <tgiese@nvidia.com>
  • Loading branch information
tobiasgiese committed Jul 24, 2024
1 parent 345f6cd commit 934a524
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 4 deletions.
4 changes: 4 additions & 0 deletions cmd/sriov-network-config-daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
snclientset "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/daemon"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/featuregate"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/helper"
snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms"
Expand Down Expand Up @@ -276,6 +277,8 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
}
go nodeWriter.Run(stopCh, refreshCh, syncCh)

featureGates := featuregate.New()

setupLog.V(0).Info("Starting SriovNetworkConfigDaemon")
err = daemon.New(
kClient,
Expand All @@ -288,6 +291,7 @@ func runStartCmd(cmd *cobra.Command, args []string) error {
syncCh,
refreshCh,
eventRecorder,
featureGates,
startOpts.disabledPlugins,
).Run(stopCh, exitCh)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions pkg/consts/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,9 @@ const (

// The path to the file on the host filesystem that contains the IB GUID distribution for IB VFs
InfinibandGUIDConfigFilePath = SriovConfBasePath + "/infiniband/guids"

// MellanoxFirmwareResetFeatureGate: enables the firmware reset via mstfwreset before a reboot
MellanoxFirmwareResetFeatureGate = "mellanoxFirmwareReset"
)

const (
Expand Down
12 changes: 12 additions & 0 deletions pkg/daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
snclientset "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned"
sninformer "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/informers/externalversions"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/featuregate"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/helper"
snolog "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/log"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms"
Expand Down Expand Up @@ -82,6 +83,8 @@ type Daemon struct {
workqueue workqueue.RateLimitingInterface

eventRecorder *EventRecorder

featureGate featuregate.FeatureGate
}

func New(
Expand All @@ -95,6 +98,7 @@ func New(
syncCh <-chan struct{},
refreshCh chan<- Message,
er *EventRecorder,
featureGates featuregate.FeatureGate,
disabledPlugins []string,
) *Daemon {
return &Daemon{
Expand All @@ -113,6 +117,7 @@ func New(
&workqueue.BucketRateLimiter{Limiter: rate.NewLimiter(rate.Limit(updateDelay), 1)},
workqueue.NewItemExponentialFailureRateLimiter(1*time.Second, maxUpdateBackoff)), "SriovNetworkNodeState"),
eventRecorder: er,
featureGate: featureGates,
disabledPlugins: disabledPlugins,
}
}
Expand Down Expand Up @@ -299,6 +304,13 @@ func (dn *Daemon) operatorConfigChangeHandler(old, new interface{}) {
dn.disableDrain = newDisableDrain
log.Log.Info("Set Disable Drain", "value", dn.disableDrain)
}

dn.featureGate.Init(newCfg.Spec.FeatureGates)
log.Log.Info("Enabled featureGates", "featureGates", dn.featureGate.String())

if dn.featureGate.IsEnabled(consts.MellanoxFirmwareResetFeatureGate) {
vars.MlxPluginFwReset = true
}
}

func (dn *Daemon) nodeStateSyncHandler() error {
Expand Down
9 changes: 6 additions & 3 deletions pkg/daemon/daemon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ import (
"sigs.k8s.io/controller-runtime/pkg/log/zap"

sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
mock_platforms "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/mock"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/fakefilesystem"

snclient "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned"
snclientset "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/client/clientset/versioned/fake"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/consts"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/featuregate"
mock_helper "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/helper/mock"
mock_platforms "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/mock"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/platforms/openshift"
plugin "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins/fake"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins/generic"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
"github.com/k8snetworkplumbingwg/sriov-network-operator/test/util/fakefilesystem"
)

func TestConfigDaemon(t *testing.T) {
Expand Down Expand Up @@ -151,6 +151,8 @@ var _ = Describe("Config Daemon", func() {
vendorHelper.EXPECT().PrepareNMUdevRule([]string{"0x1014", "0x154c"}).Return(nil).AnyTimes()
vendorHelper.EXPECT().PrepareVFRepUdevRule().Return(nil).AnyTimes()

featureGates := featuregate.New()

sut = New(
kClient,
snclient,
Expand All @@ -162,6 +164,7 @@ var _ = Describe("Config Daemon", func() {
syncCh,
refreshCh,
er,
featureGates,
nil,
)

Expand Down
6 changes: 5 additions & 1 deletion pkg/plugins/mellanox/mellanox_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
sriovnetworkv1 "github.com/k8snetworkplumbingwg/sriov-network-operator/api/v1"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/helper"
plugin "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/plugins"
"github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vars"
mlx "github.com/k8snetworkplumbingwg/sriov-network-operator/pkg/vendors/mellanox"
)

Expand Down Expand Up @@ -198,7 +199,10 @@ func (p *MellanoxPlugin) Apply() error {
if err := p.helpers.MlxConfigFW(attributesToChange); err != nil {
return err
}
return p.helpers.MlxResetFW(pciAddressesToReset)
if vars.MlxPluginFwReset {
return p.helpers.MlxResetFW(pciAddressesToReset)
}
return nil
}

// nicHasExternallyManagedPFs returns true if one of the ports(interface) of the NIC is marked as externally managed
Expand Down
3 changes: 3 additions & 0 deletions pkg/vars/vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ var (
// ManageSoftwareBridges global variable which reflects state of manageSoftwareBridges feature
ManageSoftwareBridges = false

// MlxPluginFwReset global variable enables mstfwreset before rebooting a node on VF changes
MlxPluginFwReset = false

// FilesystemRoot used by test to mock interactions with filesystem
FilesystemRoot = ""

Expand Down

0 comments on commit 934a524

Please sign in to comment.