@@ -21,6 +21,7 @@ package v1
2121
2222import (
2323 "context"
24+ "strings"
2425 "testing"
2526
2627 "github.com/google/go-cmp/cmp"
@@ -618,6 +619,9 @@ func TestAnnotationPropagation(t *testing.T) {
618619 if err := validateAnnotations (objects ); err != nil {
619620 t .Error ("Annotations are incorrect:" , err )
620621 }
622+ if err := validateK8sServiceAnnotations (t , clients , names ); err != nil {
623+ t .Error (err )
624+ }
621625
622626 if objects .Service , err = v1test .UpdateService (t , clients , names ,
623627 rtesting .WithServiceAnnotation ("juicy" , "jamba" )); err != nil {
@@ -651,6 +655,9 @@ func TestAnnotationPropagation(t *testing.T) {
651655 if err := validateAnnotations (objects , "juicy" ); err != nil {
652656 t .Error ("Annotations are incorrect:" , err )
653657 }
658+ if err := validateK8sServiceAnnotations (t , clients , names , "juicy" ); err != nil {
659+ t .Error (err )
660+ }
654661
655662 if objects .Service , err = v1test .UpdateService (t , clients , names ,
656663 rtesting .WithServiceAnnotationRemoved ("juicy" )); err != nil {
@@ -684,12 +691,20 @@ func TestAnnotationPropagation(t *testing.T) {
684691 if err := validateAnnotations (objects ); err != nil {
685692 t .Error ("Annotations are incorrect:" , err )
686693 }
694+ if err := validateK8sServiceAnnotations (t , clients , names , "juicy" ); err != nil {
695+ t .Error (err )
696+ }
687697 if _ , ok := objects .Config .Annotations ["juicy" ]; ok {
688698 t .Error ("Config still has `juicy` annotation" )
689699 }
690700 if _ , ok := objects .Route .Annotations ["juicy" ]; ok {
691701 t .Error ("Route still has `juicy` annotation" )
692702 }
703+ if err := validateK8sServiceAnnotations (t , clients , names , "juicy" ); err != nil {
704+ if ! strings .Contains (err .Error (), "was empty" ) {
705+ t .Error (err )
706+ }
707+ }
693708}
694709
695710// TestServiceCreateWithMultipleContainers tests both Creation paths for a service.
@@ -750,6 +765,126 @@ func TestServiceCreateWithMultipleContainers(t *testing.T) {
750765 }
751766}
752767
768+ func TestLabelPropagation (t * testing.T ) {
769+ t .Parallel ()
770+ clients := test .Setup (t )
771+
772+ names := test.ResourceNames {
773+ Service : test .ObjectNameForTest (t ),
774+ Image : test .PizzaPlanet1 ,
775+ }
776+
777+ // Clean up on test failure or interrupt
778+ test .EnsureTearDown (t , clients , & names )
779+
780+ // Setup initial Service
781+ objects , err := v1test .CreateServiceReady (t , clients , & names )
782+ if err != nil {
783+ t .Fatalf ("Failed to create initial Service %v: %v" , names .Service , err )
784+ }
785+
786+ // Validate State after Creation
787+ if err = validateControlPlane (t , clients , names , "1" ); err != nil {
788+ t .Error (err )
789+ }
790+
791+ // Validate State after Creation
792+
793+ if err = validateControlPlane (t , clients , names , "1" ); err != nil {
794+ t .Error (err )
795+ }
796+
797+ if err := validateLabelsPropagation (t , * objects , names ); err != nil {
798+ t .Error (err )
799+ }
800+ if err := validateK8sServiceLabels (t , clients , names ); err != nil {
801+ t .Error (err )
802+ }
803+
804+ if objects .Service , err = v1test .UpdateService (t , clients , names ,
805+ rtesting .WithServiceLabel ("juicy" , "jamba" )); err != nil {
806+ t .Fatalf ("Service %s was not updated with new annotation: %v" , names .Service , err )
807+ }
808+
809+ // Trigger new Revision generation
810+ t .Log ("Updating the Service to use a different image." )
811+ image2 := pkgtest .ImagePath (test .PizzaPlanet2 )
812+ if objects .Service , err = v1test .UpdateService (t , clients , names , rtesting .WithServiceImage (image2 )); err != nil {
813+ t .Fatalf ("Update for Service %s with new image %s failed: %v" , names .Service , image2 , err )
814+ }
815+ t .Log ("Service should reflect new revision created and ready in status." )
816+ names .Revision , err = v1test .WaitForServiceLatestRevision (clients , names )
817+ if err != nil {
818+ t .Fatal ("New image not reflected in Service:" , err )
819+ }
820+ t .Log ("Waiting for Service to transition to Ready." )
821+ if err := v1test .WaitForServiceState (clients .ServingClient , names .Service , v1test .IsServiceReady , "ServiceIsReady" ); err != nil {
822+ t .Fatal ("Error waiting for the service to become ready for the latest revision:" , err )
823+ }
824+ objects , err = v1test .GetResourceObjects (clients , names )
825+ if err != nil {
826+ t .Error ("Error getting objects:" , err )
827+ }
828+
829+ // Validate updated labels
830+ if err := validateLabelsPropagation (t , * objects , names ); err != nil {
831+ t .Error ("Annotations are incorrect:" , err )
832+ }
833+ if _ , ok := objects .Config .Labels ["juicy" ]; ! ok {
834+ t .Error ("Config missing `juicy` label" )
835+ }
836+ if _ , ok := objects .Route .Labels ["juicy" ]; ! ok {
837+ t .Error ("Route missing `juicy` label" )
838+ }
839+ if err := validateK8sServiceLabels (t , clients , names , "juicy" ); err != nil {
840+ t .Error (err )
841+ }
842+
843+ if objects .Service , err = v1test .UpdateService (t , clients , names ,
844+ rtesting .WithServiceLabelRemoved ("juicy" )); err != nil {
845+ t .Fatalf ("Service %s was not updated with annotation deleted: %v" , names .Service , err )
846+ }
847+
848+ // Trigger new Revision generation
849+ t .Log ("Updating the Service to use a different image." )
850+ image3 := pkgtest .ImagePath (test .HelloWorld )
851+ if objects .Service , err = v1test .UpdateService (t , clients , names , rtesting .WithServiceImage (image3 )); err != nil {
852+ t .Fatalf ("Update for Service %s with new image %s failed: %v" , names .Service , image3 , err )
853+ }
854+ t .Log ("Service should reflect new revision created and ready in status." )
855+ names .Revision , err = v1test .WaitForServiceLatestRevision (clients , names )
856+ if err != nil {
857+ t .Fatal ("New image not reflected in Service:" , err )
858+ }
859+ t .Log ("Waiting for Service to transition to Ready." )
860+ if err := v1test .WaitForServiceState (clients .ServingClient , names .Service , v1test .IsServiceReady , "ServiceIsReady" ); err != nil {
861+ t .Fatal ("Error waiting for the service to become ready for the latest revision:" , err )
862+ }
863+ objects , err = v1test .GetResourceObjects (clients , names )
864+ if err != nil {
865+ t .Error ("Error getting objects:" , err )
866+ }
867+
868+ // Now we can validate the annotations.
869+ if err := validateLabelsPropagation (t , * objects , names ); err != nil {
870+ t .Error (err )
871+ }
872+ if err := validateK8sServiceLabels (t , clients , names , "juicy" ); err != nil {
873+ t .Error (err )
874+ }
875+ if _ , ok := objects .Config .Labels ["juicy" ]; ok {
876+ t .Error ("Config still has `juicy` annotation" )
877+ }
878+ if _ , ok := objects .Route .Labels ["juicy" ]; ok {
879+ t .Error ("Route still has `juicy` annotation" )
880+ }
881+ if err := validateK8sServiceLabels (t , clients , names , "juicy" ); err != nil {
882+ if ! strings .Contains (err .Error (), "was empty" ) {
883+ t .Error (err )
884+ }
885+ }
886+ }
887+
753888// TestServiceCreateWithEmptyDir tests both Creation paths for a service with emptydir enabled.
754889// The test performs a series of Validate steps to ensure that the service transitions as expected during each step.
755890func TestServiceCreateWithEmptyDir (t * testing.T ) {
0 commit comments