diff --git a/pkg/resourcecreator/ingress/ingress.go b/pkg/resourcecreator/ingress/ingress.go index aec39887..421b55c0 100644 --- a/pkg/resourcecreator/ingress/ingress.go +++ b/pkg/resourcecreator/ingress/ingress.go @@ -37,7 +37,6 @@ type Config interface { func ingressRule(appName string, u *url.URL) networkingv1.IngressRule { pathType := networkingv1.PathTypeImplementationSpecific - return networkingv1.IngressRule{ Host: u.Host, IngressRuleValue: networkingv1.IngressRuleValue{ @@ -67,6 +66,7 @@ func ingressRules(source Source) ([]networkingv1.IngressRule, error) { for _, ingress := range ingresses { parsedUrl, err := parseIngress(string(ingress)) + fmt.Println("parsedUrl", parsedUrl) if err != nil { return nil, err } @@ -104,7 +104,7 @@ func copyNginxAnnotations(dst, src map[string]string) { } } -func createIngressBase(source Source, rules []networkingv1.IngressRule) *networkingv1.Ingress { +func createIngressBase(source Source) *networkingv1.Ingress { objectMeta := resource.CreateObjectMeta(source) objectMeta.Annotations["prometheus.io/scrape"] = "true" objectMeta.Annotations["prometheus.io/path"] = source.GetLiveness().Path @@ -116,14 +116,14 @@ func createIngressBase(source Source, rules []networkingv1.IngressRule) *network }, ObjectMeta: objectMeta, Spec: networkingv1.IngressSpec{ - Rules: rules, + Rules: []networkingv1.IngressRule{}, }, } } func createIngressBaseNginx(source Source, ingressClass string, redirect string) (*networkingv1.Ingress, error) { var err error - ingress := createIngressBase(source, []networkingv1.IngressRule{}) + ingress := createIngressBase(source) baseName := fmt.Sprintf("%s-%s", source.GetName(), ingressClass) ingress.Name, err = namegen.ShortName(baseName, validation.DNS1035LabelMaxLength) if err != nil { @@ -205,6 +205,10 @@ func createRedirectIngresses(source Source, cfg Config, redirects []nais_io_v1.R for _, ing := range ingresses { for _, redirect := range redirects { for _, rule := range ing.Spec.Rules { + parsedFromRedirectUrl, err := parseIngress(string(redirect.From)) + if err != nil { + return err + } parsedToRedirectUrl, err := parseIngress(string(redirect.To)) if err != nil { return err @@ -212,14 +216,17 @@ func createRedirectIngresses(source Source, cfg Config, redirects []nais_io_v1.R // found the ingress that matches the redirect if rule.Host == parsedToRedirectUrl.Host { - r := ingressRule(source.GetName(), parsedToRedirectUrl) + urlPath, err := url.Parse(strings.TrimRight(parsedFromRedirectUrl.String(), "/")) + if err != nil { + return err + } + urlPath.Path = urlPath.Path + regexSuffix + r := ingressRule(source.GetName(), urlPath) parsedFromUrl, err := parseIngress(string(redirect.From)) if err != nil { return err } ingressClass := util.ResolveIngressClass(parsedFromUrl.Host, cfg.GetGatewayMappings()) - fmt.Println("ingressClass", *ingressClass) - fmt.Println("redirectTo", string(redirect.To)) rdIngress, err := getIngress(source, cfg, r, ingressClass, string(redirect.To)) if err != nil { return err diff --git a/pkg/resourcecreator/testdata/ingress_redirect.yaml b/pkg/resourcecreator/testdata/ingress_redirect.yaml index 98b14f64..6b58df33 100644 --- a/pkg/resourcecreator/testdata/ingress_redirect.yaml +++ b/pkg/resourcecreator/testdata/ingress_redirect.yaml @@ -48,6 +48,7 @@ tests: port: number: 80 path: / + pathType: ImplementationSpecific - operation: CreateOrUpdate apiVersion: networking.k8s.io/v1 @@ -64,7 +65,7 @@ tests: spec: ingressClassName: "nais-ingress" rules: - - host: "myapplication-other.domain" + - host: "myapplication.from.redirect.old.dev.nais.io" http: paths: - backend: @@ -72,4 +73,5 @@ tests: name: myapplicationredirect port: number: 80 - path: / + path: (/.*)? + pathType: ImplementationSpecific \ No newline at end of file diff --git a/pkg/resourcecreator/testdata/ingress_redirect_no_ingress.yaml b/pkg/resourcecreator/testdata/ingress_redirect_no_ingress.yaml index fe629c08..94194ca8 100644 --- a/pkg/resourcecreator/testdata/ingress_redirect_no_ingress.yaml +++ b/pkg/resourcecreator/testdata/ingress_redirect_no_ingress.yaml @@ -19,7 +19,7 @@ input: spec: image: navikt/myapplication:1.2.3 ingresses: - - "https://myapplication-other.domain" + - "https://notspecinredirects.to.domain" redirects: - from: "https://myapplication.from.redirect.old.dev.nais.io" to: "https://myapplication.dev.nais.io"