From 94f45dbd58682ad749aca09885e45132e1a46a5e Mon Sep 17 00:00:00 2001 From: Benjamin Schimke Date: Mon, 3 Jun 2024 14:39:28 +0200 Subject: [PATCH] Add dualstack configuration (#445) --- src/k8s/pkg/k8sd/features/cilium/network.go | 6 +++ src/k8s/pkg/k8sd/setup/kube_apiserver_test.go | 13 +++++++ .../templates/nginx-dualstack.yaml | 37 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 tests/integration/templates/nginx-dualstack.yaml diff --git a/src/k8s/pkg/k8sd/features/cilium/network.go b/src/k8s/pkg/k8sd/features/cilium/network.go index f116eb6b8..e7d8051e3 100644 --- a/src/k8s/pkg/k8sd/features/cilium/network.go +++ b/src/k8s/pkg/k8sd/features/cilium/network.go @@ -71,6 +71,12 @@ func ApplyNetwork(ctx context.Context, snap snap.Snap, cfg types.Network) error "useDigest": false, }, }, + "ipv4": map[string]any{ + "enabled": ipv4CIDR != "", + }, + "ipv6": map[string]any{ + "enabled": ipv6CIDR != "", + }, "ipam": map[string]any{ "operator": map[string]any{ "clusterPoolIPv4PodCIDRList": ipv4CIDR, diff --git a/src/k8s/pkg/k8sd/setup/kube_apiserver_test.go b/src/k8s/pkg/k8sd/setup/kube_apiserver_test.go index 1749f042c..6eede1f05 100644 --- a/src/k8s/pkg/k8sd/setup/kube_apiserver_test.go +++ b/src/k8s/pkg/k8sd/setup/kube_apiserver_test.go @@ -132,6 +132,19 @@ func TestKubeAPIServer(t *testing.T) { g.Expect(len(args)).To(Equal(len(tests))) }) + t.Run("ArgsDualstack", func(t *testing.T) { + g := NewWithT(t) + + s := mustSetupSnapAndDirectories(t, setKubeAPIServerMock) + + // Setup without proxy to simplify argument list + g.Expect(setup.KubeAPIServer(s, "10.0.0.0/24,fd01::/64", "https://auth-webhook.url", false, types.Datastore{Type: utils.Pointer("external"), ExternalServers: utils.Pointer([]string{"datastoreurl1", "datastoreurl2"})}, "Node,RBAC")).To(BeNil()) + + g.Expect(snaputil.GetServiceArgument(s, "kube-apiserver", "--service-cluster-ip-range")).To(Equal("10.0.0.0/24,fd01::/64")) + _, err := utils.ParseArgumentFile(path.Join(s.Mock.ServiceArgumentsDir, "kube-apiserver")) + g.Expect(err).ToNot(HaveOccurred()) + }) + t.Run("ArgsExternalDatastore", func(t *testing.T) { g := NewWithT(t) diff --git a/tests/integration/templates/nginx-dualstack.yaml b/tests/integration/templates/nginx-dualstack.yaml new file mode 100644 index 000000000..959fc2a11 --- /dev/null +++ b/tests/integration/templates/nginx-dualstack.yaml @@ -0,0 +1,37 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nginxdualstack +spec: + selector: + matchLabels: + run: nginxdualstack + replicas: 1 + template: + metadata: + labels: + run: nginxdualstack + spec: + containers: + - name: nginxdualstack + image: rocks.canonical.com/cdk/diverdane/nginxdualstack:1.0.0 + ports: + - containerPort: 80 +--- +apiVersion: v1 +kind: Service +metadata: + name: nginx6 + labels: + run: nginxdualstack +spec: + type: NodePort + ipFamilies: + - IPv4 + - IPv6 + ipFamilyPolicy: RequireDualStack + ports: + - port: 80 + protocol: TCP + selector: + run: nginxdualstack