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

Daemon redesign - using controller-runtime #788

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

SchSeba
Copy link
Collaborator

@SchSeba SchSeba commented Oct 10, 2024

No description provided.

Copy link

Thanks for your PR,
To run vendors CIs, Maintainers can use one of:

  • /test-all: To run all tests for all vendors.
  • /test-e2e-all: To run all E2E tests for all vendors.
  • /test-e2e-nvidia-all: To run all E2E tests for NVIDIA vendor.

To skip the vendors CIs, Maintainers can use one of:

  • /skip-all: To skip all tests for all vendors.
  • /skip-e2e-all: To skip all E2E tests for all vendors.
  • /skip-e2e-nvidia-all: To skip all E2E tests for NVIDIA vendor.
    Best regards.

pkg/daemon/daemon.go Fixed Show fixed Hide fixed
@SchSeba SchSeba force-pushed the daemon_redesign branch 3 times, most recently from 9f5207e to 7d4e946 Compare October 10, 2024 10:23
@coveralls
Copy link

coveralls commented Oct 10, 2024

Pull Request Test Coverage Report for Build 12559552266

Details

  • 261 of 604 (43.21%) changed or added relevant lines in 15 files are covered.
  • 209 unchanged lines in 14 files lost coverage.
  • Overall coverage increased (+0.8%) to 48.003%

Changes Missing Coverage Covered Lines Changed/Added Lines %
pkg/host/internal/network/network.go 0 1 0.0%
pkg/host/store/store.go 0 1 0.0%
pkg/plugins/mellanox/mellanox_plugin.go 0 1 0.0%
pkg/daemon/config.go 30 32 93.75%
controllers/drain_controller.go 4 7 57.14%
pkg/systemd/systemd.go 2 6 33.33%
pkg/daemon/status.go 59 96 61.46%
cmd/sriov-network-config-daemon/start.go 7 141 4.96%
pkg/daemon/daemon.go 140 300 46.67%
Files with Coverage Reduction New Missed Lines %
controllers/drain_controller_helper.go 1 63.59%
pkg/systemd/systemd.go 4 25.24%
pkg/client/clientset/versioned/fake/clientset_generated.go 5 46.15%
cmd/sriov-network-config-daemon/start.go 5 8.64%
pkg/client/informers/externalversions/sriovnetwork/interface.go 6 0.0%
pkg/plugins/fake/fake_plugin.go 6 20.0%
pkg/client/informers/externalversions/sriovnetwork/v1/interface.go 9 0.0%
pkg/client/clientset/versioned/typed/sriovnetwork/v1/fake/fake_sriovoperatorconfig.go 15 10.81%
pkg/client/clientset/versioned/typed/sriovnetwork/v1/fake/fake_sriovnetworknodestate.go 17 25.68%
pkg/client/informers/externalversions/sriovnetwork/v1/sriovnetworknodestate.go 19 0.0%
Totals Coverage Status
Change from base Build 12557982099: 0.8%
Covered Lines: 7248
Relevant Lines: 15099

💛 - Coveralls

@SchSeba SchSeba force-pushed the daemon_redesign branch 2 times, most recently from e17b584 to ddc70f2 Compare October 10, 2024 12:45
@SchSeba SchSeba force-pushed the daemon_redesign branch 2 times, most recently from 929886d to 9377404 Compare December 12, 2024 11:54
@SchSeba SchSeba force-pushed the daemon_redesign branch 4 times, most recently from 79cc69b to dc6eb11 Compare December 16, 2024 14:03
@SchSeba SchSeba changed the title [WIP] Daemon redesign Daemon redesign - using controller-runtime Dec 26, 2024
Copy link
Member

@zeeke zeeke left a comment

Choose a reason for hiding this comment

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

Left a few minor comments. This PR hugely improves the config-daemon shape.

