Skip to content

Commit

Permalink
feat(KONFLUX-2547): Make it possible to configure BuildPipelineSelector
Browse files Browse the repository at this point in the history
  • Loading branch information
jhutar committed Apr 5, 2024
1 parent aee2181 commit 4988249
Showing 1 changed file with 79 additions and 0 deletions.
79 changes: 79 additions & 0 deletions cmd/loadTests.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ import (
metricsConstants "github.com/redhat-appstudio-qe/perf-monitoring/api/pkg/constants"
"github.com/redhat-appstudio-qe/perf-monitoring/api/pkg/metrics"
appstudioApi "github.com/redhat-appstudio/application-api/api/v1alpha1"
buildservice "github.com/redhat-appstudio/build-service/api/v1alpha1"
"github.com/redhat-appstudio/e2e-tests/pkg/constants"
"github.com/redhat-appstudio/e2e-tests/pkg/framework"
"github.com/redhat-appstudio/e2e-tests/pkg/utils"
loadtestUtils "github.com/redhat-appstudio/e2e-tests/pkg/utils/loadtests"
"github.com/redhat-appstudio/e2e-tests/pkg/utils/tekton"
integrationv1beta1 "github.com/redhat-appstudio/integration-service/api/v1beta1"
"github.com/spf13/cobra"
pipeline "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
Expand All @@ -31,6 +33,7 @@ import (
k8swait "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/klog/v2"
"knative.dev/pkg/apis"
rclient "sigs.k8s.io/controller-runtime/pkg/client"
)

var (
Expand All @@ -55,6 +58,7 @@ var (
enableProgressBars bool
pushGatewayURI string = ""
jobName string = ""
buildPipelineSelectorBundle string = ""
)

var (
Expand Down Expand Up @@ -297,6 +301,7 @@ func init() {
rootCmd.Flags().BoolVar(&enableProgressBars, "enable-progress-bars", false, "if you want to enable progress bars")
rootCmd.Flags().StringVar(&pushGatewayURI, "pushgateway-url", pushGatewayURI, "PushGateway url (needs to be set if metrics are enabled)")
rootCmd.Flags().StringVar(&jobName, "job-name", jobName, "Job Name to track Metrics (needs to be set if metrics are enabled)")
rootCmd.Flags().StringVar(&buildPipelineSelectorBundle, "build-pipeline-selector-bundle", buildPipelineSelectorBundle, "BuildPipelineSelector bundle to use when testing with build-definition PR")
}

func logError(errCode int, message string) {
Expand Down Expand Up @@ -794,6 +799,11 @@ func StageCleanup(users []loadtestUtils.User) {
if err != nil {
klog.Errorf("while deleting component detection queries for user: %s, got error: %v\n", user.Username, err)
}

err = deleteAllBuildPipelineSelectors(framework, time.Minute)
if err != nil {
klog.Errorf("while deleting build pipeline selectors for user: %s, got error: %v\n", user.Username, err)
}
}
}

Expand Down Expand Up @@ -850,11 +860,80 @@ func componentForUser(username string) string {
return ""
}

func listAllBuildPipelineSelectors(f *framework.Framework) (*buildservice.BuildPipelineSelectorList, error) {
list := &buildservice.BuildPipelineSelectorList{}
err := f.AsKubeDeveloper.HasController.KubeRest().List(context.Background(), list, &rclient.ListOptions{Namespace: f.UserNamespace})
klog.V(5).Infof("listAllBuildPipelineSelectors namespace: %s, len: %d, err: %v", f.UserNamespace, len(list.Items), err)
return list, err
}

func deleteAllBuildPipelineSelectors(f *framework.Framework, timeout time.Duration) error {
klog.V(5).Infof("deleteAllBuildPipelineSelectors start namespace: %s", f.UserNamespace)
defer klog.V(5).Infof("deleteAllBuildPipelineSelectors end")

list, err := listAllBuildPipelineSelectors(f)
if err != nil {
return fmt.Errorf("error listing build pipeline selectors from %s: %v", f.UserNamespace, err)
}

for i, bps := range list.Items {
err := f.AsKubeDeveloper.HasController.KubeRest().Delete(context.Background(), &bps)

Check failure

Code scanning / gosec

Implicit memory aliasing in for loop. Error

Implicit memory aliasing in for loop.
if err != nil {
return fmt.Errorf("error deleting build pipeline selector %d from %s: %v", i, f.UserNamespace, err)
}
}

return utils.WaitUntil(func() (done bool, err error) {
list, err := listAllBuildPipelineSelectors(f)
if err != nil {
return false, nil
}
return len(list.Items) == 0, nil
}, timeout)
}

func createBuildPipelineSelector(f *framework.Framework, bundle *string) error {
klog.V(5).Infof("createBuildPipelineSelector start bundle: %s, namespace: %s", *bundle, f.UserNamespace)
defer klog.V(5).Infof("createBuildPipelineSelector end")

var err error

err = deleteAllBuildPipelineSelectors(f, time.Minute)
if err != nil {
klog.Errorf("error deleting build pipeline selectors from %s: %v\n", f.UserNamespace, err)
}

bps := &buildservice.BuildPipelineSelector{
ObjectMeta: metav1.ObjectMeta{
Name: "build-pipeline-selector",
Namespace: f.UserNamespace,
},
Spec: buildservice.BuildPipelineSelectorSpec{Selectors: []buildservice.PipelineSelector{
{
Name: "all-pipelines",
PipelineRef: *tekton.NewBundleResolverPipelineRef("docker-build", *bundle),
},
}},
}
err = f.AsKubeAdmin.CommonController.KubeRest().Create(context.TODO(), bps)
if err != nil {
return fmt.Errorf("error creating build pipeline selector in %s with bundle %s: %v", f.UserNamespace, *bundle, err)
}

return nil
}

func frameworkForUser(username string) *framework.Framework {
val, ok := frameworkMap.Load(username)
if ok {
framework, ok2 := val.(*framework.Framework)
if ok2 {
if buildPipelineSelectorBundle != "" {
err := createBuildPipelineSelector(framework, &buildPipelineSelectorBundle)
if err != nil {
klog.Errorf("Error creating build pipeline selector: %v", err)
}
}
return framework
} else {
klog.Errorf("Invalid type of map value: %+v", val)
Expand Down

0 comments on commit 4988249

Please sign in to comment.