From a0a36c37955a9ec51238734c393d287ee07bd240 Mon Sep 17 00:00:00 2001 From: louiseschmidtgen Date: Wed, 5 Jun 2024 10:47:52 +0200 Subject: [PATCH] more wip --- .../snap/howto/networking/default-network.md | 4 ++-- src/k8s/pkg/k8sd/features/contour/chart.go | 2 +- src/k8s/pkg/k8sd/features/contour/gateway.go | 2 +- src/k8s/pkg/k8sd/features/contour/ingress.go | 23 +++++++++++++------ src/k8s/pkg/k8sd/features/fake/gateway.go | 13 +++++++++++ .../k8sd/features/implementation_default.go | 2 +- 6 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/k8s/pkg/k8sd/features/fake/gateway.go diff --git a/docs/src/snap/howto/networking/default-network.md b/docs/src/snap/howto/networking/default-network.md index ef951c6d1..246184fe7 100644 --- a/docs/src/snap/howto/networking/default-network.md +++ b/docs/src/snap/howto/networking/default-network.md @@ -76,8 +76,8 @@ You can `disable` the built-in network: disabling Network. ``` -If your underlying network is cilium you will have to run `sudo k8s disable gateway` -before disabling network. +If your underlying network is cilium you will have to run +`sudo k8s disable gateway` before disabling network. ``` sudo k8s disable network diff --git a/src/k8s/pkg/k8sd/features/contour/chart.go b/src/k8s/pkg/k8sd/features/contour/chart.go index ff81c5af8..aedc18c39 100644 --- a/src/k8s/pkg/k8sd/features/contour/chart.go +++ b/src/k8s/pkg/k8sd/features/contour/chart.go @@ -10,7 +10,7 @@ var ( // chartContour represents manifests to deploy Contour. chartContour = helm.InstallableChart{ Name: "ck-ingress", - Namespace: "project-contour", + Namespace: "projectcontour", ManifestPath: path.Join("charts", "contour-18.1.2.tgz"), } ) diff --git a/src/k8s/pkg/k8sd/features/contour/gateway.go b/src/k8s/pkg/k8sd/features/contour/gateway.go index c17a1c603..e78a9f61e 100644 --- a/src/k8s/pkg/k8sd/features/contour/gateway.go +++ b/src/k8s/pkg/k8sd/features/contour/gateway.go @@ -23,7 +23,7 @@ func ApplyGateway(ctx context.Context, snap snap.Snap, gateway types.Gateway, ne "gateway": map[string]any{ "gatewayRef": map[string]any{ "name": "gateway", - "namespace": "project-contour", + "namespace": "projectcontour", }, }, } diff --git a/src/k8s/pkg/k8sd/features/contour/ingress.go b/src/k8s/pkg/k8sd/features/contour/ingress.go index ae3ee9bf9..b882eb9bd 100644 --- a/src/k8s/pkg/k8sd/features/contour/ingress.go +++ b/src/k8s/pkg/k8sd/features/contour/ingress.go @@ -18,18 +18,27 @@ import ( func ApplyIngress(ctx context.Context, snap snap.Snap, ingress types.Ingress, network types.Network, _ types.Annotations) error { m := snap.HelmClient() + //TODO: map these friends + // enableProxyProtocol = ingress.GetEnableProxyProtocol() + // defaultTLSSecret = ingress.GetDefaultTLSSecret() + + if !ingress.GetEnabled() { + if _, err := m.Apply(ctx, chartContour, helm.StateDeleted, nil); err != nil { + return fmt.Errorf("failed to uninstall ingress: %w", err) + } + } var values map[string]any if ingress.GetEnabled() { values = map[string]any{ - "envoy-service-namespace": "project-contour", + "envoy-service-namespace": "projectcontour", "envoy-service-name": "envoy", - "tls": map[string]any{ - "envoy-client-certificate": ingress.GetDefaultTLSSecret(), //TODO: I think this is wrong - }, + // "tls": map[string]any{ + // "envoy-client-certificate": ingress.GetDefaultTLSSecret(), //TODO: I think this is wrong + // }, } } - changed, err := m.Apply(ctx, chartContour, helm.StateUpgradeOnlyOrDeleted(network.GetEnabled()), values) + changed, err := m.Apply(ctx, chartContour, helm.StatePresent, values) if err != nil { return fmt.Errorf("failed to enable ingress: %w", err) } @@ -50,7 +59,7 @@ func rolloutRestartContour(ctx context.Context, snap snap.Snap, attempts int) er } if err := control.RetryFor(ctx, attempts, 0, func() error { - if err := client.RestartDeployment(ctx, "contour-contour", "project-contour"); err != nil { //TODO: check name of deployment + if err := client.RestartDeployment(ctx, "contour-contour", "projectcontour"); err != nil { //TODO: check name of deployment return fmt.Errorf("failed to restart contour deployment: %w", err) } return nil @@ -59,7 +68,7 @@ func rolloutRestartContour(ctx context.Context, snap snap.Snap, attempts int) er } if err := control.RetryFor(ctx, attempts, 0, func() error { - if err := client.RestartDaemonset(ctx, "contour-envoy", "project-contour"); err != nil { + if err := client.RestartDaemonset(ctx, "contour-envoy", "projectcontour"); err != nil { return fmt.Errorf("failed to restart contour daemonset: %w", err) } return nil diff --git a/src/k8s/pkg/k8sd/features/fake/gateway.go b/src/k8s/pkg/k8sd/features/fake/gateway.go new file mode 100644 index 000000000..628a1cc4a --- /dev/null +++ b/src/k8s/pkg/k8sd/features/fake/gateway.go @@ -0,0 +1,13 @@ +package fake + +import ( + "context" + + "github.com/canonical/k8s/pkg/k8sd/types" + "github.com/canonical/k8s/pkg/snap" +) + +// ApplyGateway is a dummy implementation of the ApplyGateway function. It does nothing and returns nil. +func ApplyGateway(ctx context.Context, snap snap.Snap, gateway types.Gateway, network types.Network, _ types.Annotations) error { + return nil +} diff --git a/src/k8s/pkg/k8sd/features/implementation_default.go b/src/k8s/pkg/k8sd/features/implementation_default.go index 288ab455f..e4672f692 100644 --- a/src/k8s/pkg/k8sd/features/implementation_default.go +++ b/src/k8s/pkg/k8sd/features/implementation_default.go @@ -18,7 +18,7 @@ var Implementation Interface = &implementation{ applyNetwork: fake.ApplyNetwork, //TODO: remove default overwrite for testing applyLoadBalancer: fake.ApplyLoadBalancer, applyIngress: contour.ApplyIngress, - applyGateway: contour.ApplyGateway, + applyGateway: fake.ApplyGateway, applyMetricsServer: metrics_server.ApplyMetricsServer, applyLocalStorage: localpv.ApplyLocalStorage, }