@@ -22,6 +22,7 @@ import (
2222 . "github.com/onsi/gomega"
2323 v1 "k8s.io/api/apps/v1"
2424 corev1 "k8s.io/api/core/v1"
25+ apierrors "k8s.io/apimachinery/pkg/api/errors"
2526 "k8s.io/apimachinery/pkg/api/meta"
2627 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728 "k8s.io/apimachinery/pkg/types"
@@ -31,6 +32,7 @@ import (
3132 testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
3233 . "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants"
3334 "github.com/ydb-platform/ydb-kubernetes-operator/internal/resources"
35+ "github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
3436)
3537
3638const (
@@ -158,7 +160,7 @@ func bringYdbCliToPod(podName, podNamespace string) {
158160 }, Timeout , Interval ).Should (BeNil ())
159161}
160162
161- func executeSimpleQuery (ctx context. Context , podName , podNamespace , storageEndpoint string ) {
163+ func executeSimpleQuery (podName , podNamespace , storageEndpoint string ) {
162164 Eventually (func (g Gomega ) string {
163165 args := []string {
164166 "-n" ,
@@ -345,7 +347,7 @@ var _ = Describe("Operator smoke test", func() {
345347 bringYdbCliToPod (podName , testobjects .YdbNamespace )
346348
347349 By ("execute simple query inside ydb database pod..." )
348- executeSimpleQuery (ctx , podName , testobjects .YdbNamespace , storageEndpoint )
350+ executeSimpleQuery (podName , testobjects .YdbNamespace , storageEndpoint )
349351 })
350352
351353 It ("pause and un-pause Storage, should destroy and bring up Pods" , func () {
@@ -492,7 +494,6 @@ var _ = Describe("Operator smoke test", func() {
492494 It ("create storage and database with nodeSets" , func () {
493495 By ("issuing create commands..." )
494496 storageSample = testobjects .DefaultStorage (filepath .Join ("." , "data" , "storage-block-4-2-config-nodeSets.yaml" ))
495- databaseSample = testobjects .DefaultDatabase ()
496497 testNodeSetName := "nodeset"
497498 for idx := 1 ; idx <= 2 ; idx ++ {
498499 storageSample .Spec .NodeSets = append (storageSample .Spec .NodeSets , v1alpha1.StorageNodeSetSpecInline {
@@ -572,7 +573,7 @@ var _ = Describe("Operator smoke test", func() {
572573 bringYdbCliToPod (podName , testobjects .YdbNamespace )
573574
574575 By ("execute simple query inside ydb database pod..." )
575- executeSimpleQuery (ctx , podName , testobjects .YdbNamespace , storageEndpoint )
576+ executeSimpleQuery (podName , testobjects .YdbNamespace , storageEndpoint )
576577 })
577578
578579 It ("operatorConnection check, create storage with default staticCredentials" , func () {
@@ -652,28 +653,115 @@ var _ = Describe("Operator smoke test", func() {
652653 LocalObjectReference : corev1.LocalObjectReference {Name : testobjects .CertificateSecretName },
653654 Key : "ca.crt" ,
654655 }
655-
656656 Expect (k8sClient .Create (ctx , storageSample )).Should (Succeed ())
657657 defer func () {
658658 Expect (k8sClient .Delete (ctx , storageSample )).Should (Succeed ())
659659 }()
660+
661+ By ("waiting until Storage is ready..." )
662+ waitUntilStorageReady (ctx , storageSample .Name , testobjects .YdbNamespace )
663+
664+ By ("checking that all the storage pods are running and ready..." )
665+ checkPodsRunningAndReady (ctx , "ydb-cluster" , "kind-storage" , storageSample .Spec .Nodes )
666+
660667 By ("create database..." )
668+ databaseSample .Spec .Service .GRPC .TLSConfiguration .Enabled = true
669+ databaseSample .Spec .Service .GRPC .TLSConfiguration .Certificate = corev1.SecretKeySelector {
670+ LocalObjectReference : corev1.LocalObjectReference {Name : testobjects .CertificateSecretName },
671+ Key : "tls.crt" ,
672+ }
673+ databaseSample .Spec .Service .GRPC .TLSConfiguration .Key = corev1.SecretKeySelector {
674+ LocalObjectReference : corev1.LocalObjectReference {Name : testobjects .CertificateSecretName },
675+ Key : "tls.key" ,
676+ }
677+ databaseSample .Spec .Service .GRPC .TLSConfiguration .CertificateAuthority = corev1.SecretKeySelector {
678+ LocalObjectReference : corev1.LocalObjectReference {Name : testobjects .CertificateSecretName },
679+ Key : "ca.crt" ,
680+ }
661681 Expect (k8sClient .Create (ctx , databaseSample )).Should (Succeed ())
662682 defer func () {
663683 Expect (k8sClient .Delete (ctx , databaseSample )).Should (Succeed ())
664684 }()
665685
686+ By ("waiting until database is ready..." )
687+ waitUntilDatabaseReady (ctx , databaseSample .Name , testobjects .YdbNamespace )
688+
689+ By ("checking that all the database pods are running and ready..." )
690+ checkPodsRunningAndReady (ctx , "ydb-cluster" , "kind-database" , databaseSample .Spec .Nodes )
691+
692+ storagePods := corev1.PodList {}
693+ Expect (k8sClient .List (ctx , & storagePods ,
694+ client .InNamespace (testobjects .YdbNamespace ),
695+ client.MatchingLabels {
696+ "ydb-cluster" : "kind-database" ,
697+ })).Should (Succeed ())
698+ podName := storagePods .Items [0 ].Name
699+
700+ By ("bring YDB CLI inside ydb storage pod..." )
701+ bringYdbCliToPod (podName , testobjects .YdbNamespace )
702+
703+ By ("execute simple query inside ydb storage pod..." )
704+ storageEndpoint := fmt .Sprintf ("grpcs://%s:%d" , testobjects .StorageGRPCService , testobjects .StorageGRPCPort )
705+ executeSimpleQuery (podName , testobjects .YdbNamespace , storageEndpoint )
706+ })
707+
708+ It ("Check that Storage deleted after Database..." , func () {
709+ By ("create storage..." )
710+ Expect (k8sClient .Create (ctx , storageSample )).Should (Succeed ())
711+
712+ By ("create database..." )
713+ Expect (k8sClient .Create (ctx , databaseSample )).Should (Succeed ())
714+
666715 By ("waiting until Storage is ready..." )
667716 waitUntilStorageReady (ctx , storageSample .Name , testobjects .YdbNamespace )
668717
669718 By ("checking that all the storage pods are running and ready..." )
670719 checkPodsRunningAndReady (ctx , "ydb-cluster" , "kind-storage" , storageSample .Spec .Nodes )
671720
672- By ("waiting until database is ready..." )
721+ By ("waiting until Database is ready..." )
673722 waitUntilDatabaseReady (ctx , databaseSample .Name , testobjects .YdbNamespace )
674723
675724 By ("checking that all the database pods are running and ready..." )
676725 checkPodsRunningAndReady (ctx , "ydb-cluster" , "kind-database" , databaseSample .Spec .Nodes )
726+
727+ By ("delete Storage..." )
728+ Expect (k8sClient .Delete (ctx , storageSample )).Should (Succeed ())
729+
730+ By ("checking that Storage deletionTimestamp is not nil..." )
731+ Eventually (func () bool {
732+ foundStorage := v1alpha1.Storage {}
733+ err := k8sClient .Get (ctx , types.NamespacedName {
734+ Name : storageSample .Name ,
735+ Namespace : testobjects .YdbNamespace ,
736+ }, & foundStorage )
737+ if err != nil {
738+ return false
739+ }
740+ return ! foundStorage .DeletionTimestamp .IsZero ()
741+ }, test .Timeout , test .Interval ).Should (BeTrue ())
742+
743+ By ("checking that Storage is present in cluster..." )
744+ Consistently (func () error {
745+ foundStorage := v1alpha1.Storage {}
746+ err := k8sClient .Get (ctx , types.NamespacedName {
747+ Name : storageSample .Name ,
748+ Namespace : testobjects .YdbNamespace ,
749+ }, & foundStorage )
750+ return err
751+ }, test .Timeout , test .Interval ).ShouldNot (HaveOccurred ())
752+
753+ By ("delete Database..." )
754+ Expect (k8sClient .Delete (ctx , databaseSample )).Should (Succeed ())
755+
756+ By ("checking that Storage deleted from cluster..." )
757+ Eventually (func () bool {
758+ foundStorage := v1alpha1.Storage {}
759+ err := k8sClient .Get (ctx , types.NamespacedName {
760+ Name : storageSample .Name ,
761+ Namespace : testobjects .YdbNamespace ,
762+ }, & foundStorage )
763+ return apierrors .IsNotFound (err )
764+ }, test .Timeout , test .Interval ).Should (BeTrue ())
677765 })
678766
679767 It ("TLS for status service" , func () {
@@ -740,13 +828,18 @@ var _ = Describe("Operator smoke test", func() {
740828 Key : "ca.crt" ,
741829 },
742830 }
743-
744831 Expect (k8sClient .Create (ctx , storageSample )).Should (Succeed ())
832+ defer func () {
833+ Expect (k8sClient .Delete (ctx , storageSample )).Should (Succeed ())
834+ }()
745835
746836 By ("create database..." )
747837 databaseSample .Spec .Nodes = 1
748838 databaseSample .Spec .Service .Status = * storageSample .Spec .Service .Status .DeepCopy ()
749839 Expect (k8sClient .Create (ctx , databaseSample )).Should (Succeed ())
840+ defer func () {
841+ Expect (k8sClient .Delete (ctx , databaseSample )).Should (Succeed ())
842+ }()
750843
751844 By ("waiting until Storage is ready..." )
752845 waitUntilStorageReady (ctx , storageSample .Name , testobjects .YdbNamespace )
0 commit comments