@@ -308,40 +308,47 @@ var _ = Describe("Database controller medium tests", func() {
308308 Expect (args ).To (ContainElements ([]string {"--grpc-public-address-v4" , "--grpc-public-target-name-override" }))
309309 })
310310
311+ checkContainerArg := func (expectedArgKey , expectedArgValue string ) error {
312+ foundStatefulSet := appsv1.StatefulSet {}
313+ Eventually (func () error {
314+ return k8sClient .Get (ctx ,
315+ types.NamespacedName {
316+ Name : testobjects .DatabaseName ,
317+ Namespace : testobjects .YdbNamespace ,
318+ },
319+ & foundStatefulSet ,
320+ )
321+ }, test .Timeout , test .Interval ).Should (Succeed ())
322+ podContainerArgs := foundStatefulSet .Spec .Template .Spec .Containers [0 ].Args
323+ for idx , argKey := range podContainerArgs {
324+ if argKey == expectedArgKey {
325+ if podContainerArgs [idx + 1 ] != expectedArgValue {
326+ return fmt .Errorf (
327+ "Found arg `%s` value %s does not match with expected: %s" ,
328+ expectedArgKey ,
329+ podContainerArgs [idx + 1 ],
330+ expectedArgValue ,
331+ )
332+ }
333+ }
334+ }
335+ return nil
336+ }
337+
311338 It ("Check externalPort GRPC Service field propagation" , func () {
312339 By ("Create test database" )
313340 databaseSample = * testobjects .DefaultDatabase ()
341+ databaseSample .Spec .Service .GRPC .ExternalHost = fmt .Sprintf ("%s.%s" , testobjects .YdbNamespace , "k8s.external.net" )
314342 Expect (k8sClient .Create (ctx , & databaseSample )).Should (Succeed ())
315343
316- checkPublicPortArg := func (expectedGRPCPort string ) error {
317- foundStatefulSet := appsv1.StatefulSet {}
318- Eventually (func () error {
319- return k8sClient .Get (ctx ,
320- types.NamespacedName {
321- Name : testobjects .DatabaseName ,
322- Namespace : testobjects .YdbNamespace ,
323- },
324- & foundStatefulSet ,
325- )
326- }, test .Timeout , test .Interval ).Should (Succeed ())
327- podContainerArgs := foundStatefulSet .Spec .Template .Spec .Containers [0 ].Args
328- for idx , argKey := range podContainerArgs {
329- if argKey == "--grpc-public-port" {
330- if podContainerArgs [idx + 1 ] != expectedGRPCPort {
331- return fmt .Errorf (
332- "Found arg `--grpc-public-port` value %s does not match with expected: %s" ,
333- podContainerArgs [idx + 1 ],
334- expectedGRPCPort ,
335- )
336- }
337- }
338- }
339- return nil
340- }
341-
342344 By ("Check that args `--grpc-public-host` and `--grpc-public-port` propagated to StatefulSet pods..." )
343345 Eventually (
344- checkPublicPortArg (fmt .Sprintf ("%d" , v1alpha1 .GRPCPort )),
346+ checkContainerArg ("--grpc-public-host" , fmt .Sprintf ("%s.%s" , "$(POD_NAME)" , databaseSample .Spec .Service .GRPC .ExternalHost )),
347+ test .Timeout ,
348+ test .Interval ).ShouldNot (HaveOccurred ())
349+
350+ Eventually (
351+ checkContainerArg ("--grpc-public-port" , fmt .Sprintf ("%d" , v1alpha1 .GRPCPort )),
345352 test .Timeout ,
346353 test .Interval ).ShouldNot (HaveOccurred ())
347354
@@ -384,7 +391,29 @@ var _ = Describe("Database controller medium tests", func() {
384391
385392 By ("Check that args `--grpc-public-port` was updated in StatefulSet..." )
386393 Eventually (
387- checkPublicPortArg (fmt .Sprintf ("%d" , externalPort )),
394+ checkContainerArg ("--grpc-public-port" , fmt .Sprintf ("%d" , externalPort )),
395+ test .Timeout ,
396+ test .Interval ).ShouldNot (HaveOccurred ())
397+ })
398+
399+ It ("Checking args propagation from annotation to StatefulSet" , func () {
400+ By ("Check that Database with annotations was created..." )
401+ databaseSample = * testobjects .DefaultDatabase ()
402+ databaseSample .Annotations = map [string ]string {
403+ v1alpha1 .AnnotationGRPCPublicHost : fmt .Sprintf ("%s.%s" , testobjects .YdbNamespace , "k8s.external.net" ),
404+ v1alpha1 .AnnotationGRPCPublicPort : fmt .Sprintf ("%d" , 30001 ),
405+ }
406+ Expect (k8sClient .Create (ctx , & databaseSample )).Should (Succeed ())
407+
408+ By ("Check that args `--grpc-public-host` propagated to StatefulSet pods..." )
409+ Eventually (
410+ checkContainerArg ("--grpc-public-host" , fmt .Sprintf ("%s.%s.%s" , "$(POD_NAME)" , testobjects .YdbNamespace , "k8s.external.net" )),
411+ test .Timeout ,
412+ test .Interval ).ShouldNot (HaveOccurred ())
413+
414+ By ("Check that args `--grpc-public-port` propagated to StatefulSet pods..." )
415+ Eventually (
416+ checkContainerArg ("--grpc-public-port" , fmt .Sprintf ("%d" , 30001 )),
388417 test .Timeout ,
389418 test .Interval ).ShouldNot (HaveOccurred ())
390419 })
0 commit comments