github.com/verrazzano/verrazzano@v1.7.1/tests/e2e/verify-install/kiali/kiali_test.go (about)

     1  // Copyright (c) 2021, 2022, Oracle and/or its affiliates.
     2  // Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
     3  
     4  package kiali
     5  
     6  import (
     7  	"fmt"
     8  	"github.com/verrazzano/verrazzano/platform-operator/constants"
     9  	"github.com/verrazzano/verrazzano/platform-operator/controllers/verrazzano/component/kiali"
    10  	corev1 "k8s.io/api/core/v1"
    11  	"time"
    12  
    13  	"github.com/hashicorp/go-retryablehttp"
    14  	. "github.com/onsi/ginkgo/v2"
    15  	. "github.com/onsi/gomega"
    16  	"github.com/verrazzano/verrazzano/pkg/k8sutil"
    17  	"github.com/verrazzano/verrazzano/tests/e2e/pkg"
    18  	"github.com/verrazzano/verrazzano/tests/e2e/pkg/test/framework"
    19  	v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    20  	"k8s.io/client-go/kubernetes"
    21  )
    22  
    23  const (
    24  	waitTimeout     = 15 * time.Minute
    25  	pollingInterval = 10 * time.Second
    26  )
    27  
    28  var (
    29  	client     *kubernetes.Clientset
    30  	httpClient *retryablehttp.Client
    31  	kialiErr   error
    32  )
    33  
    34  var t = framework.NewTestFramework("kiali")
    35  
    36  var beforeSuite = t.BeforeSuiteFunc(func() {
    37  	client, kialiErr = k8sutil.GetKubernetesClientset()
    38  	Expect(kialiErr).ToNot(HaveOccurred())
    39  	httpClient = pkg.EventuallyVerrazzanoRetryableHTTPClient()
    40  })
    41  
    42  var _ = BeforeSuite(beforeSuite)
    43  
    44  // 'It' Wrapper to only run spec if Kiali is supported on the current Verrazzano installation
    45  func WhenKialiInstalledIt(description string, f interface{}) {
    46  	kubeconfigPath, err := k8sutil.GetKubeConfigLocation()
    47  	if err != nil {
    48  		Fail(fmt.Sprintf("Failed to get default kubeconfig path: %s", err.Error()))
    49  	}
    50  	supported, err := pkg.IsVerrazzanoMinVersion("1.1.0", kubeconfigPath)
    51  	if err != nil {
    52  		Fail(err.Error())
    53  	}
    54  	// Kiali only installed when VZ > 1.1.0 and not a managed cluster
    55  	if supported && !pkg.IsManagedClusterProfile() {
    56  		t.It(description, f)
    57  	} else {
    58  		t.Logs.Infof("Skipping check '%v', Kiali is not supported", description)
    59  	}
    60  }
    61  
    62  var _ = t.AfterEach(func() {})
    63  
    64  var _ = t.Describe("Kiali", Label("f:platform-lcm.install"), func() {
    65  
    66  	t.Context("after successful installation", func() {
    67  
    68  		WhenKialiInstalledIt("should have a running pod", func() {
    69  			kialiPodsRunning := func() bool {
    70  				result, err := pkg.PodsRunning(kiali.ComponentNamespace, []string{pkg.KialiName})
    71  				if err != nil {
    72  					AbortSuite(fmt.Sprintf("Pod %v is not running in the namespace: %v, error: %v", pkg.KialiName, kiali.ComponentNamespace, err))
    73  				}
    74  				return result
    75  			}
    76  			Eventually(kialiPodsRunning, waitTimeout, pollingInterval).Should(BeTrue())
    77  		})
    78  
    79  		WhenKialiInstalledIt("should have a pod with affinity configured", func() {
    80  			var pods []corev1.Pod
    81  			var err error
    82  			Eventually(func() bool {
    83  				pods, err = pkg.GetPodsFromSelector(&v1.LabelSelector{MatchLabels: map[string]string{"app": "kiali"}}, constants.VerrazzanoSystemNamespace)
    84  				if err != nil {
    85  					t.Logs.Errorf("Failed to get Kiali pods: %v", err)
    86  					return false
    87  				}
    88  				return true
    89  			}, waitTimeout, pollingInterval)
    90  			for _, pod := range pods {
    91  				affinity := pod.Spec.Affinity
    92  				Expect(affinity).ToNot(BeNil())
    93  				Expect(affinity.PodAffinity).To(BeNil())
    94  				Expect(affinity.NodeAffinity).To(BeNil())
    95  				Expect(affinity.PodAntiAffinity).ToNot(BeNil())
    96  				Expect(len(affinity.PodAntiAffinity.PreferredDuringSchedulingIgnoredDuringExecution)).To(Equal(1))
    97  			}
    98  		})
    99  
   100  		t.Context("should", func() {
   101  			var (
   102  				kialiHost string
   103  				creds     *pkg.UsernamePassword
   104  			)
   105  
   106  			BeforeEach(func() {
   107  				kialiHost = pkg.EventuallyGetKialiHost(client)
   108  				creds = pkg.EventuallyGetSystemVMICredentials()
   109  			})
   110  
   111  			WhenKialiInstalledIt("not allow unauthenticated logins", func() {
   112  				Eventually(func() bool {
   113  					unauthHTTPClient := pkg.EventuallyVerrazzanoRetryableHTTPClient()
   114  					return pkg.AssertOauthURLAccessibleAndUnauthorized(unauthHTTPClient, kialiHost)
   115  				}, waitTimeout, pollingInterval).Should(BeTrue())
   116  			})
   117  
   118  			WhenKialiInstalledIt("allow basic authentication", func() {
   119  				Eventually(func() bool {
   120  					return pkg.AssertURLAccessibleAndAuthorized(httpClient, kialiHost, creds)
   121  				}, waitTimeout, pollingInterval).Should(BeTrue())
   122  			})
   123  
   124  			WhenKialiInstalledIt("allow bearer authentication", func() {
   125  				Eventually(func() bool {
   126  					return pkg.AssertBearerAuthorized(httpClient, kialiHost)
   127  				}, waitTimeout, pollingInterval).Should(BeTrue())
   128  			})
   129  		})
   130  	})
   131  })