Skip to content

Commit

Permalink
gateway
Browse files Browse the repository at this point in the history
  • Loading branch information
louiseschmidtgen committed Jun 5, 2024
1 parent f64a160 commit 8a7ea3d
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
Binary file added k8s/manifests/charts/gateway-helm-v1.0.1.tgz
Binary file not shown.
6 changes: 6 additions & 0 deletions src/k8s/pkg/k8sd/features/contour/chart.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,10 @@ var (
Namespace: "projectcontour",
ManifestPath: path.Join("charts", "contour-18.1.2.tgz"),
}

chartEnvoyGateway = helm.InstallableChart{
Name: "ck-gateway",
Namespace: "envoy-gateway-system",
ManifestPath: path.Join("charts", "gateway-helm-v1.0.1.tgz"),
}
)
26 changes: 19 additions & 7 deletions src/k8s/pkg/k8sd/features/contour/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,28 @@ import (
"github.com/canonical/k8s/pkg/snap"
)

// ApplyGateway assumes that the managed Cilium CNI is already installed on the cluster. It will fail if that is not the case.
// ApplyGateway will deploy the Gateway API CRDs on the cluster and enable the GatewayAPI controllers on Cilium, when gateway.Enabled is true.
// ApplyGateway will remove the Gateway API CRDs from the cluster and disable the GatewayAPI controllers on Cilium, when gateway.Enabled is false.
// ApplyGateway will rollout restart the Cilium pods in case any Cilium configuration was changed.
// ApplyGateway assumes that the Contour is already installed on the cluster. It will fail if that is not the case.
// ApplyGateway will deploy the envoy-gateway-system on the cluster and enable set the right gateway configs in contour when gateway.Enabled is true.
// ApplyGateway will remove the envoy-gateway-system from the cluster and remove the right gateway configs in contour when gateway.Enabled is false.
// ApplyGateway will rollout restart the Contour pods.
// ApplyGateway returns an error if anything fails.
func ApplyGateway(ctx context.Context, snap snap.Snap, gateway types.Gateway, network types.Network, _ types.Annotations) error {
m := snap.HelmClient()
// First Install envoy-gateway-system
if gateway.GetEnabled() {
if _, err := m.Apply(ctx, chartEnvoyGateway, helm.StatePresent, nil); err != nil {
return fmt.Errorf("failed to install envoy-gateway-system: %w", err)
}

} else {
if _, err := m.Apply(ctx, chartEnvoyGateway, helm.StateDeleted, nil); err != nil {
return fmt.Errorf("failed to uninstall envoy-gateway-system: %w", err)
}
}

// Second update gateway config bits in contour ingress
var values map[string]any
if gateway.GetEnabled() { //TODO: Do we need to chek for ingress enabled?
if gateway.GetEnabled() { //TODO: Do we need to check for ingress enabled? Are we overwriting values set in ingress?
values = map[string]any{
"gateway": map[string]any{
"gatewayRef": map[string]any{
Expand All @@ -39,14 +51,14 @@ func ApplyGateway(ctx context.Context, snap snap.Snap, gateway types.Gateway, ne
}
changed, err := m.Apply(ctx, chartContour, helm.StateUpgradeOnlyOrDeleted(network.GetEnabled()), values)
if err != nil {
return fmt.Errorf("failed to apply Gateway API contour configuration: %w", err)
return fmt.Errorf("failed to apply Gateway configuration to contour: %w", err)
}

if !changed || !gateway.GetEnabled() {
return nil
}
if err := rolloutRestartContour(ctx, snap, 3); err != nil {
return fmt.Errorf("failed to rollout restart contour to apply Gateway API: %w", err)
return fmt.Errorf("failed to rollout restart contour to apply Gateway configuration: %w", err)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions src/k8s/pkg/k8sd/features/contour/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,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", "projectcontour"); err != nil { //TODO: check name of deployment
if err := client.RestartDeployment(ctx, "ck-ingress-contour-envoy", "projectcontour"); err != nil { //TODO: check name of deployment
return fmt.Errorf("failed to restart contour deployment: %w", err)
}
return nil
Expand All @@ -68,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", "projectcontour"); err != nil {
if err := client.RestartDaemonset(ctx, "ck-ingress-contour-envoy", "projectcontour"); err != nil {
return fmt.Errorf("failed to restart contour daemonset: %w", err)
}
return nil
Expand Down
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: fake.ApplyGateway,
applyGateway: contour.ApplyGateway,
applyMetricsServer: metrics_server.ApplyMetricsServer,
applyLocalStorage: localpv.ApplyLocalStorage,
}
Expand Down

0 comments on commit 8a7ea3d

Please sign in to comment.