-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NonInteractive mode for Apply and Destroy commands
- Loading branch information
1 parent
fe28f2b
commit 3cd8183
Showing
13 changed files
with
112 additions
and
45 deletions.
There are no files selected for viewing
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: 30 additions & 12 deletions
42
src/Aspirate.Cli/Actions/Manifests/ApplyManifestsToClusterAction.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 |
---|---|---|
@@ -1,30 +1,48 @@ | ||
namespace Aspirate.Cli.Actions.Manifests; | ||
|
||
public sealed class ApplyManifestsToClusterAction(IKubeCtlService kubeCtlService, IServiceProvider serviceProvider) : BaseAction(serviceProvider) | ||
public sealed class ApplyManifestsToClusterAction(IKubeCtlService kubeCtlService, IServiceProvider serviceProvider) : BaseActionWithNonInteractiveSupport(serviceProvider) | ||
{ | ||
public const string ActionKey = "ApplyManifestsToClusterAction"; | ||
|
||
public override async Task<bool> ExecuteAsync() | ||
{ | ||
Logger.WriteLine(); | ||
var shouldDeploy = Logger.Confirm("[bold]Would you like to deploy the generated manifests to a kubernetes cluster defined in your kubeconfig file?[/]"); | ||
if (!shouldDeploy) | ||
if (!CurrentState.NonInteractive) | ||
{ | ||
Logger.MarkupLine("[yellow]Cancelled![/]"); | ||
Logger.WriteLine(); | ||
var shouldDeploy = Logger.Confirm( | ||
"[bold]Would you like to deploy the generated manifests to a kubernetes cluster defined in your kubeconfig file?[/]"); | ||
|
||
return true; | ||
if (!shouldDeploy) | ||
{ | ||
Logger.MarkupLine("[yellow]Cancelled![/]"); | ||
|
||
return true; | ||
} | ||
|
||
CurrentState.KubeContext = await kubeCtlService.SelectKubernetesContextForDeployment(); | ||
|
||
if (!CurrentState.ActiveKubernetesContextIsSet) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
CurrentState.ActiveKubernetesContext = await kubeCtlService.SelectKubernetesContextForDeployment(); | ||
await kubeCtlService.ApplyManifests(CurrentState.KubeContext, CurrentState.InputPath); | ||
Logger.MarkupLine($"\r\n\t[green]({EmojiLiterals.CheckMark}) Done:[/] Deployments successfully applied to cluster [blue]'{CurrentState.KubeContext}'[/]"); | ||
|
||
return true; | ||
} | ||
|
||
public override void ValidateNonInteractiveState() | ||
{ | ||
if (!CurrentState.ActiveKubernetesContextIsSet) | ||
{ | ||
return false; | ||
NonInteractiveValidationFailed("Cannot apply manifests to cluster without specifying the kubernetes context to use."); | ||
} | ||
|
||
await kubeCtlService.ApplyManifests(CurrentState.ActiveKubernetesContext, CurrentState.InputPath); | ||
Logger.MarkupLine($"\r\n\t[green]({EmojiLiterals.CheckMark}) Done:[/] Deployments successfully applied to cluster [blue]'{CurrentState.ActiveKubernetesContext}'[/]"); | ||
|
||
return true; | ||
if (string.IsNullOrEmpty(CurrentState.InputPath)) | ||
{ | ||
NonInteractiveValidationFailed("Cannot apply manifests to cluster without specifying the input path to use for manifests."); | ||
} | ||
} | ||
} |
44 changes: 32 additions & 12 deletions
44
src/Aspirate.Cli/Actions/Manifests/RemoveManifestsFromClusterAction.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 |
---|---|---|
@@ -1,30 +1,50 @@ | ||
namespace Aspirate.Cli.Actions.Manifests; | ||
|
||
public sealed class RemoveManifestsFromClusterAction(IKubeCtlService kubeCtlService, IServiceProvider serviceProvider) : BaseAction(serviceProvider) | ||
public sealed class RemoveManifestsFromClusterAction(IKubeCtlService kubeCtlService, IServiceProvider serviceProvider) : | ||
BaseActionWithNonInteractiveSupport(serviceProvider) | ||
{ | ||
public const string ActionKey = "RemoveManifestsFromClusterAction"; | ||
|
||
public override async Task<bool> ExecuteAsync() | ||
{ | ||
Logger.WriteLine(); | ||
var shouldDeploy = Logger.Confirm("[bold]Would you like to remove the deployed manifests from a kubernetes cluster defined in your kubeconfig file?[/]"); | ||
if (!shouldDeploy) | ||
if (!CurrentState.NonInteractive) | ||
{ | ||
Logger.MarkupLine("[yellow]Cancelled![/]"); | ||
|
||
return true; | ||
Logger.WriteLine(); | ||
var shouldDeploy = Logger.Confirm( | ||
"[bold]Would you like to remove the deployed manifests from a kubernetes cluster defined in your kubeconfig file?[/]"); | ||
|
||
if (!shouldDeploy) | ||
{ | ||
Logger.MarkupLine("[yellow]Cancelled![/]"); | ||
|
||
return true; | ||
} | ||
|
||
CurrentState.KubeContext = await kubeCtlService.SelectKubernetesContextForDeployment(); | ||
|
||
if (!CurrentState.ActiveKubernetesContextIsSet) | ||
{ | ||
return false; | ||
} | ||
} | ||
|
||
CurrentState.ActiveKubernetesContext = await kubeCtlService.SelectKubernetesContextForDeployment(); | ||
await kubeCtlService.RemoveManifests(CurrentState.KubeContext, CurrentState.InputPath); | ||
Logger.MarkupLine($"\r\n\t[green]({EmojiLiterals.CheckMark}) Done:[/] Deployments removed from cluster [blue]'{CurrentState.KubeContext}'[/]"); | ||
|
||
return true; | ||
} | ||
|
||
public override void ValidateNonInteractiveState() | ||
{ | ||
if (!CurrentState.ActiveKubernetesContextIsSet) | ||
{ | ||
return false; | ||
NonInteractiveValidationFailed("Cannot remove manifests from a cluster without specifying the kubernetes context to use."); | ||
} | ||
|
||
await kubeCtlService.RemoveManifests(CurrentState.ActiveKubernetesContext, CurrentState.InputPath); | ||
Logger.MarkupLine($"\r\n\t[green]({EmojiLiterals.CheckMark}) Done:[/] Deployments removed from cluster [blue]'{CurrentState.ActiveKubernetesContext}'[/]"); | ||
|
||
return true; | ||
if (string.IsNullOrEmpty(CurrentState.InputPath)) | ||
{ | ||
NonInteractiveValidationFailed("Cannot remove manifests from a cluster without specifying the input path to use for manifests."); | ||
} | ||
} | ||
} |
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
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
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