Skip to content

Commit

Permalink
add --all-namespaces flag
Browse files Browse the repository at this point in the history
Signed-off-by: Jeromy Cannon <[email protected]>
  • Loading branch information
jeromy-cannon committed Oct 5, 2023
1 parent 32ca360 commit 2861ee9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ default Release installChart(String releaseName, Chart chart) {

/**
* Executes the Helm CLI {@code list} sub-command and returns the list of releases.
*
* @param allNamespaces if {@code true}, list releases across all namespaces.
* @return the list of releases.
*/
List<ReleaseItem> listReleases();
List<ReleaseItem> listReleases(boolean allNamespaces);

/**
* Executes the Helm CLI {@code dependency update} sub-command and updates the dependencies of the specified Helm
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ public void testChart(final String releaseName, final TestChartOptions options)
}

@Override
public List<ReleaseItem> listReleases() {
return executeAsList(new ReleaseListRequest(), ReleaseItem.class);
public List<ReleaseItem> listReleases(boolean allNamespaces) {
return executeAsList(new ReleaseListRequest(allNamespaces), ReleaseItem.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
import com.hedera.fullstack.helm.client.execution.HelmExecutionBuilder;
import com.hedera.fullstack.helm.client.proxy.request.HelmRequest;

public record ReleaseListRequest() implements HelmRequest {
public record ReleaseListRequest(boolean allNamespaces) implements HelmRequest {
@Override
public void apply(HelmExecutionBuilder builder) {
builder.argument("output", "json");

if (allNamespaces) {
builder.flag("--all-namespaces");
}

builder.subcommands("list");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,38 @@ void testInstallChartCommand(final LoggingOutput loggingOutput) {

try {
suppressExceptions(() -> helmClient.uninstallChart(HAPROXY_RELEASE_NAME));
Release release = helmClient.installChart(HAPROXY_RELEASE_NAME, HAPROXY_CHART);
List<ReleaseItem> releaseItems = helmClient.listReleases();
final Release release = helmClient.installChart(HAPROXY_RELEASE_NAME, HAPROXY_CHART);

// verify the returned release object
assertThat(release).isNotNull();
assertThat(release.name()).isEqualTo(HAPROXY_RELEASE_NAME);
assertThat(release.info().description()).isEqualTo("Install complete");
assertThat(release.info().status()).isEqualTo("deployed");

// verify the release through the helm list command using the namespace of the helm client
final List<ReleaseItem> specificNamespaceReleaseItems = helmClient.listReleases(false);
assertThat(specificNamespaceReleaseItems).isNotNull().isNotEmpty();
final ReleaseItem specificNamespaceReleaseItem = specificNamespaceReleaseItems.stream()
.filter(item -> item.name().equals(HAPROXY_RELEASE_NAME))
.findFirst()
.orElse(null);
assertThat(specificNamespaceReleaseItem).isNotNull();
assertThat(specificNamespaceReleaseItem.name()).isEqualTo(HAPROXY_RELEASE_NAME);
assertThat(specificNamespaceReleaseItem.namespace()).isEqualTo(NAMESPACE);
assertThat(specificNamespaceReleaseItem.status()).isEqualTo("deployed");
HelmClient defaultHelmClient = HelmClient.defaultClient();

// verify the release through the helm list command using the default namespace specifying --all-namespaces
final List<ReleaseItem> releaseItems = defaultHelmClient.listReleases(true);
assertThat(releaseItems).isNotNull().isNotEmpty();
ReleaseItem releaseItem = releaseItems.stream()
final ReleaseItem releaseItem = releaseItems.stream()
.filter(item -> item.name().equals(HAPROXY_RELEASE_NAME))
.findFirst()
.orElse(null);
assertThat(releaseItem).isNotNull();
assertThat(releaseItem.name()).isEqualTo(HAPROXY_RELEASE_NAME);
assertThat(releaseItem.namespace()).isEqualTo(NAMESPACE);
assertThat(releaseItem.status()).isEqualTo("deployed");
assertThat(release).isNotNull();
assertThat(release.name()).isEqualTo(HAPROXY_RELEASE_NAME);
assertThat(release.info().description()).isEqualTo("Install complete");
assertThat(release.info().status()).isEqualTo("deployed");
} finally {
suppressExceptions(() -> helmClient.uninstallChart(HAPROXY_RELEASE_NAME));
}
Expand Down

0 comments on commit 2861ee9

Please sign in to comment.