Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix unit tests
Browse files Browse the repository at this point in the history
When merging the gitops PoC code a the bugfix at
#2728 was incorrectly overwritten.
2opremio committed Feb 12, 2020
1 parent 67002a8 commit 71a6663
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions pkg/cluster/kubernetes/images.go
Original file line number Diff line number Diff line change
@@ -20,7 +20,7 @@ func mergeCredentials(log func(...interface{}) error,
client ExtendedClient,
namespace string, podTemplate apiv1.PodTemplateSpec,
imageCreds registry.ImageCreds,
seenCreds map[string]registry.Credentials) {
imagePullSecretCache map[string]registry.Credentials) {
var images []image.Name
for _, container := range podTemplate.Spec.InitContainers {
r, err := image.ParseRef(container.Image)
@@ -67,15 +67,16 @@ func mergeCredentials(log func(...interface{}) error,
}

for _, name := range imagePullSecrets {
if seen, ok := seenCreds[name]; ok {
namespacedSecretName := fmt.Sprintf("%s/%s", namespace, name)
if seen, ok := imagePullSecretCache[namespacedSecretName]; ok {
creds.Merge(seen)
continue
}

secret, err := client.CoreV1().Secrets(namespace).Get(name, meta_v1.GetOptions{})
if err != nil {
log("err", errors.Wrapf(err, "getting secret %q from namespace %q", name, namespace))
seenCreds[name] = registry.NoCredentials()
imagePullSecretCache[namespacedSecretName] = registry.NoCredentials()
continue
}

@@ -90,24 +91,24 @@ func mergeCredentials(log func(...interface{}) error,
decoded, ok = secret.Data[apiv1.DockerConfigJsonKey]
default:
log("skip", "unknown type", "secret", namespace+"/"+secret.Name, "type", secret.Type)
seenCreds[name] = registry.NoCredentials()
imagePullSecretCache[namespacedSecretName] = registry.NoCredentials()
continue
}

if !ok {
log("err", errors.Wrapf(err, "retrieving pod secret %q", secret.Name))
seenCreds[name] = registry.NoCredentials()
imagePullSecretCache[namespacedSecretName] = registry.NoCredentials()
continue
}

// Parse secret
crd, err := registry.ParseCredentials(fmt.Sprintf("%s:secret/%s", namespace, name), decoded)
if err != nil {
log("err", err.Error())
seenCreds[name] = registry.NoCredentials()
imagePullSecretCache[namespacedSecretName] = registry.NoCredentials()
continue
}
seenCreds[name] = crd
imagePullSecretCache[namespacedSecretName] = crd

// Merge into the credentials for this PodSpec
creds.Merge(crd)
@@ -124,7 +125,7 @@ func (c *Cluster) ImagesToFetch() registry.ImageCreds {
allImageCreds := make(registry.ImageCreds)
ctx := context.Background()

seenCreds := make(map[string]registry.Credentials)
imagePullSecretCache := make(map[string]registry.Credentials)
workloads, err := c.allWorkfloads(ctx, "")
if err != nil {
c.logger.Log("err", errors.Wrap(err, "getting namespaces"))
@@ -135,7 +136,7 @@ func (c *Cluster) ImagesToFetch() registry.ImageCreds {
for id, workload := range workloads {
ns, kind, _ := id.Components()
logger := log.With(c.logger, "resource", resource.MakeID(ns, kind, workload.GetName()))
mergeCredentials(logger.Log, c.includeImage, c.client, ns, workload.podTemplate, imageCreds, seenCreds)
mergeCredentials(logger.Log, c.includeImage, c.client, ns, workload.podTemplate, imageCreds, imagePullSecretCache)
}

// Merge creds

0 comments on commit 71a6663

Please sign in to comment.