6
6
import static java .util .Arrays .asList ;
7
7
8
8
import io .kubernetes .client .custom .Quantity ;
9
- import io .kubernetes .client .models .ExtensionsV1beta1Deployment ;
10
- import io .kubernetes .client .models .V1beta1ClusterRole ;
11
- import io .kubernetes .client .models .V1beta1ClusterRoleBinding ;
12
- import io .kubernetes .client .models .V1ConfigMap ;
13
- import io .kubernetes .client .models .V1Job ;
14
- import io .kubernetes .client .models .V1PersistentVolume ;
15
- import io .kubernetes .client .models .V1PersistentVolumeClaim ;
16
- import io .kubernetes .client .models .V1Service ;
17
- import io .kubernetes .client .models .V1ServiceAccount ;
9
+ import io .kubernetes .client .models .*;
10
+
18
11
import static oracle .kubernetes .operator .LabelConstants .*;
19
12
import static oracle .kubernetes .operator .create .CreateDomainInputs .readInputsYamlFile ;
20
13
import static oracle .kubernetes .operator .create .KubernetesArtifactUtils .*;
@@ -66,6 +59,14 @@ protected ParsedTraefikYaml getTraefikYaml() {
66
59
return getGeneratedFiles ().getTraefikYaml ();
67
60
}
68
61
62
+ protected ParsedApacheSecurityYaml getApacheSecurityYaml () {
63
+ return getGeneratedFiles ().getApacheSecurityYaml ();
64
+ }
65
+
66
+ protected ParsedApacheYaml getApacheYaml () {
67
+ return getGeneratedFiles ().getApacheYaml ();
68
+ }
69
+
69
70
protected ParsedWeblogicDomainPersistentVolumeClaimYaml getWeblogicDomainPersistentVolumeClaimYaml () {
70
71
return getGeneratedFiles ().getWeblogicDomainPersistentVolumeClaimYaml ();
71
72
}
@@ -108,14 +109,14 @@ public void domainCustomResourceYaml_hasCorrectNumberOfObjects() throws Exceptio
108
109
}
109
110
110
111
@ Test
111
- public void traefikSecurityYaml_hasCorrectNumberOfObjects () throws Exception {
112
+ public void loadBalancerSecurityYaml_hasCorrectNumberOfObjects () throws Exception {
112
113
assertThat (
113
114
getTraefikSecurityYaml ().getObjectCount (),
114
115
is (getTraefikSecurityYaml ().getExpectedObjectCount ()));
115
116
}
116
117
117
118
@ Test
118
- public void traefikYaml_hasCorrectNumberOfObjects () throws Exception {
119
+ public void loadBalancerYaml_hasCorrectNumberOfObjects () throws Exception {
119
120
assertThat (
120
121
getTraefikYaml ().getObjectCount (),
121
122
is (getTraefikYaml ().getExpectedObjectCount ()));
@@ -392,12 +393,28 @@ protected Domain getExpectedDomain() {
392
393
}
393
394
394
395
@ Test
395
- public void generatesCorrect_traefikServiceAccount () throws Exception {
396
+ public void generatesCorrect_loadBalancerServiceAccount () throws Exception {
396
397
assertThat (
397
398
getActualTraefikServiceAccount (),
398
399
yamlEqualTo (getExpectedTraefikServiceAccount ()));
399
400
}
400
401
402
+ protected V1ServiceAccount getActualApacheServiceAccount () {
403
+ return getApacheYaml ().getApacheServiceAccount ();
404
+ }
405
+
406
+ protected V1ServiceAccount getExpectedApacheServiceAccount () {
407
+ return
408
+ newServiceAccount ()
409
+ .metadata (newObjectMeta ()
410
+ .name (getApacheName ())
411
+ .namespace (getInputs ().getNamespace ())
412
+ .putLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
413
+ .putLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ())
414
+ .putLabelsItem (APP_LABEL , getApacheAppName ()));
415
+ }
416
+
417
+
401
418
protected V1ServiceAccount getActualTraefikServiceAccount () {
402
419
return getTraefikYaml ().getTraefikServiceAccount ();
403
420
}
@@ -414,12 +431,78 @@ protected V1ServiceAccount getExpectedTraefikServiceAccount() {
414
431
}
415
432
416
433
@ Test
417
- public void generatesCorrect_traefikDeployment () throws Exception {
434
+ public void generatesCorrect_loadBalancerDeployment () throws Exception {
418
435
assertThat (
419
436
getActualTraefikDeployment (),
420
437
yamlEqualTo (getExpectedTraefikDeployment ()));
421
438
}
422
439
440
+ protected ExtensionsV1beta1Deployment getActualApacheDeployment () {
441
+ return getApacheYaml ().getApacheDeployment ();
442
+ }
443
+
444
+ protected ExtensionsV1beta1Deployment getExpectedApacheDeployment () {
445
+ return
446
+ newDeployment ()
447
+ .apiVersion (API_VERSION_EXTENSIONS_V1BETA1 ) // TBD - why is apache using this older version?
448
+ .metadata (newObjectMeta ()
449
+ .name (getApacheName ())
450
+ .namespace (getInputs ().getNamespace ())
451
+ .putLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
452
+ .putLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ())
453
+ .putLabelsItem (APP_LABEL , getApacheAppName ()))
454
+ .spec (newDeploymentSpec ()
455
+ .replicas (1 )
456
+ .selector (newLabelSelector ()
457
+ .putMatchLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
458
+ .putMatchLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ())
459
+ .putMatchLabelsItem (APP_LABEL , getApacheAppName ()))
460
+ .template (newPodTemplateSpec ()
461
+ .metadata (newObjectMeta ()
462
+ .putLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
463
+ .putLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ())
464
+ .putLabelsItem (APP_LABEL , getApacheAppName ()))
465
+ .spec (newPodSpec ()
466
+ .serviceAccountName (getApacheName ())
467
+ .terminationGracePeriodSeconds (60L )
468
+ .addContainersItem (newContainer ()
469
+ .name (getApacheName ())
470
+ .image ("12213-apache:latest" )
471
+ .imagePullPolicy ("Never" )
472
+ .addEnvItem (newEnvVar ()
473
+ .name ("WEBLOGIC_CLUSTER" )
474
+ .value (getInputs ().getDomainUID () + "-cluster-" + getClusterNameLC () + ":" + getInputs ().getManagedServerPort ()))
475
+ .addEnvItem (newEnvVar ()
476
+ .name ("LOCATION" )
477
+ .value (getInputs ().getLoadBalancerAppPrepath ()))
478
+ .addEnvItem (newEnvVar ()
479
+ .name ("WEBLOGIC_HOST" )
480
+ .value (getInputs ().getDomainUID () + "-" + getInputs ().getAdminServerName ()))
481
+ .addEnvItem (newEnvVar ()
482
+ .name ("WEBLOGIC_PORT" )
483
+ .value (getInputs ().getAdminPort ()))
484
+ .readinessProbe (newProbe ()
485
+ .tcpSocket (newTCPSocketAction ()
486
+ .port (newIntOrString (80 )))
487
+ .failureThreshold (1 )
488
+ .initialDelaySeconds (10 )
489
+ .periodSeconds (10 )
490
+ .successThreshold (1 )
491
+ .timeoutSeconds (2 ))
492
+ .livenessProbe (newProbe ()
493
+ .tcpSocket (newTCPSocketAction ()
494
+ .port (newIntOrString (80 )))
495
+ .failureThreshold (3 )
496
+ .initialDelaySeconds (10 )
497
+ .periodSeconds (10 )
498
+ .successThreshold (1 )
499
+ .timeoutSeconds (2 ))
500
+ )
501
+ )
502
+ )
503
+ );
504
+ }
505
+
423
506
protected ExtensionsV1beta1Deployment getActualTraefikDeployment () {
424
507
return getTraefikYaml ().getTraefikDeployment ();
425
508
}
@@ -490,7 +573,7 @@ protected ExtensionsV1beta1Deployment getExpectedTraefikDeployment() {
490
573
}
491
574
492
575
@ Test
493
- public void generatesCorrect_traefikConfigMap () throws Exception {
576
+ public void generatesCorrect_loadBalancerConfigMap () throws Exception {
494
577
// The config map contains a 'traefik.toml' property that has a lot of text
495
578
// that we don't want to duplicate in the test. However, part of the text
496
579
// is computed from the inputs, so we want to validate that part of the info.
@@ -529,12 +612,35 @@ protected void assertThatActualTraefikTomlIsCorrect(String actualTraefikToml) {
529
612
}
530
613
531
614
@ Test
532
- public void generatesCorrect_traefikService () throws Exception {
615
+ public void generatesCorrect_loadBalancerService () throws Exception {
533
616
assertThat (
534
617
getActualTraefikService (),
535
618
yamlEqualTo (getExpectedTraefikService ()));
536
619
}
537
620
621
+ protected V1Service getActualApacheService () {
622
+ return getApacheYaml ().getApacheService ();
623
+ }
624
+
625
+ protected V1Service getExpectedApacheService () {
626
+ return
627
+ newService ()
628
+ .metadata (newObjectMeta ()
629
+ .name (getApacheName ())
630
+ .namespace (getInputs ().getNamespace ())
631
+ .putLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
632
+ .putLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ()))
633
+ .spec (newServiceSpec ()
634
+ .type ("NodePort" )
635
+ .putSelectorItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
636
+ .putSelectorItem (DOMAINNAME_LABEL , getInputs ().getDomainName ())
637
+ .putSelectorItem (APP_LABEL , getApacheAppName ())
638
+ .addPortsItem (newServicePort ()
639
+ .name ("rest-https" )
640
+ .port (80 )
641
+ .nodePort (Integer .parseInt (getInputs ().getLoadBalancerWebPort ()))));
642
+ }
643
+
538
644
protected V1Service getActualTraefikService () {
539
645
return getTraefikYaml ().getTraefikService ();
540
646
}
@@ -560,7 +666,7 @@ protected V1Service getExpectedTraefikService() {
560
666
}
561
667
562
668
@ Test
563
- public void generatesCorrect_traefikDashboardService () throws Exception {
669
+ public void generatesCorrect_loadBalancerDashboardService () throws Exception {
564
670
assertThat (
565
671
getActualTraefikDashboardService (),
566
672
yamlEqualTo (getExpectedTraefikDashboardService ()));
@@ -591,12 +697,33 @@ protected V1Service getExpectedTraefikDashboardService() {
591
697
}
592
698
593
699
@ Test
594
- public void generatesCorrect_traefikClusterRole () throws Exception {
700
+ public void generatesCorrect_loadBalancerClusterRole () throws Exception {
595
701
assertThat (
596
702
getActualTraefikClusterRole (),
597
703
yamlEqualTo (getExpectedTraefikClusterRole ()));
598
704
}
599
705
706
+ protected V1beta1ClusterRole getActualApacheClusterRole () {
707
+ return getApacheSecurityYaml ().getApacheClusterRole ();
708
+ }
709
+
710
+ protected V1beta1ClusterRole getExpectedApacheClusterRole () {
711
+ return
712
+ newClusterRole ()
713
+ .metadata (newObjectMeta ()
714
+ .name (getApacheName ())
715
+ .putLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
716
+ .putLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ()))
717
+ .addRulesItem (newPolicyRule ()
718
+ .addApiGroupsItem ("" )
719
+ .resources (asList ("pods" , "services" , "endpoints" , "secrets" ))
720
+ .verbs (asList ("get" , "list" , "watch" )))
721
+ .addRulesItem (newPolicyRule ()
722
+ .addApiGroupsItem ("extensions" )
723
+ .addResourcesItem ("ingresses" )
724
+ .verbs (asList ("get" , "list" , "watch" )));
725
+ }
726
+
600
727
protected V1beta1ClusterRole getActualTraefikClusterRole () {
601
728
return getTraefikSecurityYaml ().getTraefikClusterRole ();
602
729
}
@@ -620,12 +747,32 @@ protected V1beta1ClusterRole getExpectedTraefikClusterRole() {
620
747
}
621
748
622
749
@ Test
623
- public void generatesCorrect_traefikDashboardClusterRoleBinding () throws Exception {
750
+ public void generatesCorrect_loadBalancerClusterRoleBinding () throws Exception {
624
751
assertThat (
625
752
getActualTraefikDashboardClusterRoleBinding (),
626
753
yamlEqualTo (getExpectedTraefikDashboardClusterRoleBinding ()));
627
754
}
628
755
756
+ protected V1beta1ClusterRoleBinding getActualApacheClusterRoleBinding () {
757
+ return getApacheSecurityYaml ().getApacheClusterRoleBinding ();
758
+ }
759
+
760
+ protected V1beta1ClusterRoleBinding getExpectedApacheClusterRoleBinding () {
761
+ return
762
+ newClusterRoleBinding ()
763
+ .metadata (newObjectMeta ()
764
+ .name (getApacheName ())
765
+ .putLabelsItem (DOMAINUID_LABEL , getInputs ().getDomainUID ())
766
+ .putLabelsItem (DOMAINNAME_LABEL , getInputs ().getDomainName ()))
767
+ .addSubjectsItem (newSubject ()
768
+ .kind ("ServiceAccount" )
769
+ .name (getApacheName ())
770
+ .namespace (getInputs ().getNamespace ()))
771
+ .roleRef (newRoleRef ()
772
+ .name (getApacheName ())
773
+ .apiGroup ("rbac.authorization.k8s.io" ));
774
+ }
775
+
629
776
protected V1beta1ClusterRoleBinding getActualTraefikDashboardClusterRoleBinding () {
630
777
return getTraefikSecurityYaml ().getTraefikDashboardClusterRoleBinding ();
631
778
}
@@ -709,4 +856,8 @@ protected String getClusterLCScope() {
709
856
protected String getClusterNameLC () {
710
857
return getInputs ().getClusterName ().toLowerCase ();
711
858
}
859
+
860
+ protected String getApacheName () { return getInputs ().getDomainUID () + "-" + getApacheAppName (); }
861
+
862
+ protected String getApacheAppName () { return "apache-webtier" ;}
712
863
}
0 commit comments