Skip to content

Commit

Permalink
feat(): Allow deployment to kubernetes targets (#27)
Browse files Browse the repository at this point in the history
* set deployment target as enum and added k8s targets

* version bump

Co-authored-by: Vitor Moreira <[email protected]>
  • Loading branch information
vitorpmoreira and Vitor Moreira authored Feb 17, 2022
1 parent fce76d1 commit 7071174
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 28 deletions.
11 changes: 11 additions & 0 deletions src/Common/DeploymentTarget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Cmf.CustomerPortal.Sdk.Common
{
public enum DeploymentTarget
{
dockerswarm,
portainer,
KubernetesOnPremisesTarget,
OpenShiftOnPremisesTarget,
AzureKubernetesServiceTarget
}
}
2 changes: 1 addition & 1 deletion src/Common/Handlers/NewEnvironmentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public async Task Run(
string siteName,
string licenseName,
string deploymentPackageName,
string target,
DeploymentTarget target,
DirectoryInfo outputDir,
string[] replaceTokens,
bool interactive,
Expand Down
8 changes: 5 additions & 3 deletions src/Common/Services/EnvironmentDeploymentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ private void ProcessDeploymentMessage(string subject, MbMessage message)
}
}

private async Task ProcessEnvironmentDeployment(CustomerEnvironment environment, string target, DirectoryInfo outputPath)
private async Task ProcessEnvironmentDeployment(CustomerEnvironment environment, DeploymentTarget target, DirectoryInfo outputPath)
{
switch (target)
{
case "dockerswarm":
case DeploymentTarget.dockerswarm:
case DeploymentTarget.KubernetesOnPremisesTarget:
case DeploymentTarget.OpenShiftOnPremisesTarget:

// get the attachments of the current customer environment
GetAttachmentsForEntityInput input = new GetAttachmentsForEntityInput()
Expand Down Expand Up @@ -156,7 +158,7 @@ private async Task ProcessEnvironmentDeployment(CustomerEnvironment environment,

#endregion

public async Task Handle(bool interactive, CustomerEnvironment customerEnvironment, string deploymentTarget, DirectoryInfo outputDir)
public async Task Handle(bool interactive, CustomerEnvironment customerEnvironment, DeploymentTarget deploymentTarget, DirectoryInfo outputDir)
{
var messageBus = await _customerPortalClient.GetMessageBusTransport();
var subject = $"CE_DEPLOYMENT_{customerEnvironment.Id}";
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Services/IEnvironmentDeploymentHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Cmf.CustomerPortal.Sdk.Common.Services
{
public interface IEnvironmentDeploymentHandler
{
Task Handle(bool interactive, CustomerEnvironment customerEnvironment, string deploymentTarget, DirectoryInfo outputDir);
Task Handle(bool interactive, CustomerEnvironment customerEnvironment, DeploymentTarget deploymentTarget, DirectoryInfo outputDir);

Task WaitForEnvironmentsToBeTerminated(CustomerEnvironmentCollection customerEnvironments);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Common/Services/INewEnvironmentUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public interface INewEnvironmentUtilities
/// </summary>
/// <param name="abbreviatedDeploymentTarget"></param>
/// <returns></returns>
string GetDeploymentTargetValue(string abbreviatedDeploymentTarget);
string GetDeploymentTargetValue(DeploymentTarget abbreviatedDeploymentTarget);

/// <summary>
/// Gets all the other versions of the <paramref name="customerEnvironment"/> that are eligible to be terminated.
Expand Down
16 changes: 10 additions & 6 deletions src/Common/Services/NewEnvironmentUtilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,20 @@ public NewEnvironmentUtilities(ISession session, ICustomerPortalClient customerP
_customerPortalClient = customerPortalClient;
}

public string GetDeploymentTargetValue(string abbreviatedDeploymentTarget)
public string GetDeploymentTargetValue(DeploymentTarget abbreviatedDeploymentTarget)
{
switch (abbreviatedDeploymentTarget)
{
case "portainer":
return "PortainerV2Target";
case "dockerswarm":
return "DockerSwarmOnPremisesTarget";
case DeploymentTarget.dockerswarm:
return "DockerSwarmOnPremisesTarget";
case DeploymentTarget.portainer:
return "PortainerV2Target";
case DeploymentTarget.KubernetesOnPremisesTarget:
case DeploymentTarget.OpenShiftOnPremisesTarget:
case DeploymentTarget.AzureKubernetesServiceTarget:
return abbreviatedDeploymentTarget.ToString();
default:
throw new Exception($"Target parameter '{abbreviatedDeploymentTarget}' not recognized");
throw new Exception($"Target parameter '{abbreviatedDeploymentTarget}' not supported");
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/Console/DeployAgentCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cmf.CustomerPortal.Sdk.Common.Handlers;
using Cmf.CustomerPortal.Sdk.Common;
using Cmf.CustomerPortal.Sdk.Common.Handlers;
using Cmf.CustomerPortal.Sdk.Console.Base;
using Cmf.CustomerPortal.Sdk.Console.Extensions;
using Cmf.Foundation.Common.Licenses.Enums;
Expand Down Expand Up @@ -35,7 +36,8 @@ public async Task DeployHandler(bool verbose, string customerInfrastructureName,
// get new environment handler and run it
CreateSession(verbose);
NewEnvironmentHandler newEnvironmentHandler = ServiceLocator.Get<NewEnvironmentHandler>();
await newEnvironmentHandler.Run(name, parameters, (EnvironmentType)Enum.Parse(typeof(EnvironmentType), type), site, license, null, target, output,
await newEnvironmentHandler.Run(name, parameters, (EnvironmentType)Enum.Parse(typeof(EnvironmentType), type), site, license, null,
(DeploymentTarget)Enum.Parse(typeof(DeploymentTarget), target), output,
replaceTokens, interactive, customerInfrastructureName, description, templateName, false, true);
}
}
Expand Down
12 changes: 8 additions & 4 deletions src/Console/DeployCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,22 @@ public DeployCommand(string name, string description = null) : base(name, descri

protected override IEnumerable<IOptionExtension> ExtendWithRange()
{
List<IOptionExtension> extensions = new List<IOptionExtension>();
extensions.Add(new ReplaceTokensExtension());
extensions.Add(new CommonParametersExtension());
List<IOptionExtension> extensions = new List<IOptionExtension>
{
new ReplaceTokensExtension(),
new CommonParametersExtension()
};
return extensions;
}

public async Task DeployHandler(bool verbose, string customerInfrastructureName, string name, string description, FileInfo parameters, string type, string site, string license,
string package, string target, string templateName, DirectoryInfo output, string[] replaceTokens, bool interactive, bool terminateOtherVersions)
{
// get new environment handler and run it
CreateSession(verbose);
NewEnvironmentHandler newEnvironmentHandler = ServiceLocator.Get<NewEnvironmentHandler>();
await newEnvironmentHandler.Run(name, parameters, (EnvironmentType)Enum.Parse(typeof(EnvironmentType), type), site, license, package, target, output,
await newEnvironmentHandler.Run(name, parameters, (EnvironmentType)Enum.Parse(typeof(EnvironmentType), type), site, license, package,
(DeploymentTarget)Enum.Parse(typeof(DeploymentTarget), target), output,
replaceTokens, interactive, customerInfrastructureName, description, templateName, terminateOtherVersions, false);
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Console/Extensions/CommonParametersExtension.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using Cmf.CustomerPortal.Sdk.Common;
using Cmf.Foundation.Common.Licenses.Enums;
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.IO;
using System.Text;

namespace Cmf.CustomerPortal.Sdk.Console.Extensions
{
Expand Down Expand Up @@ -34,8 +32,9 @@ public void Use(Command command)
{
IsRequired = true
});
var targetArgument = new Argument<string>().FromAmong("portainer", "dockerswarm");
targetArgument.SetDefaultValue("dockerswarm");

var targetArgument = new Argument<string>().FromAmong(Enum.GetNames(typeof(DeploymentTarget)));
targetArgument.SetDefaultValue(DeploymentTarget.dockerswarm.ToString());
command.Add(new Option<string>(new[] { "--target", "-trg", }, Resources.DEPLOYMENT_TARGET_HELP)
{
Argument = targetArgument,
Expand Down
4 changes: 2 additions & 2 deletions src/Powershell/Extensions/CommonParametersExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public CommonParametersExtension()
CreateRuntimeParameter("Name", Resources.DEPLOYMENT_NAME_HELP, typeof(string));
CreateRuntimeParameter("Description", Resources.DEPLOYMENT_DESCRIPTION_HELP, typeof(string));
CreateRuntimeParameter("ParametersPath", Resources.DEPLOYMENT_PARAMETERSPATH_HELP, typeof(FileInfo));
CreateRuntimeParameter("EnvironmentType", Resources.DEPLOYMENT_ENVIRONMENTTYPE_HELP, typeof(EnvironmentType),defaultValue: EnvironmentType.Development);
CreateRuntimeParameter("EnvironmentType", Resources.DEPLOYMENT_ENVIRONMENTTYPE_HELP, typeof(EnvironmentType), defaultValue: EnvironmentType.Development);
CreateRuntimeParameter("LicenseName", Resources.DEPLOYMENT_LICENSE_HELP, typeof(string), true);
CreateRuntimeParameter("DeploymentTargetName", Resources.DEPLOYMENT_PACKAGE_HELP, typeof(string), true);
CreateRuntimeParameter("DeploymentTargetName", Resources.DEPLOYMENT_PACKAGE_HELP, typeof(DeploymentTarget), mandatory: true);
CreateRuntimeParameter("TemplateName", Resources.INFRASTRUCTURE_EXISTING_ENVIRONMENT_TEMPLATE_NAME_HELP, typeof(string));
CreateRuntimeParameter("OutputDir", Resources.DEPLOYMENT_OUTPUTDIR_HELP, typeof(DirectoryInfo));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Powershell/NewEnvironment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ protected async override Task ProcessRecordAsync()
NewEnvironmentHandler newEnvironmentHandler = ServiceLocator.Get<NewEnvironmentHandler>();
await newEnvironmentHandler.Run((string)CommonParametersExtension.GetValue("Name"), (FileInfo)CommonParametersExtension.GetValue("ParametersPath"),
(EnvironmentType)CommonParametersExtension.GetValue("EnvironmentType"), SiteName, (string)CommonParametersExtension.GetValue("LicenseName"), DeploymentPackageName,
(string)CommonParametersExtension.GetValue("DeploymentTargetName"), (DirectoryInfo)CommonParametersExtension.GetValue("OutputDir"),
(DeploymentTarget)CommonParametersExtension.GetValue("DeploymentTargetName"), (DirectoryInfo)CommonParametersExtension.GetValue("OutputDir"),
ReplaceTokensExtension.GetTokens(), Interactive.ToBool(), (string)CommonParametersExtension.GetValue("CustomerInfrastructureName"),
(string)CommonParametersExtension.GetValue("Description"), (string)CommonParametersExtension.GetValue("TemplateName"), TerminateOtherVersions.ToBool(), false);
}
Expand Down
5 changes: 3 additions & 2 deletions src/Powershell/NewInfrastructureAgent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Cmf.CustomerPortal.Sdk.Common.Handlers;
using Cmf.CustomerPortal.Sdk.Common;
using Cmf.CustomerPortal.Sdk.Common.Handlers;
using Cmf.CustomerPortal.Sdk.Powershell.Base;
using Cmf.CustomerPortal.Sdk.Powershell.Extensions;
using Cmf.Foundation.Common.Licenses.Enums;
Expand Down Expand Up @@ -32,7 +33,7 @@ protected async override Task ProcessRecordAsync()
NewEnvironmentHandler newEnvironmentHandler = ServiceLocator.Get<NewEnvironmentHandler>();
await newEnvironmentHandler.Run((string)CommonParametersExtension.GetValue("Name"),(FileInfo)CommonParametersExtension.GetValue("ParametersPath"),
(EnvironmentType)CommonParametersExtension.GetValue("EnvironmentType"), null, (string)CommonParametersExtension.GetValue("LicenseName"), null,
(string)CommonParametersExtension.GetValue("DeploymentTargetName"), (DirectoryInfo)CommonParametersExtension.GetValue("OutputDir"), ReplaceTokensExtension.GetTokens(), Interactive.ToBool(),
(DeploymentTarget)CommonParametersExtension.GetValue("DeploymentTargetName"), (DirectoryInfo)CommonParametersExtension.GetValue("OutputDir"), ReplaceTokensExtension.GetTokens(), Interactive.ToBool(),
(string)CommonParametersExtension.GetValue("CustomerInfrastructureName") , (string)CommonParametersExtension.GetValue("Description"), (string)CommonParametersExtension.GetValue("TemplateName"),
false, true);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Version.props
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project>
<PropertyGroup>
<Version>1.3.1</Version>
<Version>1.3.2</Version>
</PropertyGroup>
</Project>

0 comments on commit 7071174

Please sign in to comment.