Skip to content

Commit 4da7be2

Browse files
committed
fixes labels
1 parent aef232b commit 4da7be2

File tree

6 files changed

+36
-70
lines changed

6 files changed

+36
-70
lines changed

internal/labels/label.go

-36
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package labels
22

3-
import (
4-
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
5-
)
6-
73
// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
84
const (
95
// NameKey The name of a higher level application this one is part of
@@ -51,28 +47,6 @@ func Common(name string, defaultLabels Labels) Labels {
5147
return l
5248
}
5349

54-
func StorageLabels(cluster *v1alpha1.Storage) Labels {
55-
l := Common(cluster.Name, cluster.Labels)
56-
57-
l.Merge(cluster.Spec.AdditionalLabels)
58-
l.Merge(map[string]string{
59-
ComponentKey: StorageComponent,
60-
})
61-
62-
return l
63-
}
64-
65-
func DatabaseLabels(database *v1alpha1.Database) Labels {
66-
l := Common(database.Name, database.Labels)
67-
68-
l.Merge(database.Spec.AdditionalLabels)
69-
l.Merge(map[string]string{
70-
ComponentKey: DynamicComponent,
71-
})
72-
73-
return l
74-
}
75-
7650
func (l Labels) AsMap() map[string]string {
7751
return l
7852
}
@@ -99,16 +73,6 @@ func (l Labels) Merge(other map[string]string) map[string]string {
9973
return l
10074
}
10175

102-
func (l Labels) MergeInPlace(other map[string]string) map[string]string {
103-
result := l.Copy()
104-
105-
for k, v := range other {
106-
result[k] = v
107-
}
108-
109-
return result
110-
}
111-
11276
func makeCommonLabels(other map[string]string, instance string) map[string]string {
11377
common := make(map[string]string)
11478

internal/resources/database.go

+16-11
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,14 @@ func NewDatabase(ydbCr *api.Database) DatabaseBuilder {
2929

3030
func (b *DatabaseBuilder) NewLabels() labels.Labels {
3131
l := labels.Common(b.Name, b.Labels)
32-
33-
l.Merge(b.Spec.AdditionalLabels)
3432
l.Merge(map[string]string{labels.ComponentKey: labels.DynamicComponent})
3533

3634
return l
3735
}
3836

39-
func (b *DatabaseBuilder) NewAnnotations() map[string]string {
37+
func (b *DatabaseBuilder) NewAnnotations() annotations.Annotations {
4038
an := annotations.Common(b.Annotations)
4139

42-
an.Merge(b.Spec.AdditionalAnnotations)
43-
if b.Spec.Configuration != "" {
44-
an.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Spec.Configuration)})
45-
} else {
46-
an.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Storage.Spec.Configuration)})
47-
}
48-
4940
return an
5041
}
5142

@@ -62,8 +53,17 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
6253
databaseAnnotations := b.NewAnnotations()
6354

6455
statefulSetLabels := databaseLabels.Copy()
56+
statefulSetLabels.Merge(b.Spec.AdditionalLabels)
6557
statefulSetLabels.Merge(map[string]string{labels.StatefulsetComponent: b.Name})
6658

59+
statefulSetAnnotations := databaseAnnotations.Copy()
60+
statefulSetAnnotations.Merge(b.Spec.AdditionalAnnotations)
61+
if b.Spec.Configuration != "" {
62+
statefulSetAnnotations.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Spec.Configuration)})
63+
} else {
64+
statefulSetAnnotations.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Storage.Spec.Configuration)})
65+
}
66+
6767
grpcServiceLabels := databaseLabels.Copy()
6868
grpcServiceLabels.Merge(b.Spec.Service.GRPC.AdditionalLabels)
6969
grpcServiceLabels.Merge(map[string]string{labels.ServiceComponent: labels.GRPCComponent})
@@ -205,7 +205,7 @@ func (b *DatabaseBuilder) GetResourceBuilders(restConfig *rest.Config) []Resourc
205205

