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 10 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"
"log"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this in favor of regular CLI outut. We don't have anything consuming these logs and they're created at the time of execution so their timestamp values don't give us any extra value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented


"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] [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 {
log.Fatal(err)
}

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

var branch, chart, version string
var found bool
var err error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a problem when an error is checked and the action is not to return which leaves this value potentially untouched on a subsequent check causing issues. Let's not define a catch-all error value here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented


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

found = charts.CheckBranchArgs(branch)
if !found {
return errors.New("branch not available: " + branch)
}

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

found, err = charts.CheckVersionArgs(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 {
log.Fatal(err)
}

if len(args) == 0 {
return charts.BranchArgs(), cobra.ShellCompDirectiveNoFileComp
} else if len(args) == 1 {
chArgs, err := charts.ChartArgs(context.Background(), rootConfig.Charts)
if err != nil {
log.Fatalf("failed to get available charts: %v", err)
}

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

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
}
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