forked from quarkiverse/quarkus-argocd
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkiverse#39 from iocanel/undeclared-build-item
CLI commands requiring scm report an error in its abscence
- Loading branch information
Showing
4 changed files
with
26 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 17 additions & 77 deletions
94
cli/src/main/java/io/quarkiverse/argocd/cli/application/UninstallCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,99 +1,39 @@ | ||
package io.quarkiverse.argocd.cli.application; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.Callable; | ||
import java.util.function.Consumer; | ||
|
||
import io.fabric8.kubernetes.client.KubernetesClient; | ||
import io.fabric8.kubernetes.client.KubernetesClientBuilder; | ||
import io.quarkiverse.argocd.cli.handlers.GetArgoCDApplicationHandler; | ||
import io.quarkiverse.argocd.spi.ArgoCDApplicationListBuildItem; | ||
import io.quarkiverse.argocd.v1alpha1.Application; | ||
import io.quarkiverse.argocd.v1alpha1.ApplicationList; | ||
import io.quarkus.bootstrap.BootstrapException; | ||
import io.quarkus.bootstrap.app.AugmentAction; | ||
import io.quarkus.bootstrap.app.CuratedApplication; | ||
import io.quarkus.bootstrap.app.QuarkusBootstrap; | ||
import io.quarkus.devtools.project.BuildTool; | ||
import io.quarkus.devtools.project.QuarkusProjectHelper; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.ExitCode; | ||
|
||
@Command(name = "uninstall", sortOptions = false, mixinStandardHelpOptions = false, header = "Uninstall ArgoCD Application.", headerHeading = "%n", commandListHeading = "%nCommands:%n", synopsisHeading = "%nUsage: ", optionListHeading = "%nOptions:%n") | ||
public class UninstallCommand implements Callable<Integer> { | ||
public class UninstallCommand extends GenerationBaseCommand { | ||
|
||
Optional<String> generationPath = Optional.of(".argocd"); | ||
|
||
public Integer call() { | ||
Path projectRoot = getWorkingDirectory(); | ||
BuildTool buildTool = QuarkusProjectHelper.detectExistingBuildTool(projectRoot); | ||
if (buildTool == null) { | ||
System.out.println("Unable to determine the build tool used for the project at " + projectRoot); | ||
return ExitCode.USAGE; | ||
@Override | ||
void process(ApplicationList applicationList) { | ||
if (applicationList.getItems().isEmpty()) { | ||
System.out.println("No ArgoCD Application detected."); | ||
return; | ||
} | ||
Path targetDirecotry = projectRoot.resolve(buildTool.getBuildDirectory()); | ||
QuarkusBootstrap quarkusBootstrap = QuarkusBootstrap.builder() | ||
.setMode(QuarkusBootstrap.Mode.PROD) | ||
.setApplicationRoot(getWorkingDirectory()) | ||
.setProjectRoot(getWorkingDirectory()) | ||
.setTargetDirectory(targetDirecotry) | ||
.setLocalProjectDiscovery(true) | ||
.setIsolateDeployment(false) | ||
.setBaseClassLoader(ClassLoader.getSystemClassLoader()) | ||
.build(); | ||
|
||
List<String> resultBuildItemFQCNs = new ArrayList<>(); | ||
resultBuildItemFQCNs.add(ArgoCDApplicationListBuildItem.class.getName()); | ||
ApplicationListTable table = new ApplicationListTable(); | ||
List<ApplicationListItem> items = new ArrayList<>(); | ||
KubernetesClient kubernetesClient = new KubernetesClientBuilder().build(); | ||
|
||
// Checking | ||
try (CuratedApplication curatedApplication = quarkusBootstrap.bootstrap()) { | ||
AugmentAction action = curatedApplication.createAugmentor(); | ||
|
||
action.performCustomBuild(GetArgoCDApplicationHandler.class.getName(), new Consumer<ApplicationList>() { | ||
@Override | ||
public void accept(ApplicationList applicationList) { | ||
if (applicationList.getItems().isEmpty()) { | ||
System.out.println("No ArgoCD Application detected."); | ||
return; | ||
} | ||
|
||
ApplicationListTable table = new ApplicationListTable(); | ||
List<ApplicationListItem> items = new ArrayList<>(); | ||
KubernetesClient kubernetesClient = new KubernetesClientBuilder().build(); | ||
|
||
for (Application application : applicationList.getItems()) { | ||
kubernetesClient.resources(Application.class) | ||
.inNamespace(application.getMetadata().getNamespace()) | ||
.withName(application.getMetadata().getName()) | ||
.delete(); | ||
items.add(ApplicationListItem.from(application)); | ||
} | ||
System.out.println("Uninstalled ArgoCD applications:"); | ||
System.out.println(table.getContent(items)); | ||
} | ||
}, resultBuildItemFQCNs.toArray(new String[resultBuildItemFQCNs.size()])); | ||
|
||
} catch (BootstrapException e) { | ||
throw new RuntimeException(e); | ||
for (Application application : applicationList.getItems()) { | ||
kubernetesClient.resources(Application.class) | ||
.inNamespace(application.getMetadata().getNamespace()) | ||
.withName(application.getMetadata().getName()) | ||
.delete(); | ||
items.add(ApplicationListItem.from(application)); | ||
} | ||
return ExitCode.OK; | ||
} | ||
|
||
private void writeStringSafe(Path p, String content) { | ||
try { | ||
Files.writeString(p, content); | ||
} catch (IOException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
private Path getWorkingDirectory() { | ||
return Paths.get(System.getProperty("user.dir")); | ||
System.out.println("Uninstalled ArgoCD applications:"); | ||
System.out.println(table.getContent(items)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters