From e3e6b399491ede6125a8033c3a1cb4d97061bf3a Mon Sep 17 00:00:00 2001 From: dirgim Date: Wed, 8 Nov 2023 11:55:13 +0100 Subject: [PATCH] feat(STONEINTG-619): remove loader/integration.go * The functions within loader/integration.go are not used in the integration-service any more and are causing unneeded churn for updating to Tekton v1 APIs Signed-off-by: dirgim --- .../buildpipeline_adapter_test.go | 2 +- loader/integration.go | 57 --- loader/integration_test.go | 338 ------------------ 3 files changed, 1 insertion(+), 396 deletions(-) delete mode 100644 loader/integration.go delete mode 100644 loader/integration_test.go diff --git a/controllers/buildpipeline/buildpipeline_adapter_test.go b/controllers/buildpipeline/buildpipeline_adapter_test.go index 79560417c..48d58039c 100644 --- a/controllers/buildpipeline/buildpipeline_adapter_test.go +++ b/controllers/buildpipeline/buildpipeline_adapter_test.go @@ -36,8 +36,8 @@ import ( ctrl "sigs.k8s.io/controller-runtime" applicationapiv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1" - tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" toolkit "github.com/redhat-appstudio/operator-toolkit/loader" + tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" "github.com/tonglil/buflogr" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/loader/integration.go b/loader/integration.go deleted file mode 100644 index 31dd5e4c9..000000000 --- a/loader/integration.go +++ /dev/null @@ -1,57 +0,0 @@ -/* -Copyright 2023 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package loader - -import ( - "context" - - applicationapiv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1" - "github.com/redhat-appstudio/integration-service/api/v1beta1" - tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - "knative.dev/pkg/apis" - "sigs.k8s.io/controller-runtime/pkg/client" -) - -// GetLatestPipelineRunForSnapshotAndScenario returns the latest Integration PipelineRun for the -// associated Snapshot and IntegrationTestScenario. In the case the List operation fails, -// an error will be returned. -func GetLatestPipelineRunForSnapshotAndScenario(adapterClient client.Client, ctx context.Context, loader ObjectLoader, snapshot *applicationapiv1alpha1.Snapshot, integrationTestScenario *v1beta1.IntegrationTestScenario) (*tektonv1.PipelineRun, error) { - integrationPipelineRuns, err := loader.GetAllPipelineRunsForSnapshotAndScenario(adapterClient, ctx, snapshot, integrationTestScenario) - if err != nil { - return nil, err - } - - var latestIntegrationPipelineRun = &tektonv1.PipelineRun{} - latestIntegrationPipelineRun = nil - for _, pipelineRun := range *integrationPipelineRuns { - pipelineRun := pipelineRun // G601 - if !pipelineRun.Status.GetCondition(apis.ConditionSucceeded).IsUnknown() { - if latestIntegrationPipelineRun == nil { - latestIntegrationPipelineRun = &pipelineRun - } else { - if pipelineRun.Status.CompletionTime.Time.After(latestIntegrationPipelineRun.Status.CompletionTime.Time) { - latestIntegrationPipelineRun = &pipelineRun - } - } - } - } - if latestIntegrationPipelineRun != nil { - return latestIntegrationPipelineRun, nil - } - - return nil, err -} diff --git a/loader/integration_test.go b/loader/integration_test.go deleted file mode 100644 index 50166c205..000000000 --- a/loader/integration_test.go +++ /dev/null @@ -1,338 +0,0 @@ -/* -Copyright 2023 Red Hat Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package loader - -import ( - "time" - - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" - "github.com/redhat-appstudio/integration-service/api/v1beta1" - tektonv1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1" - - applicationapiv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1" - "github.com/redhat-appstudio/integration-service/gitops" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "knative.dev/pkg/apis" - v1 "knative.dev/pkg/apis/duck/v1" -) - -var _ = Describe("Pipeline Adapter", Ordered, func() { - const ( - applicationName = "application-sample" - SampleRepoLink = "https://github.com/devfile-samples/devfile-sample-java-springboot-basic" - ) - - var ( - taskRun *tektonv1.TaskRun - integrationPipelineRun1 *tektonv1.PipelineRun - integrationPipelineRun2 *tektonv1.PipelineRun - hasApp *applicationapiv1alpha1.Application - hasSnapshot *applicationapiv1alpha1.Snapshot - integrationTestScenario *v1beta1.IntegrationTestScenario - loader ObjectLoader - sample_image string - ) - - BeforeAll(func() { - loader = NewLoader() - sample_image = "quay.io/redhat-appstudio/sample-image" - - hasApp = &applicationapiv1alpha1.Application{ - ObjectMeta: metav1.ObjectMeta{ - Name: applicationName, - Namespace: "default", - }, - Spec: applicationapiv1alpha1.ApplicationSpec{ - DisplayName: applicationName, - Description: "This is an example application", - }, - } - Expect(k8sClient.Create(ctx, hasApp)).Should(Succeed()) - - hasSnapshot = &applicationapiv1alpha1.Snapshot{ - ObjectMeta: metav1.ObjectMeta{ - Name: "snapshot-sample", - Namespace: "default", - Labels: map[string]string{ - gitops.SnapshotTypeLabel: "component", - gitops.SnapshotComponentLabel: "component-sample", - }, - }, - Spec: applicationapiv1alpha1.SnapshotSpec{ - Application: hasApp.Name, - Components: []applicationapiv1alpha1.SnapshotComponent{ - { - Name: "component-sample", - ContainerImage: sample_image, - }, - }, - }, - } - Expect(k8sClient.Create(ctx, hasSnapshot)).Should(Succeed()) - - integrationTestScenario = &v1beta1.IntegrationTestScenario{ - ObjectMeta: metav1.ObjectMeta{ - Name: "example-pass", - Namespace: "default", - - Labels: map[string]string{ - "test.appstudio.openshift.io/optional": "false", - }, - }, - Spec: v1beta1.IntegrationTestScenarioSpec{ - Application: hasApp.Name, - ResolverRef: v1beta1.ResolverRef{ - Resolver: "git", - Params: []v1beta1.ResolverParameter{ - { - Name: "url", - Value: "https://github.com/redhat-appstudio/integration-examples.git", - }, - { - Name: "revision", - Value: "main", - }, - { - Name: "pathInRepo", - Value: "pipelineruns/integration_pipelinerun_pass.yaml", - }, - }, - }, - Environment: v1beta1.TestEnvironment{ - Name: "envname", - Type: "POC", - Configuration: &applicationapiv1alpha1.EnvironmentConfiguration{ - Env: []applicationapiv1alpha1.EnvVarPair{}, - }, - }, - }, - } - Expect(k8sClient.Create(ctx, integrationTestScenario)).Should(Succeed()) - - taskRun = &tektonv1.TaskRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "test-taskrun-pass", - Namespace: "default", - }, - Spec: tektonv1.TaskRunSpec{ - TaskRef: &tektonv1.TaskRef{ - Name: "test-taskrun-pass", - ResolverRef: tektonv1.ResolverRef{ - Resolver: "bundle", - Params: tektonv1.Params{ - { - Name: "bundle", - Value: tektonv1.ParamValue{Type: "string", StringVal: "quay.io/redhat-appstudio/example-tekton-bundle:test"}, - }, - { - Name: "name", - Value: tektonv1.ParamValue{Type: "string", StringVal: "test-task"}, - }, - }, - }, - }, - }, - } - - Expect(k8sClient.Create(ctx, taskRun)).Should(Succeed()) - - now := time.Now() - taskRun.Status = tektonv1.TaskRunStatus{ - TaskRunStatusFields: tektonv1.TaskRunStatusFields{ - StartTime: &metav1.Time{Time: now}, - CompletionTime: &metav1.Time{Time: now.Add(5 * time.Minute)}, - Results: []tektonv1.TaskRunResult{ - { - Name: "TEST_OUTPUT", - Value: *tektonv1.NewStructuredValues(`{ - "result": "SUCCESS", - "timestamp": "1665405318", - "failures": 0, - "successes": 10, - "warnings": 0 - }`), - }, - }, - }, - } - Expect(k8sClient.Status().Update(ctx, taskRun)).Should(Succeed()) - - integrationPipelineRun1 = &tektonv1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun-component-sample-1", - Namespace: "default", - Labels: map[string]string{ - "pipelines.appstudio.openshift.io/type": "test", - "pac.test.appstudio.openshift.io/url-org": "redhat-appstudio", - "pac.test.appstudio.openshift.io/original-prname": "build-service-on-push", - "pac.test.appstudio.openshift.io/url-repository": "build-service", - "pac.test.appstudio.openshift.io/repository": "build-service-pac", - "appstudio.openshift.io/snapshot": "snapshot-sample", - "test.appstudio.openshift.io/scenario": integrationTestScenario.Name, - }, - - Annotations: map[string]string{ - "pac.test.appstudio.openshift.io/on-target-branch": "[main]", - }, - }, - Spec: tektonv1.PipelineRunSpec{ - PipelineRef: &tektonv1.PipelineRef{ - Name: "component-pipeline-pass", - ResolverRef: tektonv1.ResolverRef{ - Resolver: "bundle", - Params: tektonv1.Params{ - { - Name: "bundle", - Value: tektonv1.ParamValue{Type: "string", StringVal: "quay.io/kpavic/test-bundle:component-pipeline-pass"}, - }, - { - Name: "name", - Value: tektonv1.ParamValue{Type: "string", StringVal: "test-task"}, - }, - }, - }, - }, - }, - } - Expect(k8sClient.Create(ctx, integrationPipelineRun1)).Should(Succeed()) - - integrationPipelineRun1.Status = tektonv1.PipelineRunStatus{ - PipelineRunStatusFields: tektonv1.PipelineRunStatusFields{ - CompletionTime: &metav1.Time{Time: time.Now()}, - ChildReferences: []tektonv1.ChildStatusReference{ - { - Name: taskRun.Name, - PipelineTaskName: "pipeline1-task1", - }, - }, - }, - Status: v1.Status{ - Conditions: v1.Conditions{ - apis.Condition{ - Reason: "Completed", - Status: "True", - Type: apis.ConditionSucceeded, - }, - }, - }, - } - Expect(k8sClient.Status().Update(ctx, integrationPipelineRun1)).Should(Succeed()) - - pr := &tektonv1.PipelineRun{} - Eventually(func() bool { - err := k8sClient.Get(ctx, types.NamespacedName{ - Name: integrationPipelineRun1.Name, - Namespace: integrationPipelineRun1.Namespace, - }, pr) - return err == nil && pr.Status.CompletionTime != nil - }, time.Second*10).Should(BeTrue(), "timed out when waiting for the PipelineRun to be updated") - - integrationPipelineRun2 = &tektonv1.PipelineRun{ - ObjectMeta: metav1.ObjectMeta{ - Name: "pipelinerun-component-sample-2", - Namespace: "default", - Labels: map[string]string{ - "pipelines.appstudio.openshift.io/type": "test", - "pac.test.appstudio.openshift.io/url-org": "redhat-appstudio", - "pac.test.appstudio.openshift.io/original-prname": "build-service-on-push", - "pac.test.appstudio.openshift.io/url-repository": "build-service", - "pac.test.appstudio.openshift.io/repository": "build-service-pac", - "appstudio.openshift.io/snapshot": "snapshot-sample", - "test.appstudio.openshift.io/scenario": integrationTestScenario.Name, - }, - - Annotations: map[string]string{ - "pac.test.appstudio.openshift.io/on-target-branch": "[main]", - }, - }, - Spec: tektonv1.PipelineRunSpec{ - PipelineRef: &tektonv1.PipelineRef{ - Name: "component-pipeline-pass", - ResolverRef: tektonv1.ResolverRef{ - Resolver: "bundle", - Params: tektonv1.Params{ - { - Name: "bundle", - Value: tektonv1.ParamValue{Type: "string", StringVal: "quay.io/kpavic/test-bundle:component-pipeline-pass"}, - }, - { - Name: "name", - Value: tektonv1.ParamValue{Type: "string", StringVal: "test-task"}, - }, - }, - }, - }, - }, - } - Expect(k8sClient.Create(ctx, integrationPipelineRun2)).Should(Succeed()) - - integrationPipelineRun2.Status = tektonv1.PipelineRunStatus{ - PipelineRunStatusFields: tektonv1.PipelineRunStatusFields{ - CompletionTime: &metav1.Time{Time: time.Now().Add(5 * time.Minute)}, - ChildReferences: []tektonv1.ChildStatusReference{ - { - Name: taskRun.Name, - PipelineTaskName: "pipeline1-task1", - }, - }, - }, - Status: v1.Status{ - Conditions: v1.Conditions{ - apis.Condition{ - Reason: "Completed", - Status: "True", - Type: apis.ConditionSucceeded, - }, - }, - }, - } - Expect(k8sClient.Status().Update(ctx, integrationPipelineRun2)).Should(Succeed()) - - pr = &tektonv1.PipelineRun{} - Eventually(func() bool { - err := k8sClient.Get(ctx, types.NamespacedName{ - Name: integrationPipelineRun2.Name, - Namespace: integrationPipelineRun2.Namespace, - }, pr) - return err == nil && pr.Status.CompletionTime != nil - }, time.Second*10).Should(BeTrue(), "timed out when waiting for the PipelineRun to be updated") - }) - - AfterAll(func() { - err := k8sClient.Delete(ctx, hasSnapshot) - Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) - err = k8sClient.Delete(ctx, integrationPipelineRun1) - Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) - err = k8sClient.Delete(ctx, integrationPipelineRun2) - Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) - err = k8sClient.Delete(ctx, hasApp) - Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) - err = k8sClient.Delete(ctx, integrationTestScenario) - Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) - err = k8sClient.Delete(ctx, taskRun) - Expect(err == nil || errors.IsNotFound(err)).To(BeTrue()) - }) - - It("can fetch latest pipelineRun for snapshot and scenario", func() { - pipelineRun, err := GetLatestPipelineRunForSnapshotAndScenario(k8sClient, ctx, loader, hasSnapshot, integrationTestScenario) - Expect(pipelineRun.Name == integrationPipelineRun2.Name).To(BeTrue()) - Expect(err).To(BeNil()) - }) -})