Skip to content

Commit

Permalink
chore: Remove BuildPipelineSelector (konflux-ci#1212)
Browse files Browse the repository at this point in the history
* Remove BuildPipelineSelector

* Update go.mod

* fix bundle name

* Remove unused bundles
  • Loading branch information
mmorhun authored Jun 7, 2024
1 parent c38d855 commit e979a06
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 183 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ require (
golang.org/x/crypto v0.22.0
golang.org/x/oauth2 v0.20.0
golang.org/x/tools v0.20.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/api v0.29.4
k8s.io/apimachinery v0.29.4
k8s.io/cli-runtime v0.28.5
Expand Down Expand Up @@ -332,7 +333,6 @@ require (
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/apiextensions-apiserver v0.29.2 // indirect
k8s.io/apiserver v0.29.2 // indirect
Expand Down
12 changes: 6 additions & 6 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,6 @@ func setRequiredEnvVars() error {

klog.Infof("going to override default Tekton bundle s2i-java task for the purpose of testing jvm-build-service PR")
var err error
var defaultBundleRef string
var tektonObj runtime.Object

tag := fmt.Sprintf("%d-%s", time.Now().Unix(), util.GenerateRandomString(4))
Expand All @@ -404,9 +403,10 @@ func setRequiredEnvVars() error {
if err = utils.CreateDockerConfigFile(os.Getenv("QUAY_TOKEN")); err != nil {
return fmt.Errorf("failed to create docker config file: %+v", err)
}
if defaultBundleRef, err = tekton.GetDefaultPipelineBundleRef(constants.BuildPipelineSelectorYamlURL, "Java"); err != nil {
return fmt.Errorf("failed to get the pipeline bundle ref: %+v", err)
}
// Since we do not include java builder in the default pipelines list, it's not possible
// to use GetDefaultPipelineBundleRef and get it from build pipeline config Config Map.
// Fallback to the latest dev version for now.
defaultBundleRef := "quay.io/konflux-ci/tekton-catalog/pipeline-java-builder:devel"
if tektonObj, err = tekton.ExtractTektonObjectFromBundle(defaultBundleRef, "pipeline", "java-builder"); err != nil {
return fmt.Errorf("failed to extract the Tekton Pipeline from bundle: %+v", err)
}
Expand Down Expand Up @@ -571,7 +571,7 @@ func SetupMultiPlatformTests() error {
if err = utils.CreateDockerConfigFile(os.Getenv("QUAY_TOKEN")); err != nil {
return fmt.Errorf("failed to create docker config file: %+v", err)
}
if defaultBundleRef, err = tekton.GetDefaultPipelineBundleRef(constants.BuildPipelineSelectorYamlURL, "Docker build"); err != nil {
if defaultBundleRef, err = tekton.GetDefaultPipelineBundleRef(constants.BuildPipelineConfigConfigMapYamlURL, "docker-build"); err != nil {
return fmt.Errorf("failed to get the pipeline bundle ref: %+v", err)
}
if tektonObj, err = tekton.ExtractTektonObjectFromBundle(defaultBundleRef, "pipeline", "docker-build"); err != nil {
Expand Down Expand Up @@ -643,7 +643,7 @@ func SetupSourceBuild() {
// klog.Errorf("failed to create docker config file: %+v", err)
// return
// }
if defaultBundleRef, err = tekton.GetDefaultPipelineBundleRef(constants.BuildPipelineSelectorYamlURL, "Docker build"); err != nil {
if defaultBundleRef, err = tekton.GetDefaultPipelineBundleRef(constants.BuildPipelineConfigConfigMapYamlURL, "docker-build"); err != nil {
klog.Errorf("failed to get the pipeline bundle ref: %+v", err)
return
}
Expand Down
33 changes: 0 additions & 33 deletions pkg/clients/has/components.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,8 @@ func (h *HasController) WaitForComponentPipelineToBeFinished(component *appservi

// Universal method to create a component in the kubernetes clusters.
func (h *HasController) CreateComponent(componentSpec appservice.ComponentSpec, namespace string, outputContainerImage string, secret string, applicationName string, skipInitialChecks bool, annotations map[string]string) (*appservice.Component, error) {

componentObject := &appservice.Component{
ObjectMeta: metav1.ObjectMeta{
// adding default label because of the BuildPipelineSelector in build test
Labels: constants.ComponentDefaultLabel,
Name: componentSpec.ComponentName,
Namespace: namespace,
Annotations: map[string]string{
Expand Down Expand Up @@ -533,36 +530,6 @@ func (h *HasController) StoreAllComponents(namespace string) error {
return nil
}

// specific for tests/remote-secret/image-repository-cr-image-pull-remote-secret.go
func (h *HasController) CreateComponentWithoutGenerateAnnotation(componentSpec appservice.ComponentSpec, namespace string, secret string, applicationName string, skipInitialChecks bool) (*appservice.Component, error) {
componentObject := &appservice.Component{
ObjectMeta: metav1.ObjectMeta{
// adding default label because of the BuildPipelineSelector in build test
Labels: constants.ComponentDefaultLabel,
Name: componentSpec.ComponentName,
Namespace: namespace,
Annotations: map[string]string{
"skip-initial-checks": strconv.FormatBool(skipInitialChecks),
},
},
Spec: componentSpec,
}
componentObject.Spec.Secret = secret
componentObject.Spec.Application = applicationName

componentObject.Annotations = utils.MergeMaps(componentObject.Annotations, constants.DefaultDockerBuildPipelineBundle)

if componentObject.Spec.TargetPort == 0 {
componentObject.Spec.TargetPort = 8081
}

if err := h.KubeRest().Create(context.Background(), componentObject); err != nil {
return nil, err
}

return componentObject, nil
}

// UpdateComponent updates a component
func (h *HasController) UpdateComponent(component *appservice.Component) error {
err := h.KubeRest().Update(context.Background(), component, &rclient.UpdateOptions{})
Expand Down
41 changes: 22 additions & 19 deletions pkg/clients/tekton/bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,46 @@ package tekton

import (
"context"
"fmt"

"gopkg.in/yaml.v2"
corev1 "k8s.io/api/core/v1"

"github.com/konflux-ci/e2e-tests/pkg/utils/tekton"
buildservice "github.com/redhat-appstudio/build-service/api/v1alpha1"
"k8s.io/apimachinery/pkg/types"

"github.com/konflux-ci/e2e-tests/pkg/utils/tekton"
)

type Bundles struct {
FBCBuilderBundle string
DockerBuildBundle string
JavaBuilderBundle string
NodeJSBuilderBundle string
DockerBuildBundle string
FBCBuilderBundle string
}

// NewBundles returns new Bundles.
func (t *TektonController) NewBundles() (*Bundles, error) {
namespacedName := types.NamespacedName{
Name: "build-pipeline-selector",
Name: "build-pipeline-config",
Namespace: "build-service",
}
bundles := &Bundles{}
pipelineSelector := &buildservice.BuildPipelineSelector{}
err := t.KubeRest().Get(context.Background(), namespacedName, pipelineSelector)
configMap := &corev1.ConfigMap{}
err := t.KubeRest().Get(context.Background(), namespacedName, configMap)
if err != nil {
return nil, err
}
for i := range pipelineSelector.Spec.Selectors {
selector := &pipelineSelector.Spec.Selectors[i]
bundleName, bundleRef := tekton.GetPipelineNameAndBundleRef(&selector.PipelineRef)
switch bundleName {

bpc := &tekton.BuildPipelineConfig{}
if err = yaml.Unmarshal([]byte(configMap.Data["config.yaml"]), bpc); err != nil {
return nil, fmt.Errorf("failed to unmarshal build pipeline config: %v", err)
}

for i := range bpc.Pipelines {
pipeline := bpc.Pipelines[i]
switch pipeline.Name {
case "docker-build":
bundles.DockerBuildBundle = bundleRef
bundles.DockerBuildBundle = pipeline.Bundle
case "fbc-builder":
bundles.FBCBuilderBundle = bundleRef
case "java-builder":
bundles.JavaBuilderBundle = bundleRef
case "nodejs-builder":
bundles.NodeJSBuilderBundle = bundleRef
bundles.FBCBuilderBundle = pipeline.Bundle
}
}
return bundles, nil
Expand Down
7 changes: 3 additions & 4 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ const (
// Managed workspace for release pipelines tests
RELEASE_MANAGED_WORKSPACE_ENV = "RELEASE_MANAGED_WORKSPACE"

// Bundle ref for overriding the default Java build bundle specified in BuildPipelineSelectorYamlURL
// Bundle ref for overriding the default Java build bundle specified in BuildPipelineConfigConfigMapYamlURL
CUSTOM_JAVA_PIPELINE_BUILD_BUNDLE_ENV string = "CUSTOM_JAVA_PIPELINE_BUILD_BUNDLE"

// Bundle ref for a buildah-remote build
CUSTOM_BUILDAH_REMOTE_PIPELINE_BUILD_BUNDLE_ENV string = "CUSTOM_BUILDAH_REMOTE_PIPELINE_BUILD_BUNDLE"

//Bundle ref for custom source-build, format example: quay.io/redhat-appstudio-qe/test-images:pipeline-bundle-1715584704-fftb
// Bundle ref for custom source-build, format example: quay.io/redhat-appstudio-qe/test-images:pipeline-bundle-1715584704-fftb
CUSTOM_SOURCE_BUILD_PIPELINE_BUNDLE_ENV string = "CUSTOM_SOURCE_BUILD_PIPELINE_BUNDLE"

// QE slack bot token used for delivering messages about critical failures during CI runs
Expand Down Expand Up @@ -140,7 +140,7 @@ const (
JVMBuildImageSecretName = "jvm-build-image-secrets"
JBSConfigName = "jvm-build-config"

BuildPipelineSelectorYamlURL = "https://raw.githubusercontent.com/redhat-appstudio/infra-deployments/main/components/build-service/base/build-pipeline-selectors/build-pipeline-selector.yaml"
BuildPipelineConfigConfigMapYamlURL = "https://raw.githubusercontent.com/redhat-appstudio/infra-deployments/main/components/build-service/base/build-pipeline-config/build-pipeline-config.yaml"

DefaultImagePushRepo = "quay.io/" + DefaultQuayOrg + "/test-images"
DefaultReleasedImagePushRepo = "quay.io/" + DefaultQuayOrg + "/test-release-images"
Expand Down Expand Up @@ -215,7 +215,6 @@ const (
)

var (
ComponentDefaultLabel = map[string]string{"e2e-test": "true"}
ComponentPaCRequestAnnotation = map[string]string{"build.appstudio.openshift.io/request": "configure-pac"}
ComponentTriggerSimpleBuildAnnotation = map[string]string{"build.appstudio.openshift.io/request": "trigger-simple-build"}
ImageControllerAnnotationRequestPublicRepo = map[string]string{"image.redhat.com/generate": `{"visibility": "public"}`}
Expand Down
44 changes: 30 additions & 14 deletions pkg/utils/tekton/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,25 @@ import (
"github.com/google/go-containerregistry/pkg/authn"
"github.com/google/go-containerregistry/pkg/name"
remoteimg "github.com/google/go-containerregistry/pkg/v1/remote"
buildservice "github.com/redhat-appstudio/build-service/api/v1alpha1"
"github.com/tektoncd/cli/pkg/bundle"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
"github.com/tektoncd/pipeline/pkg/remote/oci"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/klog"
"sigs.k8s.io/yaml"
)

type BuildPipelineConfig struct {
DefaultPipelineName string `json:"default-pipeline-name"`
Pipelines []PipelineRef `json:"pipelines"`
}

type PipelineRef struct {
Name string `json:"name"`
Bundle string `json:"bundle"`
}

// ExtractTektonObjectFromBundle extracts specified Tekton object from specified bundle reference
func ExtractTektonObjectFromBundle(bundleRef, kind, name string) (runtime.Object, error) {
var obj runtime.Object
Expand Down Expand Up @@ -53,35 +63,41 @@ func GetBundleRef(pipelineRef *pipeline.PipelineRef) string {
return bundleRef
}

// GetDefaultPipelineBundleRef gets the specific Tekton pipeline bundle reference from a Build pipeline selector
// (in a YAML format) from a URL specified in the parameter
func GetDefaultPipelineBundleRef(buildPipelineSelectorYamlURL, selectorName string) (string, error) {
request, err := http.NewRequest("GET", buildPipelineSelectorYamlURL, nil)
// GetDefaultPipelineBundleRef gets the specific Tekton pipeline bundle reference from a Build pipeline config
// ConfigMap (in a YAML format) from a URL specified in the parameter
func GetDefaultPipelineBundleRef(buildPipelineConfigConfigMapYamlURL, name string) (string, error) {
request, err := http.NewRequest("GET", buildPipelineConfigConfigMapYamlURL, nil)
if err != nil {
return "", fmt.Errorf("error creating GET request: %s", err)
}

client := &http.Client{}
res, err := client.Do(request)
if err != nil {
return "", fmt.Errorf("failed to get a build pipeline selector from url %s: %v", buildPipelineSelectorYamlURL, err)
return "", fmt.Errorf("failed to get a build pipeline selector from url %s: %v", buildPipelineConfigConfigMapYamlURL, err)
}

defer res.Body.Close()
body, err := io.ReadAll(res.Body)
if err != nil {
return "", fmt.Errorf("failed to read the body response of a build pipeline selector: %v", err)
}
ps := &buildservice.BuildPipelineSelector{}
if err = yaml.Unmarshal(body, ps); err != nil {
return "", fmt.Errorf("failed to unmarshal build pipeline selector: %v", err)

configMap := &corev1.ConfigMap{}
if err = yaml.Unmarshal(body, configMap); err != nil {
return "", fmt.Errorf("failed to unmarshal build pipeline config config map: %v", err)
}
bpc := &BuildPipelineConfig{}
if err = yaml.Unmarshal([]byte(configMap.Data["config.yaml"]), bpc); err != nil {
return "", fmt.Errorf("failed to unmarshal build pipeline config: %v", err)
}
for i := range ps.Spec.Selectors {
s := &ps.Spec.Selectors[i]
if s.Name == selectorName {
return GetBundleRef(&s.PipelineRef), nil

for i := range bpc.Pipelines {
pipeline := bpc.Pipelines[i]
if pipeline.Name == name {
return pipeline.Bundle, nil
}
}

return "", fmt.Errorf("could not find %s pipeline bundle in build pipeline selector fetched from %s", selectorName, buildPipelineSelectorYamlURL)
return "", fmt.Errorf("could not find %s pipeline bundle in build pipeline config fetched from %s", name, buildPipelineConfigConfigMapYamlURL)
}
4 changes: 2 additions & 2 deletions pkg/utils/tekton/pipeline_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
func TestPipelineExtraction(t *testing.T) {
var defaultBundleRef string
var err error
if defaultBundleRef, err = GetDefaultPipelineBundleRef(constants.BuildPipelineSelectorYamlURL, "Java"); err != nil {
if defaultBundleRef, err = GetDefaultPipelineBundleRef(constants.BuildPipelineConfigConfigMapYamlURL, "docker-build"); err != nil {
assert.Error(t, err, "failed to parse bundle ref")
panic(err)
}
assert.Contains(t, defaultBundleRef, "pipeline-java-builder", "failed to retrieve bundle ref")
assert.Contains(t, defaultBundleRef, "pipeline-docker-build", "failed to retrieve bundle ref")
}
Loading

0 comments on commit e979a06

Please sign in to comment.