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 Discovery Service (KDS) server #839

Merged
merged 8 commits into from
Jun 24, 2020
Merged

Conversation

lobkovilya
Copy link
Contributor

Summary

This PR introduces a new API between Kuma CP Local and Global. That API is needed for resource synchronization. API based on Envoy xDS.

Limitations:

  • client is not implemented, it doesn't make sense without Store sync.
  • e2e test is not implemented as well, without Store sync it also doesn't make sense

Full changelog

  • Kuma Discovery Service (KDS)
  • Integration tests

Issues resolved

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

Documentation

@lobkovilya lobkovilya requested a review from a team June 18, 2020 17:03
Copy link
Contributor

@nickolaev nickolaev left a comment

Choose a reason for hiding this comment

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

I am impressed by the simplicity of the solution and the huge work you did to provide through testing. A few minor notes from me.
I'll leave it for @jakubdyszkiewicz to approve.

pkg/kds/generator/snapshot_generator.go Outdated Show resolved Hide resolved
"github.com/Kong/kuma/pkg/core/runtime/component"
)

const grpcMaxConcurrentStreams = 1000000
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess an arbitrary number, but still - do we have a proof this can be supported in practice?

nit: I also prefer these numbers to be in the form 1*1000*1000 so one can read it easier.

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 number is taken from another xDS implementations:

  • pkg/sds/server/grpc.go
  • pkg/mads/server/grpc.go
  • pkg/xds/server/grpc.go

All of them have the same constant with the same value. @jakubdyszkiewicz do you have a notion where is that number taken from?

Copy link
Contributor

Choose a reason for hiding this comment

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

Out of the thin air ;)

You have to pick a number, measure with metrics it and adjust if needed. This was our pick.

grpcOptions = append(grpcOptions, grpc.MaxConcurrentStreams(grpcMaxConcurrentStreams))
grpcServer := grpc.NewServer(grpcOptions...)

lis, err := net.Listen("tcp", fmt.Sprintf(":%d", s.config.GrpcPort))
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that is not a problem for K8s, but how safe is to listen on "all" interfaces in Universal? Shall we have also IP configuration to be able to denote the specific IP:port where the service is running?

Copy link
Contributor

Choose a reason for hiding this comment

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

That is probably a nit though, as we have most of our servers behaving the same way. We might want to handle this in a separate task and to go and fix all the servers. Don't bother with it here.

<-tc.stop()

})
})
Copy link
Contributor

Choose a reason for hiding this comment

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

That is an impressive set of tests. Great job!

pkg/kds/types.go Outdated Show resolved Hide resolved
pkg/kds/server/server_test.go Outdated Show resolved Hide resolved
Conf: &mesh_proto.ProxyTemplate_Conf{
Imports: []string{"default-kuma-profile"},
},
}
Copy link
Contributor

Choose a reason for hiding this comment

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

The painful bit here is that we don't automagically get this tested once we add a new type. All the tests will just pas without even noticing the new resource type. I guess that's the best we can do today though.

func kumaResources(response *v2.DiscoveryResponse) (resources []*mesh_proto.KumaResource, _ error) {
for _, r := range response.Resources {
kr := &mesh_proto.KumaResource{}
if err := ptypes.UnmarshalAny(r, kr); 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.

Hmm is this consistent with Maps?

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 replaced MarshalAny to MarshalAnyDeterministic, but I'm not sure I understand what is the problem with UnmarshalAny and maps, could you please give more details.

pkg/kds/server/server_test.go Show resolved Hide resolved
api/mesh/v1alpha1/kds.proto Show resolved Hide resolved
if 65535 < c.GrpcPort {
errs = multierr.Append(errs, errors.Errorf(".GrpcPort must be in the range [0, 65535]"))
}
if c.RefreshInterval <= 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be negative though?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Duration is int64 so yes it can

pkg/config/kds/config.go Outdated Show resolved Hide resolved
pkg/kds/generator/snapshot_generator.go Outdated Show resolved Hide resolved
pkg/kds/types.go Show resolved Hide resolved
pkg/kds/types.go Outdated Show resolved Hide resolved
pkg/kds/server/server.go Outdated Show resolved Hide resolved
# Conflicts:
#	app/kuma-cp/cmd/run.go
#	pkg/config/app/kuma-cp/config.go
#	pkg/config/app/kuma-cp/kuma-cp.defaults.yaml
Copy link
Contributor

@nickolaev nickolaev left a comment

Choose a reason for hiding this comment

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

LGTM

@lobkovilya lobkovilya merged commit cd92f86 into master Jun 24, 2020
@lobkovilya lobkovilya deleted the feat/kds-server 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(Global)/client(Local) for Kuma Resources (Policies/Ingress)
3 participants