diff --git a/main.go b/main.go index 0aff57b..02e372a 100644 --- a/main.go +++ b/main.go @@ -17,7 +17,7 @@ func main() { }, { Image: "nginx", - Path: "/api", + Path: "/api", }, }, Env: map[string]string{ diff --git a/pkg/application/generic.go b/pkg/application/generic.go index ffe8dba..fcf91ff 100644 --- a/pkg/application/generic.go +++ b/pkg/application/generic.go @@ -212,27 +212,37 @@ func createMiddlewareAddResponseHeader( namespace *corev1.Namespace, application *Application, ) (*traefikv1alpha1.Middleware, error) { - middlewareName := fmt.Sprintf("%s-response-header-middleware", configuration.Name) - return traefikv1alpha1.NewMiddleware(ctx, middlewareName, &traefikv1alpha1.MiddlewareArgs{ - Metadata: &metav1.ObjectMetaArgs{ - Namespace: namespace.Metadata.Name(), - Labels: pulumi.StringMap{ - "app.kubernetes.io/part-of": pulumi.String(configuration.Name), - "app.kubernetes.io/managed-by": pulumi.String("pulumi"), + if configuration.ResponseHeaders != nil { + middlewareName := fmt.Sprintf("%s-response-header-middleware", configuration.Name) + return traefikv1alpha1.NewMiddleware(ctx, middlewareName, &traefikv1alpha1.MiddlewareArgs{ + Metadata: &metav1.ObjectMetaArgs{ + Namespace: namespace.Metadata.Name(), + Labels: pulumi.StringMap{ + "app.kubernetes.io/part-of": pulumi.String(configuration.Name), + "app.kubernetes.io/managed-by": pulumi.String("pulumi"), + }, }, - }, - Spec: &traefikv1alpha1.MiddlewareSpecArgs{ - Headers: configuration.ResponseHeaders, - }, - }, pulumi.Parent(application)) + Spec: &traefikv1alpha1.MiddlewareSpecArgs{ + Headers: configuration.ResponseHeaders, + }, + }, pulumi.Parent(application)) + } + return nil, nil } func createIngress(ctx *pulumi.Context, configuration *configuration, namespace *corev1.Namespace, certificate *v1.Certificate, servicesConfiguration []ingressConfiguration, application *Application, responseHeaderMiddleware *traefikv1alpha1.Middleware) (*netv1.Ingress, error) { if configuration.ShouldCreateIngress { host := pulumi.String(configuration.Dns) - middlewares := pulumi.All(namespace.Metadata.Name().Elem(), responseHeaderMiddleware.Metadata.Name().Elem()).ApplyT(func(args []interface{}) string { - return fmt.Sprintf("kube-ingress-gzip-compress@kubernetescrd,%s-%s@kubernetescrd", args[0], args[1]) - }).(pulumi.StringOutput) + + var middlewares pulumi.StringInput + if configuration.ResponseHeaders != nil { + middlewares = pulumi.All(namespace.Metadata.Name().Elem(), responseHeaderMiddleware.Metadata.Name().Elem()).ApplyT(func(args []interface{}) string { + return fmt.Sprintf("kube-ingress-gzip-compress@kubernetescrd,%s-%s@kubernetescrd", args[0], args[1]) + }).(pulumi.StringOutput) + } else { + middlewares = pulumi.String("kube-ingress-gzip-compress@kubernetescrd") + } + ingressAnnotations := pulumi.StringMap{ "traefik.ingress.kubernetes.io/router.middlewares": middlewares, "traefik.ingress.kubernetes.io/router.entrypoints": pulumi.String("websecure"),