206206
Name: b.Name,
207207
Labels: statefulSetLabels,
208-
Annotations: databaseAnnotations,
208+
Annotations: statefulSetAnnotations,
209209
},
210210
)
211211
} else {
@@ -235,6 +235,11 @@ func (b *DatabaseBuilder) getNodeSetBuilders(
235235

236236
nodeSetAnnotations := databaseAnnotations.Copy()
237237
nodeSetAnnotations.Merge(nodeSetSpecInline.Annotations)
238+
if b.Spec.Configuration != "" {
239+
nodeSetAnnotations.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Spec.Configuration)})
240+
} else {
241+
nodeSetAnnotations.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Storage.Spec.Configuration)})
242+
}
238243

239244
databaseNodeSetSpec := b.recastDatabaseNodeSetSpecInline(nodeSetSpecInline.DeepCopy())
240245
if nodeSetSpecInline.Remote != nil {

internal/resources/databasenodeset.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ type DatabaseNodeSetResource struct {
5656

5757
func (b *DatabaseNodeSetResource) NewLabels() labels.Labels {
5858
l := labels.Common(b.Name, b.Labels)
59-
60-
l.Merge(b.Spec.AdditionalLabels)
6159
l.Merge(map[string]string{labels.ComponentKey: labels.DynamicComponent})
6260

6361
databaseNodeSetName := b.Labels[labels.DatabaseNodeSetComponent]
@@ -70,11 +68,9 @@ func (b *DatabaseNodeSetResource) NewLabels() labels.Labels {
7068
return l
7169
}
7270

73-
func (b *DatabaseNodeSetResource) NewAnnotations() map[string]string {
71+
func (b *DatabaseNodeSetResource) NewAnnotations() annotations.Annotations {
7472
an := annotations.Common(b.Annotations)
7573

76-
an.Merge(b.Spec.AdditionalAnnotations)
77-
7874
return an
7975
}
8076

@@ -83,8 +79,12 @@ func (b *DatabaseNodeSetResource) GetResourceBuilders(restConfig *rest.Config) [
8379
nodeSetAnnotations := b.NewAnnotations()
8480

8581
statefulSetLabels := nodeSetLabels.Copy()
82+
statefulSetLabels.Merge(b.Spec.AdditionalLabels)
8683
statefulSetLabels.Merge(map[string]string{labels.StatefulsetComponent: b.Name})
8784

85+
statefulSetAnnotations := nodeSetAnnotations.Copy()
86+
statefulSetAnnotations.Merge(b.Spec.AdditionalAnnotations)
87+
8888
var resourceBuilders []ResourceBuilder
8989
resourceBuilders = append(resourceBuilders,
9090
&DatabaseStatefulSetBuilder{
@@ -93,7 +93,7 @@ func (b *DatabaseNodeSetResource) GetResourceBuilders(restConfig *rest.Config) [
9393

9494
Name: b.Name,
9595
Labels: statefulSetLabels,
96-
Annotations: nodeSetAnnotations,
96+
Annotations: statefulSetAnnotations,
9797
},
9898
)
9999
return resourceBuilders

internal/resources/remotedatabasenodeset.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,13 @@ func (b *RemoteDatabaseNodeSetBuilder) Placeholder(cr client.Object) client.Obje
6161
func (b *RemoteDatabaseNodeSetResource) GetResourceBuilders() []ResourceBuilder {
6262
var resourceBuilders []ResourceBuilder
6363

64-
nodeSetAnnotations := CopyDict(b.Annotations)
65-
delete(nodeSetAnnotations, annotations.LastApplied)
66-
6764
resourceBuilders = append(resourceBuilders,
6865
&DatabaseNodeSetBuilder{
6966
Object: b,
7067

7168
Name: b.Name,
7269
Labels: b.Labels,
73-
Annotations: nodeSetAnnotations,
70+
Annotations: b.Annotations,
7471

7572
DatabaseNodeSetSpec: b.Spec,
7673
},

internal/resources/storage.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,13 @@ func (b *StorageClusterBuilder) Unwrap() *api.Storage {
3333

3434
func (b *StorageClusterBuilder) NewLabels() labels.Labels {
3535
l := labels.Common(b.Name, b.Labels)
36-
37-
l.Merge(b.Spec.AdditionalLabels)
3836
l.Merge(map[string]string{labels.ComponentKey: labels.StorageComponent})
3937

4038
return l
4139
}
4240

43-
func (b *StorageClusterBuilder) NewAnnotations() map[string]string {
41+
func (b *StorageClusterBuilder) NewAnnotations() annotations.Annotations {
4442
an := annotations.Common(b.Annotations)
45-
46-
an.Merge(b.Spec.AdditionalAnnotations)
4743
an.Merge(map[string]string{annotations.ConfigurationChecksum: GetSHA256Checksum(b.Spec.Configuration)})
4844

4945
return an
@@ -60,7 +56,7 @@ func (b *StorageClusterBuilder) NewInitJobLabels() labels.Labels {
6056
return l
6157
}
6258

63-
func (b *StorageClusterBuilder) NewInitJobAnnotations() map[string]string {
59+
func (b *StorageClusterBuilder) NewInitJobAnnotations() annotations.Annotations {
6460
an := annotations.Common(b.Annotations)
6561

6662
if b.Spec.InitJob != nil {
@@ -90,8 +86,12 @@ func (b *StorageClusterBuilder) GetResourceBuilders(restConfig *rest.Config) []R
9086
storageAnnotations := b.NewAnnotations()
9187

9288
statefulSetLabels := storageLabels.Copy()
89+
statefulSetLabels.Merge(b.Spec.AdditionalLabels)
9390
statefulSetLabels.Merge(map[string]string{labels.StatefulsetComponent: b.Name})
9491

92+
statefulSetAnnotations := storageAnnotations.Copy()
93+
statefulSetAnnotations.Merge(b.Spec.AdditionalAnnotations)
94+
9595
grpcServiceLabels := storageLabels.Copy()
9696
grpcServiceLabels.Merge(b.Spec.Service.GRPC.AdditionalLabels)
9797
grpcServiceLabels.Merge(map[string]string{labels.ServiceComponent: labels.GRPCComponent})
@@ -160,7 +160,7 @@ func (b *StorageClusterBuilder) GetResourceBuilders(restConfig *rest.Config) []R
160160

161161
Name: b.Name,
162162
Labels: statefulSetLabels,
163-
Annotations: storageAnnotations,
163+
Annotations: statefulSetAnnotations,
164164
},
165165
)
166166
} else {

internal/resources/storagenodeset.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ type StorageNodeSetResource struct {
5656

5757
func (b *StorageNodeSetResource) NewLabels() labels.Labels {
5858
l := labels.Common(b.Name, b.Labels)
59-
60-
l.Merge(b.Spec.AdditionalLabels)
6159
l.Merge(map[string]string{labels.ComponentKey: labels.StorageComponent})
6260

6361
storageNodeSetName := b.Labels[labels.StorageNodeSetComponent]
@@ -70,11 +68,9 @@ func (b *StorageNodeSetResource) NewLabels() labels.Labels {
7068
return l
7169
}
7270

73-
func (b *StorageNodeSetResource) NewAnnotations() map[string]string {
71+
func (b *StorageNodeSetResource) NewAnnotations() annotations.Annotations {
7472
an := annotations.Common(b.Annotations)
7573

76-
an.Merge(b.Spec.AdditionalAnnotations)
77-
7874
return an
7975
}
8076

@@ -83,8 +79,12 @@ func (b *StorageNodeSetResource) GetResourceBuilders(restConfig *rest.Config) []
8379
nodeSetAnnotations := b.NewAnnotations()
8480

8581
statefulSetLabels := nodeSetLabels.Copy()
82+
statefulSetLabels.Merge(b.Spec.AdditionalLabels)
8683
statefulSetLabels.Merge(map[string]string{labels.StatefulsetComponent: b.Name})
8784

85+
statefulSetAnnotations := nodeSetAnnotations.Copy()
86+
statefulSetAnnotations.Merge(b.Spec.AdditionalAnnotations)
87+
8888
var resourceBuilders []ResourceBuilder
8989
resourceBuilders = append(
9090
resourceBuilders,
@@ -94,7 +94,7 @@ func (b *StorageNodeSetResource) GetResourceBuilders(restConfig *rest.Config) []
9494

9595
Name: b.Name,
9696
Labels: statefulSetLabels,
97-
Annotations: nodeSetAnnotations,
97+
Annotations: statefulSetAnnotations,
9898
},
9999
)
100100

0 commit comments

Comments
 (0)