Skip to content

Commit

Permalink
fix: Use image configured in spec as fallback before default image f…
Browse files Browse the repository at this point in the history
…or repository server workload (#1262)

* fix: Use image configured in spec as fallback before default image for repository server workload

Signed-off-by: tomjo <[email protected]>

* docs: remove unused ARGOCD_REPOSERVER_IMAGE references and update .spec.repo.version docs with fallback information

Signed-off-by: tomjo <[email protected]>

* fix: configuration order comment

Signed-off-by: tomjo <[email protected]>

---------

Signed-off-by: tomjo <[email protected]>
Co-authored-by: tomjo <[email protected]>
  • Loading branch information
tomjo and tomjo authored Jun 18, 2024
1 parent c62c712 commit aaf77af
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 20 deletions.
4 changes: 0 additions & 4 deletions common/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ const (
// ArgoCDKeyResourceTrackingMethod is the configuration key for resource tracking method
ArgoCDKeyResourceTrackingMethod = "application.resourceTrackingMethod"

// ArgoCDRepoImageEnvName is the environment variable used to get the image
// to used for the Dex container.
ArgoCDRepoImageEnvName = "ARGOCD_REPOSERVER_IMAGE"

// ArgoCDKeyRepositories is the configuration key for repositories.
ArgoCDKeyRepositories = "repositories"

Expand Down
24 changes: 16 additions & 8 deletions controllers/argocd/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,27 +200,35 @@ func getArgoContainerImage(cr *argoproj.ArgoCD) string {

// getRepoServerContainerImage will return the container image for the Repo server.
//
// There are three possible options for configuring the image, and this is the
// There are four possible options for configuring the image, and this is the
// order of preference.
//
// 1. from the Spec, the spec.repo field has an image and version to use for
// generating an image reference.
// 2. from the Environment, this looks for the `ARGOCD_REPOSERVER_IMAGE` field and uses
// 2. from the Spec, the spec.version field has an image and version to use for
// generating an image reference
// 3. from the Environment, this looks for the `ARGOCD_IMAGE` field and uses
// that if the spec is not configured.
// 3. the default is configured in common.ArgoCDDefaultRepoServerVersion and
// common.ArgoCDDefaultRepoServerImage.
// 4. the default is configured in common.ArgoCDDefaultArgoVersion and
// common.ArgoCDDefaultArgoImage.
func getRepoServerContainerImage(cr *argoproj.ArgoCD) string {
defaultImg, defaultTag := false, false
img := cr.Spec.Repo.Image
if img == "" {
img = common.ArgoCDDefaultArgoImage
defaultImg = true
img = cr.Spec.Image
if img == "" {
img = common.ArgoCDDefaultArgoImage
defaultImg = true
}
}

tag := cr.Spec.Repo.Version
if tag == "" {
tag = common.ArgoCDDefaultArgoVersion
defaultTag = true
tag = cr.Spec.Version
if tag == "" {
tag = common.ArgoCDDefaultArgoVersion
defaultTag = true
}
}
if e := os.Getenv(common.ArgoCDImageEnvName); e != "" && (defaultTag && defaultImg) {
return e
Expand Down
40 changes: 35 additions & 5 deletions controllers/argocd/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ import (
)

const (
dexTestImage = "testing/dex:latest"
argoTestImage = "testing/argocd:latest"
redisTestImage = "testing/redis:latest"
redisHATestImage = "testing/redis:latest-ha"
redisHAProxyTestImage = "testing/redis-ha-haproxy:latest-ha"
dexTestImage = "testing/dex:latest"
argoTestImage = "testing/argocd:latest"
argoTestImageOtherVersion = "testing/argocd:test"
redisTestImage = "testing/redis:latest"
redisHATestImage = "testing/redis:latest-ha"
redisHAProxyTestImage = "testing/redis-ha-haproxy:latest-ha"
)

func parallelismLimit(n int32) argoCDOpt {
Expand Down Expand Up @@ -111,6 +112,35 @@ var imageTests = []struct {
t.Setenv(common.ArgoCDImageEnvName, argoTestImage)
},
},
{
name: "repo default configuration",
imageFunc: getRepoServerContainerImage,
want: argoutil.CombineImageTag(common.ArgoCDDefaultArgoImage, common.ArgoCDDefaultArgoVersion),
},
{
name: "repo spec configuration",
imageFunc: getRepoServerContainerImage,
want: argoTestImage, opts: []argoCDOpt{func(a *argoproj.ArgoCD) {
a.Spec.Repo.Image = "testing/argocd"
a.Spec.Repo.Version = "latest"
}},
},
{
name: "repo configuration fallback spec",
imageFunc: getRepoServerContainerImage,
want: argoTestImageOtherVersion, opts: []argoCDOpt{func(a *argoproj.ArgoCD) {
a.Spec.Image = "testing/argocd"
a.Spec.Version = "test"
}},
},
{
name: "argo env configuration",
imageFunc: getRepoServerContainerImage,
want: argoTestImage,
pre: func(t *testing.T) {
t.Setenv(common.ArgoCDImageEnvName, argoTestImage)
},
},
{
name: "redis default configuration",
imageFunc: getRedisContainerImage,
Expand Down
4 changes: 2 additions & 2 deletions docs/reference/argocd.md
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ MountSAToken | false | Whether the ServiceAccount token should be mounted to the
ServiceAccount | "" | The name of the ServiceAccount to use with the repo-server pod.
VerifyTLS | false | Whether to enforce strict TLS checking on all components when communicating with repo server
AutoTLS | "" | Provider to use for setting up TLS the repo-server's gRPC TLS certificate (one of: `openshift`). Currently only available for OpenShift.
Image | `argoproj/argocd` | The container image for ArgoCD Repo Server. This overrides the `ARGOCD_REPOSERVER_IMAGE` environment variable.
Version | same as `.spec.Version` | The tag to use with the ArgoCD Repo Server.
Image | `argoproj/argocd` | The container image for ArgoCD Repo Server. This overrides the `ARGOCD_IMAGE` environment variable for the repo server.
Version | same as `.spec.Version` | The tag to use with the ArgoCD Repo Server. Fallsback to `.spec.Version` and the default image version in that order if not specified.
LogLevel | info | The log level to be used by the ArgoCD Repo Server. Valid options are debug, info, error, and warn.
LogFormat | text | The log format to be used by the ArgoCD Repo Server. Valid options are text or json.
ExecTimeout | 180 | Execution timeout in seconds for rendering tools (e.g. Helm, Kustomize)
Expand Down
1 change: 0 additions & 1 deletion docs/usage/environment_variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ The following default value of images could be overridden by setting the environ
| Environment Variable | Default Value |
| --- | --- |
| `ARGOCD_IMAGE` | [quay.io/argoproj/argocd](quay.io/argoproj/argocd) |
| `ARGOCD_REPOSERVER_IMAGE` | [quay.io/argoproj/argocd](quay.io/argoproj/argocd) |
| `ARGOCD_DEX_IMAGE` | [ghcr.io/dexidp/dex](ghcr.io/dexidp/dex) |
| `ARGOCD_KEYCLOAK_IMAGE` | [quay.io/keycloak/keycloak](quay.io/keycloak/keycloak) |
| `ARGOCD_REDIS_IMAGE` | redis |
Expand Down

0 comments on commit aaf77af

Please sign in to comment.