Skip to content

Commit

Permalink
more wip
Browse files Browse the repository at this point in the history
  • Loading branch information
louiseschmidtgen committed Jun 5, 2024
1 parent e1cd4f2 commit a0a36c3
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
4 changes: 2 additions & 2 deletions docs/src/snap/howto/networking/default-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/k8s/pkg/k8sd/features/contour/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
}
)
2 changes: 1 addition & 1 deletion src/k8s/pkg/k8sd/features/contour/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
}
Expand Down
23 changes: 16 additions & 7 deletions src/k8s/pkg/k8sd/features/contour/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions src/k8s/pkg/k8sd/features/fake/gateway.go
Original file line number Diff line number Diff line change
@@ -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
}
2 changes: 1 addition & 1 deletion src/k8s/pkg/k8sd/features/implementation_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit a0a36c3

Please sign in to comment.