Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New field additionalPodLabels #237

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
Open
1 change: 0 additions & 1 deletion api/v1alpha1/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const (
BinariesDir = "/opt/ydb/bin"
DaemonBinaryName = "ydbd"

DefaultRootUsername = "root"
DefaultRootPassword = ""
DefaultDatabaseDomain = "Root"
DefaultDatabaseEncryptionPin = "EmptyPin"
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/database_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ type DatabaseNodeSpec struct {
// +optional
AdditionalLabels map[string]string `json:"additionalLabels,omitempty"`

// (Optional) Additional custom resource labels that are added to Pods
// +optional
AdditionalPodLabels map[string]string `json:"additionalPodLabels,omitempty"`

// (Optional) Additional custom resource annotations that are added to all resources
// +optional
AdditionalAnnotations map[string]string `json:"additionalAnnotations,omitempty"`
Expand Down
4 changes: 4 additions & 0 deletions api/v1alpha1/storage_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ type StorageNodeSpec struct {
// +optional
AdditionalLabels map[string]string `json:"additionalLabels,omitempty"`

// (Optional) Additional custom resource labels that are added to Pods
// +optional
AdditionalPodLabels map[string]string `json:"additionalPodLabels,omitempty"`

// (Optional) Additional custom resource annotations that are added to all resources
// +optional
AdditionalAnnotations map[string]string `json:"additionalAnnotations,omitempty"`
Expand Down
14 changes: 14 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions deploy/ydb-operator/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.5.28
version: 0.5.29

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "0.5.28"
appVersion: "0.5.29"
12 changes: 12 additions & 0 deletions deploy/ydb-operator/crds/database.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ spec:
description: (Optional) Additional custom resource labels that are
added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that are
added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down Expand Up @@ -2284,6 +2290,12 @@ spec:
description: (Optional) Additional custom resource labels that
are added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that
are added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down
6 changes: 6 additions & 0 deletions deploy/ydb-operator/crds/databasenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ spec:
description: (Optional) Additional custom resource labels that are
added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that are
added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down
6 changes: 6 additions & 0 deletions deploy/ydb-operator/crds/remotedatabasenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ spec:
description: (Optional) Additional custom resource labels that are
added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that are
added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down
6 changes: 6 additions & 0 deletions deploy/ydb-operator/crds/remotestoragenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ spec:
description: (Optional) Additional custom resource labels that are
added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that are
added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down
12 changes: 12 additions & 0 deletions deploy/ydb-operator/crds/storage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ spec:
description: (Optional) Additional custom resource labels that are
added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that are
added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down Expand Up @@ -3419,6 +3425,12 @@ spec:
description: (Optional) Additional custom resource labels that
are added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that
are added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down
6 changes: 6 additions & 0 deletions deploy/ydb-operator/crds/storagenodeset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ spec:
description: (Optional) Additional custom resource labels that are
added to all resources
type: object
additionalPodLabels:
additionalProperties:
type: string
description: (Optional) Additional custom resource labels that are
added to Pods
type: object
affinity:
description: (Optional) If specified, the pod's scheduling constraints
properties:
Expand Down
10 changes: 5 additions & 5 deletions e2e/tests/test-objects/objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ func DefaultStorage(storageYamlConfigPath string) *v1alpha1.Storage {
Nodes: 3,
DataStore: []corev1.PersistentVolumeClaimSpec{},

Resources: &corev1.ResourceRequirements{},
AdditionalLabels: map[string]string{"ydb-cluster": "kind-storage"},
Affinity: storageAntiAffinity,
Resources: &corev1.ResourceRequirements{},
AdditionalPodLabels: map[string]string{"ydb-cluster": "kind-storage"},
Affinity: storageAntiAffinity,
},
},
}
Expand Down Expand Up @@ -165,8 +165,8 @@ func DefaultDatabase() *v1alpha1.Database {
},
},
},
AdditionalLabels: map[string]string{"ydb-cluster": "kind-database"},
Affinity: databaseAntiAffinity,
AdditionalPodLabels: map[string]string{"ydb-cluster": "kind-database"},
Affinity: databaseAntiAffinity,
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/remotedatabasenodeset/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -963,10 +963,10 @@ func deleteAll(env *envtest.Environment, k8sClient client.Client, objs ...client
return client.IgnoreNotFound(err)
}
// remove `kubernetes` finalizer
const kubernetes = "kubernetes"
const finalizer = "kubernetes"
finalizers := []corev1.FinalizerName{}
for _, f := range ns.Spec.Finalizers {
if f != kubernetes {
if f != finalizer {
finalizers = append(finalizers, f)
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/controllers/remotestoragenodeset/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,10 +706,10 @@ func deleteAll(env *envtest.Environment, k8sClient client.Client, objs ...client
return client.IgnoreNotFound(err)
}
// remove `kubernetes` finalizer
const kubernetes = "kubernetes"
const finalizer = "kubernetes"
finalizers := []corev1.FinalizerName{}
for _, f := range ns.Spec.Finalizers {
if f != kubernetes {
if f != finalizer {
finalizers = append(finalizers, f)
}
}
Expand Down
43 changes: 37 additions & 6 deletions internal/controllers/storage/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,9 @@ var _ = Describe("Storage controller medium tests", func() {
if err != nil {
return err
}
value, exist := foundStatefulSets.Items[0].Labels[testLabelKey]
if !exist {
return fmt.Errorf("label key `ydb-label` does not exist in StatefulSet. Current labels: %s", foundStatefulSets.Items[0].Labels)
}
value := foundStatefulSets.Items[0].Labels[testLabelKey]
if value != testLabelValue {
return fmt.Errorf("label value `ydb-label` in StatefulSet does not equal `test`. Current labels: %s", foundStatefulSets.Items[0].Labels)
return fmt.Errorf("label value of `%s` in StatefulSet does not equal `%s`. Current labels: %s", testLabelKey, testLabelValue, foundStatefulSets.Items[0].Labels)
}
return nil
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
Expand All @@ -186,8 +183,42 @@ var _ = Describe("Storage controller medium tests", func() {
},
},
))
})

By("Check that additionalPodLabels propagated into podTemplate...", func() {
testLabelKey := "ydb-pod-label"
testLabelValue := "test-podTemplate"
By("set additional pod labels to Storage...")
Eventually(func() error {
foundStorage := v1alpha1.Storage{}
Expect(k8sClient.Get(ctx, types.NamespacedName{
Name: storageSample.Name,
Namespace: testobjects.YdbNamespace,
}, &foundStorage))
foundStorage.Spec.AdditionalPodLabels = make(map[string]string)
foundStorage.Spec.AdditionalPodLabels[testLabelKey] = testLabelValue
return k8sClient.Update(ctx, &foundStorage)
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())

By("check that additional pod labels was added...")
foundStatefulSets := appsv1.StatefulSetList{}
Eventually(func() error {
err := k8sClient.List(ctx, &foundStatefulSets,
client.InNamespace(testobjects.YdbNamespace),
)
if err != nil {
return err
}
value := foundStatefulSets.Items[0].Spec.Template.Labels[testLabelKey]
if value != testLabelValue {
return fmt.Errorf("label value of `%s` in StatefulSet does not equal `%s`. Current labels: %s", testLabelKey, testLabelValue, foundStatefulSets.Items[0].Labels)
}
return nil
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
})

By("check that delete StatefulSet event was detected...")
By("check that delete StatefulSet event was detected...", func() {
foundStatefulSets := appsv1.StatefulSetList{}
Expect(k8sClient.List(ctx, &foundStatefulSets, client.InNamespace(testobjects.YdbNamespace))).ShouldNot(HaveOccurred())
Expect(len(foundStatefulSets.Items)).Should(Equal(1))
Expect(k8sClient.Delete(ctx, &foundStatefulSets.Items[0])).ShouldNot(HaveOccurred())
Expand Down
2 changes: 1 addition & 1 deletion internal/controllers/storage/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (r *Reconciler) createInitBlobstorageJob(
ctx context.Context,
storage *resources.StorageClusterBuilder,
) error {
builder := resources.GetInitJobBuilder(storage.DeepCopy())
builder := storage.GetInitJobBuilder()
newResource := builder.Placeholder(storage)
_, err := resources.CreateOrUpdateOrMaybeIgnore(ctx, r.Client, newResource, func() error {
var err error
Expand Down
56 changes: 15 additions & 41 deletions internal/labels/label.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package labels

import (
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
)

// https://kubernetes.io/docs/concepts/overview/working-with-objects/common-labels/
const (
// NameKey The name of a higher level application this one is part of
Expand All @@ -28,11 +24,9 @@ const (
// RemoteClusterKey The specialization of a remote k8s cluster
RemoteClusterKey = "ydb.tech/remote-cluster"

StorageGeneration = "ydb.tech/storage-generation"
DatabaseGeneration = "ydb.tech/database-generation"

StorageComponent = "storage-node"
DynamicComponent = "dynamic-node"
StorageComponent = "storage-node"
DynamicComponent = "dynamic-node"
BlobstorageInitComponent = "blobstorage-init"

GRPCComponent = "grpc"
InterconnectComponent = "interconnect"
Expand All @@ -50,28 +44,6 @@ func Common(name string, defaultLabels Labels) Labels {
return l
}

func StorageLabels(cluster *v1alpha1.Storage) Labels {
l := Common(cluster.Name, cluster.Labels)

l.Merge(cluster.Spec.AdditionalLabels)
l.Merge(map[string]string{
ComponentKey: StorageComponent,
})

return l
}

func DatabaseLabels(database *v1alpha1.Database) Labels {
l := Common(database.Name, database.Labels)

l.Merge(database.Spec.AdditionalLabels)
l.Merge(map[string]string{
ComponentKey: DynamicComponent,
})

return l
}

func (l Labels) AsMap() map[string]string {
return l
}
Expand All @@ -98,16 +70,6 @@ func (l Labels) Merge(other map[string]string) map[string]string {
return l
}

func (l Labels) MergeInPlace(other map[string]string) map[string]string {
result := l.Copy()

for k, v := range other {
result[k] = v
}

return result
}

func makeCommonLabels(other map[string]string, instance string) map[string]string {
common := make(map[string]string)

Expand All @@ -122,5 +84,17 @@ func makeCommonLabels(other map[string]string, instance string) map[string]strin

common[ManagedByKey] = "ydb-operator"

if storageNodeSetName, exist := other[StorageNodeSetComponent]; exist {
common[StorageNodeSetComponent] = storageNodeSetName
}

if databaseNodeSetName, exist := other[DatabaseNodeSetComponent]; exist {
common[DatabaseNodeSetComponent] = databaseNodeSetName
}

if remoteCluster, exist := other[RemoteClusterKey]; exist {
common[RemoteClusterKey] = remoteCluster
}

return common
}
Loading
Loading