-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: enhance Helm Install to support multiple set and values parameters #367
Changes from 5 commits
c9c45f9
25ca488
622fd31
d1b70f8
72757ac
db5283d
7c5b663
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -16,7 +16,9 @@ | |||||
|
||||||
package com.hedera.fullstack.helm.client.execution; | ||||||
|
||||||
import com.hedera.fullstack.base.api.collections.KeyValuePair; | ||||||
import com.hedera.fullstack.helm.client.HelmConfigurationException; | ||||||
import java.io.File; | ||||||
import java.io.IOException; | ||||||
import java.nio.file.Path; | ||||||
import java.util.*; | ||||||
|
@@ -28,7 +30,8 @@ | |||||
*/ | ||||||
public final class HelmExecutionBuilder { | ||||||
private static final Logger LOGGER = LoggerFactory.getLogger(HelmExecutionBuilder.class); | ||||||
|
||||||
public static final String NAME_MUST_NOT_BE_NULL = "name must not be null"; | ||||||
public static final String VALUE_MUST_NOT_BE_NULL = "value must not be null"; | ||||||
/** | ||||||
* The path to the helm executable. | ||||||
*/ | ||||||
|
@@ -42,7 +45,12 @@ public final class HelmExecutionBuilder { | |||||
/** | ||||||
* The arguments to be passed to the helm command. | ||||||
*/ | ||||||
private final Map<String, String> arguments; | ||||||
private final Set<KeyValuePair<String, String>> arguments; | ||||||
|
||||||
/** | ||||||
* The arguments of sets to be passed to the helm command. | ||||||
*/ | ||||||
private final Set<KeyValuePair<String, Set<String>>> argumentsSet; | ||||||
|
||||||
/** | ||||||
* The flags to be passed to the helm command. | ||||||
|
@@ -72,11 +80,16 @@ public final class HelmExecutionBuilder { | |||||
public HelmExecutionBuilder(final Path helmExecutable) { | ||||||
this.helmExecutable = Objects.requireNonNull(helmExecutable, "helmExecutable must not be null"); | ||||||
this.subcommands = new ArrayList<>(); | ||||||
this.arguments = new HashMap<>(); | ||||||
this.arguments = new HashSet<>(); | ||||||
this.argumentsSet = new HashSet<>(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: naming this is hard but it would be good to change this name to something not containing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, not my favorite. I tried to give something better. take a look and let me know if that is good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated a second time to optionsWithMultipleValues() which I like better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: naming this is hard but it would be good to change this name to something not containing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, not my favorite. I tried to give something better. take a look and let me know if that is good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated a second time to optionsWithMultipleValues() which I like better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should most likely be a list because deduplicating on key alone is going to be a problem. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
this.positionals = new ArrayList<>(); | ||||||
this.flags = new ArrayList<>(); | ||||||
this.environmentVariables = new HashMap<>(); | ||||||
this.workingDirectory = this.helmExecutable.getParent(); | ||||||
|
||||||
String workingDirectoryString = System.getenv("PWD"); | ||||||
this.workingDirectory = workingDirectoryString == null | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||||||
? this.helmExecutable.getParent() | ||||||
: new File(workingDirectoryString).toPath(); | ||||||
} | ||||||
|
||||||
/** | ||||||
|
@@ -100,9 +113,24 @@ public HelmExecutionBuilder subcommands(final String... commands) { | |||||
* @throws NullPointerException if either {@code name} or {@code value} is {@code null}. | ||||||
*/ | ||||||
public HelmExecutionBuilder argument(final String name, final String value) { | ||||||
Objects.requireNonNull(name, "name must not be null"); | ||||||
Objects.requireNonNull(value, "value must not be null"); | ||||||
this.arguments.put(name, value); | ||||||
Objects.requireNonNull(name, NAME_MUST_NOT_BE_NULL); | ||||||
Objects.requireNonNull(value, VALUE_MUST_NOT_BE_NULL); | ||||||
this.arguments.add(new KeyValuePair<>(name, value)); | ||||||
return this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Adds an argument of sets to the helm command. | ||||||
* | ||||||
* @param name the name of the argument. | ||||||
* @param value the set of value arguments. | ||||||
* @return this builder. | ||||||
* @throws NullPointerException if either {@code name} or {@code value} is {@code null}. | ||||||
*/ | ||||||
public HelmExecutionBuilder argumentSet(final String name, final Set<String> value) { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: naming is hard but I think we should adjust this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, not my favorite. I tried to give something better. take a look and let me know if that is good. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated a second time to optionsWithMultipleValues() which I like better |
||||||
Objects.requireNonNull(name, NAME_MUST_NOT_BE_NULL); | ||||||
Objects.requireNonNull(value, VALUE_MUST_NOT_BE_NULL); | ||||||
this.argumentsSet.add(new KeyValuePair<>(name, value)); | ||||||
return this; | ||||||
} | ||||||
|
||||||
|
@@ -114,7 +142,7 @@ public HelmExecutionBuilder argument(final String name, final String value) { | |||||
* @throws NullPointerException if {@code value} is {@code null}. | ||||||
*/ | ||||||
public HelmExecutionBuilder positional(final String value) { | ||||||
Objects.requireNonNull(value, "value must not be null"); | ||||||
Objects.requireNonNull(value, VALUE_MUST_NOT_BE_NULL); | ||||||
this.positionals.add(value); | ||||||
return this; | ||||||
} | ||||||
|
@@ -128,20 +156,20 @@ public HelmExecutionBuilder positional(final String value) { | |||||
* @throws NullPointerException if either {@code name} or {@code value} is {@code null}. | ||||||
*/ | ||||||
public HelmExecutionBuilder environmentVariable(final String name, final String value) { | ||||||
Objects.requireNonNull(name, "name must not be null"); | ||||||
Objects.requireNonNull(value, "value must not be null"); | ||||||
Objects.requireNonNull(name, NAME_MUST_NOT_BE_NULL); | ||||||
Objects.requireNonNull(value, VALUE_MUST_NOT_BE_NULL); | ||||||
this.environmentVariables.put(name, value); | ||||||
return this; | ||||||
} | ||||||
|
||||||
/** | ||||||
* Sets the working directory for the helm process. | ||||||
* Sets the Path of the working directory for the helm process. | ||||||
* | ||||||
* @param workingDirectory the working directory. | ||||||
* @param workingDirectoryPath the Path of the working directory. | ||||||
* @return this builder. | ||||||
*/ | ||||||
public HelmExecutionBuilder workingDirectory(final Path workingDirectory) { | ||||||
this.workingDirectory = Objects.requireNonNull(workingDirectory, "workingDirectory must not be null"); | ||||||
public HelmExecutionBuilder workingDirectory(final Path workingDirectoryPath) { | ||||||
this.workingDirectory = Objects.requireNonNull(workingDirectoryPath, "workingDirectoryPath must not be null"); | ||||||
return this; | ||||||
} | ||||||
|
||||||
|
@@ -191,18 +219,23 @@ private String[] buildCommand() { | |||||
command.addAll(subcommands); | ||||||
command.addAll(flags); | ||||||
|
||||||
for (final Map.Entry<String, String> entry : arguments.entrySet()) { | ||||||
command.add(String.format("--%s", entry.getKey())); | ||||||
command.add(entry.getValue()); | ||||||
} | ||||||
arguments.forEach(entry -> { | ||||||
command.add(String.format("--%s", entry.key())); | ||||||
command.add(entry.value()); | ||||||
}); | ||||||
|
||||||
argumentsSet.forEach(entry -> entry.value().forEach(value -> { | ||||||
command.add(String.format("--%s", entry.key())); | ||||||
command.add(value); | ||||||
})); | ||||||
|
||||||
command.addAll(positionals); | ||||||
|
||||||
String[] commandArray = command.toArray(new String[0]); | ||||||
LOGGER.atDebug() | ||||||
.setMessage("Helm command: {}") | ||||||
.addArgument(String.join(" ", Arrays.copyOfRange(commandArray, 1, commandArray.length))) | ||||||
.log(); | ||||||
if (LOGGER.isDebugEnabled()) { | ||||||
LOGGER.debug( | ||||||
"Helm command: {}", String.join(" ", Arrays.copyOfRange(commandArray, 1, commandArray.length))); | ||||||
} | ||||||
|
||||||
return commandArray; | ||||||
} | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be a
HashMap
since some arguments may be repeatef and it is okay to do so.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done