Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(HACBS-2550): pass git resolver info for verify-ec task #248

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions controllers/release/adapter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ import (
"context"
"encoding/json"
"fmt"
"reflect"
"strings"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
"github.com/operator-framework/operator-lib/handler"
Expand All @@ -32,8 +35,6 @@ import (
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/types"
"reflect"
"strings"

ecapiv1alpha1 "github.com/enterprise-contract/enterprise-contract-controller/api/v1alpha1"
applicationapiv1alpha1 "github.com/redhat-appstudio/application-api/api/v1alpha1"
Expand Down Expand Up @@ -831,9 +832,28 @@ var _ = Describe("Release adapter", Ordered, func() {
Expect(pipelineRun.Spec.PipelineRef.Name).To(Equal(releaseStrategy.Spec.Pipeline))
})

It("contains a parameter with the verify ec task bundle", func() {
bundle := enterpriseContractConfigMap.Data["verify_ec_task_bundle"]
Expect(pipelineRun.Spec.Params).Should(ContainElement(HaveField("Value.StringVal", Equal(string(bundle)))))
It("contains parameters with the verify ec task git resolver information", func() {
url := enterpriseContractConfigMap.Data["verify_ec_task_git_url"]
revision := enterpriseContractConfigMap.Data["verify_ec_task_git_revision"]
pathInRepo := enterpriseContractConfigMap.Data["verify_ec_task_git_pathInRepo"]
params := pipelineRun.Spec.Params
checked := 0

for i := range params {
if params[i].Name == "verify_ec_task_git_url" {
Expect(params[i].Value.StringVal).To(Equal(string(url)))
checked++
}
if params[i].Name == "verify_ec_task_git_revision" {
Expect(params[i].Value.StringVal).To(Equal(string(revision)))
checked++
}
if params[i].Name == "verify_ec_task_git_pathInRepo" {
Expect(params[i].Value.StringVal).To(Equal(string(pathInRepo)))
checked++
}
}
Expect(checked).To(Equal(3))
})

It("contains a parameter with the json representation of the EnterpriseContractPolicy", func() {
Expand Down Expand Up @@ -1448,7 +1468,9 @@ var _ = Describe("Release adapter", Ordered, func() {
Namespace: "default",
},
Data: map[string]string{
"verify_ec_task_bundle": "test-bundle",
"verify_ec_task_git_url": "https://github.com/org/repo.git",
"verify_ec_task_git_revision": "abcdefghijklmnopqrstuvwxyz",
"verify_ec_task_git_pathInRepo": "catalog/tasks/verify-ec/task.yaml",
},
}
Expect(k8sClient.Create(ctx, enterpriseContractConfigMap)).Should(Succeed())
Expand Down
21 changes: 11 additions & 10 deletions tekton/pipeline_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ import (
"encoding/json"
"fmt"
"os"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"strings"
"unicode"

"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"

Expand Down Expand Up @@ -70,16 +71,16 @@ func (r *ReleasePipelineRun) AsPipelineRun() *tektonv1beta1.PipelineRun {
return &r.PipelineRun
}

// WithEnterpriseContractConfigMap adds a param providing the verify ec task bundle to the release PipelineRun.
func (r *ReleasePipelineRun) WithEnterpriseContractConfigMap(configMap *corev1.ConfigMap) *ReleasePipelineRun {
enterpriseContractConfigMapBundleField := "verify_ec_task_bundle"
// WithEnterpriseContractConfigMap adds a param providing the verify ec task git resolver information to the release PipelineRun.
func (r *ReleasePipelineRun) WithEnterpriseContractConfigMap(ecConfig *corev1.ConfigMap) *ReleasePipelineRun {
gitResolverFields := []string{"verify_ec_task_git_url", "verify_ec_task_git_revision", "verify_ec_task_git_pathInRepo"}

ecTaskBundle := configMap.Data[enterpriseContractConfigMapBundleField]

r.WithExtraParam(enterpriseContractConfigMapBundleField, tektonv1beta1.ArrayOrString{
Type: tektonv1beta1.ParamTypeString,
StringVal: string(ecTaskBundle),
})
for _, field := range gitResolverFields {
r.WithExtraParam(field, tektonv1beta1.ArrayOrString{
Type: tektonv1beta1.ParamTypeString,
StringVal: ecConfig.Data[string(field)],
})
}

return r
}
Expand Down
25 changes: 22 additions & 3 deletions tekton/pipeline_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ var _ = Describe("PipelineRun", func() {
Kind: "ConfigMap",
},
Data: map[string]string{
"verify_ec_task_bundle": "test-bundle",
"verify_ec_task_git_url": "https://github.com/org/repo.git",
"verify_ec_task_git_revision": "abcdefghijklmnopqrstuvwxyz",
"verify_ec_task_git_pathInRepo": "catalog/tasks/verify-ec/task.yaml",
},
}
enterpriseContractPolicy = &ecapiv1alpha1.EnterpriseContractPolicy{
Expand Down Expand Up @@ -214,9 +216,26 @@ var _ = Describe("PipelineRun", func() {
Expect(releasePipelineRun.Spec.Workspaces).Should(ContainElement(HaveField("PersistentVolumeClaim.ClaimName", Equal(persistentVolumeClaim))))
})

It("can add the EC task bundle parameter to the PipelineRun", func() {
It("can add the EC task git resolver parameters to the PipelineRun", func() {
releasePipelineRun.WithEnterpriseContractConfigMap(enterpriseContractConfigMap)
Expect(releasePipelineRun.Spec.Params).Should(ContainElement(HaveField("Value.StringVal", Equal(string("test-bundle")))))
params := releasePipelineRun.Spec.Params
checked := 0

for i := range params {
mmalina marked this conversation as resolved.
Show resolved Hide resolved
if params[i].Name == "verify_ec_task_git_url" {
Expect(params[i].Value.StringVal).To(Equal("https://github.com/org/repo.git"))
checked++
}
if params[i].Name == "verify_ec_task_git_revision" {
Expect(params[i].Value.StringVal).To(Equal("abcdefghijklmnopqrstuvwxyz"))
checked++
}
if params[i].Name == "verify_ec_task_git_pathInRepo" {
Expect(params[i].Value.StringVal).To(Equal("catalog/tasks/verify-ec/task.yaml"))
checked++
}
}
Expect(checked).To(Equal(3))
})

It("can add an EnterpriseContractPolicy to the PipelineRun", func() {
Expand Down