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

feat(kuma-cp) synchronization of Dataplanes over KDS #847

Merged
merged 30 commits into from
Jun 26, 2020
Merged

Conversation

lobkovilya
Copy link
Contributor

@lobkovilya lobkovilya commented Jun 24, 2020

Summary

Current PR introduces an ability to synchronize Dataplanes between Locals and Global over KDS.
It turned out it is simple to implement Dataplane synchronization first and then synchronize other resources on top of it (https://github.com/Kong/kuma/issues/804).

upd: Store resources in dedicated namespace if Global has k8s-store.

Limitations:

  • doesn't synchronize Insight
  • didn't test with enabled leader election

Issues resolved

Fix https://github.com/Kong/kuma/issues/806

Documentation

# Conflicts:
#	app/kuma-cp/cmd/run.go
#	pkg/config/app/kuma-cp/config.go
#	pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
# Conflicts:
#	app/kuma-cp/cmd/run.go
#	pkg/config/kds/config.go
#	pkg/kds/reconcile/snapshot_generator.go
#	pkg/kds/server/components.go
#	pkg/kds/server/kds.go
#	pkg/kds/server/server.go
#	pkg/kds/server/server_test.go
#	pkg/kds/types.go
#	pkg/test/kds/verifier/context.go
#	pkg/test/kds/verifier/executables.go
# Conflicts:
#	app/kumactl/pkg/install/k8s/control-plane/templates_vfsdata.go
@lobkovilya lobkovilya requested a review from a team June 24, 2020 01:38
@@ -117,8 +121,8 @@ func newRunCmdWithOpts(opts runCmdOpts) *cobra.Command {
runLog.Error(err, "unable to set up Clusters server")
return err
}
if err := kds_server.SetupServer(rt); err != nil {
runLog.Error(err, "unable to set up KDS server")
if err := kds_global.SetupServer(rt); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not exactly a server. Maybe SetupSync? SetupComponent?

Also, shouldn't this be other way around? It's local that connects to global as a client to fetch policies, but it's placed in case config_core.Global

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is Global that connects to Local in order to fetch Dataplanes. I'm planning to implement Local -> Global in the next PR, because Local by default doesn't know about Global and it gets Global IP from the first DiscoveryRequest from Global.
So it will look like this:

  1. Global starts KDSSink for every Local for fetching Dataplanes (this PR)
  2. Local start KDSSink for the first request from Global for fetching policies (next PR)

SetupComponent sounds good.

backoffTime = 5 * time.Second
)

type ComponentFactory func(log logr.Logger) k8s_manager.Runnable
Copy link
Contributor

Choose a reason for hiding this comment

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

k8s_manager.Runnable? Shouldn't this be Component?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use component.Manager to operate with multiple Component as with a single one. After your LB changes Manager doesn't implement Component interface anymore. That's why I changed the interface to Runnable just to make it work.

Probably I have to create a new entity CompositeComponent and pass it to ResilientComponent, instead of passing Manager.

pkg/core/runtime/component/resilient.go Outdated Show resolved Hide resolved
pkg/core/runtime/component/resilient.go Outdated Show resolved Hide resolved
pkg/kds/client/client.go Outdated Show resolved Hide resolved
pkg/kds/store/sync.go Show resolved Hide resolved
pkg/kds/store/sync.go Show resolved Hide resolved
pkg/kds/store/sync.go Outdated Show resolved Hide resolved
pkg/kds/store/sync.go Show resolved Hide resolved
app/kuma-cp/cmd/run.go Outdated Show resolved Hide resolved
pkg/kds/client/client.go Outdated Show resolved Hide resolved
pkg/kds/client/sink.go Show resolved Hide resolved
pkg/kds/global/components.go Outdated Show resolved Hide resolved
return nil
}
cluster := clusterTag(rs.GetItems()[0])
forEach(rs.GetItems()).apply(addPrefixToName(cluster))
Copy link
Contributor

Choose a reason for hiding this comment

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

just so we are on the same page:

  • dataplanes have to be prefixed when sync from remote to global
  • policies do not need to be prefixed when sync from global to remote
  • all stuff synchronized should be put in one namespace (do we have permissions to default?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this logic works in this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • yes, when Global fetches Dataplanes from Remotes it adds clusterName as a prefix
  • yes, pkg/kds/global/components.go creates Component just for Global, policies won't be prefixed when sync global to remote. It will be another code in pkg/kds/local/components.go
  • It works in e2e test, I guess we have permissions

addPrefixToName := func(prefix string) func(r model.Resource) {
return func(r model.Resource) {
newName := fmt.Sprintf("%s.%s", prefix, r.GetMeta().GetName())
// method Sync takes into account only 'Name' and 'Mesh' that why we can set name like this
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite get this comment. Can you elaborate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I meant Sync doesn't take into account Version, CreationTime and ModificationTime that's why we can replace the whole ResourceMeta object before Sync

return r.GetSpec().(*mesh_proto.Dataplane).GetNetworking().GetInbound()[0].GetTags()[mesh_proto.ClusterTag]
}

addPrefixToName := func(prefix string) func(r model.Resource) {
Copy link
Contributor

Choose a reason for hiding this comment

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

how about simpler impl. Instead of closures that return functions and extra forEach apply etc.

func addPrefixToNames(items, prefix)
func addSuffixToNames(items, suffix)

as a separate functions

}
cluster := clusterTag(rs.GetItems()[0])
forEach(rs.GetItems()).apply(addPrefixToName(cluster))
if k8sStore {
Copy link
Contributor

Choose a reason for hiding this comment

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

at least explain with comment why we need this

pkg/kds/store/sync.go Outdated Show resolved Hide resolved
pkg/kds/store/sync.go Show resolved Hide resolved
@@ -38,7 +35,7 @@ var _ = Describe("Test Local and Global", func() {
_ = clusters.DeleteKuma()
})

It("Should deploy Local and Global on 2 clusters", func() {
It("should deploy Local and Global on 2 clusters and sync dataplanes", func() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Remote and Global

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't merge master yet, so I have a lot of "Local" usages in this PR

@lobkovilya lobkovilya changed the base branch from feat/kds-server to master June 25, 2020 13:44
# Conflicts:
#	app/kuma-cp/cmd/run.go
#	app/kumactl/pkg/install/k8s/control-plane/templates_vfsdata.go
#	pkg/config/kds/config.go
#	pkg/kds/reconcile/snapshot_generator.go
#	pkg/kds/server/components.go
#	pkg/kds/server/grpc.go
#	pkg/kds/server/kds.go
#	pkg/kds/server/server_test.go
#	pkg/kds/types.go
#	pkg/test/kds/verifier/context.go
#	pkg/test/kds/verifier/executables.go
#	test/e2e/kuma_deploy_global_remote_test.go
@lobkovilya lobkovilya merged commit 8339fcb into master Jun 26, 2020
@lobkovilya lobkovilya deleted the feat/kds-sync branch July 29, 2020 13:59
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.

XDS server(Local)/client(Global) for Dataplane/Ingress synchronization
3 participants