@@ -3,6 +3,7 @@ package tests
33import (
44 "context"
55 "fmt"
6+ "io"
67 "os"
78 "time"
89
@@ -803,6 +804,125 @@ var _ = Describe("metallb", func() {
803804 Expect (testclient .Client .Create (context .Background (), metallb )).Should (Succeed ())
804805 })
805806 })
807+
808+ Context ("MetalLB Core Components Log Level Feature" , func () {
809+ BeforeEach (func () {
810+ metallbutils .DeleteDefaultMetalLB (OperatorNameSpace , UseMetallbResourcesFromFile )
811+
812+ })
813+
814+ AfterEach (func () {
815+ metallbutils .DeleteDefaultMetalLB (OperatorNameSpace , UseMetallbResourcesFromFile )
816+ })
817+
818+ It ("Verify logLevel default and debug behavior in speaker and controller pods" , func () {
819+ // Create MetalLB with default log level (info)
820+ metallb , err := metallbutils .Get (OperatorNameSpace , UseMetallbResourcesFromFile )
821+ Expect (err ).ToNot (HaveOccurred ())
822+ Expect (testclient .Client .Create (context .Background (), metallb )).Should (Succeed ())
823+
824+ By ("Waiting for MetalLB controller deployment to be ready" )
825+ metallbutils .WaitForControllerDeploymentReady (metallb .Namespace , metallbutils .DeployTimeout )
826+
827+ By ("Waiting for MetalLB speaker daemonset to be ready" )
828+ metallbutils .WaitForSpeakerDaemonSetReady (metallb .Namespace , metallbutils .DeployTimeout )
829+
830+ By ("Fetch controller pods from metallb-system namespace" )
831+ controllerPods := metallbutils .GetMetalLBPods (OperatorNameSpace , "controller" )
832+
833+ By ("Verify default loglevel in controller pod logs - should contain info but not debug" )
834+ for _ , controllerPod := range controllerPods .Items {
835+ req := testclient .Client .Pods (OperatorNameSpace ).GetLogs (controllerPod .Name , & corev1.PodLogOptions {
836+ Container : "controller" ,
837+ })
838+ logs , err := req .Stream (context .Background ())
839+ Expect (err ).ToNot (HaveOccurred (), "Failed to get controller pod logs" )
840+ defer logs .Close ()
841+
842+ logContent , err := io .ReadAll (logs )
843+ Expect (err ).ToNot (HaveOccurred (), "Failed to read controller pod logs" )
844+ logString := string (logContent )
845+
846+ Expect (logString ).Should (ContainSubstring (`"level":"info"` ), "Controller pod logs should contain info level logs by default" )
847+ Expect (logString ).ShouldNot (ContainSubstring (`"level":"debug"` ), "Controller pod logs should not contain debug level logs when using default info log level" )
848+ }
849+
850+ By ("Fetch speaker pods from metallb-system namespace" )
851+ speakerPods := metallbutils .GetMetalLBPods (OperatorNameSpace , "speaker" )
852+
853+ By ("Verify default loglevel in speaker pod logs - should contain info but not debug" )
854+ for _ , speakerPod := range speakerPods .Items {
855+ req := testclient .Client .Pods (OperatorNameSpace ).GetLogs (speakerPod .Name , & corev1.PodLogOptions {
856+ Container : "speaker" ,
857+ })
858+ logs , err := req .Stream (context .Background ())
859+ Expect (err ).ToNot (HaveOccurred (), "Failed to get speaker pod logs" )
860+ defer logs .Close ()
861+
862+ logContent , err := io .ReadAll (logs )
863+ Expect (err ).ToNot (HaveOccurred (), "Failed to read speaker pod logs" )
864+ logString := string (logContent )
865+
866+ Expect (logString ).Should (ContainSubstring (`"level":"info"` ), "Speaker pod logs should contain info level logs by default" )
867+ Expect (logString ).ShouldNot (ContainSubstring (`"level":"debug"` ), "Speaker pod logs should not contain debug level logs when using default info log level" )
868+ }
869+
870+ // Update MetalLB CR to set LogLevel to debug
871+ By ("Updating MetalLB CR to set LogLevel to debug" )
872+ err = testclient .Client .Get (context .Background (), goclient.ObjectKey {Namespace : metallb .Namespace , Name : metallb .Name }, metallb )
873+ Expect (err ).ToNot (HaveOccurred ())
874+ metallb .Spec .LogLevel = metallbv1beta1 .LogLevelDebug
875+ Expect (testclient .Client .Update (context .Background (), metallb )).Should (Succeed ())
876+
877+ By ("Waiting for Progressing condition to be True after update" )
878+ metallbutils .WaitForProgressingConditionTrue (metallb , 30 * time .Second )
879+
880+ By ("Waiting for Progressing condition to be False and Available condition to be True" )
881+ metallbutils .WaitForProgressingFalseAndAvailableTrue (metallb , metallbutils .DeployTimeout )
882+
883+ By ("Fetch controller pods after update" )
884+ controllerPods = metallbutils .GetMetalLBPods (OperatorNameSpace , "controller" )
885+
886+ By ("Verify debug loglevel in controller pod logs - should contain both debug and info" )
887+ for _ , controllerPod := range controllerPods .Items {
888+ req := testclient .Client .Pods (OperatorNameSpace ).GetLogs (controllerPod .Name , & corev1.PodLogOptions {
889+ Container : "controller" ,
890+ })
891+ logs , err := req .Stream (context .Background ())
892+ Expect (err ).ToNot (HaveOccurred (), "Failed to get controller pod logs" )
893+ defer logs .Close ()
894+
895+ logContent , err := io .ReadAll (logs )
896+ Expect (err ).ToNot (HaveOccurred (), "Failed to read controller pod logs" )
897+ logString := string (logContent )
898+
899+ // Verify that debug log level is set - logs should contain JSON format "level":"debug"
900+ Expect (logString ).Should (ContainSubstring (`"level":"debug"` ), "Controller pod logs should contain debug level logs when LogLevel is set to debug" )
901+ Expect (logString ).Should (ContainSubstring (`"level":"info"` ), "Controller pod logs should also contain info level logs when LogLevel is set to debug" )
902+ }
903+
904+ By ("Fetch speaker pods after update" )
905+ speakerPods = metallbutils .GetMetalLBPods (OperatorNameSpace , "speaker" )
906+
907+ By ("Verify debug loglevel in speaker pod logs - should contain both debug and info" )
908+ for _ , speakerPod := range speakerPods .Items {
909+ req := testclient .Client .Pods (OperatorNameSpace ).GetLogs (speakerPod .Name , & corev1.PodLogOptions {
910+ Container : "speaker" ,
911+ })
912+ logs , err := req .Stream (context .Background ())
913+ Expect (err ).ToNot (HaveOccurred (), "Failed to get speaker pod logs" )
914+ defer logs .Close ()
915+
916+ logContent , err := io .ReadAll (logs )
917+ Expect (err ).ToNot (HaveOccurred (), "Failed to read speaker pod logs" )
918+ logString := string (logContent )
919+
920+ // Verify that debug log level is set - logs should contain JSON format "level":"debug"
921+ Expect (logString ).Should (ContainSubstring (`"level":"debug"` ), "Speaker pod logs should contain debug level logs when LogLevel is set to debug" )
922+ Expect (logString ).Should (ContainSubstring (`"level":"info"` ), "Speaker pod logs should also contain info level logs when LogLevel is set to debug" )
923+ }
924+ })
925+ })
806926})
807927
808928// Gomega transformation functions for v1.Container
0 commit comments