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

Split fleet-agent #1905

Merged
merged 5 commits into from
Nov 2, 2023
Merged

Split fleet-agent #1905

merged 5 commits into from
Nov 2, 2023

Conversation

manno
Copy link
Member

@manno manno commented Oct 26, 2023

Refers to #1772

To prepare the agent for controller-runtime, split the code into three processes:

  • registration
  • cluster status updater
  • agent controller, watches bundledeployments

Only the last part is an actual controller. Cluster status updates work on a timer and registration is done when the agent starts up. A new function "registration.Get" was added, to just return an existing registration to the other processes.

This PR switches the agent to a statefulset, to avoid leader election. I don't expect the agent to scale horizontally, as a controller.
Updating the cluster status with information about the cluster nodes seems unrelated to Fleet's purpose and we might discuss this in the future.
The code of the handlers in the bundledeployment controller is currently spread around the "handler", a deploy "manager" and the helm deployer. The PR takes first steps to consolidate the functionality into the deployer package, making it more obvious which client is used when during reconciliation.

"Trigger" was renamed to "driftdetect" as it uses the helm history to detect drift for deployments. Which is similar to the "monitor", which updates the bundle deployments status.

@manno manno force-pushed the split-agent branch 9 times, most recently from 57892b5 to 77a8eca Compare October 30, 2023 14:59
@manno manno marked this pull request as ready for review October 30, 2023 15:11
@manno manno requested a review from a team as a code owner October 30, 2023 15:11
internal/cmd/controller/agent/manifest_test.go Outdated Show resolved Hide resolved
internal/cmd/agent/root.go Show resolved Hide resolved
internal/cmd/agent/register.go Outdated Show resolved Hide resolved
internal/cmd/agent/register.go Outdated Show resolved Hide resolved
internal/cmd/agent/register.go Outdated Show resolved Hide resolved
Copy link
Contributor

@weyfonk weyfonk left a comment

Choose a reason for hiding this comment

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

Looking good, thanks! Leaving a few nitpicks.

dev/setup-fleet Show resolved Hide resolved
.github/scripts/deploy-fleet.sh Show resolved Hide resolved
internal/cmd/agent/deployer/plan/plan.go Show resolved Hide resolved
func (cs *ClusterStatus) Run(cmd *cobra.Command, args []string) error {
// provide a logger in the context to be compatible with controller-runtime
zopts := zap.Options{
Development: true,
Copy link
Contributor

Choose a reason for hiding this comment

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

This enables stacktraces on warnings (instead of errors) and disables sampling; are we sure we want this level of verbosity in production?
Same question about register.go and root.go.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I would say we will have to come up with logging configuration later. I was hoping we could switch to https://pkg.go.dev/sigs.k8s.io/controller-runtime/pkg/log/zap#Options.BindFlags

internal/cmd/agent/clusterstatus.go Show resolved Hide resolved
internal/cmd/agent/clusterstatus.go Show resolved Hide resolved
Copy link
Contributor

@aruiz14 aruiz14 left a comment

Choose a reason for hiding this comment

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

LGTM, just a minor suggestion

Comment on lines +45 to +64
ctx, cancel := context.WithCancel(ctx)
// try to register with upstream fleet controller by obtaining
// a kubeconfig for the upstream cluster
agentInfo, err := register.Register(ctx, r.Namespace, kc)
if err != nil {
logrus.Fatal(err)
}

ns, _, err := agentInfo.ClientConfig.Namespace()
if err != nil {
logrus.Fatal(err)
}

_, err = agentInfo.ClientConfig.ClientConfig()
if err != nil {
logrus.Fatal(err)
}

setupLog.Info("successfully registered with upstream cluster", "namespace", ns)
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not using defer?

ctx, cancel := context.WithCancel(ctx)
defer cancel()

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll add it in the next PR


agentInfo, err := register.Get(ctx, namespace, kc)
if err != nil {
logrus.Fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably just moved from somewhere else, but why all these logrus.Fatal if this method already returns an error?

Copy link
Member Author

@manno manno Nov 2, 2023

Choose a reason for hiding this comment

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

Yes, all these logrus calls should be removed in the future https://github.com/rancher/fleet/pull/1772/files#diff-a08a0ecbbab37eaea426b6b8bc55a0d5107c75cac3db92153ef7d3329dc47650R79. But the second point you make is interesting. Why do we exit instead of return... I copied that from start.go 🤷

I'll change it in the next PR :)

@manno manno merged commit ba319cb into master Nov 2, 2023
10 checks passed
@manno manno deleted the split-agent branch November 2, 2023 13:24
@manno manno mentioned this pull request Jan 11, 2024
2 tasks
@manno manno changed the title Split agent Split fleet-agent Jan 11, 2024
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.

3 participants