Creating an Argo CD application:
```bash
argocd app create my-app \
--repo https://github.com/my-org/my-repo.git \
--path my-app \
--dest-server https://kubernetes.default.svc \
--dest-namespace default
```
Syncing an application:
```bash
argocd app sync my-app
```
Viewing the status of an application:
```bash
argocd app get my-app
```
Using Argo CD in a Python script:
```python
import subprocess
def create_argocd_app(app_name, repo_url, app_path, dest_server, dest_namespace):
result = subprocess.run([
'argocd', 'app', 'create', app_name,
'--repo', repo_url,
'--path', app_path,
'--dest-server', dest_server,
'--dest-namespace', dest_namespace
], capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print(f"Error: {result.stderr}")
def sync_argocd_app(app_name):
result = subprocess.run(['argocd', 'app', 'sync', app_name], capture_output=True, text=True)
print(result.stdout)
if result.stderr:
print(f"Error: {result.stderr}")
# Example usage
create_argocd_app('my-app', 'https://github.com/my-org/my-repo.git', 'my-app', 'https://kubernetes.default.svc', 'default')
sync_argocd_app('my-app')
```
Using Argo CD in a Java program:
```java
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class ArgoCDExample {
public static void createArgoCDApp(String appName, String repoUrl, String appPath, String destServer, String destNamespace) {
executeArgoCDCommand(new String[]{
"argocd", "app", "create", appName,
"--repo", repoUrl,
"--path", appPath,
"--dest-server", destServer,
"--dest-namespace", destNamespace
});
}
public static void syncArgoCDApp(String appName) {
executeArgoCDCommand(new String[]{"argocd", "app", "sync", appName});
}
private static void executeArgoCDCommand(String[] command) {
try {
Process process = new ProcessBuilder(command).start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
reader.close();
int exitCode = process.waitFor();
if (exitCode != 0) {
BufferedReader errorReader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
while ((line = errorReader.readLine()) != null) {
System.err.println("Error: " + line);
}
errorReader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Example usage
createArgoCDApp("my-app", "https://github.com/my-org/my-repo.git", "my-app", "https://kubernetes.default.svc", "default");
syncArgoCDApp("my-app");
}
}
```