diff --git a/source/Calamari/Kubernetes/Integration/AwsCli.cs b/source/Calamari/Kubernetes/Integration/AwsCli.cs index d15b679f3a..29f9cf516c 100644 --- a/source/Calamari/Kubernetes/Integration/AwsCli.cs +++ b/source/Calamari/Kubernetes/Integration/AwsCli.cs @@ -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; @@ -16,8 +17,9 @@ public AwsCli( ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, - Dictionary environmentVars) - : base(log, commandLineRunner, workingDirectory, environmentVars) + Dictionary environmentVars, + IVariables variables) + : base(log, commandLineRunner, workingDirectory, environmentVars, variables) { } diff --git a/source/Calamari/Kubernetes/Integration/AzureCli.cs b/source/Calamari/Kubernetes/Integration/AzureCli.cs index b3c28b8621..6485f2140e 100644 --- a/source/Calamari/Kubernetes/Integration/AzureCli.cs +++ b/source/Calamari/Kubernetes/Integration/AzureCli.cs @@ -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 environmentVars) - : base(log, commandLineRunner, workingDirectory, environmentVars) + public AzureCli(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary environmentVars, IVariables variables) + : base(log, commandLineRunner, workingDirectory, environmentVars, variables) { } diff --git a/source/Calamari/Kubernetes/Integration/CommandLineTool.cs b/source/Calamari/Kubernetes/Integration/CommandLineTool.cs index ec14a76bcd..16d04f1b55 100644 --- a/source/Calamari/Kubernetes/Integration/CommandLineTool.cs +++ b/source/Calamari/Kubernetes/Integration/CommandLineTool.cs @@ -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 { @@ -10,6 +11,7 @@ public class CommandLineTool protected readonly ILog log; protected string workingDirectory; protected Dictionary environmentVars; + protected readonly IVariables variables; readonly ICommandLineRunner commandLineRunner; @@ -17,16 +19,23 @@ protected CommandLineTool( ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, - Dictionary environmentVars) + Dictionary 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); + } + protected CommandResult ExecuteCommandAndLogOutput(CommandLineInvocation invocation) => ExecuteCommandAndLogOutput(invocation, false); @@ -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; } @@ -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; } diff --git a/source/Calamari/Kubernetes/Integration/GCloud.cs b/source/Calamari/Kubernetes/Integration/GCloud.cs index eba19dfde5..725e293787 100644 --- a/source/Calamari/Kubernetes/Integration/GCloud.cs +++ b/source/Calamari/Kubernetes/Integration/GCloud.cs @@ -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 environmentVars) - : base(log, commandLineRunner, workingDirectory, environmentVars) + public GCloud(ILog log, ICommandLineRunner commandLineRunner, ICalamariFileSystem fileSystem, string workingDirectory, Dictionary environmentVars, IVariables variables) + : base(log, commandLineRunner, workingDirectory, environmentVars, variables) { this.fileSystem = fileSystem; } diff --git a/source/Calamari/Kubernetes/Integration/GkeGcloudAuthPlugin.cs b/source/Calamari/Kubernetes/Integration/GkeGcloudAuthPlugin.cs index 3f812c5dd3..60df85727b 100644 --- a/source/Calamari/Kubernetes/Integration/GkeGcloudAuthPlugin.cs +++ b/source/Calamari/Kubernetes/Integration/GkeGcloudAuthPlugin.cs @@ -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 environmentVars) - : base(log, commandLineRunner, workingDirectory, environmentVars) + public GkeGcloudAuthPlugin(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary environmentVars, IVariables variables) + : base(log, commandLineRunner, workingDirectory, environmentVars, variables) { } diff --git a/source/Calamari/Kubernetes/Integration/HelmCli.cs b/source/Calamari/Kubernetes/Integration/HelmCli.cs index 740de5f9b8..ed66704f48 100644 --- a/source/Calamari/Kubernetes/Integration/HelmCli.cs +++ b/source/Calamari/Kubernetes/Integration/HelmCli.cs @@ -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(); } @@ -116,7 +114,7 @@ public string GetManifest(string releaseName, int revisionNumber) return result.Output.MergeInfoLogs(); } - + public CommandResult Upgrade(string releaseName, string packagePath, IEnumerable upgradeArgs) { var buildArgs = new List diff --git a/source/Calamari/Kubernetes/Integration/Kubectl.cs b/source/Calamari/Kubernetes/Integration/Kubectl.cs index a6e11ce3d4..3f12c97c6e 100644 --- a/source/Calamari/Kubernetes/Integration/Kubectl.cs +++ b/source/Calamari/Kubernetes/Integration/Kubectl.cs @@ -31,7 +31,7 @@ public Kubectl(IVariables variables, ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, - Dictionary environmentVariables) : base(log, commandLineRunner, workingDirectory, environmentVariables) + Dictionary environmentVariables) : base(log, commandLineRunner, workingDirectory, environmentVariables, variables) { customKubectlExecutable = variables.Get("Octopus.Action.Kubernetes.CustomKubectlExecutable"); } diff --git a/source/Calamari/Kubernetes/Integration/Kubelogin.cs b/source/Calamari/Kubernetes/Integration/Kubelogin.cs index 5da2cc2f19..149b873d9f 100644 --- a/source/Calamari/Kubernetes/Integration/Kubelogin.cs +++ b/source/Calamari/Kubernetes/Integration/Kubelogin.cs @@ -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 environmentVars) - : base(log, commandLineRunner, workingDirectory, environmentVars) + public KubeLogin(ILog log, ICommandLineRunner commandLineRunner, string workingDirectory, Dictionary environmentVars, IVariables variables) + : base(log, commandLineRunner, workingDirectory, environmentVars, variables) { } diff --git a/source/Calamari/Kubernetes/SetupKubectlAuthentication.cs b/source/Calamari/Kubernetes/SetupKubectlAuthentication.cs index b5605c0189..907fd757d6 100644 --- a/source/Calamari/Kubernetes/SetupKubectlAuthentication.cs +++ b/source/Calamari/Kubernetes/SetupKubectlAuthentication.cs @@ -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, @@ -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); } @@ -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); diff --git a/source/Calamari/Kubernetes/SpecialVariables.cs b/source/Calamari/Kubernetes/SpecialVariables.cs index c589bcb98a..a1fbd0da70 100644 --- a/source/Calamari/Kubernetes/SpecialVariables.cs +++ b/source/Calamari/Kubernetes/SpecialVariables.cs @@ -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";