github.com/argoproj-labs/argocd-operator@v0.10.0/controllers/argocd/dexUtil.go (about) 1 package argocd 2 3 import ( 4 "fmt" 5 "os" 6 7 corev1 "k8s.io/api/core/v1" 8 9 argoproj "github.com/argoproj-labs/argocd-operator/api/v1beta1" 10 "github.com/argoproj-labs/argocd-operator/common" 11 "github.com/argoproj-labs/argocd-operator/controllers/argoutil" 12 ) 13 14 // getDexContainerImage will return the container image for the Dex server. 15 // 16 // There are three possible options for configuring the image, and this is the 17 // order of preference. 18 // 19 // 1. from the Spec, the spec.sso.dex field has an image and version to use for 20 // generating an image reference. 21 // 2. from the Environment, this looks for the `ARGOCD_DEX_IMAGE` field and uses 22 // that if the spec is not configured. 23 // 3. the default is configured in common.ArgoCDDefaultDexVersion and 24 // common.ArgoCDDefaultDexImage. 25 func getDexContainerImage(cr *argoproj.ArgoCD) string { 26 defaultImg, defaultTag := false, false 27 28 img := "" 29 tag := "" 30 31 if cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && cr.Spec.SSO.Dex.Image != "" { 32 img = cr.Spec.SSO.Dex.Image 33 } 34 35 if img == "" { 36 img = common.ArgoCDDefaultDexImage 37 defaultImg = true 38 } 39 40 if cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && cr.Spec.SSO.Dex.Version != "" { 41 tag = cr.Spec.SSO.Dex.Version 42 } 43 44 if tag == "" { 45 tag = common.ArgoCDDefaultDexVersion 46 defaultTag = true 47 } 48 if e := os.Getenv(common.ArgoCDDexImageEnvName); e != "" && (defaultTag && defaultImg) { 49 return e 50 } 51 return argoutil.CombineImageTag(img, tag) 52 } 53 54 // getDexOAuthRedirectURI will return the OAuth redirect URI for the Dex server. 55 func (r *ReconcileArgoCD) getDexOAuthRedirectURI(cr *argoproj.ArgoCD) string { 56 uri := r.getArgoServerURI(cr) 57 return uri + common.ArgoCDDefaultDexOAuthRedirectPath 58 } 59 60 // getDexOAuthClientID will return the OAuth client ID for the given ArgoCD. 61 func getDexOAuthClientID(cr *argoproj.ArgoCD) string { 62 return fmt.Sprintf("system:serviceaccount:%s:%s", cr.Namespace, fmt.Sprintf("%s-%s", cr.Name, common.ArgoCDDefaultDexServiceAccountName)) 63 } 64 65 // getDexResources will return the ResourceRequirements for the Dex container. 66 func getDexResources(cr *argoproj.ArgoCD) corev1.ResourceRequirements { 67 68 resources := corev1.ResourceRequirements{} 69 70 // Allow override of resource requirements from CR 71 if cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && cr.Spec.SSO.Dex.Resources != nil { 72 resources = *cr.Spec.SSO.Dex.Resources 73 } 74 75 return resources 76 } 77 78 func getDexConfig(cr *argoproj.ArgoCD) string { 79 config := common.ArgoCDDefaultDexConfig 80 81 // Allow override of config from CR 82 if cr.Spec.ExtraConfig["dex.config"] != "" { 83 config = cr.Spec.ExtraConfig["dex.config"] 84 } else if cr.Spec.SSO != nil && cr.Spec.SSO.Dex != nil && len(cr.Spec.SSO.Dex.Config) > 0 { 85 config = cr.Spec.SSO.Dex.Config 86 } 87 return config 88 }