Skip to content

Commit

Permalink
Issue #937 - Use redis as a shared throwaway cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Matyushentsev authored and Alexander Matyushentsev committed Feb 13, 2019
1 parent b1edc18 commit f99b163
Show file tree
Hide file tree
Showing 35 changed files with 1,218 additions and 1,422 deletions.
7 changes: 4 additions & 3 deletions Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
controller: go run ./cmd/argocd-application-controller/main.go --repo-server localhost:8081
api-server: go run ./cmd/argocd-server/main.go --insecure --disable-auth --dex-server http://localhost:5556 --repo-server localhost:8081 --app-controller-server localhost:8083 --staticassets ../argo-cd-ui/dist/app
repo-server: go run ./cmd/argocd-repo-server/main.go --loglevel debug
controller: go run ./cmd/argocd-application-controller/main.go --redis localhost:6379 --repo-server localhost:8081
api-server: go run ./cmd/argocd-server/main.go --redis localhost:6379 --insecure --disable-auth --dex-server http://localhost:5556 --repo-server localhost:8081 --app-controller-server localhost:8083 --staticassets ../argo-cd-ui/dist/app
repo-server: go run ./cmd/argocd-repo-server/main.go --loglevel debug --redis localhost:6379
dex: sh -c "go run ./cmd/argocd-util/main.go gendexcfg -o `pwd`/dist/dex.yaml && docker run --rm -p 5556:5556 -v `pwd`/dist/dex.yaml:/dex.yaml quay.io/dexidp/dex:v2.12.0 serve /dex.yaml"
redis: docker run --rm -i -p 6379:6379 redis:5.0.3-alpine
48 changes: 24 additions & 24 deletions assets/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
"200": {
"description": "(empty)",
"schema": {
"$ref": "#/definitions/servicesManagedResourcesResponse"
"$ref": "#/definitions/applicationManagedResourcesResponse"
}
}
}
Expand All @@ -180,7 +180,7 @@
"200": {
"description": "(empty)",
"schema": {
"$ref": "#/definitions/servicesResourceTreeResponse"
"$ref": "#/definitions/applicationResourceTreeResponse"
}
}
}
Expand Down Expand Up @@ -1375,6 +1375,17 @@
}
}
},
"applicationManagedResourcesResponse": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ResourceDiff"
}
}
}
},
"applicationOperationTerminateResponse": {
"type": "object"
},
Expand Down Expand Up @@ -1404,6 +1415,17 @@
}
}
},
"applicationResourceTreeResponse": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ResourceNode"
}
}
}
},
"applicationv1alpha1ParameterOverrides": {
"type": "object",
"title": "ParameterOverrides masks the value so protobuf can generate\n+protobuf.nullable=true\n+protobuf.options.(gogoproto.goproto_stringer)=false",
Expand Down Expand Up @@ -1693,28 +1715,6 @@
"repositoryRepoResponse": {
"type": "object"
},
"servicesManagedResourcesResponse": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ResourceDiff"
}
}
}
},
"servicesResourceTreeResponse": {
"type": "object",
"properties": {
"items": {
"type": "array",
"items": {
"$ref": "#/definitions/v1alpha1ResourceNode"
}
}
}
},
"sessionSessionCreateRequest": {
"description": "SessionCreateRequest is for logging in.",
"type": "object",
Expand Down
40 changes: 16 additions & 24 deletions cmd/argocd-application-controller/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package main
import (
"context"
"fmt"
"net"
"os"
"time"

"github.com/argoproj/argo-cd/util/cache"

log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"k8s.io/client-go/kubernetes"
Expand All @@ -26,7 +27,6 @@ import (
"github.com/argoproj/argo-cd/util/cli"
"github.com/argoproj/argo-cd/util/settings"
"github.com/argoproj/argo-cd/util/stats"
"github.com/argoproj/argo-cd/util/tls"
)

const (
Expand All @@ -38,14 +38,14 @@ const (

func newCommand() *cobra.Command {
var (
clientConfig clientcmd.ClientConfig
appResyncPeriod int64
repoServerAddress string
statusProcessors int
operationProcessors int
logLevel string
glogLevel int
tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
clientConfig clientcmd.ClientConfig
appResyncPeriod int64
repoServerAddress string
statusProcessors int
operationProcessors int
logLevel string
glogLevel int
cacheSrc func() (*cache.Cache, error)
)
var command = cobra.Command{
Use: cliName,
Expand All @@ -70,13 +70,17 @@ func newCommand() *cobra.Command {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

cache, err := cacheSrc()
errors.CheckError(err)

settingsMgr := settings.NewSettingsManager(ctx, kubeClient, namespace)
appController, err := controller.NewApplicationController(
namespace,
settingsMgr,
kubeClient,
appClient,
repoClientset,
cache,
resyncDuration)
errors.CheckError(err)

Expand All @@ -86,19 +90,7 @@ func newCommand() *cobra.Command {
stats.RegisterHeapDumper("memprofile")

go appController.Run(ctx, statusProcessors, operationProcessors)
go func() {
tlsConfigCustomizer, err := tlsConfigCustomizerSrc()
errors.CheckError(err)
server, err := appController.CreateGRPC(tlsConfigCustomizer)
errors.CheckError(err)

listener, err := net.Listen("tcp", fmt.Sprintf(":%d", 8083))
errors.CheckError(err)
log.Infof("application-controller %s serving on %s", argocd.GetVersion(), listener.Addr())

err = server.Serve(listener)
errors.CheckError(err)
}()

// Wait forever
select {}
},
Expand All @@ -111,7 +103,7 @@ func newCommand() *cobra.Command {
command.Flags().IntVar(&operationProcessors, "operation-processors", 1, "Number of application operation processors")
command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().IntVar(&glogLevel, "gloglevel", 0, "Set the glog logging level")
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command)
cacheSrc = cache.AddCacheFlagsToCmd(&command)
return &command
}

Expand Down
33 changes: 6 additions & 27 deletions cmd/argocd-repo-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@ import (
"os"
"time"

"github.com/go-redis/redis"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/argoproj/argo-cd"
"github.com/argoproj/argo-cd/errors"
"github.com/argoproj/argo-cd/reposerver"
"github.com/argoproj/argo-cd/reposerver/repository"
"github.com/argoproj/argo-cd/util/cache"
"github.com/argoproj/argo-cd/util/cli"
"github.com/argoproj/argo-cd/util/git"
Expand All @@ -31,10 +29,8 @@ const (
func newCommand() *cobra.Command {
var (
logLevel string
redisAddress string
sentinelAddresses []string
sentinelMaster string
parallelismLimit int64
cacheSrc func() (*cache.Cache, error)
tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
)
var command = cobra.Command{
Expand All @@ -46,7 +42,10 @@ func newCommand() *cobra.Command {
tlsConfigCustomizer, err := tlsConfigCustomizerSrc()
errors.CheckError(err)

server, err := reposerver.NewServer(git.NewFactory(), newCache(redisAddress, sentinelAddresses, sentinelMaster), tlsConfigCustomizer, parallelismLimit)
cache, err := cacheSrc()
errors.CheckError(err)

server, err := reposerver.NewServer(git.NewFactory(), cache, tlsConfigCustomizer, parallelismLimit)
errors.CheckError(err)
grpc := server.CreateGRPC()
listener, err := net.Listen("tcp", fmt.Sprintf(":%d", port))
Expand All @@ -67,32 +66,12 @@ func newCommand() *cobra.Command {
}

command.Flags().StringVar(&logLevel, "loglevel", "info", "Set the logging level. One of: debug|info|warn|error")
command.Flags().StringVar(&redisAddress, "redis", "", "Redis server hostname and port (e.g. argocd-redis:6379). ")
command.Flags().StringArrayVar(&sentinelAddresses, "sentinel", []string{}, "Redis sentinel hostname and port (e.g. argocd-redis-ha-announce-0:6379). ")
command.Flags().StringVar(&sentinelMaster, "sentinelmaster", "master", "Redis sentinel master group name.")
command.Flags().Int64Var(&parallelismLimit, "parallelismlimit", 0, "Limit on number of concurrent manifests generate requests. Any value less the 1 means no limit.")
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(&command)
cacheSrc = cache.AddCacheFlagsToCmd(&command)
return &command
}

func newCache(redisAddress string, sentinelAddresses []string, sentinelMaster string) cache.Cache {
if redisAddress != "" {
client := redis.NewClient(&redis.Options{
Addr: redisAddress,
Password: "",
DB: 0,
})
return cache.NewRedisCache(client, repository.DefaultRepoCacheExpiration)
} else if len(sentinelAddresses) > 0 {
client := redis.NewFailoverClient(&redis.FailoverOptions{
MasterName: sentinelMaster,
SentinelAddrs: sentinelAddresses,
})
return cache.NewRedisCache(client, repository.DefaultRepoCacheExpiration)
}
return cache.NewInMemoryCache(repository.DefaultRepoCacheExpiration)
}

func main() {
if err := newCommand().Execute(); err != nil {
fmt.Println(err)
Expand Down
29 changes: 16 additions & 13 deletions cmd/argocd-server/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"k8s.io/client-go/tools/clientcmd"

"github.com/argoproj/argo-cd/common"
"github.com/argoproj/argo-cd/controller"
"github.com/argoproj/argo-cd/errors"
appclientset "github.com/argoproj/argo-cd/pkg/client/clientset/versioned"
"github.com/argoproj/argo-cd/reposerver"
"github.com/argoproj/argo-cd/server"
"github.com/argoproj/argo-cd/util/cache"
"github.com/argoproj/argo-cd/util/cli"
"github.com/argoproj/argo-cd/util/stats"
"github.com/argoproj/argo-cd/util/tls"
Expand All @@ -33,6 +33,7 @@ func NewCommand() *cobra.Command {
dexServerAddress string
disableAuth bool
tlsConfigCustomizerSrc func() (tls.ConfigCustomizer, error)
cacheSrc func() (*cache.Cache, error)
)
var command = &cobra.Command{
Use: cliName,
Expand All @@ -52,24 +53,25 @@ func NewCommand() *cobra.Command {

tlsConfigCustomizer, err := tlsConfigCustomizerSrc()
errors.CheckError(err)
cache, err := cacheSrc()
errors.CheckError(err)

kubeclientset := kubernetes.NewForConfigOrDie(config)
appclientset := appclientset.NewForConfigOrDie(config)
repoclientset := reposerver.NewRepositoryServerClientset(repoServerAddress)
appcontrollerclientset := controller.NewAppControllerClientset(appControllerServerAddress)

argoCDOpts := server.ArgoCDServerOpts{
Insecure: insecure,
Namespace: namespace,
StaticAssetsDir: staticAssetsDir,
BaseHRef: baseHRef,
KubeClientset: kubeclientset,
AppClientset: appclientset,
RepoClientset: repoclientset,
DexServerAddr: dexServerAddress,
DisableAuth: disableAuth,
TLSConfigCustomizer: tlsConfigCustomizer,
AppControllerClientset: appcontrollerclientset,
Insecure: insecure,
Namespace: namespace,
StaticAssetsDir: staticAssetsDir,
BaseHRef: baseHRef,
KubeClientset: kubeclientset,
AppClientset: appclientset,
RepoClientset: repoclientset,
DexServerAddr: dexServerAddress,
DisableAuth: disableAuth,
TLSConfigCustomizer: tlsConfigCustomizer,
Cache: cache,
}

stats.RegisterStackDumper()
Expand Down Expand Up @@ -98,5 +100,6 @@ func NewCommand() *cobra.Command {
command.Flags().BoolVar(&disableAuth, "disable-auth", false, "Disable client authentication")
command.AddCommand(cli.NewVersionCmd(cliName))
tlsConfigCustomizerSrc = tls.AddTLSFlagsToCmd(command)
cacheSrc = cache.AddCacheFlagsToCmd(command)
return command
}
5 changes: 2 additions & 3 deletions cmd/argocd/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"k8s.io/apimachinery/pkg/runtime/schema"

"github.com/argoproj/argo-cd/common"
"github.com/argoproj/argo-cd/controller/services"
"github.com/argoproj/argo-cd/errors"
"github.com/argoproj/argo-cd/pkg/apiclient"
argocdclient "github.com/argoproj/argo-cd/pkg/apiclient"
Expand Down Expand Up @@ -700,7 +699,7 @@ func NewApplicationDiffCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
appName := args[0]
app, err := appIf.Get(context.Background(), &application.ApplicationQuery{Name: &appName, Refresh: getRefreshType(refresh, hardRefresh)})
errors.CheckError(err)
resources, err := appIf.ManagedResources(context.Background(), &services.ResourcesQuery{ApplicationName: appName})
resources, err := appIf.ManagedResources(context.Background(), &application.ResourcesQuery{ApplicationName: &appName})
errors.CheckError(err)
liveObjs, err := liveObjects(resources.Items)
errors.CheckError(err)
Expand Down Expand Up @@ -1506,7 +1505,7 @@ func NewApplicationManifestsCommand(clientOpts *argocdclient.ClientOptions) *cob
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
defer util.Close(conn)
ctx := context.Background()
resources, err := appIf.ManagedResources(context.Background(), &services.ResourcesQuery{ApplicationName: appName})
resources, err := appIf.ManagedResources(context.Background(), &application.ResourcesQuery{ApplicationName: &appName})
errors.CheckError(err)

var unstructureds []*unstructured.Unstructured
Expand Down
3 changes: 1 addition & 2 deletions cmd/argocd/commands/rollout.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/spf13/cobra"
"k8s.io/apimachinery/pkg/types"

"github.com/argoproj/argo-cd/controller/services"
"github.com/argoproj/argo-cd/errors"
argocdclient "github.com/argoproj/argo-cd/pkg/apiclient"
"github.com/argoproj/argo-cd/server/application"
Expand Down Expand Up @@ -42,7 +41,7 @@ func NewRolloutProgressCommand(clientOpts *argocdclient.ClientOptions) *cobra.Co
conn, appIf := argocdclient.NewClientOrDie(clientOpts).NewApplicationClientOrDie()
defer util.Close(conn)
ctx := context.Background()
resources, err := appIf.ManagedResources(ctx, &services.ResourcesQuery{ApplicationName: appName})
resources, err := appIf.ManagedResources(ctx, &application.ResourcesQuery{ApplicationName: &appName})
errors.CheckError(err)
verifyingPreviewPatch := "{ \"status\": { \"verifyingPreview\": false } }"
resourceName := args[1]
Expand Down
12 changes: 12 additions & 0 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ const (
DefaultRepoServerAddr = "argocd-repo-server:8081"
// DefaultDexServerAddr is the HTTP address of the Dex OIDC server, which we run a reverse proxy against
DefaultDexServerAddr = "http://argocd-dex-server:5556"
// DefaultRedisAddr is the default redis address
DefaultRedisAddr = "argocd-redis:3679"
)

// Kubernetes ConfigMap and Secret resource names which hold Argo CD settings
Expand Down Expand Up @@ -96,3 +98,13 @@ const (
// the current kubectl context (for development purposes)
EnvVarFakeInClusterConfig = "ARGOCD_FAKE_IN_CLUSTER"
)

const (
// MinClientVersion is the minimum client version that can interface with this API server.
// When introducing breaking changes to the API or datastructures, this number should be bumped.
// The value here may be lower than the current value in VERSION
MinClientVersion = "0.11.0"
// CacheVersion is a objects version cached using util/cache/cache.go.
// Number should be bumped in case of backward incompatible change to make sure cache is invalidated after upgrade.
CacheVersion = "0.12.0"
)
Loading

0 comments on commit f99b163

Please sign in to comment.