@@ -1040,7 +1040,7 @@ var _ = framework.KubeDescribe("Services", func() {
10401040 })
10411041
10421042 It ("should create endpoints for unready pods" , func () {
1043- serviceName := "never-ready "
1043+ serviceName := "tolerate-unready "
10441044 ns := f .Namespace .Name
10451045
10461046 t := NewServerTest (cs , ns , serviceName )
@@ -1052,22 +1052,49 @@ var _ = framework.KubeDescribe("Services", func() {
10521052 }
10531053 }()
10541054
1055- service := t .BuildServiceSpec ()
1056- service .Annotations = map [string ]string {endpoint .TolerateUnreadyEndpointsAnnotation : "true" }
1055+ t .name = "slow-terminating-unready-pod"
1056+ t .image = "gcr.io/google_containers/netexec:1.7"
1057+ port := 80
1058+ terminateSeconds := int64 (600 )
1059+
1060+ service := & api.Service {
1061+ ObjectMeta : api.ObjectMeta {
1062+ Name : t .ServiceName ,
1063+ Namespace : t .Namespace ,
1064+ Annotations : map [string ]string {endpoint .TolerateUnreadyEndpointsAnnotation : "true" },
1065+ },
1066+ Spec : api.ServiceSpec {
1067+ Selector : t .Labels ,
1068+ Ports : []api.ServicePort {{
1069+ Name : "http" ,
1070+ Port : int32 (port ),
1071+ TargetPort : intstr .FromInt (port ),
1072+ }},
1073+ },
1074+ }
10571075 rcSpec := rcByNameContainer (t .name , 1 , t .image , t .Labels , api.Container {
1076+ Args : []string {fmt .Sprintf ("--http-port=%d" , port )},
10581077 Name : t .name ,
10591078 Image : t .image ,
1060- Ports : []api.ContainerPort {{ContainerPort : int32 (80 ), Protocol : api .ProtocolTCP }},
1079+ Ports : []api.ContainerPort {{ContainerPort : int32 (port ), Protocol : api .ProtocolTCP }},
10611080 ReadinessProbe : & api.Probe {
10621081 Handler : api.Handler {
10631082 Exec : & api.ExecAction {
10641083 Command : []string {"/bin/false" },
10651084 },
10661085 },
10671086 },
1087+ Lifecycle : & api.Lifecycle {
1088+ PreStop : & api.Handler {
1089+ Exec : & api.ExecAction {
1090+ Command : []string {"/bin/sleep" , fmt .Sprintf ("%d" , terminateSeconds )},
1091+ },
1092+ },
1093+ },
10681094 }, nil )
1095+ rcSpec .Spec .Template .Spec .TerminationGracePeriodSeconds = & terminateSeconds
10691096
1070- By (fmt .Sprintf ("createing RC %v with selectors %v" , rcSpec .Name , rcSpec .Spec .Selector ))
1097+ By (fmt .Sprintf ("creating RC %v with selectors %v" , rcSpec .Name , rcSpec .Spec .Selector ))
10711098 _ , err := t .createRC (rcSpec )
10721099 ExpectNoError (err )
10731100
@@ -1079,10 +1106,10 @@ var _ = framework.KubeDescribe("Services", func() {
10791106 ExpectNoError (framework .VerifyPods (t .Client , t .Namespace , t .name , false , 1 ))
10801107
10811108 svcName := fmt .Sprintf ("%v.%v" , serviceName , f .Namespace .Name )
1082- By ("waiting for endpoints of Service with DNS name " + svcName )
1109+ By ("Waiting for endpoints of Service with DNS name " + svcName )
10831110
10841111 execPodName := createExecPodOrFail (f .ClientSet , f .Namespace .Name , "execpod-" )
1085- cmd := fmt .Sprintf ("wget -qO- %v " , svcName )
1112+ cmd := fmt .Sprintf ("wget -qO- http://%s:%d/ " , svcName , port )
10861113 var stdout string
10871114 if pollErr := wait .PollImmediate (framework .Poll , kubeProxyLagTimeout , func () (bool , error ) {
10881115 var err error
@@ -1095,6 +1122,66 @@ var _ = framework.KubeDescribe("Services", func() {
10951122 }); pollErr != nil {
10961123 framework .Failf ("expected un-ready endpoint for Service %v within %v, stdout: %v" , t .name , kubeProxyLagTimeout , stdout )
10971124 }
1125+
1126+ By ("Scaling down replication controler to zero" )
1127+ framework .ScaleRC (f .ClientSet , t .Namespace , rcSpec .Name , 0 , false )
1128+
1129+ By ("Update service to not tolerate unready services" )
1130+ _ , err = updateService (f .ClientSet , t .Namespace , t .ServiceName , func (s * api.Service ) {
1131+ s .ObjectMeta .Annotations [endpoint .TolerateUnreadyEndpointsAnnotation ] = "false"
1132+ })
1133+ framework .ExpectNoError (err )
1134+
1135+ By ("Check if pod is unreachable" )
1136+ cmd = fmt .Sprintf ("wget -qO- -T 2 http://%s:%d/; test \" $?\" -eq \" 1\" " , svcName , port )
1137+ if pollErr := wait .PollImmediate (framework .Poll , kubeProxyLagTimeout , func () (bool , error ) {
1138+ var err error
1139+ stdout , err = framework .RunHostCmd (f .Namespace .Name , execPodName , cmd )
1140+ if err != nil {
1141+ framework .Logf ("expected un-ready endpoint for Service %v, stdout: %v, err %v" , t .name , stdout , err )
1142+ return false , nil
1143+ }
1144+ return true , nil
1145+ }); pollErr != nil {
1146+ framework .Failf ("expected un-ready endpoint for Service %v within %v, stdout: %v" , t .name , kubeProxyLagTimeout , stdout )
1147+ }
1148+
1149+ By ("Update service to tolerate unready services again" )
1150+ _ , err = updateService (f .ClientSet , t .Namespace , t .ServiceName , func (s * api.Service ) {
1151+ s .ObjectMeta .Annotations [endpoint .TolerateUnreadyEndpointsAnnotation ] = "true"
1152+ })
1153+ framework .ExpectNoError (err )
1154+
1155+ By ("Check if terminating pod is available through service" )
1156+ cmd = fmt .Sprintf ("wget -qO- http://%s:%d/" , svcName , port )
1157+ if pollErr := wait .PollImmediate (framework .Poll , kubeProxyLagTimeout , func () (bool , error ) {
1158+ var err error
1159+ stdout , err = framework .RunHostCmd (f .Namespace .Name , execPodName , cmd )
1160+ if err != nil {
1161+ framework .Logf ("expected un-ready endpoint for Service %v, stdout: %v, err %v" , t .name , stdout , err )
1162+ return false , nil
1163+ }
1164+ return true , nil
1165+ }); pollErr != nil {
1166+ framework .Failf ("expected un-ready endpoint for Service %v within %v, stdout: %v" , t .name , kubeProxyLagTimeout , stdout )
1167+ }
1168+
1169+ By ("Remove pods immediately" )
1170+ label := labels .SelectorFromSet (labels .Set (t .Labels ))
1171+ options := api.ListOptions {LabelSelector : label }
1172+ podClient := t .Client .Core ().Pods (f .Namespace .Name )
1173+ pods , err := podClient .List (options )
1174+ if err != nil {
1175+ framework .Logf ("warning: error retrieving pods: %s" , err )
1176+ } else {
1177+ for _ , pod := range pods .Items {
1178+ var gracePeriodSeconds int64 = 0
1179+ err := podClient .Delete (pod .Name , & api.DeleteOptions {GracePeriodSeconds : & gracePeriodSeconds })
1180+ if err != nil {
1181+ framework .Logf ("warning: error force deleting pod '%s': %s" , pod .Name , err )
1182+ }
1183+ }
1184+ }
10981185 })
10991186
11001187 It ("should only allow access from service loadbalancer source ranges [Slow]" , func () {
0 commit comments