Skip to content

Commit

Permalink
refactor(HACBS-2550): pass git resolver info for verify-ec task
Browse files Browse the repository at this point in the history
The EnterpriseContact ConfigMap now contains the information needed for
the git resolver of the proper task to use. This commit changes the
adapter from passing the task bundle information to passing the task git
resolver information.

Signed-off-by: Johnny Bieren <[email protected]>
  • Loading branch information
johnbieren committed Sep 5, 2023
1 parent 90883af commit f773678
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
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
19 changes: 10 additions & 9 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.
// WithEnterpriseContractConfigMap adds a param providing the verify ec task git resolver information to the release PipelineRun.
func (r *ReleasePipelineRun) WithEnterpriseContractConfigMap(configMap *corev1.ConfigMap) *ReleasePipelineRun {
enterpriseContractConfigMapBundleField := "verify_ec_task_bundle"
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: configMap.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 {
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

0 comments on commit f773678

Please sign in to comment.