mirror of
https://github.com/keycloak/keycloak.git
synced 2026-01-10 15:32:05 -03:30
feat(operator): add support for custom labels in ingress (#41627)
Signed-off-by: AvivGuiser <avivguiser@gmail.com>
This commit is contained in:
parent
5731cdf673
commit
9feca65665
@ -115,6 +115,7 @@ public class KeycloakIngressDependentResource extends CRUDKubernetesDependentRes
|
||||
.withNewMetadata()
|
||||
.withName(getName(keycloak))
|
||||
.withNamespace(keycloak.getMetadata().getNamespace())
|
||||
.addToLabels(optionalSpec.map(IngressSpec::getLabels).orElse(null))
|
||||
.addToLabels(Utils.allInstanceLabels(keycloak))
|
||||
.addToAnnotations(annotations)
|
||||
.endMetadata()
|
||||
|
||||
@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyDescription;
|
||||
import io.sundr.builder.annotations.Buildable;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
@ -41,6 +42,10 @@ public class IngressSpec {
|
||||
@JsonPropertyDescription("A secret containing the TLS configuration for re-encrypt or TLS termination scenarios. Reference: https://kubernetes.io/docs/concepts/configuration/secret/#tls-secrets.")
|
||||
private String tlsSecret;
|
||||
|
||||
@JsonProperty("labels")
|
||||
@JsonPropertyDescription("Additional labels to be appended to the Ingress object")
|
||||
Map<String, String> labels = new LinkedHashMap<String, String>();
|
||||
|
||||
public boolean isIngressEnabled() {
|
||||
return ingressEnabled;
|
||||
}
|
||||
@ -72,4 +77,10 @@ public class IngressSpec {
|
||||
public void setTlsSecret(String tlsSecret) {
|
||||
this.tlsSecret = tlsSecret;
|
||||
}
|
||||
public Map<String, String> getLabels() {
|
||||
return labels;
|
||||
}
|
||||
public void setLabels(Map<String, String> labels) {
|
||||
this.labels = labels;
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,18 +61,22 @@ public class IngressLogicTest {
|
||||
}
|
||||
|
||||
public static MockKeycloakIngress build(Boolean defaultIngressEnabled, boolean ingressExists, boolean ingressSpecDefined, boolean tlsConfigured) {
|
||||
return build(defaultIngressEnabled, ingressExists, ingressSpecDefined, tlsConfigured, null, null);
|
||||
return build(defaultIngressEnabled, ingressExists, ingressSpecDefined, tlsConfigured, null,null, null);
|
||||
}
|
||||
|
||||
public static MockKeycloakIngress build(String hostname) {
|
||||
return build(true, false, true, true, null, hostname);
|
||||
return build(true, false, true, true, null,null, hostname);
|
||||
}
|
||||
|
||||
public static MockKeycloakIngress build(Boolean defaultIngressEnabled, boolean ingressExists, boolean ingressSpecDefined, boolean tlsConfigured, Map<String, String> annotations) {
|
||||
return build(defaultIngressEnabled, ingressExists, ingressSpecDefined, tlsConfigured, annotations, null);
|
||||
return build(defaultIngressEnabled, ingressExists, ingressSpecDefined, tlsConfigured, annotations,null, null);
|
||||
}
|
||||
|
||||
public static MockKeycloakIngress build(Boolean defaultIngressEnabled, boolean ingressExists, boolean ingressSpecDefined, boolean tlsConfigured, Map<String, String> annotations, String hostname) {
|
||||
public static MockKeycloakIngress build(Boolean defaultIngressEnabled, boolean ingressExists, boolean ingressSpecDefined,Map<String, String> labels) {
|
||||
return build(defaultIngressEnabled, ingressExists, ingressSpecDefined, true, null, labels, null);
|
||||
}
|
||||
|
||||
public static MockKeycloakIngress build(Boolean defaultIngressEnabled, boolean ingressExists, boolean ingressSpecDefined, boolean tlsConfigured, Map<String, String> annotations, Map<String, String> labels,String hostname) {
|
||||
IngressSpec ingressSpec = null;
|
||||
if (ingressSpecDefined) {
|
||||
ingressSpec = new IngressSpec();
|
||||
@ -82,6 +86,9 @@ public class IngressLogicTest {
|
||||
if (annotations != null) {
|
||||
ingressSpec.setAnnotations(annotations);
|
||||
}
|
||||
if (labels != null) {
|
||||
ingressSpec.setLabels(labels);
|
||||
}
|
||||
}
|
||||
MockKeycloakIngress mock = new MockKeycloakIngress(tlsConfigured, ingressSpec, hostname);
|
||||
if (ingressExists) {
|
||||
@ -183,6 +190,14 @@ public class IngressLogicTest {
|
||||
assertEquals("value", reconciled.get().getMetadata().getAnnotations().get("custom"));
|
||||
assertFalse(reconciled.get().getMetadata().getAnnotations().containsKey(EXISTING_ANNOTATION_KEY));
|
||||
}
|
||||
@Test
|
||||
public void testCustomLabels() {
|
||||
var kc = MockKeycloakIngress.build(null, false, true, Map.of("custom", "value"));
|
||||
Optional<Ingress> reconciled = kc.getReconciledResource();
|
||||
assertTrue(reconciled.isPresent());
|
||||
assertFalse(kc.deleted());
|
||||
assertEquals("value", reconciled.get().getMetadata().getLabels().get("custom"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveCustomAnnotation() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user