Skip to content

Commit

Permalink
Use chartVersion instead of targetVersion as parameter name
Browse files Browse the repository at this point in the history
  • Loading branch information
burmanm committed Feb 1, 2024
1 parent 1cd0bd5 commit e71182b
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/tools-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ on:
description: 'Name of the chart to be embedded in the image'
required: true
type: string
targetVersion:
chartVersion:
description: 'Target version to upgrade CRDs to. If used with git, give the tag name'
required: true
type: string
Expand Down Expand Up @@ -57,23 +57,23 @@ jobs:
- name: Create release name
id: vars
run: |
echo "tag=${{ inputs.chartName }}-${{ inputs.targetVersion }}" >> $GITHUB_OUTPUT
echo "tag=${{ inputs.chartName }}-${{ inputs.chartVersion }}" >> $GITHUB_OUTPUT
- name: Download the requested charts
if: ${{ inputs.repoName }}
id: download_charts
run: |
helm repo add ${{ inputs.repoName }} ${{ inputs.repoURL }}
helm repo update
helm pull ${{ inputs.repoName }}/${{ inputs.chartName }} --version ${{ inputs.targetVersion }}
helm pull ${{ inputs.repoName }}/${{ inputs.chartName }} --version ${{ inputs.chartVersion }}
mkdir -p build/${{ inputs.repoName }}
tar -xvf ${{ inputs.chartName }}-${{ inputs.targetVersion }}.tgz -C build/${{ inputs.repoName }}
tar -xvf ${{ inputs.chartName }}-${{ inputs.chartVersion }}.tgz -C build/${{ inputs.repoName }}
- name: Download the requested chart from another repository
if: ${{ !inputs.repoName }}
id: download_charts_github
run: |
gh repo clone ${{ inputs.gitRepo }} ${{ inputs.repoName }}
cd ${{ inputs.repoName }}
git checkout ${{ inputs.targetVersion }}
git checkout ${{ inputs.chartVersion }}
cd ..
mkdir -p build/${{ inputs.repoName }}
cp -R ${{ inputs.repoName }}/${{ inputs.chartDir }}/* build/${{ inputs.repoName }}
Expand Down
34 changes: 17 additions & 17 deletions cmd/kubectl-k8ssandra/helm/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ import (

var (
upgraderExample = `
# update CRDs in the namespace to targetVersion
%[1]s crds --chartName <chartName> --targetVersion <targetVersion> [<args>]
# update CRDs in the namespace to chartVersion
%[1]s upgrade --chartName <chartName> --chartVersion <chartVersion> [<args>]
# update CRDs in the namespace to targetVersion with non-default chartRepo (helm.k8ssandra.io)
%[1]s crds --chartName <chartName> --targetVersion <targetVersion> --chartRepo <repository> [<args>]
# update CRDs in the namespace to chartVersion with non-default chartRepo (helm.k8ssandra.io)
%[1]s upgrade --chartName <chartName> --chartVersion <chartVersion> --chartRepo <repository> [<args>]
`
errNotEnoughParameters = fmt.Errorf("not enough parameters, requires chartName and targetVersion")
errNotEnoughParameters = fmt.Errorf("not enough parameters, requires chartName and chartVersion")
)

type options struct {
configFlags *genericclioptions.ConfigFlags
genericclioptions.IOStreams
namespace string
chartName string
targetVersion string
chartRepo string
repoURL string
download bool
namespace string
chartName string
chartVersion string
chartRepo string
repoURL string
download bool
}

func newOptions(streams genericclioptions.IOStreams) *options {
Expand All @@ -44,8 +44,8 @@ func NewUpgradeCmd(streams genericclioptions.IOStreams) *cobra.Command {
o := newOptions(streams)

cmd := &cobra.Command{
Use: "upgrade <targetVersion> [flags]",
Short: "upgrade k8ssandra CRDs to target release version",
Use: "upgrade [flags]",
Short: "upgrade CRDs from chart to target version",
Example: fmt.Sprintf(upgraderExample, "kubectl k8ssandra helm crds"),
SilenceUsage: true,
RunE: func(c *cobra.Command, args []string) error {
Expand All @@ -65,7 +65,7 @@ func NewUpgradeCmd(streams genericclioptions.IOStreams) *cobra.Command {

fl := cmd.Flags()
fl.StringVar(&o.chartName, "chartName", "", "chartName to upgrade")
fl.StringVar(&o.targetVersion, "targetVersion", "", "targetVersion to upgrade to")
fl.StringVar(&o.chartVersion, "chartVersion", "", "chartVersion to upgrade to")
fl.StringVar(&o.chartRepo, "chartRepo", "", "optional chart repository name to override the default (k8ssandra)")
fl.StringVar(&o.repoURL, "repoURL", "", "optional chart repository url to override the default (helm.k8ssandra.io)")
fl.BoolVar(&o.download, "download", false, "only download the chart")
Expand All @@ -77,7 +77,7 @@ func NewUpgradeCmd(streams genericclioptions.IOStreams) *cobra.Command {
// Complete parses the arguments and necessary flags to options
func (c *options) Complete(cmd *cobra.Command, args []string) error {
var err error
if c.chartName == "" && c.targetVersion == "" {
if c.chartName == "" && c.chartVersion == "" {
return errNotEnoughParameters
}

Expand All @@ -95,7 +95,7 @@ func (c *options) Complete(cmd *cobra.Command, args []string) error {

// Validate ensures that all required arguments and flag values are provided
func (c *options) Validate() error {
// TODO Validate that the targetVersion is valid
// TODO Validate that the chartVersion is valid
return nil
}

Expand All @@ -121,6 +121,6 @@ func (c *options) Run() error {
return err
}

_, err = upgrader.Upgrade(ctx, c.targetVersion)
_, err = upgrader.Upgrade(ctx, c.chartVersion)
return err
}
6 changes: 3 additions & 3 deletions pkg/helmutil/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ func NewUpgrader(c client.Client, repoName, repoURL, chartName string) (*Upgrade
}

// Upgrade installs the missing CRDs or updates them if they exists already
func (u *Upgrader) Upgrade(ctx context.Context, targetVersion string) ([]unstructured.Unstructured, error) {
func (u *Upgrader) Upgrade(ctx context.Context, chartVersion string) ([]unstructured.Unstructured, error) {
chartDir, err := GetChartTargetDir(u.chartName)
if err != nil {
return nil, err
}

if _, err := os.Stat(chartDir); os.IsNotExist(err) {
downloadDir, err := DownloadChartRelease(u.repoName, u.repoURL, u.chartName, targetVersion)
downloadDir, err := DownloadChartRelease(u.repoName, u.repoURL, u.chartName, chartVersion)
if err != nil {
return nil, err
}

extractDir, err := ExtractChartRelease(downloadDir, u.chartName, targetVersion)
extractDir, err := ExtractChartRelease(downloadDir, u.chartName, chartVersion)
if err != nil {
return nil, err
}
Expand Down
12 changes: 6 additions & 6 deletions pkg/helmutil/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
)

// DownloadChartRelease fetches the k8ssandra target version and extracts it to a directory which path is returned
func DownloadChartRelease(repoName, repoURL, chartName, targetVersion string) (string, error) {
func DownloadChartRelease(repoName, repoURL, chartName, chartVersion string) (string, error) {
// Unfortunately, the helm's chart pull command uses "internal" marked structs, so it can't be used for
// pulling the data. Thus, we need to replicate the implementation here and use our own cache
settings := cli.New()
Expand Down Expand Up @@ -61,7 +61,7 @@ func DownloadChartRelease(repoName, repoURL, chartName, targetVersion string) (s
}

// chart name, chart version
cv, err := repoIndex.Get(chartName, targetVersion)
cv, err := repoIndex.Get(chartName, chartVersion)
if err != nil {
return "", err
}
Expand All @@ -78,17 +78,17 @@ func DownloadChartRelease(repoName, repoURL, chartName, targetVersion string) (s
}

// _ is ProvenanceVerify (TODO we might want to verify the release)
saved, _, err := c.DownloadTo(url, targetVersion, dir)
saved, _, err := c.DownloadTo(url, chartVersion, dir)
if err != nil {
return "", err
}

return saved, nil
}

func ExtractChartRelease(saved, chartName, targetVersion string) (string, error) {
func ExtractChartRelease(saved, chartName, chartVersion string) (string, error) {
// Extract the files
subDir := filepath.Join(chartName, targetVersion)
subDir := filepath.Join(chartName, chartVersion)
extractDir, err := util.GetCacheDir(subDir)
if err != nil {
return "", err
Expand Down Expand Up @@ -152,6 +152,6 @@ func Uninstall(cfg *action.Configuration, releaseName string) (*release.Uninstal
}

// ValuesYaml fetches the chartVersion's values.yaml file for editing purposes
func ValuesYaml(targetVersion string) (io.Reader, error) {
func ValuesYaml(chartVersion string) (io.Reader, error) {
return nil, nil
}
2 changes: 1 addition & 1 deletion pkg/helmutil/release.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func UpgradeValues(cfg *action.Configuration, chartDir, chartName, releaseName s
return u.Run(releaseName, ch, values)
}

func MergeValuesFile(cfg *action.Configuration, settings *cli.EnvSettings, chartDir, targetVersion, chartName, releaseName string) (*os.File, error) {
func MergeValuesFile(cfg *action.Configuration, settings *cli.EnvSettings, chartDir, chartVersion, chartName, releaseName string) (*os.File, error) {
// Create temp file with merged default values.yaml (with comments) and helm modified values
// If there were changes, upgrade Helm release with the new overridden settings

Expand Down

0 comments on commit e71182b

Please sign in to comment.