Skip to content

Commit

Permalink
Better option
Browse files Browse the repository at this point in the history
  • Loading branch information
Yihao committed Aug 29, 2023
1 parent 9e8e165 commit 59cea76
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,14 @@ public async Task<bool> Execute(RunningDeployment deployment, Func<ResourceIdent
var globs = variables.GetPaths(SpecialVariables.CustomResourceYamlFileName);
if (globs.IsNullOrEmpty())
return true;
var defaultNamespace = variables.Get(SpecialVariables.Namespace, "default");
// When the namespace on a target was set and then cleared, it's going to be "" instead of null
if (string.IsNullOrEmpty(defaultNamespace))
{
defaultNamespace = "default";
}
var directories = GroupFilesIntoDirectories(deployment, globs, variables);
var resources = new HashSet<Resource>();
foreach (var directory in directories)
{
var res = ApplyBatchAndReturnResources(directory).ToList();
if (appliedResourcesCallback != null)
{
await appliedResourcesCallback(res.Select(r => r.ToResourceIdentifier(defaultNamespace)).ToArray());
await appliedResourcesCallback(res.Select(r => r.ToResourceIdentifier()).ToArray());
}
resources.UnionWith(res);
}
Expand Down Expand Up @@ -239,9 +233,9 @@ private class Resource
public string Kind { get; set; }
public ResourceMetadata Metadata { get; set; }

public ResourceIdentifier ToResourceIdentifier(string defaultNamespace = null)
public ResourceIdentifier ToResourceIdentifier()
{
return new ResourceIdentifier(Kind, Metadata.Name, Metadata.Namespace ?? defaultNamespace);
return new ResourceIdentifier(Kind, Metadata.Name, Metadata.Namespace);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Amazon.CloudFormation;
using Calamari.Kubernetes.Integration;
using Calamari.Kubernetes.ResourceStatus.Resources;
using Octopus.CoreUtilities.Extensions;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class ResourceStatusCheckTask
// Filter out cluster-wide resources
definedResources = definedResources
.Where(resource => !nonNamespacedDefinedResources.Contains(new ResourceIdentifier(resource.Kind, resource.Name, string.Empty)))
.Where(resource => !string.IsNullOrEmpty(resource.Namespace) && !nonNamespacedDefinedResources.Contains(new ResourceIdentifier(resource.Kind, resource.Name, string.Empty)))
.ToArray();
var resourceStatuses = definedResourceStatuses
Expand Down

0 comments on commit 59cea76

Please sign in to comment.