Skip to content

Commit ddae817

Browse files
authored
Merge pull request #256 from nicholasSUSE/fix-push-oci-5
Fix push oci 5
2 parents c5f3fd0 + 1774372 commit ddae817

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

pkg/auto/oci.go

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,21 +115,20 @@ func setupHelm(ctx context.Context, ociDNS, ociUser, ociPass string, debug bool)
115115
var regClient *registry.Client
116116
var err error
117117

118-
registryHost := extractRegistryHost(ociDNS)
119-
isLocalHost := strings.HasPrefix(registryHost, "localhost:")
118+
isLocalHost := strings.HasPrefix(ociDNS, "localhost:")
120119

121120
switch {
122121
// Debug Mode but pointing to a server with custom-certificates
123122
case debug && !isLocalHost:
124123
logger.Log(ctx, slog.LevelDebug, "debug mode", slog.Bool("localhost", isLocalHost))
125-
caFile := "/etc/docker/certs.d/" + registryHost + "/ca.crt"
124+
caFile := "/etc/docker/certs.d/" + ociDNS + "/ca.crt"
126125
regClient, err = registry.NewRegistryClientWithTLS(os.Stdout, "", "", caFile, false, "", true)
127126
if err != nil {
128127
logger.Log(ctx, slog.LevelError, "failed to create registry client with TLS")
129128
return nil, err
130129
}
131130
if err = regClient.Login(
132-
registryHost,
131+
ociDNS,
133132
registry.LoginOptInsecure(false),
134133
registry.LoginOptTLSClientConfig("", "", caFile),
135134
registry.LoginOptBasicAuth(ociUser, ociPass),
@@ -149,7 +148,7 @@ func setupHelm(ctx context.Context, ociDNS, ociUser, ociPass string, debug bool)
149148
logger.Log(ctx, slog.LevelError, "failed to create registry client")
150149
return nil, err
151150
}
152-
if err = regClient.Login(registryHost,
151+
if err = regClient.Login(ociDNS,
153152
registry.LoginOptInsecure(true), // true for localhost, false for production
154153
registry.LoginOptBasicAuth(ociUser, ociPass)); err != nil {
155154
logger.Log(ctx, slog.LevelError, "failed to login to registry", slog.Group(ociDNS, ociUser, ociPass))
@@ -166,7 +165,7 @@ func setupHelm(ctx context.Context, ociDNS, ociUser, ociPass string, debug bool)
166165
logger.Log(ctx, slog.LevelError, "failed to create registry client")
167166
return nil, err
168167
}
169-
if err = regClient.Login(registryHost,
168+
if err = regClient.Login(ociDNS,
170169
registry.LoginOptInsecure(false),
171170
registry.LoginOptBasicAuth(ociUser, ociPass)); err != nil {
172171
logger.Log(ctx, slog.LevelError, "failed to login")
@@ -178,14 +177,6 @@ func setupHelm(ctx context.Context, ociDNS, ociUser, ociPass string, debug bool)
178177
return regClient, nil
179178
}
180179

181-
// extractRegistryHost will extract the DNS for login
182-
func extractRegistryHost(ociDNS string) string {
183-
if idx := strings.Index(ociDNS, "/"); idx != -1 {
184-
return ociDNS[:idx]
185-
}
186-
return ociDNS
187-
}
188-
189180
// update will attempt to update a helm chart to an OCI registry.
190181
// 2 phases:
191182
// - 1: Pre-Flight validations (check the current chart + check if it already exists)
@@ -297,7 +288,7 @@ func buildPushURL(ociDNS, chart, version string) string {
297288
func checkAsset(ctx context.Context, helmClient *registry.Client, ociDNS, chart, version string) (bool, error) {
298289
// Once issue is resolved: https://github.com/helm/helm/issues/13368
299290
// Replace by: helmClient.Tags(ociDNS + "/" + chart + ":" + version)
300-
tagsURL := ociDNS + "/" + chart
291+
tagsURL := ociDNS + "/rancher/charts/" + chart
301292
logger.Log(ctx, slog.LevelDebug, "checking tags",
302293
slog.String("ociDNS", ociDNS),
303294
slog.String("chart", chart),
@@ -330,7 +321,7 @@ func (o *oci) checkRegistryTagExists(ctx context.Context, ociDNS, chart, tag str
330321
ociTag := strings.ReplaceAll(tag, "+", "_")
331322

332323
// Build repository reference first (host + path, no tag)
333-
repoStr := ociDNS + "/" + chart
324+
repoStr := ociDNS + "/rancher/charts/" + chart
334325
repo, err := name.NewRepository(repoStr, nameOpts...)
335326
if err != nil {
336327
logger.Log(ctx, slog.LevelError, "failed to parse repository", logger.Err(err))

0 commit comments

Comments
 (0)