Skip to content
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

fix/feat: Add options for 'generator installer', remove unused -o/-f options from 'generator' base command help, and change some wording #596

Merged
merged 4 commits into from
Sep 13, 2023
Merged
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
2 changes: 1 addition & 1 deletion src/KubeOps/Operator/Commands/Generators/CrdGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace KubeOps.Operator.Commands.Generators;

[Command("crd", "crds", Description = "Generates the needed CRD for kubernetes.")]
internal class CrdGenerator : GeneratorBase
internal class CrdGenerator : OutputBase
{
private readonly ICrdBuilder _crdBuilder;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace KubeOps.Operator.Commands.Generators;

[Command("docker", Description = "Generates the docker file for building.")]
internal class DockerGenerator : GeneratorBase
internal class DockerGenerator : OutputBase
{
private readonly OperatorSettings _settings;
private readonly bool _hasWebhooks;
Expand Down
2 changes: 1 addition & 1 deletion src/KubeOps/Operator/Commands/Generators/Generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace KubeOps.Operator.Commands.Generators;
[Subcommand(typeof(InstallerGenerator))]
[Subcommand(typeof(OperatorGenerator))]
[Subcommand(typeof(RbacGenerator))]
internal class Generator : GeneratorBase
internal class Generator
{
public Task<int> OnExecuteAsync(CommandLineApplication app)
{
Expand Down
36 changes: 21 additions & 15 deletions src/KubeOps/Operator/Commands/Generators/InstallerGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@

namespace KubeOps.Operator.Commands.Generators;

[Command("installer", Description = "Generates kustomization yaml for the whole installation of the operator.")]
internal class InstallerGenerator : GeneratorBase
[Command("installer", Description = "Generates kustomization YAML for installing the entire operator.")]
internal class InstallerGenerator : OutputBase
{
private readonly OperatorSettings _settings;

public InstallerGenerator(OperatorSettings settings) => _settings = settings;

[Option("--crds-dir", Description = "The path where the crds are located.")]
public string? CrdsPath { get; set; }
[Option("--crds-dir", Description = "The path where the CRD YAML files are located.")]
public string CrdsPath { get; set; } = "../crds";

[Option("--rbac-dir", Description = "The path where the rbac yamls are located.")]
public string? RbacPath { get; set; }
[Option("--rbac-dir", Description = "The path where the RBAC YAML files are located.")]
public string RbacPath { get; set; } = "../rbac";

[Option("--operator-dir", Description = "The path where the operator yamls are located.")]
public string? OperatorPath { get; set; }
[Option("--operator-dir", Description = "The path where the operator YAML files are located.")]
public string OperatorPath { get; set; } = "../operator";

[Option("--image-name", Description = "The name of the operator's Docker image.")]
public string ImageName { get; set; } = "public-docker-image-path";

[Option("--image-tag", Description = "The tag for the Docker image.")]
public string ImageTag { get; set; } = "latest";

public async Task<int> OnExecuteAsync(CommandLineApplication app)
{
Expand All @@ -44,19 +50,19 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
Resources = new List<string>
{
$"./namespace.{Format.ToString().ToLower()}",
CrdsPath == null || OutputPath == null
? "../crds"
OutputPath == null
? CrdsPath
: Path.GetRelativePath(OutputPath, CrdsPath).Replace('\\', '/'),
RbacPath == null || OutputPath == null
? "../rbac"
OutputPath == null
? RbacPath
: Path.GetRelativePath(OutputPath, RbacPath).Replace('\\', '/'),
OperatorPath == null || OutputPath == null
? "../operator"
OutputPath == null
? OperatorPath
: Path.GetRelativePath(OutputPath, OperatorPath).Replace('\\', '/'),
},
Images = new List<KustomizationImage>
{
new() { Name = "operator", NewName = "public-docker-image-path", NewTag = "latest", },
new() { Name = "operator", NewName = ImageName, NewTag = ImageTag, },
},
},
Format));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace KubeOps.Operator.Commands.Generators;

[Command("operator", "op", Description = "Generates the needed yamls to run the operator.")]
internal class OperatorGenerator : GeneratorBase
internal class OperatorGenerator : OutputBase
{
private readonly OperatorSettings _settings;
private readonly bool _hasWebhooks;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

namespace KubeOps.Operator.Commands.Generators;

internal abstract class GeneratorBase
internal abstract class OutputBase
{
[Option(CommandOptionType.SingleValue, Description = "Determines the output format for the generator.")]
[Option(
CommandOptionType.SingleValue,
Description = "Sets the output format for the generator.")]
public SerializerOutputFormat Format { get; set; }

[Option(
Description = @"The ""root"" path for the generator to put files in - if empty, prints to console.",
Description = @"The path the command will write the files to. If empty, prints output to console.",
LongName = "out")]
public string? OutputPath { get; set; }
}
2 changes: 1 addition & 1 deletion src/KubeOps/Operator/Commands/Generators/RbacGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace KubeOps.Operator.Commands.Generators;

[Command("rbac", Description = "Generates the needed rbac roles for the operator.")]
internal class RbacGenerator : GeneratorBase
internal class RbacGenerator : OutputBase
{
private readonly IRbacBuilder _rbacBuilder;

Expand Down
Loading