diff --git a/api/v1beta1/common_types.go b/api/v1beta1/common_types.go index 848b7cdbd2dd952c3d0667126d60e92954042e20..eb3c40d6c4dfe3691de3cbc2e993bc66b075c93d 100644 --- a/api/v1beta1/common_types.go +++ b/api/v1beta1/common_types.go @@ -22,11 +22,12 @@ import ( // KubernetesConfig will be the JSON struct for Basic Redis Config type KubernetesConfig struct { - Image string `json:"image"` - ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` - Resources *corev1.ResourceRequirements `json:"resources,omitempty"` - ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"` - ServiceType string `json:"serviceType"` + Image string `json:"image"` + ImagePullPolicy corev1.PullPolicy `json:"imagePullPolicy,omitempty"` + Resources *corev1.ResourceRequirements `json:"resources,omitempty"` + ExistingPasswordSecret *ExistingPasswordSecret `json:"redisSecret,omitempty"` + ServiceType string `json:"serviceType"` + ImagePullSecrets *[]corev1.LocalObjectReference `json:"imagePullSecrets,omitempty"` } // ExistingPasswordSecret is the struct to access the existing secret diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index e92f0003119a121c2a2289f37e77be4e9d260f82..27b90d4efdbb1340446c486909038b80868e1fd2 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -63,6 +63,15 @@ func (in *KubernetesConfig) DeepCopyInto(out *KubernetesConfig) { *out = new(ExistingPasswordSecret) (*in).DeepCopyInto(*out) } + if in.ImagePullSecrets != nil { + in, out := &in.ImagePullSecrets, &out.ImagePullSecrets + *out = new([]v1.LocalObjectReference) + if **in != nil { + in, out := *in, *out + *out = make([]v1.LocalObjectReference, len(*in)) + copy(*out, *in) + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KubernetesConfig. diff --git a/config/crd/bases/redis.redis.opstreelabs.in_redis.yaml b/config/crd/bases/redis.redis.opstreelabs.in_redis.yaml index c1f67d65a9f708b647bba954042077a7bf929819..df6aa27749bad2cb5ce8c1bba0083af9a912b1e1 100644 --- a/config/crd/bases/redis.redis.opstreelabs.in_redis.yaml +++ b/config/crd/bases/redis.redis.opstreelabs.in_redis.yaml @@ -637,6 +637,17 @@ spec: description: PullPolicy describes a policy for if/when to pull a container image type: string + imagePullSecrets: + items: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same namespace. + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + type: array redisSecret: description: ExistingPasswordSecret is the struct to access the existing secret @@ -1880,6 +1891,18 @@ spec: description: PullPolicy describes a policy for if/when to pull a container image type: string + imagePullSecrets: + items: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same + namespace. + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + type: array redisSecret: description: ExistingPasswordSecret is the struct to access the existing secret diff --git a/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml b/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml index fabf959889b0d3c692f30db570bb225d65f9a45b..963a45f98ebf856e81ff35ff558093a2cb37fb48 100644 --- a/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml +++ b/config/crd/bases/redis.redis.opstreelabs.in_redisclusters.yaml @@ -658,6 +658,17 @@ spec: description: PullPolicy describes a policy for if/when to pull a container image type: string + imagePullSecrets: + items: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same namespace. + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + type: array redisSecret: description: ExistingPasswordSecret is the struct to access the existing secret @@ -1918,6 +1929,17 @@ spec: description: PullPolicy describes a policy for if/when to pull a container image type: string + imagePullSecrets: + items: + description: LocalObjectReference contains enough information + to let you locate the referenced object inside the same namespace. + properties: + name: + description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + TODO: Add other useful fields. apiVersion, kind, uid?' + type: string + type: object + type: array redisSecret: description: ExistingPasswordSecret is the struct to access the existing secret diff --git a/example/redis-cluster.yaml b/example/redis-cluster.yaml index f6421bf50f1ea6b7af2da6ee5d5fb4efb9824512..a779ffa15cec934b27d464f27eadbd2da35d0d6e 100644 --- a/example/redis-cluster.yaml +++ b/example/redis-cluster.yaml @@ -19,8 +19,10 @@ spec: name: redis-secret key: password serviceType: ClusterIP + # imagePullSecrets: + # - name: regcred redisExporter: - enabled: true + enabled: false image: quay.io/opstree/redis-exporter:1.0 imagePullPolicy: Always resources: @@ -45,9 +47,9 @@ spec: # name: mysecret # key: username redisLeader: - serviceType: LoadBalancer + serviceType: ClusterIP redisFollower: - serviceType: LoadBalancer + serviceType: ClusterIP storage: volumeClaimTemplate: spec: diff --git a/example/redis-standalone.yaml b/example/redis-standalone.yaml index 3338509a4bd129b15cbd4296e424b91538991181..14c7b9675c2dc7f2085224d6f33b0077b6e756d9 100644 --- a/example/redis-standalone.yaml +++ b/example/redis-standalone.yaml @@ -43,6 +43,8 @@ spec: # name: redis-secret # key: password serviceType: ClusterIP + # imagePullSecrets: + # - name: regcred redisConfig: {} storage: volumeClaimTemplate: diff --git a/k8sutils/redis-cluster.go b/k8sutils/redis-cluster.go index 6029f70f4ca21255fd518cfba34313ede99fc5db..1ec2ee0a7e262e4bc626cc17323971a1a086f2ca 100644 --- a/k8sutils/redis-cluster.go +++ b/k8sutils/redis-cluster.go @@ -17,16 +17,22 @@ type RedisClusterService struct { // generateRedisStandalone generates Redis standalone information func generateRedisClusterParams(cr *redisv1beta1.RedisCluster, replicas *int32) statefulSetParameters { - return statefulSetParameters{ - Replicas: replicas, - NodeSelector: cr.Spec.NodeSelector, - SecurityContext: cr.Spec.SecurityContext, - PriorityClassName: cr.Spec.PriorityClassName, - Affinity: cr.Spec.Affinity, - Tolerations: cr.Spec.Tolerations, - EnableMetrics: cr.Spec.RedisExporter.Enabled, - PersistentVolumeClaim: cr.Spec.Storage.VolumeClaimTemplate, + res := statefulSetParameters{ + Replicas: replicas, + NodeSelector: cr.Spec.NodeSelector, + SecurityContext: cr.Spec.SecurityContext, + PriorityClassName: cr.Spec.PriorityClassName, + Affinity: cr.Spec.Affinity, + Tolerations: cr.Spec.Tolerations, + EnableMetrics: cr.Spec.RedisExporter.Enabled, + } + if cr.Spec.KubernetesConfig.ImagePullSecrets != nil { + res.ImagePullSecrets = cr.Spec.KubernetesConfig.ImagePullSecrets } + if cr.Spec.Storage != nil { + res.PersistentVolumeClaim = cr.Spec.Storage.VolumeClaimTemplate + } + return res } // generateRedisStandaloneContainerParams generates Redis container information diff --git a/k8sutils/redis-standalone.go b/k8sutils/redis-standalone.go index 33a2106a9c0069c104b0084153621a924c143b73..d2ecb9b9ed673048d2f7517559afa9a7b316999d 100644 --- a/k8sutils/redis-standalone.go +++ b/k8sutils/redis-standalone.go @@ -63,6 +63,9 @@ func generateRedisStandaloneParams(cr *redisv1beta1.Redis) statefulSetParameters Tolerations: cr.Spec.Tolerations, EnableMetrics: cr.Spec.RedisExporter.Enabled, } + if cr.Spec.KubernetesConfig.ImagePullSecrets != nil { + res.ImagePullSecrets = cr.Spec.KubernetesConfig.ImagePullSecrets + } if cr.Spec.Storage != nil { res.PersistentVolumeClaim = cr.Spec.Storage.VolumeClaimTemplate } diff --git a/k8sutils/statefulset.go b/k8sutils/statefulset.go index e2ecb3b3634d846ee8e13beac3e5d7dbbe79910e..e5d8be2ec8dcb944f665259bb4680c6f6bc210d8 100644 --- a/k8sutils/statefulset.go +++ b/k8sutils/statefulset.go @@ -27,6 +27,7 @@ type statefulSetParameters struct { Tolerations *[]corev1.Toleration EnableMetrics bool PersistentVolumeClaim corev1.PersistentVolumeClaim + ImagePullSecrets *[]corev1.LocalObjectReference } // containerParameters will define container input params @@ -115,6 +116,9 @@ func generateStateFulSetsDef(stsMeta metav1.ObjectMeta, labels map[string]string if params.Tolerations != nil { statefulset.Spec.Template.Spec.Tolerations = *params.Tolerations } + if params.ImagePullSecrets != nil { + statefulset.Spec.Template.Spec.ImagePullSecrets = *params.ImagePullSecrets + } if containerParams.PersistenceEnabled != nil && *containerParams.PersistenceEnabled { statefulset.Spec.VolumeClaimTemplates = append(statefulset.Spec.VolumeClaimTemplates, createPVCTemplate(stsMeta.Name, params.PersistentVolumeClaim)) }