-
Notifications
You must be signed in to change notification settings - Fork 111
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
Report helm manifests for live status #1368
Open
eddymoulton
wants to merge
4
commits into
main
Choose a base branch
from
em/report-helm-manifests-for-live-status
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
source/Calamari.Tests/KubernetesFixtures/Integration/HelmCliTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Calamari.Common.Features.Processes; | ||
using Calamari.Common.Plumbing.FileSystem; | ||
using Calamari.Common.Plumbing.Variables; | ||
using Calamari.Kubernetes; | ||
using Calamari.Kubernetes.Integration; | ||
using Calamari.Testing.Helpers; | ||
using FluentAssertions; | ||
using FluentAssertions.Execution; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Calamari.Tests.KubernetesFixtures.Integration | ||
{ | ||
[TestFixture] | ||
public class HelmCliTests | ||
{ | ||
[Test] | ||
public void ExecutesWithBuiltInArguments() | ||
{ | ||
const string expectedExecutable = "some-exe"; | ||
const string expectedNamespace = "some-namespace"; | ||
const string expectedArgument = "additional-arg"; | ||
|
||
var (helm, commandLineRunner, _) = GetHelmCli(); | ||
CommandLineInvocation actual = null; | ||
commandLineRunner.When(x => x.Execute(Arg.Any<CommandLineInvocation>())).Do(x => actual = x.Arg<CommandLineInvocation>()); | ||
|
||
helm.WithExecutable(expectedExecutable); | ||
helm.WithNamespace(expectedNamespace); | ||
|
||
helm.ExecuteCommandAndReturnOutput(expectedArgument); | ||
|
||
using (var _ = new AssertionScope()) | ||
{ | ||
actual.Executable.Should().BeEquivalentTo(expectedExecutable); | ||
actual.Arguments.Should().BeEquivalentTo($"--namespace {expectedNamespace} {expectedArgument}"); | ||
} | ||
} | ||
|
||
[Test] | ||
public void UsesCustomHelmExecutable() | ||
{ | ||
var (helm, commandLineRunner, _) = GetHelmCli(); | ||
CommandLineInvocation actual = null; | ||
commandLineRunner.When(x => x.Execute(Arg.Any<CommandLineInvocation>())).Do(x => actual = x.Arg<CommandLineInvocation>()); | ||
|
||
const string expectedExecutable = "my-custom-exe"; | ||
|
||
helm.WithExecutable(new CalamariVariables | ||
{ | ||
{ SpecialVariables.Helm.CustomHelmExecutable, expectedExecutable } | ||
}); | ||
|
||
helm.ExecuteCommandAndReturnOutput(); | ||
|
||
actual.Executable.Should().BeEquivalentTo(expectedExecutable); | ||
} | ||
|
||
[Test] | ||
public void UsesCustomHelmExecutableFromPackage() | ||
{ | ||
var (helm, commandLineRunner, workingDirectory) = GetHelmCli(); | ||
CommandLineInvocation actual = null; | ||
commandLineRunner.When(x => x.Execute(Arg.Any<CommandLineInvocation>())).Do(x => actual = x.Arg<CommandLineInvocation>()); | ||
|
||
const string expectedExecutable = "my-custom-exe"; | ||
const string expectedPackageKey = "helm-exe-package"; | ||
var expectedExecutablePath = Path.Combine(workingDirectory.DirectoryPath, SpecialVariables.Helm.Packages.CustomHelmExePackageKey, expectedExecutable); | ||
|
||
helm.WithExecutable(new CalamariVariables | ||
{ | ||
{ SpecialVariables.Helm.CustomHelmExecutable, expectedExecutable }, | ||
{ SpecialVariables.Helm.Packages.CustomHelmExePackageKey, expectedPackageKey }, | ||
{ $"{PackageVariables.PackageCollection}[{expectedPackageKey}]", SpecialVariables.Helm.Packages.CustomHelmExePackageKey } | ||
}); | ||
|
||
helm.ExecuteCommandAndReturnOutput(); | ||
|
||
actual.Executable.Should().BeEquivalentTo(expectedExecutablePath); | ||
} | ||
|
||
[Test] | ||
public void AlwaysUsesCustomHelmExecutableWhenRooted() | ||
{ | ||
var (helm, commandLineRunner, _) = GetHelmCli(); | ||
CommandLineInvocation actual = null; | ||
commandLineRunner.When(x => x.Execute(Arg.Any<CommandLineInvocation>())).Do(x => actual = x.Arg<CommandLineInvocation>()); | ||
|
||
const string expectedExecutable = "/my-custom-exe"; | ||
const string expectedPackageKey = "helm-exe-package"; | ||
|
||
helm.WithExecutable(new CalamariVariables | ||
{ | ||
{ SpecialVariables.Helm.CustomHelmExecutable, expectedExecutable }, | ||
{ SpecialVariables.Helm.Packages.CustomHelmExePackageKey, expectedPackageKey }, | ||
{ $"{PackageVariables.PackageCollection}[{expectedPackageKey}]", SpecialVariables.Helm.Packages.CustomHelmExePackageKey } | ||
}); | ||
|
||
helm.ExecuteCommandAndReturnOutput(); | ||
|
||
actual.Executable.Should().BeEquivalentTo(expectedExecutable); | ||
} | ||
|
||
static (HelmCli, ICommandLineRunner, TemporaryDirectory) GetHelmCli() | ||
{ | ||
var memoryLog = new InMemoryLog(); | ||
var commandLineRunner = Substitute.For<ICommandLineRunner>(); | ||
var workingDirectory = TemporaryDirectory.Create(); | ||
var helm = new HelmCli(memoryLog, commandLineRunner, workingDirectory.DirectoryPath, new Dictionary<string, string>()); | ||
|
||
return (helm, commandLineRunner, workingDirectory); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
source/Calamari/Kubernetes/Conventions/ReportHelmManifestConvention.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using Calamari.Common.Commands; | ||
using Calamari.Common.Features.Processes; | ||
using Calamari.Common.FeatureToggles; | ||
using Calamari.Common.Plumbing.Logging; | ||
using Calamari.Deployment.Conventions; | ||
using Calamari.Kubernetes.Integration; | ||
|
||
namespace Calamari.Kubernetes.Conventions | ||
{ | ||
public class ReportHelmManifestConvention : IInstallConvention | ||
{ | ||
readonly ILog log; | ||
readonly ICommandLineRunner commandLineRunner; | ||
readonly IManifestReporter manifestReporter; | ||
|
||
public ReportHelmManifestConvention(ILog log, | ||
ICommandLineRunner commandLineRunner, | ||
IManifestReporter manifestReporter) | ||
{ | ||
this.log = log; | ||
this.commandLineRunner = commandLineRunner; | ||
this.manifestReporter = manifestReporter; | ||
} | ||
|
||
public void Install(RunningDeployment deployment) | ||
{ | ||
if (!FeatureToggle.KubernetesLiveObjectStatusFeatureToggle.IsEnabled(deployment.Variables) | ||
&& !OctopusFeatureToggles.KubernetesObjectManifestInspectionFeatureToggle.IsEnabled(deployment.Variables)) | ||
return; | ||
|
||
var releaseName = deployment.Variables.Get("ReleaseName"); | ||
|
||
var helm = new HelmCli(log, commandLineRunner, deployment.CurrentDirectory, deployment.EnvironmentVariables) | ||
.WithExecutable(deployment.Variables) | ||
.WithNamespace(deployment.Variables.Get(SpecialVariables.Helm.Namespace)); | ||
|
||
var manifest = helm.GetManifest(releaseName); | ||
manifestReporter.ReportManifestApplied(manifest); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are your thoughts on having the newline character depend on the OS where Calamari is running?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have a lot of them - there are existing examples of joining these log messages with
Environment.NewLine
so my assumption is that it works fine in all cases we're using it at the moment.Sticking with Unix newlines might be a good idea to be consistent - perhaps there is a bug we just haven't seen come up yet?
By the same token, perhaps there is no bug because windows people tend to have everything on windows so we're just getting lucky...
I don't have any good answers aside from sticking with the status quo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, status quo is good