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

clustermesh-apiserver: extract kvstore client initialization and heartbeat logic in separate cells #25554

Merged
merged 3 commits into from Jun 1, 2023

Conversation

giorio94
Copy link
Member

This PR extracts the kvstore client initialization and heartbeat logic from the clustermesh-apiserver in two separate cells, to better integrate in the hive paradigm and allow them to be reused by other components. In this phase, the clustermesh-apiserver still relies on a global variable for the kvstore client, which is planned to be removed with subsequent refactoring (in particular, it involves much less changes once #25049 is in).

clustermesh-apiserver: extract kvstore client initialization and heartbeat logic in separate cells

@giorio94 giorio94 added area/clustermesh Relates to multi-cluster routing functionality in Cilium. release-note/misc This PR makes changes that have no direct user impact. labels May 19, 2023
@giorio94 giorio94 requested review from a team as code owners May 19, 2023 13:17
@giorio94
Copy link
Member Author

giorio94 commented May 19, 2023

/test

(Jenkins tests did not run due to the outage)

@giorio94
Copy link
Member Author

/test

Copy link
Member

@aanm aanm left a comment

Choose a reason for hiding this comment

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

just one small nit.

v := vp.GetStringSlice(k)
if len(v) > 0 {
entry.Infof(" --%s='%s'", k, strings.Join(v, ","))
ss := vp.GetStringSlice(k)
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 move this commit into a separate PR so that it can be backported to all branches?

Copy link
Member Author

Choose a reason for hiding this comment

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

It actually seems that flags.StringToString should not be used (https://github.com/cilium/cilium/blob/main/contrib/scripts/check-viper.sh#L20-L23). Let me try to figure out how to make option.NewNamedMapOptions work for hive flags. In that way, this commit should no longer be necessary.

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've opened #25643 which includes the logic to correctly parse StringMap flags through the hive machinery, and the commit to fix the logging of that type of flags. Backporting is not required, since StringMap flags are not currently used (an intermediate wrapper is used to support both json and KV encoding for legacy flags).

Copy link
Contributor

@thorn3r thorn3r left a comment

Choose a reason for hiding this comment

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

excellent work! 👍
looks like at least one of your CI failures is due to: #25483

Copy link
Member

@YutaroHayakawa YutaroHayakawa left a comment

Choose a reason for hiding this comment

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

LGTM!

@giorio94 giorio94 added the dont-merge/blocked Another PR must be merged before this one. label May 24, 2023
@giorio94
Copy link
Member Author

Force-pushed to rebase on top of #25643. Marking as blocked until that PR is merged.

Copy link
Member

@asauber asauber left a comment

Choose a reason for hiding this comment

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

LGTM. I appreciate that the temporary global has a good comment.

@giorio94
Copy link
Member Author

Rebased onto main to include the changes introduced in #25643

@giorio94 giorio94 removed the dont-merge/blocked Another PR must be merged before this one. label May 31, 2023
@giorio94
Copy link
Member Author

/test

This commit implements a cell which handles the operations required to
setup the kvstore client, based on the specified parameters (which are
also propagated to the existing global variables to prevent changes for
functions relying on those). In this first pass, the cell is expected to
be used for self-contained components (like the clustermesh-apiserver),
which don't involve complex dependencies during initialization.

The kvstore client is returned through a promise, accounting for a possibly
slow setup phase. The client is not explicitly closed when the cell is stopped,
since that would attempt to revoke the lease, causing all entries associated
with that lease to be deleted. This would not be the behavior expected by
the consumers of this cell.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
This commit refactors the clustermesh-apiserver to use the newly
introduced kvstore cell to initialize the etcd client. In order to reduce
the amount of changes in this first phase, given the parallel refactoring
already in progress, the backend is stored as a global variable and
accessed by the different functions. The global variable will be removed
in future commits, appropriately passing around the backend instance.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
This commit extracts the logic which periodically updates the heartbeat
key in the kvstore in a separate cell, to reduce the coupling and allow
it to be reused.

Signed-off-by: Marco Iorio <marco.iorio@isovalent.com>
@giorio94
Copy link
Member Author

Rebased onto main to fix a conflict. I've additionally dropped a leftover kvstore initialization, which caused the spurious creation of an additional etcd client:

--- a/clustermesh-apiserver/main.go
+++ b/clustermesh-apiserver/main.go
@@ -576,21 +588,19 @@ func startServer(startCtx hive.HookContext, clientset k8sClient.Clientset, servi
 	}
 
 	var err error
-	if err = kvstore.Setup(context.Background(), "etcd", option.Config.KVStoreOpt, nil); err != nil {
-		log.WithError(err).Fatal("Unable to connect to etcd")
-	}
 
 	config := cmtypes.CiliumClusterConfig{
 		ID: cfg.clusterID,
 	}
@@ -602,6 +612,7 @@ func startServer(startCtx hive.HookContext, clientset k8sClient.Clientset, servi
 	}
 
 	ciliumNodeStore, err = store.JoinSharedStore(store.Configuration{
+		Backend:    backend,
 		Prefix:     nodeStore.NodeStorePrefix,
 		KeyCreator: nodeStore.KeyCreator,
 	})

@giorio94
Copy link
Member Author

/test

@giorio94
Copy link
Member Author

giorio94 commented Jun 1, 2023

/test-1.24-5.4

@maintainer-s-little-helper maintainer-s-little-helper bot added the ready-to-merge This PR has passed all tests and received consensus from code owners to merge. label Jun 1, 2023
@julianwiedmann julianwiedmann merged commit 7b93086 into cilium:main Jun 1, 2023
61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/clustermesh Relates to multi-cluster routing functionality in Cilium. ready-to-merge This PR has passed all tests and received consensus from code owners to merge. release-note/misc This PR makes changes that have no direct user impact.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants