Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not attempt to retrieve the applied Helm manifest when ResourceStatusCheck is disabled #1402

Merged
merged 2 commits into from
Dec 10, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading.Tasks;
using Calamari.Common.Commands;
using Calamari.Common.Features.Processes;
using Calamari.Common.FeatureToggles;
using Calamari.Common.Plumbing.Logging;
using Calamari.Kubernetes.Integration;
using Calamari.Kubernetes.ResourceStatus;
Expand Down Expand Up @@ -40,15 +41,22 @@ public async Task StartBackgroundMonitoringAndReporting(
{
await Task.Run(async () =>
{
var manifest = await PollForManifest(deployment, helmCli, releaseName, revisionNumber);
var resourceStatusCheckIsEnabled = deployment.Variables.GetFlag(SpecialVariables.ResourceStatusCheck);

if (resourceStatusCheckIsEnabled
|| FeatureToggle.KubernetesLiveObjectStatusFeatureToggle.IsEnabled(deployment.Variables)
|| OctopusFeatureToggles.KubernetesObjectManifestInspectionFeatureToggle.IsEnabled(deployment.Variables))
{
var manifest = await PollForManifest(deployment, helmCli, releaseName, revisionNumber);

//report the manifest has been applied
manifestReporter.ReportManifestApplied(manifest);
//report the manifest has been applied
manifestReporter.ReportManifestApplied(manifest);

//if resource status (KOS) is enabled, parse the manifest and start monitored the resources
if (deployment.Variables.GetFlag(SpecialVariables.ResourceStatusCheck))
{
await ParseManifestAndMonitorResourceStatuses(deployment, manifest, cancellationToken);
//if resource status (KOS) is enabled, parse the manifest and start monitoring the resources
if (resourceStatusCheckIsEnabled)
{
await ParseManifestAndMonitorResourceStatuses(deployment, manifest, cancellationToken);
}
}
},
cancellationToken);
Expand All @@ -63,8 +71,8 @@ async Task<string> PollForManifest(RunningDeployment deployment,
var timeout = GoDurationParser.TryParseDuration(deployment.Variables.Get(SpecialVariables.Helm.Timeout), out var timespan) ? timespan : TimeSpan.FromMinutes(5);
ct.CancelAfter(timeout);
string manifest = null;
log.Verbose($"Retrieving manifest for {releaseName}, revision {revisionNumber}.");
while (!ct.IsCancellationRequested)
{
try
{
manifest = helmCli.GetManifest(releaseName, revisionNumber);
Expand All @@ -73,15 +81,12 @@ async Task<string> PollForManifest(RunningDeployment deployment,
}
catch (CommandLineException)
{
log.Verbose("Helm manifest was not ready for retrieval. Retrying in 1s.");
log.Verbose($"Manifest could not be retrieved for {releaseName}, revision {revisionNumber}. Retrying in 1s.");
await Task.Delay(TimeSpan.FromSeconds(1), ct.Token);
}
}

if (string.IsNullOrWhiteSpace(manifest))
{
throw new CommandException("Failed to retrieve helm manifest in a timely manner");
}

return manifest;
}
Expand All @@ -101,6 +106,7 @@ async Task ParseManifestAndMonitorResourceStatuses(RunningDeployment deployment,
log.Warn("Could not parse manifest, resources will not be added to kubernetes object status");
continue;
}

var gvk = rootNode.ToResourceGroupVersionKind();

var metadataNode = rootNode.GetChildNode<YamlMappingNode>("metadata");
Expand All @@ -113,9 +119,7 @@ async Task ParseManifestAndMonitorResourceStatuses(RunningDeployment deployment,
//we aren't changing the manifest here, just changing where the kubectl looks for our resource.
//We also try and filter out known non-namespaced resources
if (string.IsNullOrWhiteSpace(@namespace) && !KubernetesApiResources.NonNamespacedKinds.Contains(gvk.Kind))
{
@namespace = deployment.Variables.Get(SpecialVariables.Helm.Namespace)?.Trim();
}

var resourceIdentifier = new ResourceIdentifier(gvk, name, @namespace);
resources.Add(resourceIdentifier);
Expand Down