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 18, 2024
1 parent 398e7c6 commit bf0c0e6
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 0 deletions.
80 changes: 80 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,81 @@ 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 _, bps := range list.Items {
toDelete := bps
err = f.AsKubeDeveloper.HasController.KubeRest().Delete(context.Background(), &toDelete)
if err != nil {
return fmt.Errorf("error deleting build pipeline selector %s from %s: %v", bps.Name, 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
4 changes: 4 additions & 0 deletions tests/load-tests/ci-scripts/collect-results.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ find "$output_dir" -type f -name '*.pprof' -exec cp -vf {} "${ARTIFACT_DIR}" \;
pipelineruns_json=$ARTIFACT_DIR/pipelineruns.json
taskruns_json=$ARTIFACT_DIR/taskruns.json
pods_json=$ARTIFACT_DIR/pods.json
buildpipelineselectors_json=$ARTIFACT_DIR/buildpipelineselectors.json

application_timestamps=$ARTIFACT_DIR/applications.appstudio.redhat.com_timestamps
application_timestamps_csv=${application_timestamps}.csv
Expand Down Expand Up @@ -182,6 +183,9 @@ jq -r ".items[] | .spec.nodeName" "$pods_json" | sort | uniq -c | sed -e 's,\s\+
echo "Node;Pods" >"$task_pods_distribution_csv"
jq -r '.items[] | select(.metadata.labels."appstudio.openshift.io/application" != null).spec.nodeName' "$pods_json" | sort | uniq -c | sed -e 's,\s\+\([0-9]\+\)\s\+\(.*\),\2;\1,g' >>"$task_pods_distribution_csv"

## Record BuildPipelineSelectors
oc get BuildPipelineSelectors -A -o json >"$buildpipelineselectors_json"

## Tekton Artifact Performance Analysis
tapa_dir=./tapa.git

Expand Down
1 change: 1 addition & 0 deletions tests/load-tests/run-stage.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
go run loadtest.go \
--component-repo "${COMPONENT_REPO:-https://github.com/devfile-samples/devfile-sample-code-with-quarkus}" \
--build-pipeline-selector-bundle "${BUILD_PIPELINE_SELECTOR_BUNDLE:-}" \
--username "$USER_PREFIX" \
--users "${USERS_PER_THREAD:-2}" \
--test-scenario-git-url "${TEST_SCENARIO_GIT_URL:-https://github.com/redhat-appstudio/integration-examples.git}" \
Expand Down
1 change: 1 addition & 0 deletions tests/load-tests/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ else
## To enable progress bar , add `--enable-progress-bars` in [OPTIONS]
go run loadtest.go \
--component-repo "${COMPONENT_REPO:-https://github.com/devfile-samples/devfile-sample-code-with-quarkus}" \
--build-pipeline-selector-bundle "${BUILD_PIPELINE_SELECTOR_BUNDLE:-}" \
--username "$USER_PREFIX" \
--users "${USERS_PER_THREAD:-50}" \
--test-scenario-git-url "${TEST_SCENARIO_GIT_URL:-https://github.com/redhat-appstudio/integration-examples.git}" \
Expand Down

0 comments on commit bf0c0e6

Please sign in to comment.