@@ -622,6 +622,49 @@ def test_cross_namespace_secrets(self):
622622 self .eventuallyEqual (lambda : k8s .count_secrets_with_label ("cluster-name=acid-minimal-cluster,application=spilo" , self .test_namespace ),
623623 1 , "Secret not created for user in namespace" )
624624
625+ @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
626+ def test_custom_ssl_certificate (self ):
627+ '''
628+ Test if spilo uses a custom SSL certificate
629+ '''
630+
631+ k8s = self .k8s
632+ cluster_label = 'application=spilo,cluster-name=acid-minimal-cluster'
633+ tls_secret = "pg-tls"
634+
635+ # get nodes of master and replica(s) (expected target of new master)
636+ _ , replica_nodes = k8s .get_pg_nodes (cluster_label )
637+ self .assertNotEqual (replica_nodes , [])
638+
639+ try :
640+ # create secret containing ssl certificate
641+ result = self .k8s .create_tls_secret_with_kubectl (tls_secret )
642+ print ("stdout: {}, stderr: {}" .format (result .stdout , result .stderr ))
643+
644+ # enable load balancer services
645+ pg_patch_tls = {
646+ "spec" : {
647+ "spiloFSGroup" : 103 ,
648+ "tls" : {
649+ "secretName" : tls_secret
650+ }
651+ }
652+ }
653+ k8s .api .custom_objects_api .patch_namespaced_custom_object (
654+ "acid.zalan.do" , "v1" , "default" , "postgresqls" , "acid-minimal-cluster" , pg_patch_tls )
655+
656+ # wait for switched over
657+ k8s .wait_for_pod_failover (replica_nodes , 'spilo-role=master,' + cluster_label )
658+ k8s .wait_for_pod_start ('spilo-role=replica,' + cluster_label )
659+
660+ self .eventuallyEqual (lambda : k8s .count_pods_with_env_variable ("SSL_CERTIFICATE_FILE" , cluster_label ), 2 , "TLS env variable SSL_CERTIFICATE_FILE missing in Spilo pods" )
661+ self .eventuallyEqual (lambda : k8s .count_pods_with_env_variable ("SSL_PRIVATE_KEY_FILE" , cluster_label ), 2 , "TLS env variable SSL_PRIVATE_KEY_FILE missing in Spilo pods" )
662+ self .eventuallyEqual (lambda : k8s .count_pods_with_volume_mount (tls_secret , cluster_label ), 2 , "TLS volume mount missing in Spilo pods" )
663+
664+ except timeout_decorator .TimeoutError :
665+ print ('Operator log: {}' .format (k8s .get_operator_log ()))
666+ raise
667+
625668 @timeout_decorator .timeout (TEST_TIMEOUT_SEC )
626669 def test_enable_disable_connection_pooler (self ):
627670 '''
@@ -653,6 +696,11 @@ def test_enable_disable_connection_pooler(self):
653696 self .eventuallyEqual (lambda : k8s .count_services_with_label (pooler_label ), 2 , "No pooler service found" )
654697 self .eventuallyEqual (lambda : k8s .count_secrets_with_label (pooler_label ), 1 , "Pooler secret not created" )
655698
699+ # TLS still enabled so check existing env variables and volume mounts
700+ self .eventuallyEqual (lambda : k8s .count_pods_with_env_variable ("CONNECTION_POOLER_CLIENT_TLS_CRT" , pooler_label ), 4 , "TLS env variable CONNECTION_POOLER_CLIENT_TLS_CRT missing in pooler pods" )
701+ self .eventuallyEqual (lambda : k8s .count_pods_with_env_variable ("CONNECTION_POOLER_CLIENT_TLS_KEY" , pooler_label ), 4 , "TLS env variable CONNECTION_POOLER_CLIENT_TLS_KEY missing in pooler pods" )
702+ self .eventuallyEqual (lambda : k8s .count_pods_with_volume_mount ("pg-tls" , pooler_label ), 4 , "TLS volume mount missing in pooler pods" )
703+
656704 k8s .api .custom_objects_api .patch_namespaced_custom_object (
657705 'acid.zalan.do' , 'v1' , 'default' ,
658706 'postgresqls' , 'acid-minimal-cluster' ,
0 commit comments