This commit contains the Kubernetes implementation of peer relays via the new `PeerRelay` CRD. It's a mega branch consisting of the commits of other PRs gone into this work: 1. https://github.com/tailscale/tailscale/pull/20211 2. https://github.com/tailscale/tailscale/pull/20329 3. https://github.com/tailscale/tailscale/pull/20423 4. https://github.com/tailscale/tailscale/pull/20503 An instance of the `PeerRelay` CRD deploys a `StatefulSet` of containerboot instances configured to advertise themselves as peer relays using the IP addresses configured via `LoadBalancer` services on each cloud provider (with some AWS specifics as it's less automatic than its competing cloud providers). Per replica, a `LoadBalancer` type `Service` resource is provisioned and its IP address is used to configure the respective relay. This has been tested with success in AWS, GCP & Azure and provides additional modification to `Service` resources via the CRD for any other kinds of deployment environments. It also contains some work that may appear to be duplication of what already exists within `cmd/k8s-operator` so we can start building an appropriate migration path for `Connector`, `ProxyGroup` etc into respective `k8s-operator/reconciler/*` packages. Closes https://github.com/tailscale/corp/issues/34524
81 lines
2.3 KiB
Go
81 lines
2.3 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
package v1alpha1
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"tailscale.com/k8s-operator/apis"
|
|
|
|
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
"k8s.io/apimachinery/pkg/runtime/schema"
|
|
"k8s.io/client-go/kubernetes/scheme"
|
|
)
|
|
|
|
// SchemeGroupVersion is group version used to register these objects
|
|
var SchemeGroupVersion = schema.GroupVersion{Group: apis.GroupName, Version: "v1alpha1"}
|
|
|
|
// Resource takes an unqualified resource and returns a Group qualified GroupResource
|
|
func Resource(resource string) schema.GroupResource {
|
|
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
|
}
|
|
|
|
var (
|
|
SchemeBuilder runtime.SchemeBuilder
|
|
localSchemeBuilder = &SchemeBuilder
|
|
AddToScheme = localSchemeBuilder.AddToScheme
|
|
|
|
GlobalScheme *runtime.Scheme
|
|
)
|
|
|
|
func init() {
|
|
// We only register manually written functions here. The registration of the
|
|
// generated functions takes place in the generated files. The separation
|
|
// makes the code compile even when the generated files are missing.
|
|
localSchemeBuilder.Register(addKnownTypes)
|
|
|
|
GlobalScheme = runtime.NewScheme()
|
|
// Add core types
|
|
if err := scheme.AddToScheme(GlobalScheme); err != nil {
|
|
panic(fmt.Sprintf("failed to add k8s.io scheme: %s", err))
|
|
}
|
|
// Add tailscale.com types
|
|
if err := AddToScheme(GlobalScheme); err != nil {
|
|
panic(fmt.Sprintf("failed to add tailscale.com scheme: %s", err))
|
|
}
|
|
// Add apiextensions types (CustomResourceDefinitions/CustomResourceDefinitionLists)
|
|
if err := apiextensionsv1.AddToScheme(GlobalScheme); err != nil {
|
|
panic(fmt.Sprintf("failed to add apiextensions.k8s.io scheme: %s", err))
|
|
}
|
|
}
|
|
|
|
// Adds the list of known types to api.Scheme.
|
|
func addKnownTypes(scheme *runtime.Scheme) error {
|
|
scheme.AddKnownTypes(SchemeGroupVersion,
|
|
&Connector{},
|
|
&ConnectorList{},
|
|
&ProxyClass{},
|
|
&ProxyClassList{},
|
|
&DNSConfig{},
|
|
&DNSConfigList{},
|
|
&Recorder{},
|
|
&RecorderList{},
|
|
&ProxyGroup{},
|
|
&ProxyGroupList{},
|
|
&Tailnet{},
|
|
&TailnetList{},
|
|
&ProxyGroupPolicy{},
|
|
&ProxyGroupPolicyList{},
|
|
&PeerRelay{},
|
|
&PeerRelayList{},
|
|
)
|
|
|
|
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
|
|
return nil
|
|
}
|