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

Commit

Permalink
Merge pull request #2539 from fluxcd/issue/2537-missing-namespaces
Browse files Browse the repository at this point in the history
Restore missing namespaces to workload IDs
  • Loading branch information
squaremo authored Oct 22, 2019
2 parents c0b0dca + 1dbeff3 commit 2f6bdbc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
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

0 comments on commit 2f6bdbc

Please sign in to comment.