Skip to content

Commit

Permalink
Add pipeline config to component RPA (#346)
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr authored Oct 15, 2024
1 parent e72446c commit f88a2c5
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 13 deletions.
44 changes: 32 additions & 12 deletions pkg/konfluxgen/konfluxgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (
"strings"
"text/template"

"github.com/operator-framework/api/pkg/lib/version"

"github.com/openshift-knative/hack/pkg/soversion"
"github.com/openshift-knative/hack/pkg/util"

Expand Down Expand Up @@ -760,6 +758,17 @@ func GenerateFBCReleasePlanAdmission(applications []string, resourceOutputPath s
return nil
}

type rpaComponentData struct {
Name string
ApplicationName string
Components []ComponentImageRepoRef

SOVersion string
PyxisSecret string
PyxisServer string
PipelineSA string
}

func GenerateComponentReleasePlanAdmission(csvPath string, resourceOutputPath string, appName string) error {
csv, err := loadClusterServiceVerion(csvPath)
if err != nil {
Expand All @@ -778,8 +787,17 @@ func GenerateComponentReleasePlanAdmission(csvPath string, resourceOutputPath st
}

rpaName := Truncate(Sanitize(fmt.Sprintf("%s-%s-prod", appName, soVersion)))
rpaData := rpaComponentData{
Name: rpaName,
ApplicationName: appName,
Components: components,
SOVersion: soVersion.String(),
PyxisSecret: "pyxis-prod-secret",
PyxisServer: "production",
PipelineSA: "release-registry-prod",
}
outputFilePath := filepath.Join(outputDir, fmt.Sprintf("%s.yaml", rpaName))
if err := executeComponentReleasePlanAdmissionTemplate(components, outputFilePath, rpaName, appName, soVersion); err != nil {
if err := executeComponentReleasePlanAdmissionTemplate(rpaData, outputFilePath); err != nil {
return fmt.Errorf("failed to execute release plan admission template: %w", err)
}

Expand All @@ -793,8 +811,17 @@ func GenerateComponentReleasePlanAdmission(csvPath string, resourceOutputPath st
}

rpaName = Truncate(Sanitize(fmt.Sprintf("%s-%s-stage", appName, soVersion)))
rpaData = rpaComponentData{
Name: rpaName,
ApplicationName: appName,
Components: componentWithStageRepoRef,
SOVersion: soVersion.String(),
PyxisSecret: "pyxis-staging-secret",
PyxisServer: "stage",
PipelineSA: "release-registry-staging",
}
outputFilePath = filepath.Join(outputDir, fmt.Sprintf("%s.yaml", rpaName))
if err := executeComponentReleasePlanAdmissionTemplate(componentWithStageRepoRef, outputFilePath, rpaName, appName, soVersion); err != nil {
if err := executeComponentReleasePlanAdmissionTemplate(rpaData, outputFilePath); err != nil {
return fmt.Errorf("failed to execute release plan admission template: %w", err)
}

Expand Down Expand Up @@ -824,7 +851,7 @@ func executeFBCReleasePlanAdmissionTemplate(data rpaFBCData, outputFilePath stri
return nil
}

func executeComponentReleasePlanAdmissionTemplate(components []ComponentImageRepoRef, outputFilePath string, rpaName string, appName string, soVersion version.OperatorVersion) error {
func executeComponentReleasePlanAdmissionTemplate(data rpaComponentData, outputFilePath string) error {
funcs := template.FuncMap{
"sanitize": Sanitize,
"truncate": Truncate,
Expand All @@ -836,13 +863,6 @@ func executeComponentReleasePlanAdmissionTemplate(components []ComponentImageRep
return fmt.Errorf("failed to parse component RPA template: %w", err)
}

data := map[string]interface{}{
"Name": rpaName,
"ApplicationName": appName,
"Components": components,
"Version": soVersion.String(),
}

buf := &bytes.Buffer{}
if err := rpaTemplate.Execute(buf, data); err != nil {
return fmt.Errorf("failed to execute template for ReleasePlanAdmission: %w", err)
Expand Down
20 changes: 19 additions & 1 deletion pkg/konfluxgen/releaseplanadmission-component.template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,26 @@ spec:
repository: {{{ $component.ImageRepository }}}
pushSourceContainer: true
{{{- end }}}
pyxis:
secret: {{{ .PyxisSecret }}}
server: {{{ .PyxisServer }}}
sign:
configMapName: "hacbs-signing-pipeline-config-redhatrelease2"
defaults:
tags:
- "{{ git_sha }}"
- "{{ git_short_sha }}"
- "{{{ .Version }}}"
- "{{{ .SOVersion }}}"
pipeline:
pipelineRef:
resolver: git
params:
- name: url
value: "https://github.com/konflux-ci/release-service-catalog.git"
- name: revision
value: production
- name: pathInRepo
value: "pipelines/rh-advisories/rh-advisories.yaml"
serviceAccountName: {{{ .PipelineSA }}}
timeouts:
pipeline: "4h0m0s"

0 comments on commit f88a2c5

Please sign in to comment.