Skip to content

Commit

Permalink
feat: allow providing kubeconfig contents from string (#217)
Browse files Browse the repository at this point in the history
* feature: allow providing kubeconfig from string

* review:feat: allow providing kubeconfig from string

---------

Co-authored-by: Marc Nuri <[email protected]>
  • Loading branch information
christiangebhard and manusa authored Dec 23, 2024
1 parent bd84097 commit 3310768
Show file tree
Hide file tree
Showing 21 changed files with 374 additions and 122 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ Release result = installCommand
.withValuesFile(Paths.get("path", "to", "valuesFile"))
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally set the contents of the kubeconfig file as a string (takes precedence over the path)
.withKubeConfigContents("apiVersion: v1\nkind: Config\nclusters:\n...")
// Optionally specify an SSL certificate file to identify the registry client
.withCertFile(Paths.get("path", "to", "cert"))
// Optionally specify an SSL key file to identify the registry client
Expand Down Expand Up @@ -199,6 +201,8 @@ List<Release> releases = Helm.list()
.withNamespace("namespace")
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally set the contents of the kubeconfig file as a string (takes precedence over the path)
.withKubeConfigContents("apiVersion: v1\nkind: Config\nclusters:\n...")
// Optionally show all releases without any filter applied
.all()
// Optionally show releases across all namespaces
Expand Down Expand Up @@ -628,6 +632,8 @@ Release result = Helm.test("chart/reference")
.withNamespace("namespace")
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally set the contents of the kubeconfig file as a string (takes precedence over the path)
.withKubeConfigContents("apiVersion: v1\nkind: Config\nclusters:\n...")
// Optionally enable verbose output
.debug()
.call();
Expand Down Expand Up @@ -655,6 +661,8 @@ String result = Helm.uninstall("chart/reference")
.withNamespace("namespace")
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally set the contents of the kubeconfig file as a string (takes precedence over the path)
.withKubeConfigContents("apiVersion: v1\nkind: Config\nclusters:\n...")
// Optionally enable verbose output
.debug()
.call();
Expand Down Expand Up @@ -721,6 +729,8 @@ Release result = upgradeCommand
.withValuesFile(Paths.get("path", "to", "valuesFile"))
// Optionally specify the path to the kubeconfig file to use for CLI requests
.withKubeConfig(Paths.get("path", "to", "kubeconfig"))
// Optionally set the contents of the kubeconfig file as a string (takes precedence over the path)
.withKubeConfigContents("apiVersion: v1\nkind: Config\nclusters:\n...")
// Optionally specify an SSL certificate file to identify the registry client
.withCertFile(Paths.get("path", "to", "cert"))
// Optionally specify an SSL key file to identify the registry client
Expand Down
14 changes: 14 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/InstallCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @author Marc Nuri
* @author Miriam Schmidt
* @author Kevin J. Mckernan
* @author Christian Gebhard
*/
public class InstallCommand extends HelmCommand<Release> {

Expand All @@ -54,6 +55,7 @@ public class InstallCommand extends HelmCommand<Release> {
private final Map<String, String> values;
private final List<Path> valuesFiles;
private Path kubeConfig;
private String kubeConfigContents;
private Path certFile;
private Path keyFile;
private Path caFile;
Expand Down Expand Up @@ -97,6 +99,7 @@ public Release call() {
urlEncode(values),
toString(valuesFiles),
toString(kubeConfig),
kubeConfigContents,
toString(certFile),
toString(keyFile),
toString(caFile),
Expand Down Expand Up @@ -321,6 +324,17 @@ public InstallCommand withKubeConfig(Path kubeConfig) {
return this;
}

/**
* Set the kube config to use
*
* @param kubeConfigContents the contents of the kube config file.
* @return this {@link TestCommand} instance.
*/
public InstallCommand withKubeConfigContents(String kubeConfigContents) {
this.kubeConfigContents = kubeConfigContents;
return this;
}

/**
* Identify registry client using this SSL certificate file.
*
Expand Down
16 changes: 15 additions & 1 deletion helm-java/src/main/java/com/marcnuri/helm/ListCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

/**
* @author Marc Nuri
* @author Christian Gebhard
*/
public class ListCommand extends HelmCommand<List<Release>> {

Expand All @@ -39,6 +40,7 @@ public class ListCommand extends HelmCommand<List<Release>> {
private boolean uninstalling;
private String namespace;
private Path kubeConfig;
private String kubeConfigContents;

public ListCommand(HelmLib helmLib) {
super(helmLib);
Expand All @@ -56,7 +58,8 @@ public List<Release> call() {
toInt(uninstalled),
toInt(uninstalling),
namespace,
toString(kubeConfig)
toString(kubeConfig),
kubeConfigContents
))));
}

Expand Down Expand Up @@ -161,4 +164,15 @@ public ListCommand withKubeConfig(Path kubeConfig) {
this.kubeConfig = kubeConfig;
return this;
}

/**
* Set the kube config to use
*
* @param kubeConfigContents the contents of the kube config file.
* @return this {@link ListCommand} instance.
*/
public ListCommand withKubeConfigContents(String kubeConfigContents) {
this.kubeConfigContents = kubeConfigContents;
return this;
}
}
14 changes: 14 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/TestCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

/**
* @author Marc Nuri
* @author Christian Gebhard
*/
public class TestCommand extends HelmCommand<Release> {

private final String releaseName;
private int timeout;
private String namespace;
private Path kubeConfig;
private String kubeConfigContents;
private boolean debug;

public TestCommand(HelmLib helmLib, String releaseName) {
Expand All @@ -46,6 +48,7 @@ public Release call() {
timeout,
namespace,
toString(kubeConfig),
kubeConfigContents,
toInt(debug)
))));
}
Expand Down Expand Up @@ -83,6 +86,17 @@ public TestCommand withKubeConfig(Path kubeConfig) {
return this;
}

