chainloop_test.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. package chainloop_test
  2. import (
  3. "context"
  4. "fmt"
  5. "time"
  6. utils "github.com/bitnami/charts/.vib/common-tests/ginkgo-utils"
  7. . "github.com/onsi/ginkgo/v2"
  8. . "github.com/onsi/gomega"
  9. appsv1 "k8s.io/api/apps/v1"
  10. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  11. "k8s.io/client-go/kubernetes"
  12. )
  13. const (
  14. PollingInterval = 1 * time.Second
  15. )
  16. // portDefinition is a struct to define a port in a service
  17. type portDefinition struct {
  18. name string
  19. number string
  20. }
  21. var _ = Describe("Chainloop", Ordered, func() {
  22. var c *kubernetes.Clientset
  23. var ctx context.Context
  24. var cancel context.CancelFunc
  25. BeforeEach(func() {
  26. ctx, cancel = context.WithCancel(context.Background())
  27. conf := utils.MustBuildClusterConfig(kubeconfig)
  28. c = kubernetes.NewForConfigOrDie(conf)
  29. })
  30. When("Chainloop chart is fully deployed", func() {
  31. It("cas deployment is running", func() {
  32. getReadyReplicas := func(ss *appsv1.Deployment) int32 { return ss.Status.ReadyReplicas }
  33. getOpts := metav1.GetOptions{}
  34. By("checking all the replicas are available")
  35. stsName := fmt.Sprintf("%s-cas", releaseName)
  36. dpl, err := c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
  37. Expect(err).NotTo(HaveOccurred())
  38. Expect(dpl.Status.Replicas).NotTo(BeZero())
  39. origReplicas := *dpl.Spec.Replicas
  40. Eventually(func() (*appsv1.Deployment, error) {
  41. return c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
  42. }, timeout, PollingInterval).Should(WithTransform(getReadyReplicas, Equal(origReplicas)))
  43. By("checking all the services are available")
  44. svcs := []struct {
  45. name string
  46. ports []portDefinition
  47. }{
  48. {
  49. name: "cas",
  50. ports: []portDefinition{
  51. {
  52. name: "http",
  53. number: "80",
  54. },
  55. },
  56. },
  57. {
  58. name: "cas-api",
  59. ports: []portDefinition{
  60. {
  61. name: "grpc",
  62. number: "80",
  63. },
  64. },
  65. },
  66. }
  67. for _, inSvc := range svcs {
  68. svcName := fmt.Sprintf("%v-%v", releaseName, inSvc.name)
  69. svc, err := c.CoreV1().Services(namespace).Get(ctx, svcName, metav1.GetOptions{})
  70. Expect(err).NotTo(HaveOccurred())
  71. for _, port := range inSvc.ports {
  72. outPort, err := utils.SvcGetPortByName(svc, port.name)
  73. Expect(err).NotTo(HaveOccurred())
  74. Expect(outPort).NotTo(BeNil())
  75. Expect(outPort).To(Equal(port.number))
  76. }
  77. }
  78. By("checking main container image is running")
  79. _, err = utils.DplGetContainerImage(dpl, "cas")
  80. Expect(err).NotTo(HaveOccurred())
  81. })
  82. It("controlplane deployment is running", func() {
  83. getReadyReplicas := func(ss *appsv1.Deployment) int32 { return ss.Status.ReadyReplicas }
  84. getOpts := metav1.GetOptions{}
  85. By("checking all the replicas are available")
  86. stsName := fmt.Sprintf("%s-controlplane", releaseName)
  87. dpl, err := c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
  88. Expect(err).NotTo(HaveOccurred())
  89. Expect(dpl.Status.Replicas).NotTo(BeZero())
  90. origReplicas := *dpl.Spec.Replicas
  91. Eventually(func() (*appsv1.Deployment, error) {
  92. return c.AppsV1().Deployments(namespace).Get(ctx, stsName, getOpts)
  93. }, timeout, PollingInterval).Should(WithTransform(getReadyReplicas, Equal(origReplicas)))
  94. By("checking all the services are available")
  95. svcs := []struct {
  96. name string
  97. ports []portDefinition
  98. }{
  99. {
  100. name: "controlplane",
  101. ports: []portDefinition{
  102. {
  103. name: "http",
  104. number: "80",
  105. },
  106. },
  107. },
  108. {
  109. name: "controlplane-api",
  110. ports: []portDefinition{
  111. {
  112. name: "grpc",
  113. number: "80",
  114. },
  115. },
  116. },
  117. }
  118. for _, inSvc := range svcs {
  119. svcName := fmt.Sprintf("%v-%v", releaseName, inSvc.name)
  120. svc, err := c.CoreV1().Services(namespace).Get(ctx, svcName, metav1.GetOptions{})
  121. Expect(err).NotTo(HaveOccurred())
  122. for _, port := range inSvc.ports {
  123. outPort, err := utils.SvcGetPortByName(svc, port.name)
  124. Expect(err).NotTo(HaveOccurred())
  125. Expect(outPort).NotTo(BeNil())
  126. Expect(outPort).To(Equal(port.number))
  127. }
  128. }
  129. By("checking main container image is running")
  130. _, err = utils.DplGetContainerImage(dpl, "controlplane")
  131. Expect(err).NotTo(HaveOccurred())
  132. })
  133. })
  134. AfterEach(func() {
  135. cancel()
  136. })
  137. })