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 13109407767

Details

  • 263 of 606 (43.4%) changed or added relevant lines in 18 files are covered.
  • 204 unchanged lines in 12 files lost coverage.
  • Overall coverage increased (+0.9%) to 48.173%

Changes Missing Coverage Covered Lines Changed/Added Lines %
controllers/sriovnetworknodepolicy_controller.go 1 2 50.0%
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/utils/shutdown.go 0 1 0.0%
controllers/drain_controller_helper.go 1 3 33.33%
pkg/daemon/config.go 30 32 93.75%
controllers/drain_controller.go 4 7 57.14%
pkg/systemd/systemd.go 2 7 28.57%
pkg/daemon/status.go 59 96 61.46%
Files with Coverage Reduction New Missed Lines %
pkg/client/clientset/versioned/fake/clientset_generated.go 5 46.15%
cmd/sriov-network-config-daemon/start.go 5 8.68%
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%
pkg/client/informers/externalversions/sriovnetwork/v1/sriovoperatorconfig.go 19 0.0%
api/v1/helper.go 21 73.32%
Totals Coverage Status
Change from base Build 13109399258: 0.9%
Covered Lines: 7318
Relevant Lines: 15191

💛 - 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.

controllers/drain_controller.go Outdated Show resolved Hide resolved
pkg/systemd/systemd.go Outdated Show resolved Hide resolved
pkg/daemon/status.go Outdated Show resolved Hide resolved
pkg/daemon/daemon.go Outdated Show resolved Hide resolved
pkg/daemon/writer.go Show resolved Hide resolved
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?

Copy link
Member

Choose a reason for hiding this comment

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

in both case, the if idx >= len(c) { can save a nil dereferencing. right?

pkg/daemon/status.go Outdated Show resolved Hide resolved
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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I give it a try and I needed to add it. without it I was not able to get the create calls :(

I can give it another try

// 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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

from the code I can see that we always write the file. I am missing something?

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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we return an error it will get stuck in a loop as if the result for the systemd operator return an error we don't retry to not put the node into a bootloop

<-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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it was moved out of this function so we should be ok I remove this

@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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yes it will make a reboot one time

@@ -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 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

nope I open a different PR for that :)

@SchSeba SchSeba force-pushed the daemon_redesign branch 3 times, most recently from 4ecc95a to 80564fa Compare February 2, 2025 14:07
Signed-off-by: Sebastian Sch <[email protected]>
Signed-off-by: Sebastian Sch <[email protected]>
It's only a one time run script so it should not be a problem to run
with debug logs.

Signed-off-by: Sebastian Sch <[email protected]>
DNM before squash

Signed-off-by: Sebastian Sch <[email protected]>
@SchSeba
Copy link
Collaborator Author

SchSeba commented Feb 3, 2025

Hi @zeeke @adrianchiris @ykulazhenkov can you please make another round of review here?

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