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

fix OCI chart support #75

Merged
merged 2 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions example/oci-dependency/Chart.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
dependencies:
- name: karpenter
repository: oci://public.ecr.aws/karpenter
version: 0.35.0
digest: sha256:c351689f0d2d254c02b7e8aac54c06fb66e8871dfae3479cfbf1af88e1fee268
generated: "2024-04-11T01:47:48.41682948+02:00"
8 changes: 8 additions & 0 deletions example/oci-dependency/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v2
description: example chart with OCI chart as dependency
name: oci-dependency
version: 0.0.0
dependencies:
- name: karpenter
version: "0.35.0"
repository: "oci://public.ecr.aws/karpenter"
6 changes: 6 additions & 0 deletions example/oci-dependency/generator.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: khelm.mgoltzsche.github.com/v2
kind: ChartRenderer
metadata:
name: oci-dependency
namespace: kube-system
chart: .
3 changes: 2 additions & 1 deletion example/oci-image/generator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ kind: ChartRenderer
metadata:
name: karpenter
namespace: kube-system
chart: "oci://public.ecr.aws/karpenter/karpenter"
chart: karpenter
version: 0.35.0
repository: "oci://public.ecr.aws/karpenter"
13 changes: 12 additions & 1 deletion pkg/helm/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ func (h *Helm) loadChart(ctx context.Context, cfg *config.ChartConfig) (*chart.C
} else {
return nil, errors.Errorf("chart directory %q not found and no repository specified", cfg.Chart)
}
} else if registry.IsOCI(cfg.Repository) {
cfg.Chart = fmt.Sprintf("%s/%s", cfg.Repository, cfg.Chart)
cfg.Repository = ""
return h.loadOCIChart(ctx, cfg)
}
return h.loadRemoteChart(ctx, cfg)
}
Expand Down Expand Up @@ -230,12 +234,19 @@ func buildLocalCharts(ctx context.Context, localCharts []localChart, cfg *config
}

func buildChartDependencies(ctx context.Context, chartRequested *chart.Chart, chartPath string, cfg *config.LoaderConfig, repos repositoryConfig, settings *cli.EnvSettings, getters getter.Providers) error {
registryClient, err := registry.NewClient(
registry.ClientOptEnableCache(true),
)
if err != nil {
return errors.WithStack(err)
}
man := &downloader.Manager{
Out: log.Writer(),
ChartPath: chartPath,
Keyring: cfg.Keyring,
SkipUpdate: true,
Getters: getters,
RegistryClient: registryClient,
RepositoryConfig: settings.RepositoryConfig,
RepositoryCache: settings.RepositoryCache,
Debug: settings.Debug,
Expand All @@ -244,7 +255,7 @@ func buildChartDependencies(ctx context.Context, chartRequested *chart.Chart, ch
man.Verify = downloader.VerifyAlways
}
// Workaround for leftover tmpcharts dir (which makes Build() fail)
err := os.RemoveAll(filepath.Join(chartPath, "tmpcharts"))
err = os.RemoveAll(filepath.Join(chartPath, "tmpcharts"))
if err != nil {
return errors.WithStack(err)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/helm/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ func TestRender(t *testing.T) {
{"include", "example/include/generator.yaml", []string{}, " key: b", nil},
{"local-chart-with-local-dependency-and-transitive-remote", "example/localrefref/generator.yaml", []string{}, "rook-ceph-v0.9.3", nil},
{"local-chart-with-remote-dependency", "example/localref/generator.yaml", []string{}, "rook-ceph-v0.9.3", nil},
{"oci-chart", "example/oci-image/generator.yaml", []string{"kube-system", "kube-node-lease"}, "name: ec2nodeclasses.karpenter.k8s.aws", nil},
{"oci-dependency", "example/oci-dependency/generator.yaml", []string{"kube-system", "kube-node-lease"}, "name: ec2nodeclasses.karpenter.k8s.aws", nil},
{"values-inheritance", "example/values-inheritance/generator.yaml", []string{}, " inherited: inherited value\n fileoverwrite: overwritten by file\n valueoverwrite: overwritten by generator config", nil},
{"cluster-scoped", "example/cluster-scoped/generator.yaml", []string{}, "myrolebinding", nil},
{"chart-hooks", "example/chart-hooks/generator.yaml", []string{"default"}, " key: myvalue", []string{
Expand Down
Loading