Skip to content

Commit

Permalink
Add workflow in each repo to apply Konflux manifests on changes
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Sep 30, 2024
1 parent d7fe8cc commit 6cc93a7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
name: Apply Konflux Manifests
name: Reusable Apply Konflux Manifests
on:
schedule:
- cron: "0 6 * * *" # Daily at 06:00.
workflow_dispatch: # Manual workflow trigger
push:
paths:
- ".konflux/**"
branches:
- 'main',
- 'release-v*'
defaults:
run:
shell: bash
Expand All @@ -32,4 +35,4 @@ jobs:
kubectl config use-context konflux-sa@konflux
- name: Apply Manifests
run: make konflux-apply
run: kubectl apply -Rf .konflux/
11 changes: 9 additions & 2 deletions cmd/konflux-apply/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,14 @@ As we use by default Tokens with a validity of 6 months, we need to recreate the
kubectl delete -f https://raw.githubusercontent.com/openshift-knative/hack/main/cmd/konflux-apply/manifests/gh-action-serviceaccount.yaml
kubectl apply -f https://raw.githubusercontent.com/openshift-knative/hack/main/cmd/konflux-apply/manifests/gh-action-serviceaccount.yaml
```
2. 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:
2. Create a new Token for 6 months and [update the `KONFLUX_SA_TOKEN` secret](https://github.com/openshift-knative/settings/secrets/actions) with its value:
```
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:
0. 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)
1. 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
12 changes: 12 additions & 0 deletions pkg/konfluxgen/apply-konflux-manifests-workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
name: Apply Konflux Manifests
on:
workflow_dispatch: # Manual workflow trigger
push:
paths:
- ".konflux/**"
branches:
- 'main',
- 'release-v*'
jobs:
konflux-apply:
uses: openshift-knative/hack/.github/workflows/reusable-apply-konflux-manifests.yaml@main
20 changes: 20 additions & 0 deletions pkg/konfluxgen/konfluxgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import (
cioperatorapi "github.com/openshift/ci-tools/pkg/api"
)

const (
APPLY_KONFLUX_MANIFESTS_WORKFLOW_FILE = "apply-konflux-manifests.yaml"
)

//go:embed application.template.yaml
var ApplicationTemplate embed.FS

Expand All @@ -39,6 +43,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

type Config struct {
OpenShiftReleasePath string
ApplicationName string
Expand All @@ -54,6 +61,7 @@ type Config struct {
ResourcesOutputPathSkipRemove bool
ResourcesOutputPath string
PipelinesOutputPath string
WorkflowsPath string

AdditionalTektonCELExpressionFunc func(cfg cioperatorapi.ReleaseBuildConfiguration, ib cioperatorapi.ProjectDirectoryImageBuildStepConfiguration) string

Expand Down Expand Up @@ -367,9 +375,21 @@ func Generate(cfg Config) error {

buf.Reset()

if err := addApplyKonfluxManifestsWorkflow(cfg); err != nil {
return fmt.Errorf("failed to set 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, APPLY_KONFLUX_MANIFESTS_WORKFLOW_FILE), ApplyKonfluxManifestsWorkflow, 0644)
}

func collectConfigurations(openshiftReleasePath string, includes []*regexp.Regexp, excludes []*regexp.Regexp) ([]TemplateConfig, error) {
configs := make([]TemplateConfig, 0, 8)
err := filepath.WalkDir(openshiftReleasePath, func(path string, info fs.DirEntry, err error) error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/prowgen/prowgen_konflux.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ func GenerateKonflux(ctx context.Context, openshiftRelease Repository, configs [
FBCImages: b.Konflux.FBCImages,
ResourcesOutputPath: fmt.Sprintf("%s/.konflux", r.RepositoryDirectory()),
PipelinesOutputPath: fmt.Sprintf("%s/.tekton", r.RepositoryDirectory()),
WorkflowsPath: fmt.Sprintf("%s/.github/workflows", r.RepositoryDirectory()),
Nudges: nudges,
Tags: []string{versionLabel},
PrefetchDeps: prefetchDeps,
Expand Down Expand Up @@ -295,6 +296,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-index") {
Expand Down

0 comments on commit 6cc93a7

Please sign in to comment.