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: make oci login work #68

Merged
merged 1 commit into from
Jan 8, 2025
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Chart.lock
!./charts
k8s-helm-dep-updater
dist/
.DS_Store
6 changes: 5 additions & 1 deletion charts/benchmark-subchart-level-2a/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,8 @@ dependencies:
- name: mysql
alias: mysql-bitnami-benchmark-subchart-level-2a
version: 12.0.0
repository: https://charts.bitnami.com/bitnami
repository: https://charts.bitnami.com/bitnami
- name: redis
alias: redis-bitnami-benchmark-subchart-level-2a
version: 20.6.1
repository: oci://registry-1.docker.io/bitnamicharts
4 changes: 2 additions & 2 deletions helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@ func TestUpdateDependencies(t *testing.T) {
name: "With Refresh",
chartPath: "charts/benchmark-subchart-level-1",
helmDepsSkipRefresh: false,
expectedNumObjects: 42,
expectedNumObjects: 56,
},
{
name: "Without Refresh",
chartPath: "charts/benchmark-subchart-level-1",
helmDepsSkipRefresh: true,
expectedNumObjects: 42,
expectedNumObjects: 56,
},
}

Expand Down
30 changes: 27 additions & 3 deletions kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"log"
"net/url"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -80,6 +81,14 @@ func (d *DefaultStrategy) Logout() error {
return nil
}

// return the registry hostname in case of oci://hostname we return hostname
func (info *RegistryInfo) GetRegistryHost() string {
if info.EnableOCI {
info.Hostname = GetRegistryHostName(info.Hostname)
}
return info.Hostname
}

// NewRegistryHelper creates a new RegistryHelper
// secretNames is a comma separated list of registry secrets
func NewRegistryHelper(secretNames string, namespace string, config *HelmUpdateConfig) (*RegistryHelper, error) {
Expand Down Expand Up @@ -138,9 +147,9 @@ func (r *RegistryHelper) RemoveTempHelmCacheDir() {
}

// GetRegistry returns the credential protected registry by hostname
func (r *RegistryHelper) GetRegistryByHostname(registry string) *RegistryInfo {
func (r *RegistryHelper) GetRegistryByHostname(registry RegistryInfo) *RegistryInfo {
for _, registryInfo := range r.Registries {
if registryInfo.Hostname == registry {
if registryInfo.Hostname == registry.GetRegistryHost() {
return registryInfo
}
}
Expand All @@ -160,7 +169,7 @@ func (r *RegistryHelper) LoginIfExists(registry *RegistryInfo) error {
log.Printf("Registry %s found in helm repos, skipping login", registry.SecretName)
return nil
}
foundRegistry := r.GetRegistryByHostname(registry.Hostname)
foundRegistry := r.GetRegistryByHostname(*registry)
if foundRegistry != nil {
action := GetRegistryAction(foundRegistry)
log.Printf("Registry %s found in secrets, logging in", foundRegistry.SecretName)
Expand Down Expand Up @@ -235,6 +244,9 @@ func (r *RegistryHelper) SetRegistriesByLabel() {
return
}
for _, secret := range secrets.Items {
if string(secret.Data["type"]) != "helm" {
continue
}
secretName := secret.Name
r.Registries[secretName] = &RegistryInfo{
Hostname: string(secret.Data["url"]),
Expand Down Expand Up @@ -275,3 +287,15 @@ func (r *RegistryHelper) LogoutAll() error {
}
return nil
}

func GetRegistryHostName(registryUrl string) string {
parsedURL, err := url.Parse(registryUrl)
if parsedURL.Scheme == "" {
return registryUrl
}
if err != nil {
log.Printf("Failed to parse URL: %s", registryUrl)
return ""
}
return parsedURL.Host
}
Loading