github.com/argoproj/argo-cd@v1.8.7/common/common.go (about)

     1  package common
     2  
     3  import (
     4  	"os"
     5  	"strconv"
     6  	"time"
     7  )
     8  
     9  // Default service addresses and URLS of Argo CD internal services
    10  const (
    11  	// DefaultRepoServerAddr is the gRPC address of the Argo CD repo server
    12  	DefaultRepoServerAddr = "argocd-repo-server:8081"
    13  	// DefaultDexServerAddr is the HTTP address of the Dex OIDC server, which we run a reverse proxy against
    14  	DefaultDexServerAddr = "http://argocd-dex-server:5556"
    15  	// DefaultRedisAddr is the default redis address
    16  	DefaultRedisAddr = "argocd-redis:6379"
    17  )
    18  
    19  // Kubernetes ConfigMap and Secret resource names which hold Argo CD settings
    20  const (
    21  	ArgoCDConfigMapName     = "argocd-cm"
    22  	ArgoCDSecretName        = "argocd-secret"
    23  	ArgoCDRBACConfigMapName = "argocd-rbac-cm"
    24  	// Contains SSH known hosts data for connecting repositories. Will get mounted as volume to pods
    25  	ArgoCDKnownHostsConfigMapName = "argocd-ssh-known-hosts-cm"
    26  	// Contains TLS certificate data for connecting repositories. Will get mounted as volume to pods
    27  	ArgoCDTLSCertsConfigMapName = "argocd-tls-certs-cm"
    28  	ArgoCDGPGKeysConfigMapName  = "argocd-gpg-keys-cm"
    29  )
    30  
    31  // Some default configurables
    32  const (
    33  	DefaultSystemNamespace = "kube-system"
    34  	DefaultRepoType        = "git"
    35  )
    36  
    37  // Default listener ports for ArgoCD components
    38  const (
    39  	DefaultPortAPIServer              = 8080
    40  	DefaultPortRepoServer             = 8081
    41  	DefaultPortArgoCDMetrics          = 8082
    42  	DefaultPortArgoCDAPIServerMetrics = 8083
    43  	DefaultPortRepoServerMetrics      = 8084
    44  )
    45  
    46  // Default paths on the pod's file system
    47  const (
    48  	// The default path where TLS certificates for repositories are located
    49  	DefaultPathTLSConfig = "/app/config/tls"
    50  	// The default path where SSH known hosts are stored
    51  	DefaultPathSSHConfig = "/app/config/ssh"
    52  	// Default name for the SSH known hosts file
    53  	DefaultSSHKnownHostsName = "ssh_known_hosts"
    54  	// Default path to GnuPG home directory
    55  	DefaultGnuPgHomePath = "/app/config/gpg/keys"
    56  )
    57  
    58  const (
    59  	DefaultSyncRetryDuration    = 5 * time.Second
    60  	DefaultSyncRetryMaxDuration = 3 * time.Minute
    61  	DefaultSyncRetryFactor      = int64(2)
    62  )
    63  
    64  // Argo CD application related constants
    65  const (
    66  	// KubernetesInternalAPIServerAddr is address of the k8s API server when accessing internal to the cluster
    67  	KubernetesInternalAPIServerAddr = "https://kubernetes.default.svc"
    68  	// DefaultAppProjectName contains name of 'default' app project, which is available in every Argo CD installation
    69  	DefaultAppProjectName = "default"
    70  	// ArgoCDAdminUsername is the username of the 'admin' user
    71  	ArgoCDAdminUsername = "admin"
    72  	// ArgoCDUserAgentName is the default user-agent name used by the gRPC API client library and grpc-gateway
    73  	ArgoCDUserAgentName = "argocd-client"
    74  	// AuthCookieName is the HTTP cookie name where we store our auth token
    75  	AuthCookieName = "argocd.token"
    76  	// RevisionHistoryLimit is the max number of successful sync to keep in history
    77  	RevisionHistoryLimit = 10
    78  	// ChangePasswordSSOTokenMaxAge is the max token age for password change operation
    79  	ChangePasswordSSOTokenMaxAge = time.Minute * 5
    80  )
    81  
    82  // Dex related constants
    83  const (
    84  	// DexAPIEndpoint is the endpoint where we serve the Dex API server
    85  	DexAPIEndpoint = "/api/dex"
    86  	// LoginEndpoint is Argo CD's shorthand login endpoint which redirects to dex's OAuth 2.0 provider's consent page
    87  	LoginEndpoint = "/auth/login"
    88  	// LogoutEndpoint is Argo CD's shorthand logout endpoint which invalidates OIDC session after logout
    89  	LogoutEndpoint = "/auth/logout"
    90  	// CallbackEndpoint is Argo CD's final callback endpoint we reach after OAuth 2.0 login flow has been completed
    91  	CallbackEndpoint = "/auth/callback"
    92  	// DexCallbackEndpoint is Argo CD's final callback endpoint when Dex is configured
    93  	DexCallbackEndpoint = "/api/dex/callback"
    94  	// ArgoCDClientAppName is name of the Oauth client app used when registering our web app to dex
    95  	ArgoCDClientAppName = "Argo CD"
    96  	// ArgoCDClientAppID is the Oauth client ID we will use when registering our app to dex
    97  	ArgoCDClientAppID = "argo-cd"
    98  	// ArgoCDCLIClientAppName is name of the Oauth client app used when registering our CLI to dex
    99  	ArgoCDCLIClientAppName = "Argo CD CLI"
   100  	// ArgoCDCLIClientAppID is the Oauth client ID we will use when registering our CLI to dex
   101  	ArgoCDCLIClientAppID = "argo-cd-cli"
   102  )
   103  
   104  // Resource metadata labels and annotations (keys and values) used by Argo CD components
   105  const (
   106  	// LabelKeyAppInstance is the label key to use to uniquely identify the instance of an application
   107  	// The Argo CD application name is used as the instance name
   108  	LabelKeyAppInstance = "app.kubernetes.io/instance"
   109  	// LegacyLabelApplicationName is the legacy label (v0.10 and below) and is superceded by 'app.kubernetes.io/instance'
   110  	LabelKeyLegacyApplicationName = "applications.argoproj.io/app-name"
   111  	// LabelKeySecretType contains the type of argocd secret (currently: 'cluster')
   112  	LabelKeySecretType = "argocd.argoproj.io/secret-type"
   113  	// LabelValueSecretTypeCluster indicates a secret type of cluster
   114  	LabelValueSecretTypeCluster = "cluster"
   115  
   116  	// AnnotationCompareOptions is a comma-separated list of options for comparison
   117  	AnnotationCompareOptions = "argocd.argoproj.io/compare-options"
   118  
   119  	// AnnotationKeyRefresh is the annotation key which indicates that app needs to be refreshed. Removed by application controller after app is refreshed.
   120  	// Might take values 'normal'/'hard'. Value 'hard' means manifest cache and target cluster state cache should be invalidated before refresh.
   121  	AnnotationKeyRefresh = "argocd.argoproj.io/refresh"
   122  	// AnnotationKeyManagedBy is annotation name which indicates that k8s resource is managed by an application.
   123  	AnnotationKeyManagedBy = "managed-by"
   124  	// AnnotationValueManagedByArgoCD is a 'managed-by' annotation value for resources managed by Argo CD
   125  	AnnotationValueManagedByArgoCD = "argocd.argoproj.io"
   126  	// ResourcesFinalizerName the finalizer value which we inject to finalize deletion of an application
   127  	ResourcesFinalizerName = "resources-finalizer.argocd.argoproj.io"
   128  
   129  	// AnnotationKeyManifestGeneratePaths is an annotation that contains a list of semicolon-separated paths in the
   130  	// manifests repository that affects the manifest generation. Paths might be either relative or absolute. The
   131  	// absolute path means an absolute path within the repository and the relative path is relative to the application
   132  	// source path within the repository.
   133  	AnnotationKeyManifestGeneratePaths = "argocd.argoproj.io/manifest-generate-paths"
   134  
   135  	// AnnotationKeyLinkPrefix tells the UI to add an external link icon to the application node
   136  	// that links to the value given in the annotation.
   137  	// The annotation key must be followed by a unique identifier. Ex: link.argocd.argoproj.io/dashboard
   138  	// It's valid to have multiple annotations that match the prefix.
   139  	// Values can simply be a url or they can have
   140  	// an optional link title separated by a "|"
   141  	// Ex: "http://grafana.example.com/d/yu5UH4MMz/deployments"
   142  	// Ex: "Go to Dashboard|http://grafana.example.com/d/yu5UH4MMz/deployments"
   143  	AnnotationKeyLinkPrefix = "link.argocd.argoproj.io/"
   144  )
   145  
   146  // Environment variables for tuning and debugging Argo CD
   147  const (
   148  	// EnvVarSSODebug is an environment variable to enable additional OAuth debugging in the API server
   149  	EnvVarSSODebug = "ARGOCD_SSO_DEBUG"
   150  	// EnvVarRBACDebug is an environment variable to enable additional RBAC debugging in the API server
   151  	EnvVarRBACDebug = "ARGOCD_RBAC_DEBUG"
   152  	// EnvVarFakeInClusterConfig is an environment variable to fake an in-cluster RESTConfig using
   153  	// the current kubectl context (for development purposes)
   154  	EnvVarFakeInClusterConfig = "ARGOCD_FAKE_IN_CLUSTER"
   155  	// Overrides the location where SSH known hosts for repo access data is stored
   156  	EnvVarSSHDataPath = "ARGOCD_SSH_DATA_PATH"
   157  	// Overrides the location where TLS certificate for repo access data is stored
   158  	EnvVarTLSDataPath = "ARGOCD_TLS_DATA_PATH"
   159  	// Specifies number of git remote operations attempts count
   160  	EnvGitAttemptsCount = "ARGOCD_GIT_ATTEMPTS_COUNT"
   161  	// Overrides git submodule support, true by default
   162  	EnvGitSubmoduleEnabled = "ARGOCD_GIT_MODULES_ENABLED"
   163  	// EnvK8sClientQPS is the QPS value used for the kubernetes client (default: 50)
   164  	EnvK8sClientQPS = "ARGOCD_K8S_CLIENT_QPS"
   165  	// EnvK8sClientBurst is the burst value used for the kubernetes client (default: twice the client QPS)
   166  	EnvK8sClientBurst = "ARGOCD_K8S_CLIENT_BURST"
   167  	// EnvClusterCacheResyncDuration is the env variable that holds cluster cache re-sync duration
   168  	EnvClusterCacheResyncDuration = "ARGOCD_CLUSTER_CACHE_RESYNC_DURATION"
   169  	// EnvK8sClientMaxIdleConnections is the number of max idle connections in K8s REST client HTTP transport (default: 500)
   170  	EnvK8sClientMaxIdleConnections = "ARGOCD_K8S_CLIENT_MAX_IDLE_CONNECTIONS"
   171  	// EnvGnuPGHome is the path to ArgoCD's GnuPG keyring for signature verification
   172  	EnvGnuPGHome = "ARGOCD_GNUPGHOME"
   173  	// EnvWatchAPIBufferSize is the buffer size used to transfer K8S watch events to watch API consumer
   174  	EnvWatchAPIBufferSize = "ARGOCD_WATCH_API_BUFFER_SIZE"
   175  	// EnvPauseGenerationAfterFailedAttempts will pause manifest generation after the specified number of failed generation attempts
   176  	EnvPauseGenerationAfterFailedAttempts = "ARGOCD_PAUSE_GEN_AFTER_FAILED_ATTEMPTS"
   177  	// EnvPauseGenerationMinutes pauses manifest generation for the specified number of minutes, after sufficient manifest generation failures
   178  	EnvPauseGenerationMinutes = "ARGOCD_PAUSE_GEN_MINUTES"
   179  	// EnvPauseGenerationRequests pauses manifest generation for the specified number of requests, after sufficient manifest generation failures
   180  	EnvPauseGenerationRequests = "ARGOCD_PAUSE_GEN_REQUESTS"
   181  	// EnvControllerReplicas is the number of controller replicas
   182  	EnvControllerReplicas = "ARGOCD_CONTROLLER_REPLICAS"
   183  	// EnvControllerShard is the shard number that should be handled by controller
   184  	EnvControllerShard = "ARGOCD_CONTROLLER_SHARD"
   185  	// EnvEnableGRPCTimeHistogramEnv enables gRPC metrics collection
   186  	EnvEnableGRPCTimeHistogramEnv = "ARGOCD_ENABLE_GRPC_TIME_HISTOGRAM"
   187  )
   188  
   189  const (
   190  	// MinClientVersion is the minimum client version that can interface with this API server.
   191  	// When introducing breaking changes to the API or datastructures, this number should be bumped.
   192  	// The value here may be lower than the current value in VERSION
   193  	MinClientVersion = "1.4.0"
   194  	// CacheVersion is a objects version cached using util/cache/cache.go.
   195  	// Number should be bumped in case of backward incompatible change to make sure cache is invalidated after upgrade.
   196  	CacheVersion = "1.8.3"
   197  )
   198  
   199  // GetGnuPGHomePath retrieves the path to use for GnuPG home directory, which is either taken from GNUPGHOME environment or a default value
   200  func GetGnuPGHomePath() string {
   201  	if gnuPgHome := os.Getenv(EnvGnuPGHome); gnuPgHome == "" {
   202  		return DefaultGnuPgHomePath
   203  	} else {
   204  		return gnuPgHome
   205  	}
   206  }
   207  
   208  var (
   209  	// K8sClientConfigQPS controls the QPS to be used in K8s REST client configs
   210  	K8sClientConfigQPS float32 = 50
   211  	// K8sClientConfigBurst controls the burst to be used in K8s REST client configs
   212  	K8sClientConfigBurst int = 100
   213  	// K8sMaxIdleConnections controls the number of max idle connections in K8s REST client HTTP transport
   214  	K8sMaxIdleConnections = 500
   215  	// K8sMaxIdleConnections controls the duration of cluster cache refresh
   216  	K8SClusterResyncDuration = 12 * time.Hour
   217  )
   218  
   219  func init() {
   220  	if envQPS := os.Getenv(EnvK8sClientQPS); envQPS != "" {
   221  		if qps, err := strconv.ParseFloat(envQPS, 32); err != nil {
   222  			K8sClientConfigQPS = float32(qps)
   223  		}
   224  	}
   225  	if envBurst := os.Getenv(EnvK8sClientBurst); envBurst != "" {
   226  		if burst, err := strconv.Atoi(envBurst); err != nil {
   227  			K8sClientConfigBurst = burst
   228  		}
   229  	} else {
   230  		K8sClientConfigBurst = 2 * int(K8sClientConfigQPS)
   231  	}
   232  
   233  	if envMaxConn := os.Getenv(EnvK8sClientMaxIdleConnections); envMaxConn != "" {
   234  		if maxConn, err := strconv.Atoi(envMaxConn); err != nil {
   235  			K8sMaxIdleConnections = maxConn
   236  		}
   237  	}
   238  	if clusterResyncDurationStr := os.Getenv(EnvClusterCacheResyncDuration); clusterResyncDurationStr != "" {
   239  		if duration, err := time.ParseDuration(clusterResyncDurationStr); err == nil {
   240  			K8SClusterResyncDuration = duration
   241  		}
   242  	}
   243  }