From 00694283b3caa7f352e0789af133ae8546ef104c Mon Sep 17 00:00:00 2001 From: Pierangelo Di Pilato Date: Thu, 30 Jan 2025 12:21:16 +0100 Subject: [PATCH] Push global resources only to hack repo (#541) Push applications and tests only to hack for all repos. Signed-off-by: Pierangelo Di Pilato --- pkg/konfluxgen/konfluxgen.go | 5 +++-- pkg/prowgen/prowgen_konflux.go | 41 ++++++++++++++++++---------------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/pkg/konfluxgen/konfluxgen.go b/pkg/konfluxgen/konfluxgen.go index 8e6acb273..21bafc62a 100644 --- a/pkg/konfluxgen/konfluxgen.go +++ b/pkg/konfluxgen/konfluxgen.go @@ -95,6 +95,7 @@ type Config struct { ResourcesOutputPathSkipRemove bool ResourcesOutputPath string + GlobalResourcesOutputPath string PipelinesOutputPathSkipRemove bool PipelinesOutputPath string @@ -357,7 +358,7 @@ func Generate(cfg Config) error { for componentKey, config := range components { buf := &bytes.Buffer{} - appPath := filepath.Join(cfg.ResourcesOutputPath, ApplicationsDirectoryName, appKey, fmt.Sprintf("%s.yaml", appKey)) + appPath := filepath.Join(cfg.GlobalResourcesOutputPath, ApplicationsDirectoryName, appKey, fmt.Sprintf("%s.yaml", appKey)) if err := os.MkdirAll(filepath.Dir(appPath), 0777); err != nil { return fmt.Errorf("failed to create directory for %q: %w", appPath, err) } @@ -465,7 +466,7 @@ func Generate(cfg Config) error { config.ECPolicyConfiguration = "rhtap-releng-tenant/registry-standard-stage" } - ecTestDir := filepath.Join(cfg.ResourcesOutputPath, ApplicationsDirectoryName, appKey, "tests") + ecTestDir := filepath.Join(cfg.GlobalResourcesOutputPath, ApplicationsDirectoryName, appKey, "tests") if err := os.MkdirAll(ecTestDir, 0777); err != nil { return fmt.Errorf("failed to create directory for %q: %w", appKey, err) } diff --git a/pkg/prowgen/prowgen_konflux.go b/pkg/prowgen/prowgen_konflux.go index a7c161015..e45d21c98 100644 --- a/pkg/prowgen/prowgen_konflux.go +++ b/pkg/prowgen/prowgen_konflux.go @@ -29,6 +29,8 @@ const ( NudgeFilesAnnotationName = "build.appstudio.openshift.io/build-nudge-files" ) +var hackRepo = Repository{Org: "openshift-knative", Repo: "hack"} + func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs []*Config) error { operatorVersions, err := ServerlessOperatorKonfluxVersions(ctx) @@ -36,6 +38,13 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [ return fmt.Errorf("failed to get konflux versions for serverless-operator: %w", err) } + if err := GitMirror(ctx, hackRepo); err != nil { + return err + } + if err := GitCheckout(ctx, hackRepo, "main"); err != nil { + return err + } + for _, config := range configs { for _, r := range config.Repositories { @@ -176,12 +185,13 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [ Includes: []string{ fmt.Sprintf("ci-operator/config/%s/.*%s.*.yaml", r.RepositoryDirectory(), branchName), }, - Excludes: b.Konflux.Excludes, - ExcludesImages: b.Konflux.ExcludesImages, - JavaImages: b.Konflux.JavaImages, - ResourcesOutputPath: fmt.Sprintf("%s/.konflux", r.RepositoryDirectory()), - PipelinesOutputPath: fmt.Sprintf("%s/.tekton", r.RepositoryDirectory()), - Nudges: nudges, + Excludes: b.Konflux.Excludes, + ExcludesImages: b.Konflux.ExcludesImages, + JavaImages: b.Konflux.JavaImages, + ResourcesOutputPath: fmt.Sprintf("%s/.konflux", r.RepositoryDirectory()), + GlobalResourcesOutputPath: fmt.Sprintf("%s/.konflux", hackRepo.RepositoryDirectory()), + PipelinesOutputPath: fmt.Sprintf("%s/.tekton", r.RepositoryDirectory()), + Nudges: nudges, // Preserve the version tag as first tag in any instance since SO, when bumping the patch version // will change it before merging the PR. // See `openshift-knative/serverless-operator/hack/generate/update-pipelines.sh` for more details. @@ -217,6 +227,11 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [ } } + commitMsg := fmt.Sprintf("Sync Konflux configurations for serverless operator") + if err := PushBranch(ctx, hackRepo, nil, fmt.Sprintf("%s%s", KonfluxBranchPrefix, "main"), commitMsg); err != nil { + return err + } + return nil } @@ -290,14 +305,6 @@ func GenerateKonfluxServerlessOperator(ctx context.Context, openshiftRelease Rep if err != nil { return fmt.Errorf("failed to get Konflux versions for serverless operator: %w", err) } - - hackRepo := Repository{Org: "openshift-knative", Repo: "hack"} - if err := GitMirror(ctx, hackRepo); err != nil { - return err - } - if err := GitCheckout(ctx, hackRepo, "main"); err != nil { - return err - } log.Println("Recreating konflux configurations for serverless operator") resourceOutputPath := fmt.Sprintf("%s/.konflux", hackRepo.RepositoryDirectory()) @@ -387,6 +394,7 @@ func GenerateKonfluxServerlessOperator(ctx context.Context, openshiftRelease Rep // main with the same name but different "revision" (branch). ResourcesOutputPathSkipRemove: true, ResourcesOutputPath: resourceOutputPath, + GlobalResourcesOutputPath: resourceOutputPath, PipelinesOutputPath: fmt.Sprintf("%s/.tekton", r.RepositoryDirectory()), Nudges: b.Konflux.Nudges, NudgesFunc: func(cfg cioperatorapi.ReleaseBuildConfiguration, ib cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) []string { @@ -448,11 +456,6 @@ func GenerateKonfluxServerlessOperator(ctx context.Context, openshiftRelease Rep log.Printf("::endgroup::\n\n") } - commitMsg := fmt.Sprintf("Sync Konflux configurations for serverless operator") - if err := PushBranch(ctx, hackRepo, nil, fmt.Sprintf("%s%s", KonfluxBranchPrefix, "main"), commitMsg); err != nil { - return err - } - if err := writeDependabotConfig(ctx, dependabotConfig, r); err != nil { return err }