Skip to content

Commit 5696dca

Browse files
committed
add support to scaffold oci helm registry charts
Signed-off-by: Adam D. Cornett <[email protected]>
1 parent e27207c commit 5696dca

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

internal/plugins/helm/v1/api.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,15 +108,18 @@ func (p *createAPISubcommand) UpdateMetadata(cliMeta plugin.CLIMetadata, subcmdM
108108
109109
$ %[1]s create api \
110110
--helm-chart=/path/to/local/chart-archives/app-1.2.3.tgz
111+
112+
$ %[1]s create api \
113+
--helm-chart=oci://charts.mycompany.com/example-namespace/app:1.2.3
111114
`, cliMeta.CommandName)
112115
}
113116

114117
// BindFlags will set the flags for the plugin
115118
func (p *createAPISubcommand) BindFlags(fs *pflag.FlagSet) {
116119
fs.SortFlags = false
117120

118-
fs.StringVar(&p.options.chartOptions.Chart, helmChartFlag, "", "helm chart")
119-
fs.StringVar(&p.options.chartOptions.Repo, helmChartRepoFlag, "", "helm chart repository")
121+
fs.StringVar(&p.options.chartOptions.Chart, helmChartFlag, "", "helm chart, if using an OCI registry, this needs to contain the entire chart address, just like the helm cli")
122+
fs.StringVar(&p.options.chartOptions.Repo, helmChartRepoFlag, "", "helm chart repository, only provide for non-OCI repositories")
120123
fs.StringVar(&p.options.chartOptions.Version, helmChartVersionFlag, "", "helm chart version (default: latest)")
121124

122125
fs.StringVar(&p.options.CRDVersion, crdVersionFlag, defaultCrdVersion, "crd version to generate")

internal/plugins/helm/v1/chartutil/chart.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"helm.sh/helm/v3/pkg/cli"
2828
"helm.sh/helm/v3/pkg/downloader"
2929
"helm.sh/helm/v3/pkg/getter"
30+
"helm.sh/helm/v3/pkg/registry"
3031
"helm.sh/helm/v3/pkg/repo"
3132
)
3233

@@ -126,11 +127,19 @@ func LoadChart(opts Options) (*chart.Chart, error) {
126127
func downloadChart(destDir string, opts Options) (string, error) {
127128
settings := cli.New()
128129
getters := getter.All(settings)
130+
131+
// Create registry client for OCI registry support
132+
registryClient, err := registry.NewClient()
133+
if err != nil {
134+
return "", fmt.Errorf("failed to create registry client: %w", err)
135+
}
136+
129137
c := downloader.ChartDownloader{
130138
Out: os.Stderr,
131139
Getters: getters,
132140
RepositoryConfig: settings.RepositoryConfig,
133141
RepositoryCache: settings.RepositoryCache,
142+
RegistryClient: registryClient,
134143
}
135144

136145
if opts.Repo != "" {
@@ -182,13 +191,20 @@ func fetchChartDependencies(chartPath string) error {
182191
settings := cli.New()
183192
getters := getter.All(settings)
184193

194+
// Create registry client for OCI registry support
195+
registryClient, err := registry.NewClient()
196+
if err != nil {
197+
return fmt.Errorf("failed to create registry client: %w", err)
198+
}
199+
185200
out := &bytes.Buffer{}
186201
man := &downloader.Manager{
187202
Out: out,
188203
ChartPath: chartPath,
189204
Getters: getters,
190205
RepositoryConfig: settings.RepositoryConfig,
191206
RepositoryCache: settings.RepositoryCache,
207+
RegistryClient: registryClient,
192208
}
193209
if err := man.Build(); err != nil {
194210
fmt.Println(out.String())

0 commit comments

Comments
 (0)