github.com/redhat-appstudio/e2e-tests@v0.0.0-20240520140907-9709f6f59323/tests/remote-secret/component-annotation-image-pull-remote-secret.go (about)

     1  package remotesecret
     2  
     3  import (
     4  	"fmt"
     5  	"time"
     6  
     7  	. "github.com/onsi/ginkgo/v2"
     8  	. "github.com/onsi/gomega"
     9  	appservice "github.com/redhat-appstudio/application-api/api/v1alpha1"
    10  	"github.com/redhat-appstudio/e2e-tests/pkg/clients/has"
    11  	"github.com/redhat-appstudio/e2e-tests/pkg/framework"
    12  	"github.com/redhat-appstudio/e2e-tests/pkg/utils"
    13  	rs "github.com/redhat-appstudio/remote-secret/api/v1beta1"
    14  	"k8s.io/apimachinery/pkg/api/meta"
    15  )
    16  
    17  /*
    18   * Component: remote secret
    19   * Description: SVPI-574 - Ensure existence of image pull remote secret and image pull secret when component is created
    20   * Note: This test covers the current approach (component annotation)
    21   * More info: https://github.com/konflux-ci/image-controller#legacy-deprecated-component-image-repository
    22   */
    23  
    24  var _ = framework.RemoteSecretSuiteDescribe(Label("remote-secret", "component-annotation-image-pull-remote-secret"), func() {
    25  
    26  	defer GinkgoRecover()
    27  
    28  	var fw *framework.Framework
    29  	var err error
    30  	var namespace string
    31  	var timeout, interval time.Duration
    32  
    33  	application := &appservice.Application{}
    34  	cdq := &appservice.ComponentDetectionQuery{}
    35  	componentList := []*appservice.Component{}
    36  	imagePullRemoteSecret := &rs.RemoteSecret{}
    37  	component := &appservice.Component{}
    38  	targets := []rs.TargetStatus{}
    39  	snapshot := &appservice.Snapshot{}
    40  
    41  	applicationName := "component-annotation-dotnet-component"
    42  	gitSourceUrl := "https://github.com/devfile-samples/devfile-sample-dotnet60-basic"
    43  	secret := ""
    44  
    45  	AfterEach(framework.ReportFailure(&fw))
    46  
    47  	Describe("SVPI-601 - Ensure existence of image pull remote secret and image pull secret when component is created", Ordered, func() {
    48  		BeforeAll(func() {
    49  			// Initialize the tests controllers
    50  			fw, err = framework.NewFramework(utils.GetGeneratedNamespace("rs-demos"))
    51  			Expect(err).NotTo(HaveOccurred())
    52  			namespace = fw.UserNamespace
    53  			Expect(namespace).NotTo(BeEmpty())
    54  		})
    55  
    56  		AfterAll(func() {
    57  			if !CurrentSpecReport().Failed() {
    58  				Expect(fw.SandboxController.DeleteUserSignup(fw.UserName)).To(BeTrue())
    59  			}
    60  		})
    61  
    62  		It("creates an application", func() {
    63  			createdApplication, err := fw.AsKubeDeveloper.HasController.CreateApplication(applicationName, namespace)
    64  			Expect(err).NotTo(HaveOccurred())
    65  			Expect(createdApplication.Spec.DisplayName).To(Equal(applicationName))
    66  			Expect(createdApplication.Namespace).To(Equal(namespace))
    67  		})
    68  
    69  		It("checks if application is healthy", func() {
    70  			Eventually(func() string {
    71  				appstudioApp, err := fw.AsKubeDeveloper.HasController.GetApplication(applicationName, namespace)
    72  				Expect(err).NotTo(HaveOccurred())
    73  				application = appstudioApp
    74  
    75  				return application.Status.Devfile
    76  			}, 3*time.Minute, 100*time.Millisecond).Should(Not(BeEmpty()), fmt.Sprintf("timed out waiting for the %s application in %s namespace to be ready", applicationName, fw.UserNamespace))
    77  		})
    78  
    79  		It("creates component detection query", func() {
    80  			cdq, err = fw.AsKubeDeveloper.HasController.CreateComponentDetectionQuery(applicationName, namespace, gitSourceUrl, "", "", secret, false)
    81  			Expect(err).NotTo(HaveOccurred())
    82  		})
    83  
    84  		It("creates component", func() {
    85  			for _, compDetected := range cdq.Status.ComponentDetected {
    86  				c, err := fw.AsKubeDeveloper.HasController.CreateComponent(compDetected.ComponentStub, namespace, "", secret, applicationName, true, map[string]string{})
    87  				Expect(err).NotTo(HaveOccurred())
    88  				Expect(c.Name).To(Equal(compDetected.ComponentStub.ComponentName))
    89  
    90  				componentList = append(componentList, c)
    91  			}
    92  
    93  			Expect(componentList).To(HaveLen(1))
    94  			component = componentList[0]
    95  
    96  			Expect(component.Annotations["image.redhat.com/generate"]).To(Equal("{\"visibility\": \"public\"}"))
    97  		})
    98  
    99  		It("waits for components pipeline to be finished", func() {
   100  			for _, component := range componentList {
   101  				component, err = fw.AsKubeAdmin.HasController.GetComponent(component.GetName(), namespace)
   102  				Expect(err).ShouldNot(HaveOccurred(), "failed to get component: %v", err)
   103  
   104  				Expect(fw.AsKubeAdmin.HasController.WaitForComponentPipelineToBeFinished(component, "",
   105  					fw.AsKubeAdmin.TektonController, &has.RetryOptions{Retries: 2, Always: true}, nil)).To(Succeed())
   106  			}
   107  		})
   108  
   109  		It("finds the snapshot and checks if it is marked as successful", func() {
   110  			timeout = time.Second * 600
   111  			interval = time.Second * 10
   112  			for _, component := range componentList {
   113  				Eventually(func() error {
   114  					snapshot, err = fw.AsKubeAdmin.IntegrationController.GetSnapshot("", "", component.Name, namespace)
   115  					if err != nil {
   116  						GinkgoWriter.Println("snapshot has not been found yet")
   117  						return err
   118  					}
   119  					if !fw.AsKubeAdmin.CommonController.HaveTestsSucceeded(snapshot) {
   120  						return fmt.Errorf("tests haven't succeeded for snapshot %s/%s. snapshot status: %+v", snapshot.GetNamespace(), snapshot.GetName(), snapshot.Status)
   121  					}
   122  					return nil
   123  				}, timeout, interval).Should(Succeed(), fmt.Sprintf("timed out waiting for the snapshot for the component %s/%s to be marked as successful", component.GetNamespace(), component.GetName()))
   124  			}
   125  		})
   126  
   127  		It("checks if image pull remote secret was deployed", func() {
   128  			Eventually(func() bool {
   129  				imagePullRemoteSecret, err = fw.AsKubeAdmin.RemoteSecretController.GetImageRepositoryRemoteSecret(component.Spec.ComponentName+"-pull", applicationName, component.Spec.ComponentName, namespace)
   130  				Expect(err).NotTo(HaveOccurred())
   131  
   132  				return meta.IsStatusConditionTrue(imagePullRemoteSecret.Status.Conditions, "Deployed")
   133  			}, 5*time.Minute, 5*time.Second).Should(BeTrue(), fmt.Sprintf("Pull RemoteSecret %s/%s is not in deployed phase", namespace, imagePullRemoteSecret.GetName()))
   134  		})
   135  
   136  		It("checks if image pull secret is set and linked to the default service account", func() {
   137  			targets = imagePullRemoteSecret.Status.Targets
   138  			Expect(targets).To(HaveLen(1))
   139  
   140  			IsTargetSecretLinkedToRightSA(namespace, imagePullRemoteSecret.Name, "default", targets[0])
   141  		})
   142  
   143  		It("checks if image pull secret is correct", func() {
   144  			IsRobotAccountTokenCorrect(targets[0].DeployedSecret.Name, namespace, "", nil, fw)
   145  		})
   146  	})
   147  })