@@ -31,6 +31,7 @@ import (
3131 chopClientSet "github.com/altinity/clickhouse-operator/pkg/client/clientset/versioned"
3232 "github.com/altinity/clickhouse-operator/pkg/controller"
3333 "github.com/altinity/clickhouse-operator/pkg/interfaces"
34+ "github.com/altinity/clickhouse-operator/pkg/model/chi/creator"
3435 "github.com/altinity/clickhouse-operator/pkg/model/chi/macro"
3536 "github.com/altinity/clickhouse-operator/pkg/model/managers"
3637 "github.com/altinity/clickhouse-operator/pkg/util"
@@ -196,34 +197,53 @@ func (c *CR) statusUpdate(ctx context.Context, chi *api.ClickHouseInstallation)
196197}
197198
198199func (c * CR ) buildResources (chi * api.ClickHouseInstallation ) (* api.ClickHouseInstallation , * core.ConfigMap ) {
199- var normalized , normalizedCompleted []byte
200- if chi .Status .NormalizedCR != nil {
201- normalized , _ = json .Marshal (chi .Status .NormalizedCR )
202- }
203- if chi .Status .NormalizedCRCompleted != nil {
204- normalizedCompleted , _ = json .Marshal (chi .Status .NormalizedCRCompleted )
205- }
206-
200+ // Build required components
201+ normalized , normalizedCompleted := c .buildNormalized (chi )
207202 tagger := managers .NewTagManager (managers .TagManagerTypeClickHouse , chi )
203+ namespace , name := c .buildNamespaceName (chi )
204+
205+ // Build ConfigMap
208206 cm := & core.ConfigMap {
209207 ObjectMeta : meta.ObjectMeta {
210- Namespace : c .buildCMNamespace (chi ),
211- Name : c .buildCMName (chi ),
212- Labels : c .macro .Scope (chi ).Map (tagger .Label (interfaces .LabelConfigMapStorage )),
213- Annotations : c .macro .Scope (chi ).Map (tagger .Annotate (interfaces .AnnotateConfigMapStorage )),
208+ Namespace : namespace ,
209+ Name : name ,
210+ Labels : c .macro .Scope (chi ).Map (tagger .Label (interfaces .LabelConfigMapStorage )),
211+ Annotations : c .macro .Scope (chi ).Map (tagger .Annotate (interfaces .AnnotateConfigMapStorage )),
212+ OwnerReferences : creator .NewOwnerReferencer ().CreateOwnerReferences (chi ),
214213 },
215214 Data : map [string ]string {
216- statusNormalized : string ( normalized ) ,
217- statusNormalizedCompleted : string ( normalizedCompleted ) ,
215+ statusNormalized : normalized ,
216+ statusNormalizedCompleted : normalizedCompleted ,
218217 },
219218 }
220219
221- chi . Status . NormalizedCR = nil
222- chi . Status . NormalizedCRCompleted = nil
220+ // Finalize resources
221+ c . postprocessNormalized ( chi )
223222
224223 return chi , cm
225224}
226225
226+ func (c * CR ) buildNamespaceName (chi * api.ClickHouseInstallation ) (string , string ) {
227+ return c .buildCMNamespace (chi ), c .buildCMName (chi )
228+ }
229+
230+ func (c * CR ) buildNormalized (chi * api.ClickHouseInstallation ) (normalized string , normalizedCompleted string ) {
231+ if chi .Status .NormalizedCR != nil {
232+ bytes , _ := json .Marshal (chi .Status .NormalizedCR )
233+ normalized = string (bytes )
234+ }
235+ if chi .Status .NormalizedCRCompleted != nil {
236+ bytes , _ := json .Marshal (chi .Status .NormalizedCRCompleted )
237+ normalizedCompleted = string (bytes )
238+ }
239+ return normalized , normalizedCompleted
240+ }
241+
242+ func (c * CR ) postprocessNormalized (chi * api.ClickHouseInstallation ) {
243+ chi .Status .NormalizedCR = nil
244+ chi .Status .NormalizedCRCompleted = nil
245+ }
246+
227247func (c * CR ) statusUpdateCR (ctx context.Context , chi * api.ClickHouseInstallation ) error {
228248 _ , err := c .chopClient .ClickhouseV1 ().ClickHouseInstallations (chi .GetNamespace ()).UpdateStatus (ctx , chi , controller .NewUpdateOptions ())
229249 return err
0 commit comments