Repository navigation
cmd/k8s-operator: operator can create subnetrouter - #9505
Conversation
| @@ -0,0 +1,89 @@ | |||
| apiVersion: apiextensions.k8s.io/v1 | |||
There was a problem hiding this comment.
Autogenerated from Go types in kube/apis/v1alpha1/types_connector.go.
| @@ -0,0 +1,54 @@ | |||
| // Copyright (c) Tailscale Inc & AUTHORS | |||
There was a problem hiding this comment.
This file is all boilerplate
0652d24 to
8c997b9
Compare
25dfc79 to
2239a73
Compare
| @@ -0,0 +1,129 @@ | |||
| apiVersion: apiextensions.k8s.io/v1 | |||
There was a problem hiding this comment.
I still need to figure out the best way how to add this to the Helm chart. Probably will opt for a similar mechanism to how it was done for cert-manager because the Helm CRD management is still suboptimal
cert-manager/cert-manager#2775
https://helm.sh/docs/chart_best_practices/custom_resource_definitions/#method-2-separate-charts
There was a problem hiding this comment.
I will update this part once #10436 merges.
There was a problem hiding this comment.
In fact, since the Connector functionality is now opt-in, it should be ok to merge this PR as is and add the Helm chart CRD generation in a separate step.
2239a73 to
416df07
Compare
5542fc3 to
ea30974
Compare
| priorityClassName = defaultEnv("PROXY_PRIORITY_CLASS_NAME", "") | ||
| tags = defaultEnv("PROXY_TAGS", "tag:k8s") | ||
| tsFirewallMode = defaultEnv("PROXY_FIREWALL_MODE", "") | ||
| tsEnableConnector = defaultBool("ENABLE_CONNECTOR", false) |
There was a problem hiding this comment.
I am actually not very opinionated on this- we discussed this with @knyar before.
Disabling would allow folks to not install the Connector CRD in the cluster if they don't need it and they might prefer that for some reasons (a large resource? being generally cautious of additional CRDs?). However, none of those are very strong reasons.
It would make it slightly easier for us to get this PR in and deal with updating helm packaging mechanism to include the CRD in after we finally have published helm charts without breaking everyone who is currently installing the operator by helm install ./cmd/k8s-operator .. . This is because I am planning to add the CRD to the chart at package time rather than make it a helm template which doesn't work nicely with the codegen yaml generator.
… Connector kube CRD. Connector allows users to configure the Tailscale operator to deploy a subnet router to expose cluster CIDRs or other CIDRs available from within the cluster to their tailnet. Also adds various CRD related machinery to generate CRD YAML, deep copy implementations etc. Engineers will now have to run 'make kube-generate-all` after changing kube files to ensure that all generated files are up to date. Updates #502 Signed-off-by: Irbe Krumina <[email protected]>
ea30974 to
8dbd9ff
Compare
|
Thanks for the review @maisem I have restructured it so that the I still left the |
Reconcile Connector resources, create/delete subnetrouter resources in response to changes to Connector(s). Signed-off-by: Irbe Krumina <[email protected]>
… via the operator Signed-off-by: Irbe Krumina <[email protected]>
8dbd9ff to
77dddf8
Compare
Connector reconciler will not be started unless ENABLE_CONNECTOR env var is set to true. This means that users who don't want to use the alpha Connector custom resource don't have to install the Connector CRD to their cluster. For users who do want to use it the flow is: - install the CRD - install the operator (via Helm chart or using static manifests). For Helm users set .values.enableConnector to true, for static manifest users, set ENABLE_CONNECTOR to true in the static manifest. Signed-off-by: Irbe Krumina <[email protected]>
77dddf8 to
56935da
Compare
| Message: fmt.Sprintf(messageSubnetRouterCreated, cidrsS), | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
if you return here then you can unindent the block below too.
There was a problem hiding this comment.
I will set subnetrouter as required and remove the block below altogether. When we start supporting more component types, we can anyway not support removing one component definition from a Connector and adding another.
| // that will change in the future - so run the cleanup and provision | ||
| // conditionally already now. | ||
| if cn.Spec.SubnetRouter == nil { | ||
| return true, nil |
There was a problem hiding this comment.
I think this will result in always returning true from line 171, which means the cleanup won't ever happen but we will consider it did.
There was a problem hiding this comment.
I am going to set the subnet router def as required in the CRD spec, so it won't be possible to apply a Connector without a subnet router or routes defined. Then we can remove this check altogether.
| if cn.Spec.SubnetRouter != nil && len(cn.Spec.SubnetRouter.Routes) > 0 { | ||
| var sb strings.Builder | ||
| sb.WriteString(string(cn.Spec.SubnetRouter.Routes[0])) | ||
| for _, r := range cn.Spec.SubnetRouter.Routes[1:] { |
There was a problem hiding this comment.
control (or tailscaled, i forget which) rejects routes that have pfx.Masked() != pfx, we might want to check that here.
There was a problem hiding this comment.
There was a problem hiding this comment.
Would be nice to eventually be able to put this into the validation at apply time, but CEL does not have IP parsing, not sure if this would be too expensive for them to ever do it.
| //go:generate go run tailscale.com/cmd/k8s-operator/generate | ||
|
|
||
| // Generate Connector CustomResourceDefinition yaml from its Go types. | ||
| //go:generate go run sigs.k8s.io/controller-tools/cmd/controller-gen crd schemapatch:manifests=./deploy/crds output:dir=./deploy/crds paths=../../k8s-operator/apis/... |
There was a problem hiding this comment.
I think because of this go:generate line you don't need an additional .github action. but fine as is.
There was a problem hiding this comment.
The github action is to test that the generated code is up to date, without it we could still push a PR with yamls out of date wrt the Go types- or you meant something else?
Signed-off-by: Irbe Krumina <[email protected]>
* k8s-operator,cmd/k8s-operator,Makefile,scripts,.github/workflows: add Connector kube CRD. Connector CRD allows users to configure the Tailscale Kubernetes operator to deploy a subnet router to expose cluster CIDRs or other CIDRs available from within the cluster to their tailnet. Also adds various CRD related machinery to generate CRD YAML, deep copy implementations etc. Engineers will now have to run 'make kube-generate-all` after changing kube files to ensure that all generated files are up to date. * cmd/k8s-operator,k8s-operator: reconcile Connector resources Reconcile Connector resources, create/delete subnetrouter resources in response to changes to Connector(s). Connector reconciler will not be started unless ENABLE_CONNECTOR env var is set to true. This means that users who don't want to use the alpha Connector custom resource don't have to install the Connector CRD to their cluster. For users who do want to use it the flow is: - install the CRD - install the operator (via Helm chart or using static manifests). For Helm users set .values.enableConnector to true, for static manifest users, set ENABLE_CONNECTOR to true in the static manifest. Updates tailscale#502 Signed-off-by: Irbe Krumina <[email protected]>
This PR makes it possible to deploy a Tailscale subnet router in a Kuberntes cluster to expose range(s) of CIDR(s) accessible from within the cluster to tailnet. This could be either cluster
Pod/ServiceCIDR ranges or routes to other private network segments that can be accessed from within the cluster, such as routes to private cloud networks that can be accessed from Kubernetes deployed on that cloud and should be made accessible to tailnet users without exposing them to the internet.It introduces a new cluster-scoped Kubernetes custom resource
Connector.Connectoris intended to be used to allow users to define additional components that the Tailscale operator should create, such as subnet routers, exit nodes etc. Currently the only supported component type is subnet router. There will be 1:1 mapping between aConnectorcustom resource and a component to be deployed (so 1Connectorcan only contain a definition for 1 subnet router, exit node etc).Connectorfunctionality is currently off by default. Users who wish to use it, will have to install theConnectorCRD and setENABLE_CONNECTORenv var on operator manifest to true (or set.values.enableConnectorto true if using Helm).User flow
With auto-approval mechanism
tag:k8sACL tag that operator tags all nodes that it creates able to advertize routes without manual approval).kubectl apply -f ./cmd/k8s-operator/deploy/crdsto install theConnectorCRDENABLE_CONNECTORenv var to "true"Connectorresource:Connectorstatus:With manual approval
Connectorresource:ConnectorstatusNext steps
ConnectorCRD and the operator with a single helm command/cc @maisem