nodeStateDrainAnnotationCurrent, nodeStateExist, err := dr.ensureAnnotationExists(ctx, nodeNetworkState, constants.NodeStateDrainAnnotationCurrent)
nodeStateDrainAnnotationCurrent, currentNodeStateExist, err := dr.ensureAnnotationExists(ctx, nodeNetworkState, constants.NodeStateDrainAnnotationCurrent)
if err != nil {
reqLogger.Error(err, "failed to ensure nodeStateDrainAnnotation")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
reqLogger.Error(err, "failed to ensure nodeStateDrainAnnotation")
reqLogger.Error(err, "failed to ensure nodeStateDrainAnnotationCurrent")

can you also fix on L123 with nodeStateDrainAnnotation -> nodeDrainAnnotation ?

Comment on lines 187 to +188
log.Log.V(2).Info("ReadSriovResult(): file does not exist, return empty result")
return &SriovResult{}, nil
return nil, false, nil
Copy link
Member

Choose a reason for hiding this comment

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

This does not return an empty SriovResult anymore. who's right, the log or the code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

code always! :P

return false, nil
}

func (dn *DaemonReconcile) getHostNetworkStatus(nodeState *sriovnetworkv1.SriovNetworkNodeState) error {
Copy link
Member

Choose a reason for hiding this comment

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

nit: please rename to updateStatusFromHost() or something similar.
a get*() function does not sound like something that changes the passed parameters.

var sriovResult = &systemd.SriovResult{SyncStatus: consts.SyncStatusSucceeded, LastSyncError: ""}
dn.desiredNodeState, err = dn.sriovClient.SriovnetworkV1().SriovNetworkNodeStates(vars.Namespace).Get(context.Background(), vars.NodeName, metav1.GetOptions{})
// if we are running in systemd mode we want to get the sriov result from the config-daemon that runs in systemd
sriovResult, exist, err := dn.checkSystemdStatus(ctx, desiredNodeState)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
sriovResult, exist, err := dn.checkSystemdStatus(ctx, desiredNodeState)
sriovResult, sriovResultExists, err := dn.checkSystemdStatus(ctx, desiredNodeState)

Renaming this variable might be useful when reading around L235, where it's not obvious to know what "exist" refers to.

@@ -1,290 +0,0 @@
package daemon
Copy link
Member

Choose a reason for hiding this comment

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

It's great to see this file go away! :)

c := current.Status.DeepCopy().Interfaces
d := desiredNodeState.Status.DeepCopy().Interfaces
for idx := range d {
// check if it's a new device
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// check if it's a new device
if idx >= len(c) {
return true, nil
}
// check if it's a new device

I don't know if it can ever happen (maybe if a new device is hot-plugged between reconcile loops). But it's safer to check for slice length

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but in theory (not sure if it's possible) you can have a new device like hot-unplug and after that hot-plug so the len will be the same but the device is not no?

return nil
}

func (dn *DaemonReconcile) shouldUpdateStatus(current, desiredNodeState *sriovnetworkv1.SriovNetworkNodeState) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this function returns no error. can get rid of the second return parameter?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

you are right!

Copy link
Collaborator

@adrianchiris adrianchiris left a comment

Choose a reason for hiding this comment

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

partial review

@@ -108,14 +108,7 @@ type DrainStateAnnotationPredicate struct {
}

func (DrainStateAnnotationPredicate) Create(e event.CreateEvent) bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

WDYT about removing the Create fn ?

the default of predicate.Funcs is true.

is object being nil a real concern here ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the concern is not nil. without this when a new node is added to the cluster the reconcile will not get called without this.
and if the reconcile is not created no one adds the labels to make the drain possible.

Copy link
Collaborator

Choose a reason for hiding this comment

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

without this when a new node is added to the cluster the reconcile will not get called without this

are you sure ? i thought by default it will call reconcile since predicate.Funcs contains implementation that will return true. which means to enqueue event for reconcile.

// creates the in-cluster config
config, err = rest.InClusterConfig()
func getOperatorConfig(kClient runtimeclient.Client) (*sriovnetworkv1.SriovOperatorConfig, error) {
// Init feature gates once to prevent race conditions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: unrelated comment


refreshCh := make(chan daemon.Message)
defer close(refreshCh)
func UseKubeletKubeConfig() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it need to start with upper case ?


// Setup reconcile loop with manager
if err = dm.SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create setup daemon manager for SriovNetworkNodeState")
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: unable to setup daemon with manager for SriovNetworkNodeState

}

type Daemon struct {
type DaemonReconcile struct {
Copy link
Collaborator

Choose a reason for hiding this comment

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

DaemonReconciler ? or better yet, NodeReconciler ?

ns := &sriovnetworkv1.SriovNetworkNodeState{}
// init openstack info
if vars.PlatformType == consts.VirtualOpenStack {
ns, err = dn.HostHelpers.GetCheckPointNodeState()
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we limit the usage of nodestate from checkpoint to just this block ? i.e define a new var.

it seems odd that other platform types we dont load from checkpoint during init (which initializes InitialState global var


// save init state
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: // save init state if it does not exist on host

log.Log.Error(err, "nodeStateSyncHandler(): Failed to fetch node state", "name", vars.NodeName)
return err
reqLogger.Error(err, "failed to check systemd status unexpected error")
return ctrl.Result{}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

we dont want to fail here ?

<-dn.syncCh
return nil
}
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: lets define requeueTime as a const

return err
}
postNetworkServiceEnabled, err := dn.HostHelpers.IsServiceEnabled(systemd.SriovPostNetworkServicePath)
// if there are no node drifted changes, and we are on the latest applied policy
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: // if there are no host state drift changes, ...

}
reqDrain = reqDrain || systemdConfModified || !exist
// require reboot if drain needed for systemd mode
reqReboot = reqReboot || systemdConfModified || reqDrain || !exist
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: you can drop : || systemdConfModified and || !exist
they are checked in reqDrain

log.Log.Error(err, "nodeStateSyncHandler(): failed to write supported nic ids file for systemd mode")
return err
}
func (dn *DaemonReconcile) checkSystemdStatus(ctx context.Context, desiredNodeState *sriovnetworkv1.SriovNetworkNodeState) (*systemd.SriovResult, bool, error) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add docstring explaining the returned args ?


// update the lastAppliedGeneration
dn.lastAppliedGeneration = desiredNodeState.Generation
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: same as previous comment. lets use a const

// return sriovResult, err
//}

// TODO: check if we need this
Copy link
Collaborator

@adrianchiris adrianchiris Jan 19, 2025

Choose a reason for hiding this comment

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

i believe we need.

in case systemd services were enabled, and there is error in sriovResult, we want to reflect that in status and stop reconcile. else we end up in a reboot loop no ? (which we dont want here)

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ykulazhenkov for some more feedback on this bit

@adrianchiris
Copy link
Collaborator

once we get this in, i think we should move the node controllers under controllers/node/ pkg

@@ -7,7 +7,7 @@ contents: |

[Service]
Type=oneshot
ExecStart=/var/lib/sriov/sriov-network-config-daemon -v 2 --zap-log-level 2 service --phase pre
ExecStart=/var/lib/sriov/sriov-network-config-daemon service --phase pre
Copy link
Collaborator

@adrianchiris adrianchiris Jan 19, 2025

Choose a reason for hiding this comment

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

this means reboot on update ? since systemd file changes

@@ -7,4 +7,4 @@ GOPATH="${GOPATH:-$HOME/go}"
JUNIT_OUTPUT="${JUNIT_OUTPUT:-/tmp/artifacts}"
export PATH=$PATH:$GOPATH/bin

${root}/bin/ginkgo -output-dir=$JUNIT_OUTPUT --junit-report "unit_report.xml" -v "$SUITE" -- -report=$JUNIT_OUTPUT
${root}/bin/ginkgo --timeout 3h -output-dir=$JUNIT_OUTPUT --junit-report "unit_report.xml" -v "$SUITE" -- -report=$JUNIT_OUTPUT
Copy link
Collaborator

Choose a reason for hiding this comment

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

is this change related ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants