Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow in each repo to apply Konflux manifests on changes #305

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/apply-konflux-manifests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ on:
push:
paths:
- ".konflux/**"
branches:
- 'main'
defaults:
run:
shell: bash
Expand Down
9 changes: 8 additions & 1 deletion cmd/konflux-apply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ As we use by default Tokens with a validity of 6 months, we need to recreate the
3. Create a new Token for 6 months and [update the `KONFLUX_SA_TOKEN` secret](https://github.com/openshift-knative/hack/settings/secrets/actions) with its value:
```shell
kubectl create token gh-action --duration $((6*30*24))h
```
```

## Manually apply all Konflux Manifests

In case you want to manually apply all Konflux manifests across all repos, do the following:

1. Make sure, you're logged in to Konflux via the CLI and have access to the `ocp-serverless` workspace. Check for example the [Konflux kickstart recording](https://drive.google.com/drive/u/0/folders/0AB3Zk0vHI6ulUk9PVA) or the [Konflux docs](https://gitlab.cee.redhat.com/konflux/docs/users/-/blob/main/topics/getting-started/getting-access.md#accessing-konflux-via-cli)
2. Run `make konflux-apply`. This will clone all repos and checkout the branches which have Konflux enabled and apply their Konflux manifests.
2 changes: 2 additions & 0 deletions cmd/konflux-gen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
fbcBuilderImagesFlag = "fbc-images"
outputFlag = "output"
pipelineOutputFlag = "pipeline-output"
workflowsPathFlag = "workflows-path"
)

func main() {
Expand All @@ -34,6 +35,7 @@ func run() error {
pflag.StringVar(&cfg.ApplicationName, applicationNameFlag, "", "Konflux application name")
pflag.StringVar(&cfg.ResourcesOutputPath, outputFlag, "", "output path")
pflag.StringVar(&cfg.PipelinesOutputPath, pipelineOutputFlag, ".tekton", "output path for pipelines")
pflag.StringVar(&cfg.WorkflowsPath, workflowsPathFlag, ".github/workflows", "output path for Github workflows")
pflag.StringArrayVar(&cfg.Includes, includesFlag, nil, "Regex to select CI config files to include")
pflag.StringArrayVar(&cfg.Excludes, excludesFlag, nil, "Regex to select CI config files to exclude")
pflag.StringArrayVar(&cfg.ExcludesImages, excludeImagesFlag, nil, "Regex to select CI config images to exclude")
Expand Down
25 changes: 25 additions & 0 deletions pkg/konfluxgen/apply-konflux-manifests-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Apply Konflux Manifests
on:
workflow_dispatch: # Manual workflow trigger
push:
paths:
- ".konflux/**"
branches:
- 'main'
- 'release-v*'
jobs:
trigger-konflux-apply:
name: Trigger Konflux Apply
runs-on: ubuntu-latest
steps:
- name: Trigger Konflux Apply
uses: actions/github-script@v7
with:
github-token: ${{ secrets.SERVERLESS_QE_ROBOT }}
script: |
github.rest.actions.createWorkflowDispatch({
owner: context.repo.owner,
repo: 'hack',
workflow_id: 'apply-konflux-manifests.yaml',
ref: 'main',
})
22 changes: 22 additions & 0 deletions pkg/konfluxgen/konfluxgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ const (
registryRepoName = "openshift-serverless-1"
prodRegistry = prodRegistryHost + "/" + registryRepoName
stageRegistry = stageRegistryHost + "/" + registryRepoName

triggerKonfluxApplyManifestsWorkflowFile = "apply-konflux-manifests.yaml"
)

//go:embed application.template.yaml
Expand All @@ -64,6 +66,9 @@ var PipelineFBCBuildTemplate embed.FS
//go:embed integration-test-scenario.template.yaml
var EnterpriseContractTestScenarioTemplate embed.FS

//go:embed apply-konflux-manifests-workflow.yaml
var ApplyKonfluxManifestsWorkflow []byte

//go:embed releaseplanadmission-component.template.yaml
var ComponentReleasePlanAdmissionsTemplate embed.FS

Expand Down Expand Up @@ -91,6 +96,7 @@ type Config struct {

PipelinesOutputPathSkipRemove bool
PipelinesOutputPath string
WorkflowsPath string

AdditionalTektonCELExpressionFunc func(cfg cioperatorapi.ReleaseBuildConfiguration, ib cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) string
NudgesFunc func(cfg cioperatorapi.ReleaseBuildConfiguration, ib cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) []string
Expand All @@ -108,6 +114,8 @@ type Config struct {

ComponentReleasePlanConfig *ComponentReleasePlanConfig
AdditionalComponentConfigs []TemplateConfig

SkipApplyKonfluxWorkflowCreation bool
}

type PrefetchDeps struct {
Expand Down Expand Up @@ -473,9 +481,23 @@ func Generate(cfg Config) error {
}
}

if !cfg.SkipApplyKonfluxWorkflowCreation {
if err := addApplyKonfluxManifestsWorkflow(cfg); err != nil {
return fmt.Errorf("failed to add apply-konflux-manifests workflow: %w", err)
}
}

return nil
}

func addApplyKonfluxManifestsWorkflow(cfg Config) error {
if err := os.MkdirAll(cfg.WorkflowsPath, 0755); err != nil {
return fmt.Errorf("failed to create %s: %w", cfg.WorkflowsPath, err)
}

return os.WriteFile(filepath.Join(cfg.WorkflowsPath, triggerKonfluxApplyManifestsWorkflowFile), ApplyKonfluxManifestsWorkflow, 0644)
}

func collectConfigurations(openshiftReleasePath string, includes []*regexp.Regexp, excludes []*regexp.Regexp, additionalConfigs []TemplateConfig) ([]TemplateConfig, error) {
configs := make([]TemplateConfig, 0, 8)
err := filepath.WalkDir(openshiftReleasePath, func(path string, info fs.DirEntry, err error) error {
Expand Down
8 changes: 8 additions & 0 deletions pkg/prowgen/prowgen_konflux.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
JavaImages: b.Konflux.JavaImages,
ResourcesOutputPath: fmt.Sprintf("%s/.konflux", r.RepositoryDirectory()),
PipelinesOutputPath: fmt.Sprintf("%s/.tekton", r.RepositoryDirectory()),
WorkflowsPath: fmt.Sprintf("%s/.github/workflows", 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.
Expand Down Expand Up @@ -304,6 +305,7 @@ func GenerateKonfluxServerlessOperator(ctx context.Context, openshiftRelease Rep
ResourcesOutputPathSkipRemove: true,
ResourcesOutputPath: resourceOutputPath,
PipelinesOutputPath: fmt.Sprintf("%s/.tekton", r.RepositoryDirectory()),
WorkflowsPath: fmt.Sprintf("%s/.github/workflows", r.RepositoryDirectory()),
Nudges: b.Konflux.Nudges,
NudgesFunc: func(cfg cioperatorapi.ReleaseBuildConfiguration, ib cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) []string {
if strings.Contains(string(ib.To), "serverless-bundle") {
Expand All @@ -320,6 +322,9 @@ func GenerateKonfluxServerlessOperator(ctx context.Context, openshiftRelease Rep
// will change it before merging the PR.
// See `openshift-knative/serverless-operator/hack/generate/update-pipelines.sh` for more details.
Tags: []string{soMetadata.Project.Version},
// We can skip the GH workflow creation to apply the Konflux manifests, as the SO
// manifests are stored in the hack repo and the workflow is anyhow present in there
SkipApplyKonfluxWorkflowCreation: true,
}
if len(cfg.ExcludesImages) == 0 {
cfg.ExcludesImages = []string{
Expand Down Expand Up @@ -413,6 +418,9 @@ func generateFBCApplications(soMetadata *project.Metadata, openshiftRelease Repo
// will change it before merging the PR.
// See `openshift-knative/serverless-operator/hack/generate/update-pipelines.sh` for more details.
Tags: []string{soMetadata.Project.Version},
// We can skip the GH workflow creation to apply the Konflux manifests, as the SO
// manifests are stored in the hack repo and the workflow is anyhow present in there
SkipApplyKonfluxWorkflowCreation: true,
}

if err := konfluxgen.Generate(c); err != nil {
Expand Down
Loading