Skip to content

Commit

Permalink
Support older github workflow for now which is missing chartVersion f…
Browse files Browse the repository at this point in the history
…rom the pkg download
  • Loading branch information
burmanm committed Nov 29, 2024
1 parent f5731b4 commit f376f9c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
4 changes: 2 additions & 2 deletions pkg/helmutil/crds.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ func NewUpgrader(c client.Client, repoName, repoURL, chartName string, subCharts
func (u *Upgrader) Upgrade(ctx context.Context, chartVersion string) ([]unstructured.Unstructured, error) {
log.SetLevel(log.DebugLevel)
log.Info("Processing request to upgrade project CustomResourceDefinitions", "repoName", u.repoName, "chartName", u.chartName, "chartVersion", chartVersion)
chartDir, err := GetChartTargetDir(u.repoName, u.chartName, chartVersion)
chartDir, err := GetChartTargetDir(u.repoName, u.chartName)
if err != nil {
return nil, err
}

if fs, err := os.Stat(chartDir); os.IsNotExist(err) {
log.Info("Downloading chart release from remote repository", "repoURL", u.repoURL, "chartName", u.chartName, "chartVersion", chartVersion)
log.Info("Downloading chart release from remote repository", "repoURL", u.repoURL, "chartName", u.chartName, "chartVersion", chartVersion, "chartDir", chartDir)
downloadDir, err := DownloadChartRelease(u.repoName, u.repoURL, u.chartName, chartVersion)
if err != nil {
return nil, err
Expand Down
56 changes: 30 additions & 26 deletions pkg/helmutil/crds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestUpgradingCRDs(t *testing.T) {
for _, chartName := range chartNames {
namespace := env.CreateNamespace(t)
kubeClient := env.GetClientInNamespace(namespace)
require.NoError(cleanCache("k8ssandra", chartName, "0.42.0"))
require.NoError(cleanCache("k8ssandra", chartName))

// creating new upgrader
u, err := helmutil.NewUpgrader(kubeClient, helmutil.K8ssandraRepoName, helmutil.StableK8ssandraRepoURL, chartName, []string{})
Expand Down Expand Up @@ -64,7 +64,7 @@ func TestUpgradingCRDs(t *testing.T) {
require.False(strings.HasPrefix(descRunsAsCassandra, "DEPRECATED"))

// Upgrading to 0.46.1
require.NoError(cleanCache("k8ssandra", chartName, "0.46.1"))
require.NoError(cleanCache("k8ssandra", chartName))
_, err = u.Upgrade(context.TODO(), "0.46.1")
require.NoError(err)

Expand All @@ -82,8 +82,8 @@ func TestUpgradingCRDs(t *testing.T) {
}
}

func cleanCache(repoName, chartName, version string) error {
chartDir, err := helmutil.GetChartTargetDir(repoName, chartName, version)
func cleanCache(repoName, chartName string) error {
chartDir, err := helmutil.GetChartTargetDir(repoName, chartName)
if err != nil {
return err
}
Expand All @@ -100,12 +100,10 @@ func TestUpgradingStoredVersions(t *testing.T) {
chartName := "test-chart"
namespace := env.CreateNamespace(t)
kubeClient := env.GetClientInNamespace(namespace)
require.NoError(cleanCache("k8ssandra", chartName, "0.1.0"))
require.NoError(cleanCache("k8ssandra", chartName, "0.2.0"))
require.NoError(cleanCache("k8ssandra", chartName, "0.3.0"))
require.NoError(cleanCache("k8ssandra", chartName))

// Copy testfiles
chartDir, err := helmutil.GetChartTargetDir(helmutil.K8ssandraRepoName, chartName, "0.1.0")
chartDir, err := helmutil.GetChartTargetDir(helmutil.K8ssandraRepoName, chartName)
require.NoError(err)

crdDir := filepath.Join(chartDir, "crds")
Expand All @@ -114,24 +112,6 @@ func TestUpgradingStoredVersions(t *testing.T) {
crdSrc := filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-v1alpha1.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

chartDir, err = helmutil.GetChartTargetDir(helmutil.K8ssandraRepoName, chartName, "0.2.0")
require.NoError(err)

crdDir = filepath.Join(chartDir, "crds")
_, err = util.CreateIfNotExistsDir(crdDir)
require.NoError(err)
crdSrc = filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-both.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

chartDir, err = helmutil.GetChartTargetDir(helmutil.K8ssandraRepoName, chartName, "0.3.0")
require.NoError(err)

crdDir = filepath.Join(chartDir, "crds")
_, err = util.CreateIfNotExistsDir(crdDir)
require.NoError(err)
crdSrc = filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-v1beta1.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

testOptions := envtest.CRDInstallOptions{
PollInterval: 100 * time.Millisecond,
MaxTime: 10 * time.Second,
Expand Down Expand Up @@ -161,6 +141,12 @@ func TestUpgradingStoredVersions(t *testing.T) {

// Upgrade to 0.2.0

require.NoError(cleanCache("k8ssandra", chartName))
_, err = util.CreateIfNotExistsDir(crdDir)
require.NoError(err)
crdSrc = filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-both.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

crds, err = u.Upgrade(context.TODO(), "0.2.0")
require.NoError(err)
for _, crd := range crds {
Expand All @@ -175,6 +161,12 @@ func TestUpgradingStoredVersions(t *testing.T) {

// Upgrade to 0.3.0

require.NoError(cleanCache("k8ssandra", chartName))
_, err = util.CreateIfNotExistsDir(crdDir)
require.NoError(err)
crdSrc = filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-v1beta1.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

crds, err = u.Upgrade(context.TODO(), "0.3.0")
require.NoError(err)
for _, crd := range crds {
Expand All @@ -196,6 +188,12 @@ func TestUpgradingStoredVersions(t *testing.T) {

// Install 0.2.0

require.NoError(cleanCache("k8ssandra", chartName))
_, err = util.CreateIfNotExistsDir(crdDir)
require.NoError(err)
crdSrc = filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-both.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

crds, err = u.Upgrade(context.TODO(), "0.2.0")
require.NoError(err)
for _, crd := range crds {
Expand All @@ -210,6 +208,12 @@ func TestUpgradingStoredVersions(t *testing.T) {

// Upgrade to 0.3.0

require.NoError(cleanCache("k8ssandra", chartName))
_, err = util.CreateIfNotExistsDir(crdDir)
require.NoError(err)
crdSrc = filepath.Join("..", "..", "testfiles", "crd-upgrader", "multiversion-clientconfig-mockup-v1beta1.yaml")
require.NoError(copyFile(crdSrc, filepath.Join(crdDir, "clientconfig.yaml")))

crds, err = u.Upgrade(context.TODO(), "0.3.0")
require.NoError(err)
for _, crd := range crds {
Expand Down
4 changes: 1 addition & 3 deletions pkg/helmutil/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ func ExtractChartRelease(saved, repoName, chartName, chartVersion string) (strin
return extractDir, nil
}

func GetChartTargetDir(repoName, chartName, chartVersion string) (string, error) {
func GetChartTargetDir(repoName, chartName string) (string, error) {
extractDir, err := util.GetCacheDir(repoName, chartName)
if err != nil {
return "", err
}

extractDir = filepath.Join(extractDir, chartVersion)

return extractDir, err
}

Expand Down

0 comments on commit f376f9c

Please sign in to comment.