Skip to content

Commit

Permalink
Merge pull request #424 from bagutzu/helm-remove-oci-prefix
Browse files Browse the repository at this point in the history
fix: remove oci prefix from helm url before adding it to helmfile.
  • Loading branch information
jenkins-x-bot authored Jun 8, 2023
2 parents 0e4a9b2 + aa02bd0 commit bff88ec
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/rules/helmfile/helmfile_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,9 @@ func defaultPrefix(appsConfig *state.HelmState, envctx *envctx.EnvironmentContex
}
found := false
oci := false
// we need to remove the oci:// prefix (in case it exists), because helmfile doesn't support the scheme in the repo url for oci based repositories.
// for these repositories, only url without a scheme and the oci: true flag is needed.
d.Repository = strings.TrimPrefix(d.Repository, "oci://")
if envctx.Requirements != nil {
oci = envctx.Requirements.Cluster.ChartKind == jxcore.ChartRepositoryTypeOCI
}
Expand Down
71 changes: 71 additions & 0 deletions pkg/rules/helmfile/helmfile_rule_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package helmfile_test

import (
"os"
"path/filepath"
"testing"

"github.com/jenkins-x-plugins/jx-promote/pkg/jxtesthelpers"
"github.com/jenkins-x-plugins/jx-promote/pkg/promoteconfig"
"github.com/jenkins-x-plugins/jx-promote/pkg/rules"
"github.com/jenkins-x-plugins/jx-promote/pkg/rules/helmfile"
"github.com/jenkins-x/jx-helpers/v3/pkg/files"
"github.com/jenkins-x/jx-helpers/v3/pkg/testhelpers"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestRemoveOCISchemeFromHelmfileRepositoriesDuringDefaultPrefix(t *testing.T) {
tmpDir, err := os.MkdirTemp("", "")
require.NoError(t, err, "could not make a temp dir")

t.Logf("creating tests at %s", tmpDir)

sourceData := "test_data"
fileSlice, err := os.ReadDir(sourceData)

assert.NoError(t, err)

ns := "jx"
testPromoteNS := "jx"
for _, f := range fileSlice {
if !f.IsDir() {
continue
}
name := f.Name()
if name == "jenkins-x-versions" {
continue
}

dir := filepath.Join(tmpDir, name)

src := filepath.Join("test_data", name)
err = files.CopyDirOverwrite(src, dir)
require.NoError(t, err, "could not copy source data in %s to %s", src, dir)

cfg, _, err := promoteconfig.Discover(dir, testPromoteNS)
require.NoError(t, err, "failed to load cfg dir %s", dir)
require.NotNil(t, cfg, "no project cfg found in dir %s", dir)

envctx := jxtesthelpers.CreateTestDevEnvironmentContext(t, ns)
envctx.Requirements.Cluster.ChartKind = "oci"

r := &rules.PromoteRule{
TemplateContext: rules.TemplateContext{
GitURL: "https://github.com/myorg/myapp.git",
Version: "1.2.3",
AppName: "myapp",
Namespace: ns,
HelmRepositoryURL: "oci://chartmuseum-jx.34.78.195.22.nip.io",
},
Dir: dir,
Config: *cfg,
DevEnvContext: envctx,
}

e := helmfile.Rule(r)
require.Nil(t, e)
testhelpers.AssertTextFilesEqual(t, filepath.Join(src, "helmfile.yaml.expected"), filepath.Join(dir, "helmfile.yaml"), "The OCI prefix has not been removed before adding it to the helmfile")

}
}
8 changes: 8 additions & 0 deletions pkg/rules/helmfile/test_data/helmfile/helmfile.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
repositories:
- name: yourorg
url: https://yourorg.example.com/charts
releases:
- name: dbmigrator
labels:
job: dbmigrator
chart: ./dbmigrator
18 changes: 18 additions & 0 deletions pkg/rules/helmfile/test_data/helmfile/helmfile.yaml.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
filepath: ""
repositories:
- name: yourorg
url: https://yourorg.example.com/charts
- name: dev
url: chartmuseum-jx.34.78.195.22.nip.io
oci: true
releases:
- chart: ./dbmigrator
name: dbmigrator
labels:
job: dbmigrator
- chart: dev/myapp
version: 1.2.3
name: myapp
namespace: jx
templates: {}
renderedvalues: {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
version: 2.15.0
upperLimit: 3.0.0
gitUrl: https://github.com/git/git.git
url: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git

0 comments on commit bff88ec

Please sign in to comment.