66import static java .util .Arrays .asList ;
77
88import 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+
1811import static oracle .kubernetes .operator .LabelConstants .*;
1912import static oracle .kubernetes .operator .create .CreateDomainInputs .readInputsYamlFile ;
2013import static oracle .kubernetes .operator .create .KubernetesArtifactUtils .*;
@@ -66,6 +59,14 @@ protected ParsedTraefikYaml getTraefikYaml() {
6659 return getGeneratedFiles ().getTraefikYaml ();
6760 }
6861
62+ protected ParsedApacheSecurityYaml getApacheSecurityYaml () {
63+ return getGeneratedFiles ().getApacheSecurityYaml ();
64+ }
65+
66+ protected ParsedApacheYaml getApacheYaml () {
67+ return getGeneratedFiles ().getApacheYaml ();
68+ }
69+
6970 protected ParsedWeblogicDomainPersistentVolumeClaimYaml getWeblogicDomainPersistentVolumeClaimYaml () {
7071 return getGeneratedFiles ().getWeblogicDomainPersistentVolumeClaimYaml ();
7172 }
@@ -108,14 +109,14 @@ public void domainCustomResourceYaml_hasCorrectNumberOfObjects() throws Exceptio
108109 }
109110
110111 @ Test
111- public void traefikSecurityYaml_hasCorrectNumberOfObjects () throws Exception {
112+ public void loadBalancerSecurityYaml_hasCorrectNumberOfObjects () throws Exception {
112113 assertThat (
113114 getTraefikSecurityYaml ().getObjectCount (),
114115 is (getTraefikSecurityYaml ().getExpectedObjectCount ()));
115116 }
116117
117118 @ Test
118- public void traefikYaml_hasCorrectNumberOfObjects () throws Exception {
119+ public void loadBalancerYaml_hasCorrectNumberOfObjects () throws Exception {
119120 assertThat (
120121 getTraefikYaml ().getObjectCount (),
121122 is (getTraefikYaml ().getExpectedObjectCount ()));
@@ -392,12 +393,28 @@ protected Domain getExpectedDomain() {
392393 }
393394
394395 @ Test
395- public void generatesCorrect_traefikServiceAccount () throws Exception {
396+ public void generatesCorrect_loadBalancerServiceAccount () throws Exception {
396397 assertThat (
397398 getActualTraefikServiceAccount (),
398399 yamlEqualTo (getExpectedTraefikServiceAccount ()));
399400 }
400401
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+
401418 protected V1ServiceAccount getActualTraefikServiceAccount () {
402419 return getTraefikYaml ().getTraefikServiceAccount ();
403420 }
@@ -414,12 +431,78 @@ protected V1ServiceAccount getExpectedTraefikServiceAccount() {
414431 }
415432
416433 @ Test
417- public void generatesCorrect_traefikDeployment () throws Exception {
434+ public void generatesCorrect_loadBalancerDeployment () throws Exception {
418435 assertThat (
419436 getActualTraefikDeployment (),
420437 yamlEqualTo (getExpectedTraefikDeployment ()));
421438 }
422439
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+
423506 protected ExtensionsV1beta1Deployment getActualTraefikDeployment () {
424507 return getTraefikYaml ().getTraefikDeployment ();
425508 }
@@ -490,7 +573,7 @@ protected ExtensionsV1beta1Deployment getExpectedTraefikDeployment() {
490573 }
491574
492575 @ Test
493- public void generatesCorrect_traefikConfigMap () throws Exception {
576+ public void generatesCorrect_loadBalancerConfigMap () throws Exception {
494577 // The config map contains a 'traefik.toml' property that has a lot of text
495578 // that we don't want to duplicate in the test. However, part of the text
496579 // is computed from the inputs, so we want to validate that part of the info.
@@ -529,12 +612,35 @@ protected void assertThatActualTraefikTomlIsCorrect(String actualTraefikToml) {
529612 }
530613
531614 @ Test
532- public void generatesCorrect_traefikService () throws Exception {
615+ public void generatesCorrect_loadBalancerService () throws Exception {
533616 assertThat (
534617 getActualTraefikService (),
535618 yamlEqualTo (getExpectedTraefikService ()));
536619 }
537620
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+
538644 protected V1Service getActualTraefikService () {
539645 return getTraefikYaml ().getTraefikService ();
540646 }
@@ -560,7 +666,7 @@ protected V1Service getExpectedTraefikService() {
560666 }
561667
562668 @ Test
563- public void generatesCorrect_traefikDashboardService () throws Exception {
669+ public void generatesCorrect_loadBalancerDashboardService () throws Exception {
564670 assertThat (
565671 getActualTraefikDashboardService (),
566672 yamlEqualTo (getExpectedTraefikDashboardService ()));
@@ -591,12 +697,33 @@ protected V1Service getExpectedTraefikDashboardService() {
591697 }
592698
593699 @ Test
594- public void generatesCorrect_traefikClusterRole () throws Exception {
700+ public void generatesCorrect_loadBalancerClusterRole () throws Exception {
595701 assertThat (
596702 getActualTraefikClusterRole (),
597703 yamlEqualTo (getExpectedTraefikClusterRole ()));
598704 }
599705
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+
600727 protected V1beta1ClusterRole getActualTraefikClusterRole () {
601728 return getTraefikSecurityYaml ().getTraefikClusterRole ();
602729 }
@@ -620,12 +747,32 @@ protected V1beta1ClusterRole getExpectedTraefikClusterRole() {
620747 }
621748
622749 @ Test
623- public void generatesCorrect_traefikDashboardClusterRoleBinding () throws Exception {
750+ public void generatesCorrect_loadBalancerClusterRoleBinding () throws Exception {
624751 assertThat (
625752 getActualTraefikDashboardClusterRoleBinding (),
626753 yamlEqualTo (getExpectedTraefikDashboardClusterRoleBinding ()));
627754 }
628755
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+
629776 protected V1beta1ClusterRoleBinding getActualTraefikDashboardClusterRoleBinding () {
630777 return getTraefikSecurityYaml ().getTraefikDashboardClusterRoleBinding ();
631778 }
@@ -709,4 +856,8 @@ protected String getClusterLCScope() {
709856 protected String getClusterNameLC () {
710857 return getInputs ().getClusterName ().toLowerCase ();
711858 }
859+
860+ protected String getApacheName () { return getInputs ().getDomainUID () + "-" + getApacheAppName (); }
861+
862+ protected String getApacheAppName () { return "apache-webtier" ;}
712863}
0 commit comments