Skip to content

Commit a43866e

Browse files
committed
use additionalLabels only from initJob
1 parent 057717b commit a43866e

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

internal/controllers/storage/init.go

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

internal/resources/storage.go

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

53-
func (b *StorageClusterBuilder) GetInitJobBuilder() ResourceBuilder {
54-
jobName := fmt.Sprintf(InitJobNameFormat, b.Name)
55-
jobLabels := b.NewLabels()
56-
jobLabels[labels.ComponentKey] = labels.InitComponent
57-
jobAnnotations := b.NewAnnotations()
58-
59-
if b.Spec.InitJob != nil {
60-
if b.Spec.InitJob.AdditionalLabels != nil {
61-
for k, v := range b.Spec.InitJob.AdditionalLabels {
62-
jobLabels[k] = v
63-
}
64-
}
65-
if b.Spec.InitJob.AdditionalAnnotations != nil {
66-
for k, v := range b.Spec.InitJob.AdditionalAnnotations {
67-
jobAnnotations[k] = v
68-
}
69-
}
70-
}
71-
72-
return &StorageInitJobBuilder{
73-
Storage: b.Unwrap(),
74-
75-
Name: jobName,
76-
Labels: jobLabels,
77-
Annotations: jobAnnotations,
78-
}
79-
}
80-
8153
func (b *StorageClusterBuilder) GetResourceBuilders(restConfig *rest.Config) []ResourceBuilder {
8254
storageLabels := b.NewLabels()
8355
storageAnnotations := b.NewAnnotations()

internal/resources/storage_init_job.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
2633
func (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+
3077
func (b *StorageInitJobBuilder) Build(obj client.Object) error {
3178
job, ok := obj.(*batchv1.Job)
3279
if !ok {

0 commit comments

Comments
 (0)