mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-25 19:15:34 +00:00
44aa809cb0
* cmd/k8s-nameserver,k8s-operator: add a nameserver that can resolve ts.net DNS names in cluster. Adds a simple nameserver that can respond to A record queries for ts.net DNS names. It can respond to queries from in-memory records, populated from a ConfigMap mounted at /config. It dynamically updates its records as the ConfigMap contents changes. It will respond with NXDOMAIN to queries for any other record types (AAAA to be implemented in the future). It can respond to queries over UDP or TCP. It runs a miekg/dns DNS server with a single registered handler for ts.net domain names. Queries for other domain names will be refused. The intended use of this is: 1) to allow non-tailnet cluster workloads to talk to HTTPS tailnet services exposed via Tailscale operator egress over HTTPS 2) to allow non-tailnet cluster workloads to talk to workloads in the same cluster that have been exposed to tailnet over their MagicDNS names but on their cluster IPs. DNSConfig CRD can be used to configure the operator to deploy kube nameserver (./cmd/k8s-nameserver) to cluster. Updates tailscale/tailscale#10499 Signed-off-by: Irbe Krumina <irbe@tailscale.com>
102 lines
2.9 KiB
Go
102 lines
2.9 KiB
Go
// Copyright (c) Tailscale Inc & AUTHORS
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
package kube
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"go.uber.org/zap"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
tsapi "tailscale.com/k8s-operator/apis/v1alpha1"
|
|
"tailscale.com/tstest"
|
|
)
|
|
|
|
func TestSetConnectorCondition(t *testing.T) {
|
|
cn := tsapi.Connector{}
|
|
clock := tstest.NewClock(tstest.ClockOpts{})
|
|
fakeNow := metav1.NewTime(clock.Now().Truncate(time.Second))
|
|
fakePast := metav1.NewTime(clock.Now().Truncate(time.Second).Add(-5 * time.Minute))
|
|
zl, err := zap.NewDevelopment()
|
|
assert.Nil(t, err)
|
|
|
|
// Set up a new condition
|
|
SetConnectorCondition(&cn, tsapi.ConnectorReady, metav1.ConditionTrue, "someReason", "someMsg", 1, clock, zl.Sugar())
|
|
assert.Equal(t, cn, tsapi.Connector{
|
|
Status: tsapi.ConnectorStatus{
|
|
Conditions: []tsapi.ConnectorCondition{
|
|
{
|
|
Type: tsapi.ConnectorReady,
|
|
Status: metav1.ConditionTrue,
|
|
Reason: "someReason",
|
|
Message: "someMsg",
|
|
ObservedGeneration: 1,
|
|
LastTransitionTime: &fakeNow,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// Modify status of an existing condition
|
|
cn.Status = tsapi.ConnectorStatus{
|
|
Conditions: []tsapi.ConnectorCondition{
|
|
{
|
|
Type: tsapi.ConnectorReady,
|
|
Status: metav1.ConditionFalse,
|
|
Reason: "someReason",
|
|
Message: "someMsg",
|
|
ObservedGeneration: 1,
|
|
LastTransitionTime: &fakePast,
|
|
},
|
|
},
|
|
}
|
|
SetConnectorCondition(&cn, tsapi.ConnectorReady, metav1.ConditionTrue, "anotherReason", "anotherMsg", 2, clock, zl.Sugar())
|
|
assert.Equal(t, cn, tsapi.Connector{
|
|
Status: tsapi.ConnectorStatus{
|
|
Conditions: []tsapi.ConnectorCondition{
|
|
{
|
|
Type: tsapi.ConnectorReady,
|
|
Status: metav1.ConditionTrue,
|
|
Reason: "anotherReason",
|
|
Message: "anotherMsg",
|
|
ObservedGeneration: 2,
|
|
LastTransitionTime: &fakeNow,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
|
|
// Don't modify last transition time if status hasn't changed
|
|
cn.Status = tsapi.ConnectorStatus{
|
|
Conditions: []tsapi.ConnectorCondition{
|
|
{
|
|
Type: tsapi.ConnectorReady,
|
|
Status: metav1.ConditionTrue,
|
|
Reason: "someReason",
|
|
Message: "someMsg",
|
|
ObservedGeneration: 1,
|
|
LastTransitionTime: &fakePast,
|
|
},
|
|
},
|
|
}
|
|
SetConnectorCondition(&cn, tsapi.ConnectorReady, metav1.ConditionTrue, "anotherReason", "anotherMsg", 2, clock, zl.Sugar())
|
|
assert.Equal(t, cn, tsapi.Connector{
|
|
Status: tsapi.ConnectorStatus{
|
|
Conditions: []tsapi.ConnectorCondition{
|
|
{
|
|
Type: tsapi.ConnectorReady,
|
|
Status: metav1.ConditionTrue,
|
|
Reason: "anotherReason",
|
|
Message: "anotherMsg",
|
|
ObservedGeneration: 2,
|
|
LastTransitionTime: &fakePast,
|
|
},
|
|
},
|
|
},
|
|
})
|
|
}
|