@@ -11,6 +11,7 @@ import (
1111
1212 api "github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
1313 "github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
14+ "github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
1415 "github.com/ydb-platform/ydb-kubernetes-operator/internal/ptr"
1516)
1617
@@ -23,10 +24,56 @@ type StorageInitJobBuilder struct {
2324 Annotations map [string ]string
2425}
2526
27+ func NewInitJob (ydbCr * api.Storage ) StorageInitJobBuilder {
28+ cr := ydbCr .DeepCopy ()
29+
30+ return StorageInitJobBuilder {Storage : cr }
31+ }
32+
2633func (b * StorageInitJobBuilder ) Unwrap () * api.Storage {
2734 return b .DeepCopy ()
2835}
2936
37+ func (b * StorageInitJobBuilder ) NewLabels () labels.Labels {
38+ l := labels .Common (b .Name , b .Labels )
39+
40+ if b .Spec .InitJob != nil {
41+ l .Merge (b .Spec .InitJob .AdditionalLabels )
42+ }
43+
44+ l .Merge (map [string ]string {labels .ComponentKey : labels .InitComponent })
45+
46+ return l
47+ }
48+
49+ func (b * StorageInitJobBuilder ) NewAnnotations () map [string ]string {
50+ an := annotations .GetYdbTechAnnotations (b .Annotations )
51+
52+ if b .Spec .InitJob .AdditionalAnnotations != nil {
53+ for k , v := range b .Spec .InitJob .AdditionalAnnotations {
54+ an [k ] = v
55+ }
56+ }
57+
58+ an [annotations .ConfigurationChecksum ] = GetSHA256Checksum (b .Spec .Configuration )
59+
60+ return an
61+ }
62+
63+ func (b * StorageInitJobBuilder ) GetResourceBuilder () ResourceBuilder {
64+ jobName := fmt .Sprintf (InitJobNameFormat , b .Name )
65+ jobLabels := b .NewLabels ()
66+ jobAnnotations := b .NewAnnotations ()
67+
68+ return & StorageInitJobBuilder {
69+ Storage : b .Unwrap (),
70+
71+ Name : jobName ,
72+ Labels : jobLabels ,
73+ Annotations : jobAnnotations ,
74+ }
75+ }
76+
3077func (b * StorageInitJobBuilder ) Build (obj client.Object ) error {
3178 job , ok := obj .(* batchv1.Job )
3279 if ! ok {
0 commit comments