Fix disableDefaultIngress CR field of the operator

This commit is contained in:
andreaTP 2022-04-27 09:54:33 +01:00 committed by Bruno Oliveira da Silva
parent e2cf6ae92b
commit 1f47cb2795
6 changed files with 65 additions and 3 deletions

View file

@ -164,6 +164,22 @@ CONDITION: RollingUpdate
=== Accessing the Keycloak Deployment
The Keycloak deployment is, by default, exposed through a basic nginx ingress and it will be accessible through the provided hostname.
If the default ingress doesn't fit your use-case you can disable it by setting `disableDefaultIngress: true`:
[source,bash]
----
cat <<EOF >> example-kc.yaml
apiVersion: k8s.keycloak.org/v2alpha1
kind: Keycloak
metadata:
name: example-kc
spec:
...
disableDefaultIngress: true
EOF
kubectl apply -f example-kc.yaml
----
And you can provide an alternative ingress resource pointing to the service `<keycloak-cr-name>-service`.
For debugging and development purposes we suggest you to directly connect to the Keycloak service using a port forward:

View file

@ -43,7 +43,7 @@ public class KeycloakIngress extends OperatorManagedResource implements StatusUp
@Override
protected Optional<HasMetadata> getReconciledResource() {
var defaultIngress = newIngress();
if (keycloak.getSpec().isDefaultIngressDisabled() && existingIngress != null) {
if (keycloak.getSpec().isDisableDefaultIngress() && existingIngress != null) {
client.network().v1().ingresses().delete(existingIngress);
return Optional.empty();
} else if (existingIngress == null) {

View file

@ -63,11 +63,11 @@ public class KeycloakSpec {
return this.hostname.equals(Constants.INSECURE_DISABLE);
}
public void setDefaultIngressDisabled(boolean value) {
public void setDisableDefaultIngress(boolean value) {
this.disableDefaultIngress = value;
}
public boolean isDefaultIngressDisabled() {
public boolean isDisableDefaultIngress() {
return this.disableDefaultIngress;
}

View file

@ -0,0 +1,22 @@
package org.keycloak.operator;
import io.fabric8.kubernetes.client.utils.Serialization;
import org.junit.jupiter.api.Test;
import org.keycloak.operator.v2alpha1.crds.Keycloak;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class CRSerializationTest {
@Test
public void testDeserialization() {
Keycloak keycloak = Serialization.unmarshal(this.getClass().getResourceAsStream("/test-serialization-keycloak-cr.yml"), Keycloak.class);
assertEquals("my-hostname", keycloak.getSpec().getHostname());
assertEquals("my-image", keycloak.getSpec().getImage());
assertEquals("my-tls-secret", keycloak.getSpec().getTlsSecret());
assertTrue(keycloak.getSpec().isDisableDefaultIngress());
}
}

View file

@ -121,5 +121,11 @@ public class KeycloakIngressE2EIT extends ClusterOperatorTest {
assertEquals("HTTPS", i.getMetadata().getAnnotations().get("nginx.ingress.kubernetes.io/backend-protocol"));
assertEquals(Constants.KEYCLOAK_HTTPS_PORT, i.getSpec().getDefaultBackend().getService().getPort().getNumber());
});
// Delete the ingress
kc.getSpec().setDisableDefaultIngress(true);
K8sUtils.deployKeycloak(k8sclient, kc, true);
assertThat(k8sclient.network().v1().ingresses().inNamespace(namespace).list().getItems().size()).isEqualTo(0);
}
}

View file

@ -0,0 +1,18 @@
apiVersion: k8s.keycloak.org/v2alpha1
kind: Keycloak
metadata:
name: test-serialization-kc
spec:
instances: 3
image: my-image
serverConfiguration:
- name: key1
value: value1
hostname: my-hostname
tlsSecret: my-tls-secret
disableDefaultIngress: true
unsupported:
podTemplate:
metadata:
labels:
my-label: "foo"