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

Release charts update cmd #464

Merged
merged 14 commits into from
Aug 12, 2024
Merged
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
96 changes: 96 additions & 0 deletions cmd/release/cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package cmd
import (
"context"
"errors"
"fmt"
"os"

"github.com/rancher/ecm-distro-tools/release/charts"
"github.com/rancher/ecm-distro-tools/release/k3s"
"github.com/rancher/ecm-distro-tools/repository"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -42,8 +45,101 @@ var updateK3sReferencesCmd = &cobra.Command{
},
}

var updateChartsCmd = &cobra.Command{
Use: "charts [branch-line] [chart] [version]",
Short: "Update charts files locally, stage and commit the changes.",
Example: "release update charts 2.9 rancher-istio 104.0.0+up1.21.1",
Args: func(cmd *cobra.Command, args []string) error {
if err := validateChartConfig(); err != nil {
fmt.Println(err)
os.Exit(1)
}

if len(args) != 3 {
return errors.New("expected 3 arguments: [branch-line] [chart] [version]")
}

var branch, chart, version string
branch = args[0]
chart = args[1]
version = args[2]
tashima42 marked this conversation as resolved.
Show resolved Hide resolved

if found := charts.IsBranchAvailable(branch, rootConfig.Charts.BranchLines); !found {
return errors.New("branch not available: " + branch)
}

found, err := charts.IsChartAvailable(context.Background(), rootConfig.Charts, chart)
if err != nil {
return err
}
if !found {
return errors.New("chart not available: " + chart)
}

found, err = charts.IsVersionAvailable(context.Background(), rootConfig.Charts, chart, version)
if err != nil {
return err
}
if !found {
return errors.New("version not available: " + version)
}

return nil
},
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if err := validateChartConfig(); err != nil {
fmt.Println(err)
os.Exit(1)
}

if len(args) == 0 {
return rootConfig.Charts.BranchLines, cobra.ShellCompDirectiveNoFileComp
} else if len(args) == 1 {
chArgs, err := charts.ChartArgs(context.Background(), rootConfig.Charts)
if err != nil {
fmt.Printf("failed to get available charts: %v\n", err)
os.Exit(1)
}

return chArgs, cobra.ShellCompDirectiveNoFileComp
} else if len(args) == 2 {
vArgs, err := charts.VersionArgs(context.Background(), rootConfig.Charts, args[1])
if err != nil {
fmt.Printf("failed to get available versions: %v", err)
os.Exit(1)
}

return vArgs, cobra.ShellCompDirectiveNoFileComp
}

return nil, cobra.ShellCompDirectiveNoFileComp
},
RunE: func(cmd *cobra.Command, args []string) error {
var branch, chart, version string
branch = args[0]
chart = args[1]
version = args[2]

output, err := charts.Update(context.Background(), rootConfig.Charts, branch, chart, version)
if err != nil {
return err
}

fmt.Println(output)
return nil
},
}

func init() {
rootCmd.AddCommand(updateCmd)
updateCmd.AddCommand(updateChartsCmd)
updateCmd.AddCommand(updateK3sCmd)
updateK3sCmd.AddCommand(updateK3sReferencesCmd)
}

func validateChartConfig() error {
if rootConfig.Charts.Workspace == "" || rootConfig.Charts.ChartsForkURL == "" {
return errors.New("verify your config file, chart configuration not implemented correctly, you must insert workspace path and your forked repo url")
}
return nil
}
15 changes: 6 additions & 9 deletions cmd/release/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,10 @@ type RKE2 struct {

// ChartsRelease
type ChartsRelease struct {
Workspace string `json:"workspace" validate:"required,dirpath"`
ChartsRepoURL string `json:"charts_repo_url" validate:"required"`
ChartsForkURL string `json:"charts_fork_url" validate:"required"`
DevBranch string `json:"dev_branch" validate:"required"`
ReleaseBranch string `json:"release_branch" validate:"required"`
Workspace string `json:"workspace" validate:"required,dirpath"`
ChartsRepoURL string `json:"charts_repo_url" validate:"required"`
ChartsForkURL string `json:"charts_fork_url" validate:"required"`
BranchLines []string `json:"branch_lines" validate:"required"`
}

// User
Expand Down Expand Up @@ -175,8 +174,7 @@ func ExampleConfig() (string, error) {
Workspace: filepath.Join(gopath, "src", "github.com", "rancher", "charts") + "/",
ChartsRepoURL: "https://github.com/rancher/charts",
ChartsForkURL: "https://github.com/your-github-username/charts",
DevBranch: "dev-v2.9",
ReleaseBranch: "release-v2.9",
BranchLines: []string{"2.10", "2.9", "2.8"},
},
Auth: &Auth{
GithubToken: "YOUR_TOKEN",
Expand Down Expand Up @@ -240,6 +238,5 @@ Charts
Workspace: {{.Charts.Workspace}}
ChartsRepoURL: {{.Charts.ChartsRepoURL}}
ChartsForkURL: {{.Charts.ChartsForkURL}}
DevBranch: {{.Charts.DevBranch}}
ReleaseBranch: {{.Charts.ReleaseBranch}}
BranchLines: {{.Charts.BranchLines}}
`
42 changes: 14 additions & 28 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,24 @@ go 1.21

require (
github.com/drone/drone-go v1.7.1
github.com/go-git/go-git/v5 v5.11.0
github.com/go-git/go-git/v5 v5.12.1-0.20240807144107-c594bae8d75d
github.com/google/go-github/v39 v39.2.0
github.com/sirupsen/logrus v1.9.3
go.opentelemetry.io/otel v1.25.0
go.opentelemetry.io/otel/sdk v1.25.0
go.opentelemetry.io/otel/trace v1.25.0
golang.org/x/crypto v0.22.0
golang.org/x/crypto v0.26.0
golang.org/x/mod v0.17.0
golang.org/x/oauth2 v0.18.0
)

require (
github.com/MetalBlueberry/go-plotly v0.4.0
github.com/go-playground/validator/v10 v10.22.0
github.com/spf13/cobra v1.8.0
github.com/urfave/cli/v2 v2.25.7
golang.org/x/sync v0.7.0
golang.org/x/text v0.14.0
golang.org/x/sync v0.8.0
golang.org/x/text v0.17.0
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1
)
Expand All @@ -29,44 +30,29 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.22.0 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/sagikazarmark/locafero v0.4.0 // indirect
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
github.com/skeema/knownhosts v1.2.1 // indirect
github.com/sourcegraph/conc v0.3.0 // indirect
github.com/spf13/afero v1.11.0 // indirect
github.com/spf13/cast v1.6.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/skeema/knownhosts v1.3.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.19.0 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
go.opentelemetry.io/otel/metric v1.25.0 // indirect
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.9.0 // indirect
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
golang.org/x/tools v0.20.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
)

require (
github.com/Masterminds/semver/v3 v3.2.1
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-git/go-billy/v5 v5.5.1-0.20240427054813-8453aa90c6ec // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
Expand All @@ -75,11 +61,11 @@ require (
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/net v0.24.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/net v0.28.0 // indirect
golang.org/x/sys v0.23.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/protobuf v1.33.0 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
Expand Down
Loading
Loading