diff --git a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/IngressBuilder.java b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/IngressBuilder.java index c332870..e702670 100644 --- a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/IngressBuilder.java +++ b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/IngressBuilder.java @@ -61,11 +61,20 @@ public interface IngressBuilder { IngressBuilder redirect(String uri); /** - * Sets the response timeout for this ingress. + * Redirect the client to the new relative or absolute URL, using status code {@code code}. * - * @param seconds timeout + * @param uri the target URI + * @param code the HTTP status code for the redirect, for example, 301 * @return the builder */ + IngressBuilder redirect(String uri, int code); + + /** + * Sets the response timeout for this ingress. + * + * @param seconds timeout + * @return the builder + */ IngressBuilder responseTimeout(int seconds); /** diff --git a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/NginxIngressBuilder.java b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/NginxIngressBuilder.java index bf6302a..6b9b89b 100644 --- a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/NginxIngressBuilder.java +++ b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/NginxIngressBuilder.java @@ -82,6 +82,7 @@ public IngressBuilder pathExact(String path, String service) { @Override public IngressBuilder pathPattern(String path, String service) { + annotations.put("nginx.ingress.kubernetes.io/use-regex", "true"); paths.add(new Path(path, PathType.PATTERN, service)); return this; } @@ -98,6 +99,14 @@ public IngressBuilder redirect(String uri) { return this; } + @Override + public IngressBuilder redirect(String uri, int code) { + annotations.put("nginx.ingress.kubernetes.io/permanent-redirect", uri); + if (code != 301) + annotations.put("nginx.ingress.kubernetes.io/permanent-redirect-code", String.valueOf(code)); + return this; + } + @Override public IngressBuilder rewrite(String pattern) { annotations.put("nginx.ingress.kubernetes.io/rewrite-target", pattern); diff --git a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/OnlyLangUrlMappingBuilder.java b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/OnlyLangUrlMappingBuilder.java index 41106d6..0db5f87 100644 --- a/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/OnlyLangUrlMappingBuilder.java +++ b/src/main/java/com/tsystemsmms/cmcc/cmccoperator/ingress/OnlyLangUrlMappingBuilder.java @@ -16,6 +16,7 @@ import com.tsystemsmms.cmcc.cmccoperator.targetstate.TargetState; import io.fabric8.kubernetes.api.model.HasMetadata; import lombok.extern.slf4j.Slf4j; +import org.springframework.http.HttpStatus; import java.util.*; import java.util.stream.Collectors; @@ -38,7 +39,7 @@ *

* The resulting rewrite rules build these mappings: *