Skip to content

Commit 7812f42

Browse files
ian-busebuehler
andauthored
feat: Add options for 'generator installer', remove unused -o/-f options from 'generator' base command help, and change some wording (#596)
Made a few changes to the 'generator installer' command to make it easier to script with. The command now has `--image-name` and `--image-tag` options so users can specify these values when the kustomization YAML is generated, instead of manually editing the file after the fact. Some of the other options for this command were not utilizing the McMaster CLI default value feature, so those values have been added in-line to make it clearer to users what the defaults are if they do not provide them. I also reworded some of the option descriptions to be more unambiguous about what is expected to be in those folders. Additionally, the `Generator` class no longer inherits from `GeneratorBase`, and `GeneratorBase` has been renamed to `OutputBase`. This is because the `--out` and `--format` options were shown under the `generator` command, but it seems they didn't actually do anything for _that_ command. Instead, it seems those options are only used by the sub-commands themselves (`docker`, `crds`, `rbac`, etc) when the YAML/JSON is generated. So now, only the `crd`, `rbac`, `docker`, `installer`, and `operator` commands inherit from `OutputBase`. This will only be a breaking change for users who are unwittingly using the options on the `generator` command that go unused by the SDK. If that shouldn't be a breaking change, some dummy options can be created and hidden under the `generator` command to prevent CLI parsing errors. However, this will result in unexpected behavior for new users if they accidentally place their -o/-f options on the wrong command (resulting in the contents being output to the console), which is somewhat similar to how it behaved before this PR. --------- Co-authored-by: Christoph Bühler <[email protected]>
1 parent c804b59 commit 7812f42

File tree

7 files changed

+31
-23
lines changed

7 files changed

+31
-23
lines changed

src/KubeOps/Operator/Commands/Generators/CrdGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
namespace KubeOps.Operator.Commands.Generators;
88

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

src/KubeOps/Operator/Commands/Generators/DockerGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace KubeOps.Operator.Commands.Generators;
66

77
[Command("docker", Description = "Generates the docker file for building.")]
8-
internal class DockerGenerator : GeneratorBase
8+
internal class DockerGenerator : OutputBase
99
{
1010
private readonly OperatorSettings _settings;
1111
private readonly bool _hasWebhooks;

src/KubeOps/Operator/Commands/Generators/Generator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace KubeOps.Operator.Commands.Generators;
88
[Subcommand(typeof(InstallerGenerator))]
99
[Subcommand(typeof(OperatorGenerator))]
1010
[Subcommand(typeof(RbacGenerator))]
11-
internal class Generator : GeneratorBase
11+
internal class Generator
1212
{
1313
public Task<int> OnExecuteAsync(CommandLineApplication app)
1414
{

src/KubeOps/Operator/Commands/Generators/InstallerGenerator.cs

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,27 @@
66

77
namespace KubeOps.Operator.Commands.Generators;
88

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

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

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

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

22-
[Option("--operator-dir", Description = "The path where the operator yamls are located.")]
23-
public string? OperatorPath { get; set; }
22+
[Option("--operator-dir", Description = "The path where the operator YAML files are located.")]
23+
public string OperatorPath { get; set; } = "../operator";
24+
25+
[Option("--image-name", Description = "The name of the operator's Docker image.")]
26+
public string ImageName { get; set; } = "public-docker-image-path";
27+
28+
[Option("--image-tag", Description = "The tag for the Docker image.")]
29+
public string ImageTag { get; set; } = "latest";
2430

2531
public async Task<int> OnExecuteAsync(CommandLineApplication app)
2632
{
@@ -44,19 +50,19 @@ public async Task<int> OnExecuteAsync(CommandLineApplication app)
4450
Resources = new List<string>
4551
{
4652
$"./namespace.{Format.ToString().ToLower()}",
47-
CrdsPath == null || OutputPath == null
48-
? "../crds"
53+
OutputPath == null
54+
? CrdsPath
4955
: Path.GetRelativePath(OutputPath, CrdsPath).Replace('\\', '/'),
50-
RbacPath == null || OutputPath == null
51-
? "../rbac"
56+
OutputPath == null
57+
? RbacPath
5258
: Path.GetRelativePath(OutputPath, RbacPath).Replace('\\', '/'),
53-
OperatorPath == null || OutputPath == null
54-
? "../operator"
59+
OutputPath == null
60+
? OperatorPath
5561
: Path.GetRelativePath(OutputPath, OperatorPath).Replace('\\', '/'),
5662
},
5763
Images = new List<KustomizationImage>
5864
{
59-
new() { Name = "operator", NewName = "public-docker-image-path", NewTag = "latest", },
65+
new() { Name = "operator", NewName = ImageName, NewTag = ImageTag, },
6066
},
6167
},
6268
Format));

src/KubeOps/Operator/Commands/Generators/OperatorGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace KubeOps.Operator.Commands.Generators;
99

1010
[Command("operator", "op", Description = "Generates the needed yamls to run the operator.")]
11-
internal class OperatorGenerator : GeneratorBase
11+
internal class OperatorGenerator : OutputBase
1212
{
1313
private readonly OperatorSettings _settings;
1414
private readonly bool _hasWebhooks;

src/KubeOps/Operator/Commands/Generators/GeneratorBase.cs renamed to src/KubeOps/Operator/Commands/Generators/OutputBase.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
namespace KubeOps.Operator.Commands.Generators;
55

6-
internal abstract class GeneratorBase
6+
internal abstract class OutputBase
77
{
8-
[Option(CommandOptionType.SingleValue, Description = "Determines the output format for the generator.")]
8+
[Option(
9+
CommandOptionType.SingleValue,
10+
Description = "Sets the output format for the generator.")]
911
public SerializerOutputFormat Format { get; set; }
1012

1113
[Option(
12-
Description = @"The ""root"" path for the generator to put files in - if empty, prints to console.",
14+
Description = @"The path the command will write the files to. If empty, prints output to console.",
1315
LongName = "out")]
1416
public string? OutputPath { get; set; }
1517
}

src/KubeOps/Operator/Commands/Generators/RbacGenerator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
namespace KubeOps.Operator.Commands.Generators;
99

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

0 commit comments

Comments
 (0)