Skip to content

Commit

Permalink
Add a fallback traefik router when there are no path matches
Browse files Browse the repository at this point in the history
Signed-off-by: dkwon17 <[email protected]>
  • Loading branch information
dkwon17 authored and ibuziuk committed Jun 5, 2024
1 parent 36750ae commit c361102
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion pkg/deploy/gateway/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,15 @@ func syncAll(deployContext *chetypes.DeployContext) (bool, error) {
return done, err
}

fallbackConfig, err := createGatewayFallbackConfig(deployContext)
if err != nil {
return false, err
}

if done, err := deploy.Sync(deployContext, &fallbackConfig, configMapDiffOpts); !done {
return false, err
}

depl, err := getGatewayDeploymentSpec(deployContext)
if err != nil {
return false, err
Expand Down Expand Up @@ -230,7 +239,7 @@ func getGatewayServerConfigSpec(deployContext *chetypes.DeployContext) (corev1.C
cfg := CreateCommonTraefikConfig(
serverComponentName,
"PathPrefix(`/api`, `/swagger`, `/_app`)",
1,
10,
"http://"+deploy.CheServiceName+":8080",
[]string{})

Expand Down Expand Up @@ -424,6 +433,26 @@ experimental:
}
}

func createGatewayFallbackConfig(ctx *chetypes.DeployContext) (corev1.ConfigMap, error) {
cfg := CreateEmptyTraefikConfig()

// clear services to prevent the following error fom traefik pod:
// "services cannot be a standalone element (type map[string]*dynamic.Service)"
cfg.HTTP.Services = nil

noopComponent := "che-no-op"
cfg.HTTP.Routers[noopComponent] = &TraefikConfigRouter{
Rule: "PathPrefix(`/`)",
Service: "noop@internal", // traefik internal no-op service
Middlewares: []string{},
Priority: 1,
}
closeHeader := map[string]string{"Connection": "close"}
cfg.AddResponseHeaders(noopComponent, closeHeader)

return GetConfigmapForGatewayConfig(ctx, "fallback", cfg)
}

func getGatewayDeploymentSpec(ctx *chetypes.DeployContext) (*appsv1.Deployment, error) {
terminationGracePeriodSeconds := int64(10)

Expand Down

0 comments on commit c361102

Please sign in to comment.