Skip to content

Commit 8ea8c56

Browse files
committed
add tests
1 parent b9442a9 commit 8ea8c56

File tree

2 files changed

+57
-31
lines changed

2 files changed

+57
-31
lines changed

internal/controllers/database/controller_test.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package database_test
33
import (
44
"context"
55
"errors"
6+
"fmt"
67
"path/filepath"
78
"strings"
89
"testing"
@@ -142,5 +143,61 @@ var _ = Describe("Database controller medium tests", func() {
142143
}
143144
}
144145
})
146+
147+
By("Check annotation has been propagated to pods...")
148+
foundDatabase := v1alpha1.Database{}
149+
Expect(k8sClient.Get(ctx, types.NamespacedName{
150+
Name: testobjects.DatabaseName,
151+
Namespace: testobjects.YdbNamespace,
152+
}, &foundDatabase)).Should(Succeed())
153+
nodeHost := fmt.Sprintf("%s.testing.k8s-c.yandex.net", testobjects.YdbNamespace)
154+
foundDatabase.Annotations = make(map[string]string)
155+
foundDatabase.Annotations[v1alpha1.AnnotationNodeHost] = nodeHost
156+
Eventually(func() error {
157+
return k8sClient.Update(ctx, &foundDatabase)
158+
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
159+
160+
Eventually(func() error {
161+
databaseStatefulSet := appsv1.StatefulSet{}
162+
foundStatefulSets := appsv1.StatefulSetList{}
163+
Eventually(func() error {
164+
err := k8sClient.List(ctx, &foundStatefulSets, client.InNamespace(
165+
testobjects.YdbNamespace))
166+
if err != nil {
167+
return err
168+
}
169+
for idx, statefulSet := range foundStatefulSets.Items {
170+
if statefulSet.Name == testobjects.DatabaseName {
171+
databaseStatefulSet = foundStatefulSets.Items[idx]
172+
return nil
173+
}
174+
}
175+
return errors.New("failed to find StatefulSet")
176+
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
177+
178+
podAnnotations := databaseStatefulSet.Spec.Template.Annotations
179+
val, exist := podAnnotations[v1alpha1.AnnotationNodeHost]
180+
if !exist {
181+
return fmt.Errorf("annotation %s does not exist on statefulset template", v1alpha1.AnnotationNodeHost)
182+
}
183+
if val != nodeHost {
184+
return fmt.Errorf("annotation value %s does not equal with desired: %s", val, nodeHost)
185+
}
186+
187+
podContainerArgs := databaseStatefulSet.Spec.Template.Spec.Containers[0].Args
188+
var nodeHostArgValue string
189+
for idx, arg := range podContainerArgs {
190+
if arg == "--node-host" {
191+
nodeHostArgValue = podContainerArgs[idx+1]
192+
}
193+
}
194+
195+
nodeHostArgDesired := fmt.Sprintf("%s.%s", "$(NODE_NAME)", nodeHost)
196+
if nodeHostArgDesired != nodeHostArgValue {
197+
return fmt.Errorf("arg value `--node-host` %s does not equal with desired %s", nodeHostArgValue, nodeHostArgDesired)
198+
}
199+
200+
return nil
201+
}, test.Timeout, test.Interval).ShouldNot(HaveOccurred())
145202
})
146203
})

internal/controllers/storage/controller_test.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"path/filepath"
7-
"strconv"
87
"strings"
98
"testing"
109

@@ -13,15 +12,12 @@ import (
1312
appsv1 "k8s.io/api/apps/v1"
1413
corev1 "k8s.io/api/core/v1"
1514
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
16-
"k8s.io/apimachinery/pkg/types"
1715
"sigs.k8s.io/controller-runtime/pkg/client"
1816
"sigs.k8s.io/controller-runtime/pkg/manager"
1917

2018
"github.com/ydb-platform/ydb-kubernetes-operator/api/v1alpha1"
2119
testobjects "github.com/ydb-platform/ydb-kubernetes-operator/e2e/tests/test-objects"
22-
"github.com/ydb-platform/ydb-kubernetes-operator/internal/annotations"
2320
"github.com/ydb-platform/ydb-kubernetes-operator/internal/controllers/storage"
24-
"github.com/ydb-platform/ydb-kubernetes-operator/internal/labels"
2521
"github.com/ydb-platform/ydb-kubernetes-operator/internal/test"
2622
)
2723

@@ -57,10 +53,6 @@ var _ = Describe("Storage controller medium tests", func() {
5753
Expect(k8sClient.Create(ctx, &namespace)).Should(Succeed())
5854
})
5955

60-
AfterEach(func() {
61-
Expect(k8sClient.Delete(ctx, &namespace)).Should(Succeed())
62-
})
63-
6456
It("Checking field propagation to objects", func() {
6557
storageSample := testobjects.DefaultStorage(filepath.Join("..", "..", "..", "e2e", "tests", "data", "storage-block-4-2-config.yaml"))
6658

@@ -113,29 +105,6 @@ var _ = Describe("Storage controller medium tests", func() {
113105
}
114106
Expect(foundVolume).To(BeTrue())
115107

116-
By("Check that label and annotation propagated to pods...", func() {
117-
podLabels := storageSS.Spec.Template.Labels
118-
podAnnotations := storageSS.Spec.Template.Annotations
119-
120-
foundStorage := v1alpha1.Storage{}
121-
Expect(k8sClient.Get(ctx, types.NamespacedName{
122-
Name: testobjects.StorageName,
123-
Namespace: testobjects.YdbNamespace,
124-
}, &foundStorage)).Should(Succeed())
125-
126-
foundStorageGenerationLabel := false
127-
if podLabels[labels.StorageGeneration] == strconv.FormatInt(foundStorage.ObjectMeta.Generation, 10) {
128-
foundStorageGenerationLabel = true
129-
}
130-
Expect(foundStorageGenerationLabel).To(BeTrue())
131-
132-
foundConfigurationChecksumAnnotation := false
133-
if podAnnotations[annotations.ConfigurationChecksum] == annotations.GetSHA256Checksum(foundStorage.Spec.Configuration) {
134-
foundConfigurationChecksumAnnotation = true
135-
}
136-
Expect(foundConfigurationChecksumAnnotation).To(BeTrue())
137-
})
138-
139108
By("Check that args with --label propagated to pods...", func() {
140109
podContainerArgs := storageSS.Spec.Template.Spec.Containers[0].Args
141110
var labelArgKey string

0 commit comments

Comments
 (0)