3030import io .fabric8 .kubernetes .api .model .networking .v1 .Ingress ;
3131import io .fabric8 .kubernetes .api .model .networking .v1 .IngressRule ;
3232import io .fabric8 .kubernetes .api .model .networking .v1 .IngressTLS ;
33+ import io .fabric8 .kubernetes .api .model .networking .v1beta1 .IngressBuilder ;
3334import io .fabric8 .kubernetes .client .KubernetesClient ;
3435import io .fabric8 .kubernetes .client .server .mock .EnableKubernetesMockClient ;
3536import org .apache .commons .lang3 .StringUtils ;
4041import java .util .List ;
4142import java .util .Map ;
4243
44+ import static org .assertj .core .api .Assertions .assertThat ;
4345import static org .junit .jupiter .api .Assertions .assertEquals ;
4446import static org .junit .jupiter .api .Assertions .assertNull ;
4547import static org .junit .jupiter .api .Assertions .assertThrows ;
@@ -51,10 +53,11 @@ class IngressUtilsTest {
5153
5254 KubernetesClient client ;
5355
56+ TestingJosdkContext testingJosdkContext ;
57+
5458 private FlinkResourceContext <?> createResourceContext (FlinkDeployment appCluster ) {
55- // todo
56- return new FlinkDeploymentContext (
57- appCluster , new TestingJosdkContext <>(client , Map .of ()), null , null , null , null );
59+ testingJosdkContext = new TestingJosdkContext <>(client );
60+ return new FlinkDeploymentContext (appCluster , testingJosdkContext , null , null , null , null );
5861 }
5962
6063 @ Test
@@ -65,7 +68,7 @@ void testIngress() {
6568 .getDeployConfig (appCluster .getMetadata (), appCluster .getSpec ());
6669
6770 // no ingress when ingressDomain is empty
68- IngressUtils .updateIngressRules (
71+ IngressUtils .reconcileIngress (
6972 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
7073 if (IngressUtils .ingressInNetworkingV1 (client )) {
7174 assertNull (
@@ -89,7 +92,7 @@ void testIngress() {
8992 IngressSpec .IngressSpecBuilder builder = IngressSpec .builder ();
9093 builder .template ("{{name}}.{{namespace}}.example.com" );
9194 appCluster .getSpec ().setIngress (builder .build ());
92- IngressUtils .updateIngressRules (
95+ IngressUtils .reconcileIngress (
9396 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
9497 Ingress ingress = null ;
9598 io .fabric8 .kubernetes .api .model .networking .v1beta1 .Ingress ingressV1beta1 = null ;
@@ -138,7 +141,7 @@ void testIngress() {
138141 builder .className ("nginx" );
139142 builder .annotations (Map .of ("nginx.ingress.kubernetes.io/rewrite-target" , "/$2" ));
140143 appCluster .getSpec ().setIngress (builder .build ());
141- IngressUtils .updateIngressRules (
144+ IngressUtils .reconcileIngress (
142145 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
143146 if (IngressUtils .ingressInNetworkingV1 (client )) {
144147 ingress =
@@ -195,7 +198,7 @@ void testIngress() {
195198 builder .template ("example.com/{{namespace}}/{{name}}(/|$)(.*)" );
196199 builder .className ("nginx" );
197200 appCluster .getSpec ().setIngress (builder .build ());
198- IngressUtils .updateIngressRules (
201+ IngressUtils .reconcileIngress (
199202 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
200203 if (IngressUtils .ingressInNetworkingV1 (client )) {
201204 ingress =
@@ -279,7 +282,7 @@ public void testIngressTls() {
279282 builder .template ("{{name}}.{{namespace}}.example.com" );
280283 builder .tls (new ArrayList <>());
281284 appCluster .getSpec ().setIngress (builder .build ());
282- IngressUtils .updateIngressRules (
285+ IngressUtils .reconcileIngress (
283286 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
284287 Ingress ingress = null ;
285288 io .fabric8 .kubernetes .api .model .networking .v1beta1 .Ingress ingressV1beta1 = null ;
@@ -316,7 +319,7 @@ public void testIngressTls() {
316319 ingressTlsSpecSecretOnly .setSecretName ("secret" );
317320 builder .tls (List .of (ingressTlsSpecSecretOnly ));
318321 appCluster .getSpec ().setIngress (builder .build ());
319- IngressUtils .updateIngressRules (
322+ IngressUtils .reconcileIngress (
320323 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
321324 if (IngressUtils .ingressInNetworkingV1 (client )) {
322325 ingress =
@@ -354,7 +357,7 @@ public void testIngressTls() {
354357 ingressTlsSpecHostsOnly .setHosts (List .of ("example.com" ));
355358 builder .tls (List .of (ingressTlsSpecHostsOnly ));
356359 appCluster .getSpec ().setIngress (builder .build ());
357- IngressUtils .updateIngressRules (
360+ IngressUtils .reconcileIngress (
358361 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
359362 if (IngressUtils .ingressInNetworkingV1 (client )) {
360363 ingress =
@@ -392,7 +395,7 @@ public void testIngressTls() {
392395 new IngressTLS (List .of ("example.com" ), "secret" );
393396 builder .tls (List .of (ingressTlsSpecSingleTLSWithHost ));
394397 appCluster .getSpec ().setIngress (builder .build ());
395- IngressUtils .updateIngressRules (
398+ IngressUtils .reconcileIngress (
396399 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
397400 if (IngressUtils .ingressInNetworkingV1 (client )) {
398401 ingress =
@@ -434,7 +437,7 @@ public void testIngressTls() {
434437 new IngressTLS (List .of ("example.com" , "example2.com" ), "secret" );
435438 builder .tls (List .of (ingressTlsSpecSingleTLSWithHosts ));
436439 appCluster .getSpec ().setIngress (builder .build ());
437- IngressUtils .updateIngressRules (
440+ IngressUtils .reconcileIngress (
438441 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
439442 if (IngressUtils .ingressInNetworkingV1 (client )) {
440443 ingress =
@@ -481,7 +484,7 @@ public void testIngressTls() {
481484 builder .tls (
482485 List .of (ingressTlsSpecMultipleTLSWithHosts1 , ingressTlsSpecMultipleTLSWithHosts2 ));
483486 appCluster .getSpec ().setIngress (builder .build ());
484- IngressUtils .updateIngressRules (
487+ IngressUtils .reconcileIngress (
485488 createResourceContext (appCluster ), appCluster .getSpec (), config , client );
486489 if (IngressUtils .ingressInNetworkingV1 (client )) {
487490 ingress =
@@ -527,4 +530,34 @@ public void testIngressTls() {
527530 assertEquals ("example4.com" , tlsV1beta1 .get (1 ).getHosts ().get (1 ));
528531 }
529532 }
533+
534+ @ Test
535+ void testDeletesIngress () {
536+ FlinkDeployment appCluster = TestUtils .buildApplicationCluster ();
537+ appCluster .getSpec ().setIngress (null );
538+ io .fabric8 .kubernetes .api .model .networking .v1beta1 .Ingress ingress =
539+ new IngressBuilder ()
540+ .withNewMetadata ()
541+ .withName (appCluster .getMetadata ().getName ())
542+ .withNamespace (appCluster .getMetadata ().getNamespace ())
543+ .endMetadata ()
544+ .build ();
545+ client .network ().v1beta1 ().ingresses ().resource (ingress ).create ();
546+ var context = createResourceContext (appCluster );
547+ testingJosdkContext .setSecondaryResources (
548+ Map .of (
549+ io .fabric8 .kubernetes .api .model .networking .v1beta1 .Ingress .class ,
550+ List .of (ingress )));
551+
552+ IngressUtils .reconcileIngress (context , appCluster .getSpec (), null , client );
553+
554+ var ingressV1beta1 =
555+ client .network ()
556+ .v1beta1 ()
557+ .ingresses ()
558+ .inNamespace (appCluster .getMetadata ().getNamespace ())
559+ .withName (appCluster .getMetadata ().getName ())
560+ .get ();
561+ assertThat (ingressV1beta1 ).isNull ();
562+ }
530563}
0 commit comments