@@ -153,8 +153,8 @@ func (r *CorootReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
153153 }
154154
155155 if cr .Spec .ExternalClickhouse == nil {
156- r . CreateOrUpdateSecret ( ctx , cr , "clickhouse" , fmt . Sprintf ( "%s-clickhouse" , cr . Name ), "password" , 16 )
157-
156+ passwordSecret := clickhousePasswordSecret ( cr )
157+ r . CreateOrUpdateSecret ( ctx , cr , passwordSecret . Name , [] string { passwordSecret . Key }, 16 , false )
158158 r .CreateOrUpdateServiceAccount (ctx , cr , "clickhouse-keeper" , sccNonroot )
159159 r .CreateOrUpdateService (ctx , cr , r .clickhouseKeeperServiceHeadless (cr ))
160160 for _ , pvc := range r .clickhouseKeeperPVCs (cr ) {
@@ -230,28 +230,24 @@ func (r *CorootReconciler) GetSecret(ctx context.Context, cr *corootv1.Coroot, s
230230 return string (data ), nil
231231}
232232
233- func (r * CorootReconciler ) CreateOrUpdateSecret (ctx context.Context , cr * corootv1.Coroot , component , name , key string , length int ) string {
234- s := & corev1.Secret {
235- ObjectMeta : metav1.ObjectMeta {
236- Name : name ,
237- Namespace : cr .Namespace ,
238- Labels : Labels (cr , component ),
239- },
233+ func (r * CorootReconciler ) CreateOrUpdateSecret (ctx context.Context , cr * corootv1.Coroot , name string , keys []string , length int , retain bool ) {
234+ if len (keys ) == 0 {
235+ return
240236 }
241- var data string
242- r .CreateOrUpdate (ctx , cr , s , false , false , func () error {
237+ s := & corev1.Secret {}
238+ s .Name = name
239+ s .Namespace = cr .Namespace
240+ r .CreateOrUpdate (ctx , cr , s , false , retain , func () error {
243241 if s .Data == nil {
244242 s .Data = map [string ][]byte {}
245243 }
246- if d , ok := s .Data [key ]; ok {
247- data = string (d )
248- } else {
249- data = RandomString (length )
250- s .Data [key ] = []byte (data )
244+ for _ , key := range keys {
245+ if _ , ok := s .Data [key ]; ! ok {
246+ s .Data [key ] = []byte (RandomString (length ))
247+ }
251248 }
252249 return nil
253250 })
254- return data
255251}
256252
257253func (r * CorootReconciler ) CreateOrUpdateConfigMap (ctx context.Context , cr * corootv1.Coroot , cm * corev1.ConfigMap ) {
0 commit comments