@@ -3,6 +3,7 @@ package database_test
33import (
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})
0 commit comments