2121import java .util .List ;
2222import java .util .Map ;
2323import java .util .Optional ;
24- import java .util .Set ;
2524import java .util .concurrent .TimeUnit ;
2625
2726import io .fabric8 .kubernetes .api .model .ConfigMap ;
3332import io .fabric8 .kubernetes .api .model .ServiceAccount ;
3433import io .fabric8 .kubernetes .api .model .apps .Deployment ;
3534import io .fabric8 .kubernetes .api .model .apps .DeploymentList ;
36- import io .fabric8 .kubernetes .api .model .networking .v1 .Ingress ;
37- import io .fabric8 .kubernetes .api .model .networking .v1 .IngressLoadBalancerIngress ;
38- import io .fabric8 .kubernetes .api .model .rbac .ClusterRole ;
3935import io .fabric8 .kubernetes .api .model .rbac .Role ;
4036import io .fabric8 .kubernetes .api .model .rbac .RoleBinding ;
4137import io .fabric8 .kubernetes .client .Config ;
4238import io .fabric8 .kubernetes .client .KubernetesClient ;
4339import io .fabric8 .kubernetes .client .KubernetesClientBuilder ;
44- import io .fabric8 .kubernetes .client .dsl .base .PatchContext ;
45- import io .fabric8 .kubernetes .client .dsl .base .PatchType ;
4640import io .fabric8 .kubernetes .client .utils .Serialization ;
4741import jakarta .annotation .Nullable ;
4842import org .apache .commons .logging .Log ;
@@ -83,7 +77,7 @@ public Util(K3sContainer container) {
8377 *
8478 */
8579 public void createAndWait (String namespace , String name , @ Nullable Deployment deployment , @ Nullable Service service ,
86- @ Nullable Ingress ingress , boolean changeVersion ) {
80+ boolean changeVersion ) {
8781 try {
8882
8983 if (deployment != null ) {
@@ -114,11 +108,6 @@ public void createAndWait(String namespace, String name, @Nullable Deployment de
114108 if (service != null ) {
115109 client .services ().inNamespace (namespace ).resource (service ).create ();
116110 }
117-
118- if (ingress != null ) {
119- client .network ().v1 ().ingresses ().inNamespace (namespace ).resource (ingress ).create ();
120- waitForIngress (namespace , ingress );
121- }
122111 }
123112 catch (Exception e ) {
124113 throw new RuntimeException (e );
@@ -138,15 +127,14 @@ public void busybox(String namespace, Phase phase) {
138127 Service service = client .services ().load (serviceStream ).item ();
139128
140129 if (phase .equals (Phase .CREATE )) {
141- createAndWait (namespace , "busybox" , deployment , service , null , false );
130+ createAndWait (namespace , "busybox" , deployment , service , false );
142131 }
143132 else if (phase .equals (Phase .DELETE )) {
144- deleteAndWait (namespace , deployment , service , null );
133+ deleteAndWait (namespace , deployment , service );
145134 }
146135 }
147136
148- public void deleteAndWait (String namespace , @ Nullable Deployment deployment , Service service ,
149- @ Nullable Ingress ingress ) {
137+ public void deleteAndWait (String namespace , @ Nullable Deployment deployment , Service service ) {
150138 try {
151139
152140 long startTime = System .currentTimeMillis ();
@@ -166,11 +154,6 @@ public void deleteAndWait(String namespace, @Nullable Deployment deployment, Ser
166154
167155 client .services ().inNamespace (namespace ).resource (service ).delete ();
168156
169- if (ingress != null ) {
170- client .network ().v1 ().ingresses ().inNamespace (namespace ).resource (ingress ).delete ();
171- waitForIngressToBeDeleted (namespace , ingress );
172- }
173-
174157 }
175158 catch (Exception e ) {
176159 throw new RuntimeException (e );
@@ -228,40 +211,6 @@ public void deleteNamespace(String name) {
228211
229212 }
230213
231- public void setUpClusterWide (String serviceAccountNamespace , Set <String > namespaces ) {
232- InputStream clusterRoleBindingAsStream = inputStream ("cluster/cluster-role.yaml" );
233- InputStream serviceAccountAsStream = inputStream ("cluster/service-account.yaml" );
234- InputStream roleBindingAsStream = inputStream ("cluster/role-binding.yaml" );
235-
236- ClusterRole clusterRole = client .rbac ().clusterRoles ().load (clusterRoleBindingAsStream ).item ();
237- if (client .rbac ().clusterRoles ().withName (clusterRole .getMetadata ().getName ()).get () == null ) {
238- client .rbac ().clusterRoles ().resource (clusterRole ).create ();
239- }
240-
241- ServiceAccount serviceAccountFromStream = client .serviceAccounts ().load (serviceAccountAsStream ).item ();
242- serviceAccountFromStream .getMetadata ().setNamespace (serviceAccountNamespace );
243- if (client .serviceAccounts ()
244- .inNamespace (serviceAccountNamespace )
245- .withName (serviceAccountFromStream .getMetadata ().getName ())
246- .get () == null ) {
247- client .serviceAccounts ().inNamespace (serviceAccountNamespace ).resource (serviceAccountFromStream ).create ();
248- }
249-
250- RoleBinding roleBindingFromStream = client .rbac ().roleBindings ().load (roleBindingAsStream ).item ();
251- namespaces .forEach (namespace -> {
252- roleBindingFromStream .getMetadata ().setNamespace (namespace );
253-
254- if (client .rbac ()
255- .roleBindings ()
256- .inNamespace (namespace )
257- .withName (roleBindingFromStream .getMetadata ().getName ())
258- .get () == null ) {
259- client .rbac ().roleBindings ().inNamespace (namespace ).resource (roleBindingFromStream ).create ();
260- }
261- });
262-
263- }
264-
265214 public void createAndWait (String namespace , @ Nullable ConfigMap configMap , @ Nullable Secret secret ) {
266215 if (configMap != null ) {
267216 client .configMaps ().resource (configMap ).create ();
@@ -308,10 +257,10 @@ public void setUpIstioctl(String namespace, Phase phase) {
308257 istioctlDeployment .getSpec ().getTemplate ().getSpec ().getContainers ().get (0 ).setImage (imageWithVersion );
309258
310259 if (phase .equals (Phase .CREATE )) {
311- createAndWait (namespace , null , istioctlDeployment , null , null , false );
260+ createAndWait (namespace , null , istioctlDeployment , null , false );
312261 }
313262 else {
314- deleteAndWait (namespace , istioctlDeployment , null , null );
263+ deleteAndWait (namespace , istioctlDeployment , null );
315264 }
316265 }
317266
@@ -332,44 +281,25 @@ private void waitForConfigMap(String namespace, ConfigMap configMap, Phase phase
332281 });
333282 }
334283
335- public void wiremock (String namespace , String path , Phase phase ) {
336- wiremock (namespace , path , phase , true );
337- }
338-
339- public void wiremock (String namespace , String path , Phase phase , boolean withIngress ) {
284+ public void wiremock (String namespace , Phase phase ) {
340285 InputStream deploymentStream = inputStream ("wiremock/wiremock-deployment.yaml" );
341286 InputStream serviceStream = inputStream ("wiremock/wiremock-service.yaml" );
342- InputStream ingressStream = inputStream ("wiremock/wiremock-ingress.yaml" );
343287
344288 Deployment deployment = client .apps ().deployments ().load (deploymentStream ).item ();
345289 String imageWithoutVersion = deployment .getSpec ().getTemplate ().getSpec ().getContainers ().get (0 ).getImage ();
346290 String imageWithVersion = imageWithoutVersion + ":" + Images .wiremockVersion ();
347291 deployment .getSpec ().getTemplate ().getSpec ().getContainers ().get (0 ).setImage (imageWithVersion );
348292
349293 Service service = client .services ().load (serviceStream ).item ();
350- Ingress ingress = null ;
351294
352295 if (phase .equals (Phase .CREATE )) {
353-
354- if (withIngress ) {
355- ingress = client .network ().v1 ().ingresses ().load (ingressStream ).get ();
356- ingress .getMetadata ().setNamespace (namespace );
357- ingress .getSpec ().getRules ().get (0 ).getHttp ().getPaths ().get (0 ).setPath (path );
358- }
359-
360296 deployment .getMetadata ().setNamespace (namespace );
361297 service .getMetadata ().setNamespace (namespace );
362- createAndWait (namespace , "wiremock" , deployment , service , ingress , false );
298+ createAndWait (namespace , "wiremock" , deployment , service , false );
363299 }
364300 else {
365-
366- if (withIngress ) {
367- ingress = client .network ().v1 ().ingresses ().load (ingressStream ).get ();
368- }
369-
370- deleteAndWait (namespace , deployment , service , ingress );
301+ deleteAndWait (namespace , deployment , service );
371302 }
372-
373303 }
374304
375305 private void waitForSecret (String namespace , Secret secret , Phase phase ) {
@@ -389,14 +319,6 @@ private void waitForSecret(String namespace, Secret secret, Phase phase) {
389319 });
390320 }
391321
392- private void waitForIngressToBeDeleted (String namespace , Ingress ingress ) {
393- String ingressName = ingressName (ingress );
394- await ().pollInterval (Duration .ofSeconds (1 )).atMost (30 , TimeUnit .SECONDS ).until (() -> {
395- Ingress inner = client .network ().v1 ().ingresses ().inNamespace (namespace ).withName (ingressName ).get ();
396- return inner == null ;
397- });
398- }
399-
400322 private void waitForDeploymentToBeDeleted (String namespace , Deployment deployment ) {
401323
402324 String deploymentName = deploymentName (deployment );
@@ -432,56 +354,6 @@ private boolean isDeploymentReady(String namespace, String deploymentName) {
432354 return availableReplicas != null && availableReplicas >= 1 ;
433355 }
434356
435- public void waitForIngress (String namespace , Ingress ingress ) {
436-
437- String ingressName = ingressName (ingress );
438-
439- try {
440- await ().pollInterval (Duration .ofSeconds (2 )).atMost (180 , TimeUnit .SECONDS ).until (() -> {
441- Ingress inner = client .network ().v1 ().ingresses ().inNamespace (namespace ).withName (ingressName ).get ();
442-
443- if (inner == null ) {
444- LOG .info ("ingress : " + ingressName + " not ready yet present" );
445- return false ;
446- }
447-
448- List <IngressLoadBalancerIngress > loadBalancerIngress = inner .getStatus ().getLoadBalancer ().getIngress ();
449- if (loadBalancerIngress == null || loadBalancerIngress .isEmpty ()) {
450- LOG .info ("ingress : " + ingressName + " not ready yet (loadbalancer ingress not yet present)" );
451- return false ;
452- }
453-
454- String ip = loadBalancerIngress .get (0 ).getIp ();
455- if (ip == null ) {
456- LOG .info ("ingress : " + ingressName + " not ready yet" );
457- return false ;
458- }
459-
460- LOG .info ("ingress : " + ingressName + " ready with ip : " + ip );
461- return true ;
462-
463- });
464- }
465- catch (Exception e ) {
466- LOG .error ("Error waiting for ingress" );
467- e .printStackTrace ();
468- }
469-
470- }
471-
472- public void patchWithReplace (String imageName , String deploymentName , String namespace , String patchBody ,
473- Map <String , String > labels ) {
474- String body = patchBody .replace ("image_name_here" , imageName );
475-
476- client .apps ()
477- .deployments ()
478- .inNamespace (namespace )
479- .withName (deploymentName )
480- .patch (PatchContext .of (PatchType .JSON_MERGE ), body );
481-
482- waitForDeploymentAfterPatch (deploymentName , namespace , labels );
483- }
484-
485357 private void waitForDeploymentAfterPatch (String deploymentName , String namespace , Map <String , String > labels ) {
486358 try {
487359 await ().pollDelay (Duration .ofSeconds (4 ))
@@ -562,10 +434,6 @@ private String deploymentName(Deployment deployment) {
562434 return deployment .getMetadata ().getName ();
563435 }
564436
565- private String ingressName (Ingress ingress ) {
566- return ingress .getMetadata ().getName ();
567- }
568-
569437 private String configMapName (ConfigMap configMap ) {
570438 return configMap .getMetadata ().getName ();
571439 }
0 commit comments