cmd/k8s-operator: migrate to tailscale-client-go-v2 (#19010)
This commit modifies the kubernetes operator to use the `tailscale-client-go-v2` package instead of the internal tailscale client it was previously using. This now gives us the ability to expand out custom resources and features as they become available via the API module. The tailnet reconciler has also been modified to manage clients as tailnets are created and removed, providing each subsequent reconciler with a single `ClientProvider` that obtains a tailscale client for the respective tailnet by name, or the operator's default when presented with a blank string. Fixes: https://github.com/tailscale/corp/issues/38418 Signed-off-by: David Bond <davidsbond93@gmail.com>
This commit is contained in:
@@ -22,15 +22,15 @@ import (
|
||||
"k8s.io/client-go/tools/record"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||
"tailscale.com/client/tailscale/v2"
|
||||
|
||||
tsoperator "tailscale.com/k8s-operator"
|
||||
tsapi "tailscale.com/k8s-operator/apis/v1alpha1"
|
||||
"tailscale.com/k8s-operator/tsclient"
|
||||
"tailscale.com/kube/ingressservices"
|
||||
"tailscale.com/kube/kubetypes"
|
||||
"tailscale.com/tstest"
|
||||
"tailscale.com/util/mak"
|
||||
|
||||
"tailscale.com/tailcfg"
|
||||
)
|
||||
|
||||
func TestServicePGReconciler(t *testing.T) {
|
||||
@@ -102,11 +102,11 @@ func TestServicePGReconciler_UpdateHostname(t *testing.T) {
|
||||
verifyTailscaleService(t, ft, fmt.Sprintf("svc:%s", hostname), []string{"do-not-validate"})
|
||||
verifyTailscaledConfig(t, fc, "test-pg", []string{fmt.Sprintf("svc:%s", hostname)})
|
||||
|
||||
_, err := ft.GetVIPService(context.Background(), tailcfg.ServiceName(fmt.Sprintf("svc:default-%s", svc.Name)))
|
||||
_, err := ft.VIPServices().Get(context.Background(), fmt.Sprintf("svc:default-%s", svc.Name))
|
||||
if err == nil {
|
||||
t.Fatalf("svc:default-%s not cleaned up", svc.Name)
|
||||
}
|
||||
if !isErrorTailscaleServiceNotFound(err) {
|
||||
if !tailscale.IsNotFound(err) {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
@@ -188,7 +188,9 @@ func setupServiceTest(t *testing.T) (*HAServiceReconciler, *corev1.Secret, clien
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
ft := &fakeTSClient{}
|
||||
ft := &fakeTSClient{
|
||||
vipServices: make(map[string]tailscale.VIPService),
|
||||
}
|
||||
zl, err := zap.NewDevelopment()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
@@ -197,7 +199,7 @@ func setupServiceTest(t *testing.T) (*HAServiceReconciler, *corev1.Secret, clien
|
||||
cl := tstest.NewClock(tstest.ClockOpts{})
|
||||
svcPGR := &HAServiceReconciler{
|
||||
Client: fc,
|
||||
tsClient: ft,
|
||||
clients: tsclient.NewProvider(ft),
|
||||
clock: cl,
|
||||
defaultTags: []string{"tag:k8s"},
|
||||
tsNamespace: "operator-ns",
|
||||
@@ -275,22 +277,22 @@ func TestServicePGReconciler_MultiCluster(t *testing.T) {
|
||||
if i == 0 {
|
||||
ft = fti
|
||||
} else {
|
||||
pgr.tsClient = ft
|
||||
pgr.clients = tsclient.NewProvider(ft)
|
||||
}
|
||||
|
||||
svc, _ := setupTestService(t, "test-multi-cluster", "", "4.3.2.1", fc, stateSecret)
|
||||
expectReconciled(t, pgr, "default", svc.Name)
|
||||
|
||||
tsSvcs, err := ft.ListVIPServices(context.Background())
|
||||
tsSvcs, err := ft.VIPServices().List(t.Context())
|
||||
if err != nil {
|
||||
t.Fatalf("getting Tailscale Service: %v", err)
|
||||
}
|
||||
|
||||
if len(tsSvcs.VIPServices) != 1 {
|
||||
t.Fatalf("unexpected number of Tailscale Services (%d)", len(tsSvcs.VIPServices))
|
||||
if len(tsSvcs) != 1 {
|
||||
t.Fatalf("unexpected number of Tailscale Services (%d)", len(tsSvcs))
|
||||
}
|
||||
|
||||
for _, svc := range tsSvcs.VIPServices {
|
||||
for _, svc := range tsSvcs {
|
||||
t.Logf("found Tailscale Service with name %q", svc.Name)
|
||||
}
|
||||
}
|
||||
@@ -322,9 +324,9 @@ func TestIgnoreRegularService(t *testing.T) {
|
||||
|
||||
verifyTailscaledConfig(t, fc, "test-pg", nil)
|
||||
|
||||
tsSvcs, err := ft.ListVIPServices(context.Background())
|
||||
tsSvcs, err := ft.VIPServices().List(t.Context())
|
||||
if err == nil {
|
||||
if len(tsSvcs.VIPServices) > 0 {
|
||||
if len(tsSvcs) > 0 {
|
||||
t.Fatal("unexpected Tailscale Services found")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user