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

✨ Registration-agent supports multiple bootstrapkubeconfigs. #443

Conversation

xuezhaojun
Copy link
Member

@xuezhaojun xuezhaojun commented Apr 25, 2024

Summary

Klusterlet supports configure multiple bootstrapkubeconfigs and switch when hub doesn't accpet it or failed to connect to a hub.

Special Notes:

  • The feature is depends on the auto-approve enabled and configured.
  • Currently, you can't rebootstrap or restart a agent by change the items in bootstrapkubeconfigs.
  • The bootstrapkubeconfigs should use long-term credentials.

@openshift-ci openshift-ci bot requested review from elgnay and zhiweiyin318 April 25, 2024 09:06
Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

can we split this to two PRs. the first one only update the registration part.

@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch 2 times, most recently from 7115d11 to 51b4c3b Compare April 25, 2024 10:02
@xuezhaojun
Copy link
Member Author

can we split this to two PRs. the first one only update the registration part.

Yes, I have split the PR and now it only contains registration part.

@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch 3 times, most recently from 649f468 to 55d1b74 Compare April 25, 2024 10:16
@xuezhaojun xuezhaojun changed the title ✨ Klusterlet support multiple bootstrapkubeconfigs. ✨ Klusterlet support multiple bootstrapkubeconfigs. [WIP] Apr 25, 2024
Copy link

codecov bot commented Apr 25, 2024

Codecov Report

Attention: Patch coverage is 44.88189% with 140 lines in your changes missing coverage. Please review.

Project coverage is 62.12%. Comparing base (add5d45) to head (19f1f5c).
Report is 9 commits behind head on main.

Files Patch % Lines
pkg/registration/spoke/bootstrapkubeconfigs.go 0.00% 60 Missing ⚠️
pkg/registration/spoke/spokeagent.go 8.33% 44 Missing ⚠️
...ation/spoke/registration/hub_timeout_controller.go 40.74% 13 Missing and 3 partials ⚠️
...ration/spoke/registration/hub_accept_controller.go 26.31% 12 Missing and 2 partials ⚠️
pkg/registration/spoke/options.go 61.53% 5 Missing ⚠️
pkg/common/helpers/ssar.go 98.80% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #443      +/-   ##
==========================================
- Coverage   62.71%   62.12%   -0.59%     
==========================================
  Files         136      140       +4     
  Lines       11578    11728     +150     
==========================================
+ Hits         7261     7286      +25     
- Misses       3549     3670     +121     
- Partials      768      772       +4     
Flag Coverage Δ
unit 62.12% <44.88%> (-0.59%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xuezhaojun xuezhaojun changed the title ✨ Klusterlet support multiple bootstrapkubeconfigs. [WIP] ✨ Klusterlet support multiple bootstrapkubeconfigs. Apr 28, 2024
@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch 2 times, most recently from eeeee2a to 73f58c6 Compare April 28, 2024 15:20
@xuezhaojun xuezhaojun requested a review from qiujian16 April 28, 2024 15:21
@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch 3 times, most recently from 2baf7de to fa7196e Compare April 29, 2024 05:59
@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch from fa7196e to fc574c1 Compare May 4, 2024 08:12
@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch 2 times, most recently from f1102ed to 294b8fa Compare May 28, 2024 08:38
Copy link
Member

@qiujian16 qiujian16 left a comment

Choose a reason for hiding this comment

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

/approve

2 nit comment on test, but should not block merge. This is a good start. Great work!

gomega.Expect(err).NotTo(gomega.HaveOccurred())
}

func assertManagedClusterSuccessfullyJoined(testNamespace, managedClusterName, hubKubeconfigSecret string,
Copy link
Member

Choose a reason for hiding this comment

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

do we have an existing assert that already cover this ?

return agentCtx, stopAgent
}

