Skip to content

Commit a992438

Browse files
committed
Merge branch 'fix-empty-pull-secrets' into 'main'
Omit creating auth.Credentials if no pull secret is configured for a runtime class See merge request nvidia/cloud-native/k8s-kata-manager!22
2 parents 6f0f421 + ea4c7f0 commit a992438

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

cmd/kata-manager/pull/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ func (m command) run(c *cli.Context, opts *options) error {
129129
}
130130
m.logger.Infof("Artifact: %v", art)
131131

132-
creds := auth.Credential{
132+
creds := &auth.Credential{
133133
Username: opts.username,
134134
Password: opts.password,
135135
}

internal/client-go/secrets.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ package kubernetes
1919
import (
2020
"context"
2121
"encoding/json"
22+
"fmt"
2223

2324
api "github.com/NVIDIA/k8s-kata-manager/api/v1alpha1/config"
2425
utils "github.com/NVIDIA/k8s-kata-manager/internal/utils"
2526

2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27-
"k8s.io/klog/v2"
2828
"oras.land/oras-go/v2/registry/remote/auth"
2929
)
3030

@@ -44,22 +44,25 @@ type RegistryCredentials struct {
4444
Auth string `json:"auth"`
4545
}
4646

47-
func (k *k8scli) GetCredentials(rc api.RuntimeClass, namespace string) (auth.Credential, error) {
48-
auths := Auths{}
47+
func (k *k8scli) GetCredentials(rc api.RuntimeClass, namespace string) (*auth.Credential, error) {
48+
if rc.Artifacts.PullSecret == "" {
49+
return nil, nil
50+
}
4951

52+
auths := Auths{}
5053
secret, err := k.Get(context.Background(), rc.Artifacts.PullSecret, metav1.GetOptions{})
5154
if err != nil {
52-
return auth.Credential{}, err
55+
return nil, fmt.Errorf("error getting secret: %v", err)
5356
}
5457
if err := json.Unmarshal(secret.Data[".dockerconfigjson"], &auths); err != nil {
55-
klog.Errorf("error decoding secret: %s", err)
58+
return nil, fmt.Errorf("error decoding secret: %v", err)
5659
}
5760
Registry, err := utils.ParseRegistry(rc.Artifacts.URL)
5861
if err != nil {
59-
klog.Errorf("error parsing registry: %s", err)
62+
return nil, fmt.Errorf("error parsing registry: %v", err)
6063
}
6164

62-
creds := auth.Credential{
65+
creds := &auth.Credential{
6366
Username: auths.Registries[Registry].Username,
6467
Password: auths.Registries[Registry].Password,
6568
}

internal/oras/pull.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func NewArtifact(ref string, output string) (*Artifact, error) {
6868
}
6969

7070
// Pull pulls the artifact from the remote repository into a local path
71-
func (a *Artifact) Pull(creds auth.Credential) (ocispec.Descriptor, error) {
71+
func (a *Artifact) Pull(creds *auth.Credential) (ocispec.Descriptor, error) {
7272
// Create a file store
7373
fs, err := file.New(a.Output)
7474
if err != nil {
@@ -83,13 +83,15 @@ func (a *Artifact) Pull(creds auth.Credential) (ocispec.Descriptor, error) {
8383
return ocispec.Descriptor{}, err
8484
}
8585

86-
repo.Client = &auth.Client{
87-
Client: retry.DefaultClient,
88-
Cache: auth.DefaultCache,
89-
Credential: auth.StaticCredential(a.Registry, auth.Credential{
90-
Username: creds.Username,
91-
Password: creds.Password,
92-
}),
86+
if creds != nil {
87+
repo.Client = &auth.Client{
88+
Client: retry.DefaultClient,
89+
Cache: auth.DefaultCache,
90+
Credential: auth.StaticCredential(a.Registry, auth.Credential{
91+
Username: creds.Username,
92+
Password: creds.Password,
93+
}),
94+
}
9395
}
9496

9597
// Copy from the remote repository to the file store

0 commit comments

Comments
 (0)