Skip to content

Commit 5f50796

Browse files
committed
fix initJobBuilder
1 parent e0f523c commit 5f50796

File tree

3 files changed

+37
-40
lines changed

3 files changed

+37
-40
lines changed

internal/controllers/storage/init.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,7 @@ func (r *Reconciler) createInitBlobstorageJob(
294294
ctx context.Context,
295295
storage *resources.StorageClusterBuilder,
296296
) error {
297-
ydbCr := storage.Unwrap()
298-
initJob := resources.NewInitJob(ydbCr)
299-
builder := initJob.GetResourceBuilder()
297+
builder := storage.GetInitJobBuilder()
300298
newResource := builder.Placeholder(storage)
301299
_, err := resources.CreateOrUpdateOrMaybeIgnore(ctx, r.Client, newResource, func() error {
302300
var err error

internal/resources/storage.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,42 @@ func (b *StorageClusterBuilder) NewAnnotations() map[string]string {
4949
return an
5050
}
5151

52+
func (b *StorageClusterBuilder) NewInitJobLabels() labels.Labels {
53+
l := labels.Common(b.Name, b.Labels)
54+
55+
if b.Spec.InitJob != nil {
56+
l.Merge(b.Spec.InitJob.AdditionalLabels)
57+
}
58+
l.Merge(map[string]string{labels.ComponentKey: labels.InitComponent})
59+
60+
return l
61+
}
62+
63+
func (b *StorageClusterBuilder) NewInitJobAnnotations() map[string]string {
64+
an := annotations.Common(b.Annotations)
65+
66+
if b.Spec.InitJob != nil {
67+
an.Merge(b.Spec.InitJob.AdditionalLabels)
68+
}
69+
an.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Spec.Configuration)})
70+
71+
return an
72+
}
73+
74+
func (b *StorageClusterBuilder) GetInitJobBuilder() ResourceBuilder {
75+
jobName := fmt.Sprintf(InitJobNameFormat, b.Name)
76+
jobLabels := b.NewInitJobLabels()
77+
jobAnnotations := b.NewInitJobAnnotations()
78+
79+
return &StorageInitJobBuilder{
80+
Storage: b.Unwrap(),
81+
82+
Name: jobName,
83+
Labels: jobLabels,
84+
Annotations: jobAnnotations,
85+
}
86+
}
87+
5288
func (b *StorageClusterBuilder) GetResourceBuilders(restConfig *rest.Config) []ResourceBuilder {
5389
storageLabels := b.NewLabels()
5490
storageAnnotations := b.NewAnnotations()

internal/resources/storage_init_job.go

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ 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"
1514
"github.com/ydb-platform/ydb-kubernetes-operator/internal/ptr"
1615
)
1716

@@ -34,42 +33,6 @@ func (b *StorageInitJobBuilder) Unwrap() *api.Storage {
3433
return b.DeepCopy()
3534
}
3635

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-
l.Merge(map[string]string{labels.ComponentKey: labels.InitComponent})
44-
45-
return l
46-
}
47-
48-
func (b *StorageInitJobBuilder) NewAnnotations() map[string]string {
49-
an := annotations.Common(b.Annotations)
50-
51-
if b.Spec.InitJob != nil {
52-
an.Merge(b.Spec.InitJob.AdditionalLabels)
53-
}
54-
an.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Spec.Configuration)})
55-
56-
return an
57-
}
58-
59-
func (b *StorageInitJobBuilder) GetResourceBuilder() ResourceBuilder {
60-
jobName := fmt.Sprintf(InitJobNameFormat, b.Name)
61-
jobLabels := b.NewLabels()
62-
jobAnnotations := b.NewAnnotations()
63-
64-
return &StorageInitJobBuilder{
65-
Storage: b.Unwrap(),
66-
67-
Name: jobName,
68-
Labels: jobLabels,
69-
Annotations: jobAnnotations,
70-
}
71-
}
72-
7336
func (b *StorageInitJobBuilder) Build(obj client.Object) error {
7437
job, ok := obj.(*batchv1.Job)
7538
if !ok {

0 commit comments

Comments
 (0)