func approveAndAcceptManagedCluster(managedClusterName string,
Copy link
Member

Choose a reason for hiding this comment

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

do we have an existing helper that already did this?

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 think you mean this function?

assertSuccessClusterBootstrap := func(testNamespace, managedClusterName, hubKubeconfigSecret string,

It's a closure function, and do multiple jobs in one function. The approveAndAcceptManagedCluster and assertManagedClusterSuccessfullyJoined is first and second parts from this function.

Copy link
Contributor

openshift-ci bot commented May 28, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qiujian16, xuezhaojun

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@xuezhaojun xuezhaojun requested a review from qiujian16 May 28, 2024 13:51
@xuezhaojun
Copy link
Member Author

/assign @zhujian7

BootstrapKubeconfigSecret string
// The differences among BootstrapKubeconfig, BootstrapKubeconfigSecret, BootstrapKubeconfigSecrets are:
// 1. BootstrapKubeconfig is a file path, the controller uses it to build the client.
// 2. BootstrapKubeconfigSecret is the secret, a eventhandler will watch it, if the secret is changed, threbootstrap.
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
// 2. BootstrapKubeconfigSecret is the secret, a eventhandler will watch it, if the secret is changed, threbootstrap.
// 2. BootstrapKubeconfigSecret is the secret, an event handler will watch it, if the secret is changed, then rebootstrap.

?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, fixed.

logger.Info("Lease timeout", "cluster", c.clusterName, "lease", leaseName)
err := c.handleTimeout(ctx)
if err != nil {
logger.Error(err, "Failed to handle lease timeout", "cluster", c.clusterName, "lease", leaseName)
Copy link
Member

Choose a reason for hiding this comment

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

should we return the error here?

Copy link
Member Author

Choose a reason for hiding this comment

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

The controller will reconcile every minute, it could be a timer actually. whether reconcile again on the error case doesn't matter, we have a TODO to implement the timeout feature in leaseController later on.

@zhujian7
Copy link
Member

@xuezhaojun great work!
/lgtm
/hold for other reviewers

…hub.

Signed-off-by: xuezhaojun <zxue@redhat.com>
@xuezhaojun xuezhaojun force-pushed the feature-switch-hub branch from 5432c2d to 19f1f5c Compare May 29, 2024 10:00
@xuezhaojun
Copy link
Member Author

xuezhaojun commented May 29, 2024

@xuezhaojun great work! /lgtm /hold for other reviewers

@zhujian7 Thanks for the review! Code updated according to the comments, also need a /lgtm again.

@xuezhaojun xuezhaojun requested a review from zhujian7 May 29, 2024 10:02
@xuezhaojun
Copy link
Member Author

/hold

@zhujian7
Copy link
Member

I think we should have more UTs to cover #443 (comment)

@xuezhaojun
Copy link
Member Author

I think we should have more UTs to cover #443 (comment)

The score doesn't perfectly reflect the coverage, we have many lines of uncovered code are imports or construction functions like:

func GetBootstrapSSARs() []authorizationv1.SelfSubjectAccessReview {
	var reviews []authorizationv1.SelfSubjectAccessReview
	clusterResource := authorizationv1.ResourceAttributes{
		Group:    "cluster.open-cluster-management.io",
		Resource: "managedclusters",
		// TODO: add the resourceName @xuezhaojun https://github.com/open-cluster-management-io/ocm/pull/443#discussion_r1609202000
	}
	reviews = append(reviews, generateSelfSubjectAccessReviews(clusterResource, "create", "get")...)

	certResource := authorizationv1.ResourceAttributes{
		Group:    "certificates.k8s.io",
		Resource: "certificatesigningrequests",
	}
	return append(reviews, generateSelfSubjectAccessReviews(certResource, "create", "get", "list", "watch")...)
}

And intergration-test also covers some logic of the controller at the high level.

@qiujian16
Copy link
Member

/lgtm

@xuezhaojun
Copy link
Member Author

/unhold

@openshift-merge-bot openshift-merge-bot bot merged commit 0357cb9 into open-cluster-management-io:main Jun 4, 2024
14 checks passed
@xuezhaojun xuezhaojun deleted the feature-switch-hub branch August 16, 2024 08:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants