-
Notifications
You must be signed in to change notification settings - Fork 29
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
Changes from 10 commits
84f898e
db7da76
63c185a
bbb36d2
60949c1
54f7c75
cfc29f4
7b82f13
a99cdb9
24523a8
1cd79df
cac4e42
ea7a5c9
cc7ab67
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,10 @@ package cmd | |
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
"log" | ||
|
||
"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" | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented