Skip to content

Commit c33c592

Browse files
authored
YDBOPS-9680 node --label command line args deployment and shared (#205)
1 parent 1a0ee3f commit c33c592

File tree

6 files changed

+187
-2
lines changed

6 files changed

+187
-2
lines changed

api/v1alpha1/const.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ const (
3636
DefaultRootUsername = "root"
3737
DefaultRootPassword = ""
3838

39+
LabelDeploymentKey = "deployment"
40+
LabelDeploymentValueKubernetes = "kubernetes"
41+
LabelSharedDatabaseKey = "shared"
42+
LabelSharedDatabaseValueTrue = "true"
43+
LabelSharedDatabaseValueFalse = "false"
44+
3945
AnnotationUpdateStrategyOnDelete = "ydb.tech/update-strategy-on-delete"
4046
AnnotationUpdateDNSPolicy = "ydb.tech/update-dns-policy"
4147
AnnotationSkipInitialization = "ydb.tech/skip-initialization"

deploy/ydb-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ type: application
1515
# This is the chart version. This version number should be incremented each time you make changes
1616
# to the chart and its templates, including the app version.
1717
# Versions are expected to follow Semantic Versioning (https://semver.org/)
18-
version: 0.5.9
18+
version: 0.5.10
1919

2020
# This is the version number of the application being deployed. This version number should be
2121
# incremented each time you make changes to the application. Versions are not expected to
2222
# follow Semantic Versioning. They should reflect the version the application is using.
2323
# It is recommended to use it with quotes.
24-
appVersion: "0.5.9"
24+
appVersion: "0.5.10"
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
package database_test
2+
3+
import (
4+
"context"
5+
"errors"
6+
"path/filepath"
7+
"strings"
8+
"testing"
9+
10+
. "github.com/onsi/ginkgo/v2"
11+
. "github.com/onsi/gomega"
12+
appsv1 "k8s.io/api/apps/v1"
13+
corev1 "k8s.io/api/core/v1"
14+
"k8s.io/apimachinery/pkg/api/meta"
15+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16+
"k8s.io/apimachinery/pkg/types"
17+
"sigs.k8s.io/controller-runtime/pkg/client"
18+
"sigs.k8s.io/controller-runtime/pkg/manager"
19+
20+
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
21+
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
22+
. "github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/constants"
23+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/database"
24+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
25+
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
26+
)
27+
28+
var (
29+
k8sClient client.Client
30+
ctx context.Context
31+
)
32+
33+
func TestAPIs(t *testing.T) {
34+
RegisterFailHandler(Fail)
35+
36+
test.SetupK8STestManager(&ctx, &k8sClient, func(mgr *manager.Manager) []test.Reconciler {
37+
return []test.Reconciler{
38+
&storage.Reconciler{
39+
Client: k8sClient,
40+
Scheme: (*mgr).GetScheme(),
41+
},
42+
&database.Reconciler{
43+
Client: k8sClient,
44+
Scheme: (*mgr).GetScheme(),
45+
},
46+
}
47+
})
48+
49+
RunSpecs(t, "Database controller medium tests suite")
50+
}
51+
52+
var _ = Describe("Database controller medium tests", func() {
53+
var namespace corev1.Namespace
54+
var storageSample v1alpha1.Storage
55+
56+
BeforeEach(func() {
57+
namespace = corev1.Namespace{
58+
ObjectMeta: metav1.ObjectMeta{
59+
Name: testobjects.YdbNamespace,
60+
},
61+
}
62+
Expect(k8sClient.Create(ctx, &namespace)).Should(Succeed())
63+
storageSample = *testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-block-4-2-config.yaml"))
64+
Expect(k8sClient.Create(ctx, &storageSample)).Should(Succeed())
65+
66+
By("checking that Storage created on local cluster...")
67+
foundStorage := v1alpha1.Storage{}
68+
Eventually(func() bool {
69+
Expect(k8sClient.Get(ctx, types.NamespacedName{
70+
Name: storageSample.Name,
71+
Namespace: testobjects.YdbNamespace,
72+
}, &foundStorage))
73+
return foundStorage.Status.State == StorageInitializing
74+
}, test.Timeout, test.Interval).Should(BeTrue())
75+
76+
By("set condition Initialized to Storage...")
77+
Eventually(func() error {
78+
foundStorage := v1alpha1.Storage{}
79+
Expect(k8sClient.Get(ctx, types.NamespacedName{
80+
Name: storageSample.Name,
81+
Namespace: testobjects.YdbNamespace,
82+
}, &foundStorage))
83+
meta.SetStatusCondition(&foundStorage.Status.Conditions, metav1.Condition{
84+
Type: StorageInitializedCondition,
85+
Status: metav1.ConditionTrue,
86+
Reason: ReasonCompleted,
87+
})
88+
return k8sClient.Status().Update(ctx, &foundStorage)
89+
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
90+
})
91+
92+
AfterEach(func() {
93+
Expect(k8sClient.Delete(ctx, &storageSample)).Should(Succeed())
94+
Expect(k8sClient.Delete(ctx, &namespace)).Should(Succeed())
95+
})
96+
97+
It("Checking field propagation to objects", func() {
98+
By("Check that Shared Database was created...")
99+
databaseSample := *testobjects.DefaultDatabase()
100+
databaseSample.Spec.SharedResources = &v1alpha1.DatabaseResources{
101+
StorageUnits: []v1alpha1.StorageUnit{
102+
{
103+
UnitKind: "ssd",
104+
Count: 1,
105+
},
106+
},
107+
}
108+
Expect(k8sClient.Create(ctx, &databaseSample)).Should(Succeed())
109+
110+
By("Check that StatefulSet was created...")
111+
databaseStatefulSet := appsv1.StatefulSet{}
112+
foundStatefulSets := appsv1.StatefulSetList{}
113+
Eventually(func() error {
114+
err := k8sClient.List(ctx, &foundStatefulSets, client.InNamespace(
115+
testobjects.YdbNamespace))
116+
if err != nil {
117+
return err
118+
}
119+
for idx, statefulSet := range foundStatefulSets.Items {
120+
if statefulSet.Name == testobjects.DatabaseName {
121+
databaseStatefulSet = foundStatefulSets.Items[idx]
122+
return nil
123+
}
124+
}
125+
return errors.New("failed to find StatefulSet")
126+
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
127+
128+
By("Check that args `--label` propagated to pods...", func() {
129+
podContainerArgs := databaseStatefulSet.Spec.Template.Spec.Containers[0].Args
130+
var labelArgKey string
131+
var labelArgValue string
132+
for idx, arg := range podContainerArgs {
133+
if arg == "--label" {
134+
labelArgKey = strings.Split(podContainerArgs[idx+1], "=")[0]
135+
labelArgValue = strings.Split(podContainerArgs[idx+1], "=")[1]
136+
if labelArgKey == v1alpha1.LabelDeploymentKey {
137+
Expect(labelArgValue).Should(BeEquivalentTo(v1alpha1.LabelDeploymentValueKubernetes))
138+
}
139+
if labelArgKey == v1alpha1.LabelSharedDatabaseKey {
140+
Expect(labelArgValue).Should(BeEquivalentTo(v1alpha1.LabelSharedDatabaseValueTrue))
141+
}
142+
}
143+
}
144+
})
145+
})
146+
})

internal/controllers/storage/controller_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"path/filepath"
77
"strconv"
8+
"strings"
89
"testing"
910

1011
. "github.com/onsi/ginkgo/v2"
@@ -135,5 +136,19 @@ var _ = Describe("Storage controller medium tests", func() {
135136
}
136137
Expect(foundConfigurationChecksumAnnotation).To(BeTrue())
137138
})
139+
140+
By("Check that args with --label propagated to pods...", func() {
141+
podContainerArgs := storageSS.Spec.Template.Spec.Containers[0].Args
142+
var labelArgKey string
143+
var labelArgValue string
144+
for idx, arg := range podContainerArgs {
145+
if arg == "--label" {
146+
labelArgKey = strings.Split(podContainerArgs[idx+1], "=")[0]
147+
labelArgValue = strings.Split(podContainerArgs[idx+1], "=")[1]
148+
}
149+
}
150+
Expect(labelArgKey).Should(BeEquivalentTo(v1alpha1.LabelDeploymentKey))
151+
Expect(labelArgValue).Should(BeEquivalentTo(v1alpha1.LabelDeploymentValueKubernetes))
152+
})
138153
})
139154
})

internal/resources/database_statefulset.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,21 @@ func (b *DatabaseStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
520520

521521
"--node-broker",
522522
b.Spec.StorageEndpoint,
523+
524+
"--label",
525+
fmt.Sprintf("%s=%s", api.LabelDeploymentKey, api.LabelDeploymentValueKubernetes),
526+
}
527+
528+
if b.Spec.SharedResources != nil {
529+
args = append(args,
530+
"--label",
531+
fmt.Sprintf("%s=%s", api.LabelSharedDatabaseKey, api.LabelSharedDatabaseValueTrue),
532+
)
533+
} else {
534+
args = append(args,
535+
"--label",
536+
fmt.Sprintf("%s=%s", api.LabelSharedDatabaseKey, api.LabelSharedDatabaseValueFalse),
537+
)
523538
}
524539

525540
for _, secret := range b.Spec.Secrets {

internal/resources/storage_statefulset.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,9 @@ func (b *StorageStatefulSetBuilder) buildContainerArgs() ([]string, []string) {
466466

467467
"--node",
468468
"static",
469+
470+
"--label",
471+
fmt.Sprintf("%s=%s", api.LabelDeploymentKey, api.LabelDeploymentValueKubernetes),
469472
)
470473

471474
for _, secret := range b.Spec.Secrets {

0 commit comments

Comments
 (0)