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

Restore missing namespaces to workload IDs #2539

Merged
merged 1 commit into from
Oct 22, 2019
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
2 changes: 1 addition & 1 deletion pkg/cluster/kubernetes/images.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func (c *Cluster) ImagesToFetch() registry.ImageCreds {

imageCreds := make(registry.ImageCreds)
for _, workload := range workloads {
logger := log.With(c.logger, "resource", resource.MakeID(ns, kind, workload.GetName()))
logger := log.With(c.logger, "resource", resource.MakeID(workload.GetNamespace(), kind, workload.GetName()))
mergeCredentials(logger.Log, c.includeImage, c.client, ns, workload.podTemplate, imageCreds, seenCreds)
}

Expand Down
22 changes: 15 additions & 7 deletions pkg/cluster/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,18 +167,26 @@ func (c *Cluster) SomeWorkloads(ctx context.Context, ids []resource.ID) (res []c

// AllWorkloads returns all workloads in allowed namespaces matching the criteria; that is, in
// the namespace (or any namespace if that argument is empty)
func (c *Cluster) AllWorkloads(ctx context.Context, namespace string) (res []cluster.Workload, err error) {
namespaces, err := c.getAllowedAndExistingNamespaces(ctx)
func (c *Cluster) AllWorkloads(ctx context.Context, restrictToNamespace string) (res []cluster.Workload, err error) {
allowedNamespaces, err := c.getAllowedAndExistingNamespaces(ctx)
if err != nil {
return nil, errors.Wrap(err, "getting namespaces")
}
// Those are the allowed namespaces (possibly just [<all of them>];
// now intersect with the restriction requested, if any.
namespaces := allowedNamespaces
if restrictToNamespace != "" {
namespaces = nil
for _, ns := range allowedNamespaces {
if ns == meta_v1.NamespaceAll || ns == restrictToNamespace {
namespaces = []string{restrictToNamespace}
break
}
}
}

var allworkloads []cluster.Workload
for _, ns := range namespaces {
if namespace != "" && ns != namespace {
continue
}

for kind, resourceKind := range resourceKinds {
workloads, err := resourceKind.getWorkloads(ctx, c, ns)
if err != nil {
Expand All @@ -197,7 +205,7 @@ func (c *Cluster) AllWorkloads(ctx context.Context, namespace string) (res []clu

for _, workload := range workloads {
if !isAddon(workload) {
id := resource.MakeID(ns, kind, workload.GetName())
id := resource.MakeID(workload.GetNamespace(), kind, workload.GetName())
c.muSyncErrors.RLock()
workload.syncError = c.syncErrors[id]
c.muSyncErrors.RUnlock()
Expand Down