forked from argoproj/argo-cd
-
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.
feat: Headless Argo CD (aka GitOps Agent) (argoproj#6361)
* feat: add --headless flag to Argo CD CLI command Signed-off-by: Alexander Matyushentsev <[email protected]> * docs: add headless installation manifests and documentation Signed-off-by: Alexander Matyushentsev <[email protected]> * Apply reviewer notes Signed-off-by: Alexander Matyushentsev <[email protected]> * Remove port forwarding logs Signed-off-by: Alexander Matyushentsev <[email protected]>
- Loading branch information
Alexander Matyushentsev
authored
Jul 21, 2021
1 parent
d7a8a87
commit 561452a
Showing
143 changed files
with
3,036 additions
and
308 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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package commands | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/argoproj/argo-cd/v2/cmd/argocd/commands/headless" | ||
"github.com/argoproj/argo-cd/v2/common" | ||
"github.com/argoproj/argo-cd/v2/pkg/apiclient" | ||
) | ||
|
||
func NewAdminCommand() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "admin", | ||
Short: "Contains a set of commands useful for Argo CD administrators and requires direct Kubernetes access", | ||
Run: func(c *cobra.Command, args []string) { | ||
c.HelpFunc()(c, args) | ||
}, | ||
} | ||
cmd.AddCommand(NewDashboardCommand()) | ||
return cmd | ||
} | ||
|
||
func NewDashboardCommand() *cobra.Command { | ||
var ( | ||
port int | ||
) | ||
cmd := &cobra.Command{ | ||
Use: "dashboard", | ||
Short: "Starts Argo CD Web UI locally", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
println(fmt.Sprintf("Argo CD UI is available at http://localhost:%d", port)) | ||
<-context.Background().Done() | ||
}, | ||
} | ||
clientOpts := &apiclient.ClientOptions{Headless: true} | ||
headless.InitCommand(cmd, clientOpts, &port) | ||
cmd.Flags().IntVar(&port, "port", common.DefaultPortAPIServer, "Listen on given port") | ||
return cmd | ||
} |
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 |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package headless | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"sync" | ||
"time" | ||
|
||
"github.com/go-redis/redis/v8" | ||
"k8s.io/client-go/tools/clientcmd" | ||
|
||
"github.com/argoproj/argo-cd/v2/reposerver/apiclient" | ||
repoapiclient "github.com/argoproj/argo-cd/v2/reposerver/apiclient" | ||
"github.com/argoproj/argo-cd/v2/util/cache" | ||
"github.com/argoproj/argo-cd/v2/util/io" | ||
kubeutil "github.com/argoproj/argo-cd/v2/util/kube" | ||
) | ||
|
||
type forwardCacheClient struct { | ||
namespace string | ||
init sync.Once | ||
client cache.CacheClient | ||
err error | ||
} | ||
|
||
func (c *forwardCacheClient) doLazy(action func(client cache.CacheClient) error) error { | ||
c.init.Do(func() { | ||
overrides := clientcmd.ConfigOverrides{} | ||
redisPort, err := kubeutil.PortForward(6379, c.namespace, &overrides, | ||
"app.kubernetes.io/name=argocd-redis-ha-haproxy", "app.kubernetes.io/name=argocd-redis") | ||
if err != nil { | ||
c.err = err | ||
return | ||
} | ||
|
||
redisClient := redis.NewClient(&redis.Options{Addr: fmt.Sprintf("localhost:%d", redisPort)}) | ||
c.client = cache.NewRedisCache(redisClient, time.Hour) | ||
}) | ||
if c.err != nil { | ||
return c.err | ||
} | ||
return action(c.client) | ||
} | ||
|
||
func (c *forwardCacheClient) Set(item *cache.Item) error { | ||
return c.doLazy(func(client cache.CacheClient) error { | ||
return client.Set(item) | ||
}) | ||
} | ||
|
||
func (c *forwardCacheClient) Get(key string, obj interface{}) error { | ||
return c.doLazy(func(client cache.CacheClient) error { | ||
return client.Get(key, obj) | ||
}) | ||
} | ||
|
||
func (c *forwardCacheClient) Delete(key string) error { | ||
return c.doLazy(func(client cache.CacheClient) error { | ||
return client.Delete(key) | ||
}) | ||
} | ||
|
||
func (c *forwardCacheClient) OnUpdated(ctx context.Context, key string, callback func() error) error { | ||
return c.doLazy(func(client cache.CacheClient) error { | ||
return client.OnUpdated(ctx, key, callback) | ||
}) | ||
} | ||
|
||
func (c *forwardCacheClient) NotifyUpdated(key string) error { | ||
return c.doLazy(func(client cache.CacheClient) error { | ||
return client.NotifyUpdated(key) | ||
}) | ||
} | ||
|
||
type forwardRepoClientset struct { | ||
namespace string | ||
init sync.Once | ||
repoClientset repoapiclient.Clientset | ||
err error | ||
} | ||
|
||
func (c *forwardRepoClientset) NewRepoServerClient() (io.Closer, repoapiclient.RepoServerServiceClient, error) { | ||
c.init.Do(func() { | ||
overrides := clientcmd.ConfigOverrides{} | ||
repoServerPort, err := kubeutil.PortForward(8081, c.namespace, &overrides, "app.kubernetes.io/name=argocd-repo-server") | ||
if err != nil { | ||
c.err = err | ||
return | ||
} | ||
c.repoClientset = apiclient.NewRepoServerClientset(fmt.Sprintf("localhost:%d", repoServerPort), 60, apiclient.TLSConfiguration{ | ||
DisableTLS: false, StrictValidation: false}) | ||
}) | ||
if c.err != nil { | ||
return nil, nil, c.err | ||
} | ||
return c.repoClientset.NewRepoServerClient() | ||
} |
Oops, something went wrong.