Skip to content

Commit

Permalink
Use embed SO config file
Browse files Browse the repository at this point in the history
  • Loading branch information
creydr committed Oct 22, 2024
1 parent 7799766 commit 08e8593
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 12 deletions.
23 changes: 19 additions & 4 deletions cmd/sorhel/rhel-version.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,33 @@
package main

import (
"flag"
"fmt"
"log"
"strings"

"github.com/coreos/go-semver/semver"
"github.com/spf13/pflag"

"github.com/openshift-knative/hack/pkg/rhel"
)

func main() {
soBranch := flag.String("so-branch", "", "Serverless Operator Branch name")
flag.Parse()
var soVersion string

pflag.StringVar(&soVersion, "so-version", "", "Serverless Operator Version (e.g. 1.35)")
pflag.Parse()

dotParts := strings.SplitN(soVersion, ".", 3)
if len(dotParts) == 2 {
soVersion = soVersion + ".0"
}

soSemVer, err := semver.NewVersion(soVersion)
if err != nil {
log.Fatal(err)
}

v, err := rhel.ForSOBranchName(*soBranch)
v, err := rhel.ForSOVersion(soSemVer)
if err != nil {
log.Fatal(err)
}
Expand Down
6 changes: 6 additions & 0 deletions config/configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package config

import "embed"

//go:embed *.yaml
var Configs embed.FS
2 changes: 1 addition & 1 deletion pkg/action/update_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func UpdateAction(ctx context.Context, cfg Config) error {
}

err = filepath.Walk(cfg.InputConfigPath, func(path string, info fs.FileInfo, err error) error {
if info.IsDir() {
if info.IsDir() || !strings.HasSuffix(path, ".yaml") {
return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/discover/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/signal"
"path/filepath"
"slices"
"strings"

gyaml "github.com/ghodss/yaml"

Expand All @@ -30,7 +31,7 @@ func Main() {
flag.Parse()

err := filepath.Walk(*inputConfig, func(path string, info fs.FileInfo, err error) error {
if info.IsDir() {
if info.IsDir() || !strings.HasSuffix(path, ".yaml") {
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/konfluxapply/konflux_apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func Apply(ctx context.Context, cfg ApplyConfig) error {
}

err := filepath.Walk(cfg.InputConfigPath, func(path string, info fs.FileInfo, err error) error {
if info.IsDir() {
if info.IsDir() || !strings.HasSuffix(path, ".yaml") {
return nil
}

Expand Down
7 changes: 6 additions & 1 deletion pkg/prowgen/prowgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,12 @@ func LoadConfig(path string) (*Config, error) {
if err != nil {
return nil, err
}
j, err := gyaml.YAMLToJSON(y)

return UnmarshalConfig(y)
}

func UnmarshalConfig(yaml []byte) (*Config, error) {
j, err := gyaml.YAMLToJSON(yaml)
if err != nil {
return nil, err
}
Expand Down
19 changes: 15 additions & 4 deletions pkg/rhel/rhel-version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,26 @@ import (
"fmt"
"regexp"

"github.com/coreos/go-semver/semver"
"github.com/openshift-knative/hack/config"
"github.com/openshift-knative/hack/pkg/soversion"

"github.com/openshift-knative/hack/pkg/prowgen"
)

func ForSOBranchName(soBranchName string) (string, error) {
soConfig, loadErr := prowgen.LoadConfig("config/serverless-operator.yaml")
if loadErr != nil {
return "", fmt.Errorf("failed to load config for serverless-operator: %w", loadErr)
func ForSOVersion(soVersion *semver.Version) (string, error) {
soYaml, err := config.Configs.ReadFile("serverless-operator.yaml")
if err != nil {
return "", fmt.Errorf("failed to load config for serverless-operator: %w", err)
}

soConfig, err := prowgen.UnmarshalConfig(soYaml)
if err != nil {
return "", fmt.Errorf("failed to parse config for serverless-operator: %w", err)
}

soBranchName := soversion.BranchName(soVersion)

br, ok := soConfig.Config.Branches[soBranchName]
if !ok {
br, ok = soConfig.Config.Branches["main"]
Expand Down

0 comments on commit 08e8593

Please sign in to comment.