@@ -797,6 +797,62 @@ func TestSyncPodFromNodePodProbe(t *testing.T) {
797797 }
798798}
799799
800+ func TestUpdatePodProbeStatusInitializesNilLabels (t * testing.T ) {
801+ pod := & corev1.Pod {
802+ ObjectMeta : metav1.ObjectMeta {
803+ Name : "pod-1" ,
804+ Namespace : "default" ,
805+ },
806+ }
807+ ppm := & appsv1alpha1.PodProbeMarker {
808+ ObjectMeta : metav1.ObjectMeta {
809+ Name : "ppm-1" ,
810+ Namespace : "default" ,
811+ },
812+ Spec : appsv1alpha1.PodProbeMarkerSpec {
813+ Probes : []appsv1alpha1.PodContainerProbe {
814+ {
815+ Name : "healthy" ,
816+ MarkerPolicy : []appsv1alpha1.ProbeMarkerPolicy {
817+ {
818+ State : appsv1alpha1 .ProbeSucceeded ,
819+ Labels : map [string ]string {
820+ "server-healthy" : "true" ,
821+ },
822+ },
823+ },
824+ },
825+ },
826+ },
827+ }
828+ status := appsv1alpha1.PodProbeStatus {
829+ ProbeStates : []appsv1alpha1.ContainerProbeState {
830+ {
831+ Name : "ppm-1#healthy" ,
832+ State : appsv1alpha1 .ProbeSucceeded ,
833+ },
834+ },
835+ }
836+
837+ fakeClient := fake .NewClientBuilder ().
838+ WithScheme (scheme ).
839+ WithObjects (pod , ppm ).
840+ Build ()
841+ recon := ReconcileNodePodProbe {Client : fakeClient }
842+
843+ if err := recon .updatePodProbeStatus (pod , status ); err != nil {
844+ t .Fatalf ("updatePodProbeStatus failed: %s" , err .Error ())
845+ }
846+
847+ updatedPod := & corev1.Pod {}
848+ if err := fakeClient .Get (context .TODO (), types.NamespacedName {Namespace : pod .Namespace , Name : pod .Name }, updatedPod ); err != nil {
849+ t .Fatalf ("get Pod failed: %s" , err .Error ())
850+ }
851+ if updatedPod .Labels ["server-healthy" ] != "true" {
852+ t .Fatalf ("expected label server-healthy=true, got %v" , updatedPod .Labels )
853+ }
854+ }
855+
800856func checkNodePodProbeEqual (c client.WithWatch , t * testing.T , expect []* appsv1alpha1.NodePodProbe ) bool {
801857 for i := range expect {
802858 obj := expect [i ]
0 commit comments