github.com/1aal/kubeblocks@v0.0.0-20231107070852-e1c03e598921/test/e2e/envcheck/envcheck.go (about)

     1  /*
     2  Copyright (C) 2022-2023 ApeCloud Co., Ltd
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package envcheck
    18  
    19  import (
    20  	"strings"
    21  
    22  	. "github.com/onsi/ginkgo/v2"
    23  	. "github.com/onsi/gomega"
    24  
    25  	corev1 "k8s.io/api/core/v1"
    26  	apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
    27  
    28  	appsv1alpha1 "github.com/1aal/kubeblocks/apis/apps/v1alpha1"
    29  	dpv1alpha1 "github.com/1aal/kubeblocks/apis/dataprotection/v1alpha1"
    30  
    31  	. "github.com/1aal/kubeblocks/test/e2e"
    32  )
    33  
    34  func EnvCheckTest() {
    35  
    36  	BeforeEach(func() {
    37  	})
    38  
    39  	AfterEach(func() {
    40  	})
    41  
    42  	Context("Real Kubernetes Cluster", func() {
    43  		It("All components' statuses (componentstatuses/v1 API) are healthy", func() {
    44  			csList := &corev1.ComponentStatusList{}
    45  			Expect(K8sClient.List(Ctx, csList)).To(Succeed())
    46  			Expect(len(csList.Items)).ShouldNot(Equal(0))
    47  			for _, cs := range csList.Items {
    48  				for _, csCond := range cs.Conditions {
    49  					if csCond.Type != corev1.ComponentHealthy {
    50  						continue
    51  					}
    52  					Expect(csCond.Status).Should(Equal(corev1.ConditionTrue))
    53  				}
    54  			}
    55  		})
    56  	})
    57  }
    58  
    59  func EnvGotCleanedTest() {
    60  
    61  	BeforeEach(func() {
    62  	})
    63  
    64  	AfterEach(func() {
    65  	})
    66  
    67  	Context("Real Kubernetes Cluster", func() {
    68  		It("Check no KubeBlocks CRD installed", CheckNoKubeBlocksCRDs)
    69  	})
    70  }
    71  
    72  func CheckNoKubeBlocksCRDs() {
    73  	apiGroups := []string{
    74  		dpv1alpha1.GroupVersion.Group,
    75  		appsv1alpha1.GroupVersion.Group,
    76  	}
    77  
    78  	crdList := &apiextv1.CustomResourceDefinitionList{}
    79  	Expect(K8sClient.List(Ctx, crdList)).To(Succeed())
    80  	for _, crd := range crdList.Items {
    81  		for _, g := range apiGroups {
    82  			Expect(strings.Contains(crd.Spec.Group, g)).Should(BeFalse())
    83  		}
    84  	}
    85  }