Skip to content
Open
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
6 changes: 4 additions & 2 deletions source/Calamari/Kubernetes/Integration/AwsCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Calamari.Common.Features.Processes;
using Calamari.Common.Plumbing;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Octopus.Versioning.Semver;
Expand All @@ -16,8 +17,9 @@ public AwsCli(
ILog log,
ICommandLineRunner commandLineRunner,
string workingDirectory,
Dictionary<string, string> environmentVars)
: base(log, commandLineRunner, workingDirectory, environmentVars)
Dictionary<string, string> environmentVars,
IVariables variables)
: base(log, commandLineRunner, workingDirectory, environmentVars, variables)
{
}

Expand Down
5 changes: 3 additions & 2 deletions source/Calamari/Kubernetes/Integration/AzureCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
using Calamari.Common.Plumbing;
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;

namespace Calamari.Kubernetes.Integration
{
public class AzureCli : CommandLineTool
{
public AzureCli(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary<string, string> environmentVars)
: base(log, commandLineRunner, workingDirectory, environmentVars)
public AzureCli(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary<string, string> environmentVars, IVariables variables)
: base(log, commandLineRunner, workingDirectory, environmentVars, variables)
{
}

Expand Down
26 changes: 22 additions & 4 deletions source/Calamari/Kubernetes/Integration/CommandLineTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using Calamari.Common.Features.Processes;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;

namespace Calamari.Kubernetes.Integration
{
Expand All @@ -10,23 +11,31 @@ public class CommandLineTool
protected readonly ILog log;
protected string workingDirectory;
protected Dictionary<string, string> environmentVars;
protected readonly IVariables variables;

readonly ICommandLineRunner commandLineRunner;

protected CommandLineTool(
ILog log,
ICommandLineRunner commandLineRunner,
string workingDirectory,
Dictionary<string, string> environmentVars)
Dictionary<string, string> environmentVars,
IVariables variables)
{
this.log = log;
this.commandLineRunner = commandLineRunner;
this.workingDirectory = workingDirectory;
this.environmentVars = environmentVars;
this.variables = variables;
}

public string ExecutableLocation { get; protected set; }

protected virtual bool ShouldLogSuccessfulOutputAsInfo()
{
return variables.GetFlag(SpecialVariables.VerboseOutput);
}
Comment on lines +34 to +37
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable name and the result don't match in language.
If I set Octopus.Action.Kubernetes.VerboseOutput to true I end up with info output?


protected CommandResult ExecuteCommandAndLogOutput(CommandLineInvocation invocation)
=> ExecuteCommandAndLogOutput(invocation, false);

Expand All @@ -52,7 +61,8 @@ CommandResult ExecuteCommandAndLogOutput(CommandLineInvocation invocation, bool

var result = commandLineRunner.Execute(invocation);

LogCapturedOutput(result, captureCommandOutput, logOutputAsVerbose);
var logSuccessAsInfo = ShouldLogSuccessfulOutputAsInfo();
LogCapturedOutput(result, captureCommandOutput, logOutputAsVerbose, logSuccessAsInfo);

return result;
}
Expand All @@ -62,13 +72,21 @@ void LogCommandText(CommandLineInvocation invocation)
log.Verbose(invocation.ToString());
}

void LogCapturedOutput(CommandResult result, CaptureCommandOutput captureCommandOutput, bool logOutputAsVerbose)
void LogCapturedOutput(CommandResult result, CaptureCommandOutput captureCommandOutput, bool logOutputAsVerbose, bool logSuccessAsInfo)
{
foreach (var message in captureCommandOutput.Messages)
{
if (result.ExitCode == 0)
{
log.Verbose(message.Text);
// When logSuccessAsInfo is true, log successful output at Info level
if (logSuccessAsInfo)
{
log.Info(message.Text);
}
else
{
log.Verbose(message.Text);
}
continue;
}

Expand Down
7 changes: 4 additions & 3 deletions source/Calamari/Kubernetes/Integration/GCloud.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
using Calamari.Common.Plumbing;
using Calamari.Common.Plumbing.FileSystem;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;

namespace Calamari.Kubernetes.Integration
{
public class GCloud : CommandLineTool
{
private readonly ICalamariFileSystem fileSystem;
readonly ICalamariFileSystem fileSystem;

public GCloud(ILog log, ICommandLineRunner commandLineRunner, ICalamariFileSystem fileSystem, string workingDirectory, Dictionary<string, string> environmentVars)
: base(log, commandLineRunner, workingDirectory, environmentVars)
public GCloud(ILog log, ICommandLineRunner commandLineRunner, ICalamariFileSystem fileSystem, string workingDirectory, Dictionary<string, string> environmentVars, IVariables variables)
: base(log, commandLineRunner, workingDirectory, environmentVars, variables)
{
this.fileSystem = fileSystem;
}
Expand Down
5 changes: 3 additions & 2 deletions source/Calamari/Kubernetes/Integration/GkeGcloudAuthPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
using Calamari.Common.Features.Processes;
using Calamari.Common.Plumbing;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;

namespace Calamari.Kubernetes.Integration
{
public class GkeGcloudAuthPlugin : CommandLineTool
{
public GkeGcloudAuthPlugin(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary<string, string> environmentVars)
: base(log, commandLineRunner, workingDirectory, environmentVars)
public GkeGcloudAuthPlugin(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary<string, string> environmentVars, IVariables variables)
: base(log, commandLineRunner, workingDirectory, environmentVars, variables)
{
}

Expand Down
6 changes: 2 additions & 4 deletions source/Calamari/Kubernetes/Integration/HelmCli.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ public class HelmCli : CommandLineTool
{
readonly ICommandLineRunner commandLineRunner;
readonly ICalamariFileSystem fileSystem;
readonly IVariables variables;
bool isCustomExecutable;

public HelmCli(ILog log, ICommandLineRunner commandLineRunner, RunningDeployment runningDeployment, ICalamariFileSystem fileSystem)
: base(log, commandLineRunner, runningDeployment.CurrentDirectory, runningDeployment.EnvironmentVariables)
: base(log, commandLineRunner, runningDeployment.CurrentDirectory, runningDeployment.EnvironmentVariables, runningDeployment.Variables)
{
this.commandLineRunner = commandLineRunner;
this.fileSystem = fileSystem;
variables = runningDeployment.Variables;
ExecutableLocation = SetExecutable();
}

Expand Down Expand Up @@ -116,7 +114,7 @@ public string GetManifest(string releaseName, int revisionNumber)

return result.Output.MergeInfoLogs();
}

public CommandResult Upgrade(string releaseName, string packagePath, IEnumerable<string> upgradeArgs)
{
var buildArgs = new List<string>
Expand Down
2 changes: 1 addition & 1 deletion source/Calamari/Kubernetes/Integration/Kubectl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public Kubectl(IVariables variables,
ILog log,
ICommandLineRunner commandLineRunner,
string workingDirectory,
Dictionary<string, string> environmentVariables) : base(log, commandLineRunner, workingDirectory, environmentVariables)
Dictionary<string, string> environmentVariables) : base(log, commandLineRunner, workingDirectory, environmentVariables, variables)
{
customKubectlExecutable = variables.Get("Octopus.Action.Kubernetes.CustomKubectlExecutable");
}
Expand Down
5 changes: 3 additions & 2 deletions source/Calamari/Kubernetes/Integration/Kubelogin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
using Calamari.Common.Features.Processes;
using Calamari.Common.Plumbing;
using Calamari.Common.Plumbing.Logging;
using Calamari.Common.Plumbing.Variables;

namespace Calamari.Kubernetes.Integration
{
public class KubeLogin : CommandLineTool
{
public KubeLogin(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary<string, string> environmentVars)
: base(log, commandLineRunner, workingDirectory, environmentVars)
public KubeLogin(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary<string, string> environmentVars, IVariables variables)
: base(log, commandLineRunner, workingDirectory, environmentVars, variables)
{
}

Expand Down
11 changes: 6 additions & 5 deletions source/Calamari/Kubernetes/SetupKubectlAuthentication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ void SetupGCloudContext(string @namespace)
commandLineRunner,
fileSystem,
workingDirectory,
environmentVars);
var gkeGcloudAuthPlugin = new GkeGcloudAuthPlugin(log, commandLineRunner, workingDirectory, environmentVars);
environmentVars,
variables);
var gkeGcloudAuthPlugin = new GkeGcloudAuthPlugin(log, commandLineRunner, workingDirectory, environmentVars, variables);
var gcloudAuth = new GoogleKubernetesEngineAuth(gcloudCli,
gkeGcloudAuthPlugin,
kubectl,
Expand All @@ -186,8 +187,8 @@ void SetupGCloudContext(string @namespace)

void SetupAzureContext(string @namespace, string kubeConfig)
{
var azureCli = new AzureCli(log, commandLineRunner, workingDirectory, environmentVars);
var kubeloginCli = new KubeLogin(log, commandLineRunner, workingDirectory, environmentVars);
var azureCli = new AzureCli(log, commandLineRunner, workingDirectory, environmentVars, variables);
var kubeloginCli = new KubeLogin(log, commandLineRunner, workingDirectory, environmentVars, variables);
var azureAuth = new AzureKubernetesServicesAuth(azureCli, kubectl, kubeloginCli, variables);
azureAuth.Configure(@namespace, kubeConfig);
}
Expand Down Expand Up @@ -317,7 +318,7 @@ void SetupContextForUsernamePassword(string user)

void SetupAwsContext(string @namespace, string clusterUrl, string user)
{
var awsCli = new AwsCli(log, commandLineRunner, workingDirectory, environmentVars);
var awsCli = new AwsCli(log, commandLineRunner, workingDirectory, environmentVars, variables);
var awsAuth = new AwsCliAuth(awsCli, kubectl, variables, environmentVars, log);

awsAuth.Configure(@namespace, clusterUrl, user);
Expand Down
1 change: 1 addition & 0 deletions source/Calamari/Kubernetes/SpecialVariables.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public static class SpecialVariables
public const string OutputKubeConfig = "Octopus.Action.Kubernetes.OutputKubeConfig";
public const string CustomKubectlExecutable = "Octopus.Action.Kubernetes.CustomKubectlExecutable";
public const string ResourceStatusCheck = "Octopus.Action.Kubernetes.ResourceStatusCheck";
public const string VerboseOutput = "Octopus.Action.Kubernetes.VerboseOutput";
public const string DeploymentStyle = "Octopus.Action.KubernetesContainers.DeploymentStyle";
public const string DeploymentWait = "Octopus.Action.KubernetesContainers.DeploymentWait";
public const string CustomResourceYamlFileName = "Octopus.Action.KubernetesContainers.CustomResourceYamlFileName";
Expand Down