/**
* Set the kube config to use
*
* @param kubeConfigContents the contents of the kube config file.
* @return this {@link TestCommand} instance.
*/
public TestCommand withKubeConfigContents(String kubeConfigContents) {
this.kubeConfigContents = kubeConfigContents;
return this;
}

/**
* Enable verbose output.
* <p>
Expand Down
14 changes: 14 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/UninstallCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

/**
* @author Marc Nuri
* @author Christian Gebhard
*/
public class UninstallCommand extends HelmCommand<String> {

Expand All @@ -39,6 +40,7 @@ public enum Cascade {
private Cascade cascade;
private String namespace;
private Path kubeConfig;
private String kubeConfigContents;
private boolean debug;

public UninstallCommand(HelmLib helmLib, String releaseName) {
Expand All @@ -57,6 +59,7 @@ public String call() {
cascade == null ? null : cascade.name().toLowerCase(Locale.ROOT),
namespace,
toString(kubeConfig),
kubeConfigContents,
toInt(debug)
))).out;
}
Expand Down Expand Up @@ -135,6 +138,17 @@ public UninstallCommand withKubeConfig(Path kubeConfig) {
return this;
}

/**
* Set the kube config to use
*
* @param kubeConfigContents the contents of the kube config file.
* @return this {@link UninstallCommand} instance.
*/
public UninstallCommand withKubeConfigContents(String kubeConfigContents) {
this.kubeConfigContents = kubeConfigContents;
return this;
}

/**
* Enable verbose output.
* <p>
Expand Down
14 changes: 14 additions & 0 deletions helm-java/src/main/java/com/marcnuri/helm/UpgradeCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
* @author Marc Nuri
* @author Miriam Schmidt
* @author Kevin J. Mckernan
* @author Christian Gebhard
*/
public class UpgradeCommand extends HelmCommand<Release> {

Expand All @@ -58,6 +59,7 @@ public class UpgradeCommand extends HelmCommand<Release> {
private final Map<String, String> values;
private final List<Path> valuesFiles;
private Path kubeConfig;
private String kubeConfigContents;
private Path certFile;
private Path keyFile;
private Path caFile;
Expand Down Expand Up @@ -105,6 +107,7 @@ public Release call() {
urlEncode(values),
toString(valuesFiles),
toString(kubeConfig),
kubeConfigContents,
toString(certFile),
toString(keyFile),
toString(caFile),
Expand Down Expand Up @@ -373,6 +376,17 @@ public UpgradeCommand withKubeConfig(Path kubeConfig) {
return this;
}

/**
* Set the kube config to use
*
* @param kubeConfigContents the contents of the kube config file.
* @return this {@link UpgradeCommand} instance.
*/
public UpgradeCommand withKubeConfigContents(String kubeConfigContents) {
this.kubeConfigContents = kubeConfigContents;
return this;
}

/**
* Identify registry client using this SSL certificate file.
*
Expand Down
Loading

0 comments on commit 3310768

Please sign in to comment.