-
Notifications
You must be signed in to change notification settings - Fork 0
/
argo-cd.go
44 lines (37 loc) · 1.17 KB
/
argo-cd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package myargo
import (
"context"
"fmt"
"github.com/spf13/cobra"
"k8s.io/utils/pointer"
"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless"
argocdclient "github.com/argoproj/argo-cd/v2/pkg/apiclient"
applicationpkg "github.com/argoproj/argo-cd/v2/pkg/apiclient/application"
argoio "github.com/argoproj/argo-cd/v2/util/io"
)
func ListApplications() {
// without env portforward uses by default "~/.kube/config"
//os.Setenv(clientcmd.RecommendedConfigPathEnvVar, "/my/kubeconfig/path")
// sets out-of-cluster kube config
clientOpts := &argocdclient.ClientOptions{Core: true}
c := &cobra.Command{}
c.SetContext(context.Background())
// starts local server and forward requests to cluster
argoCdClient := headless.NewClientOrDie(clientOpts, c)
conn, appIf := argoCdClient.NewApplicationClientOrDie()
defer argoio.Close(conn)
var (
selector = "" // all applications
appNamespace = "argocd"
)
apps, err := appIf.List(context.Background(), &applicationpkg.ApplicationQuery{
Selector: pointer.String(selector),
AppNamespace: &appNamespace,
})
if err != nil {
panic(err)
}
for _, app := range apps.Items {
fmt.Println(app.QualifiedName())
}
}