44 "context"
55 "encoding/json"
66 "fmt"
7+ "strings"
8+ "time"
79
810 "github.com/ghodss/yaml"
911 g "github.com/onsi/ginkgo/v2"
@@ -12,6 +14,8 @@ import (
1214 exutil "github.com/openshift/origin/test/extended/util"
1315 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1416 "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
17+ "k8s.io/apimachinery/pkg/util/wait"
18+ e2e "k8s.io/kubernetes/test/e2e/framework"
1519)
1620
1721const cloudControllerNamespace = "openshift-cloud-controller-manager"
@@ -88,6 +92,38 @@ var _ = g.Describe("[sig-cloud-provider][Feature:OpenShiftCloudControllerManager
8892 o .HaveField ("Contents" , o .ContainSubstring ("cloud-provider=external" )),
8993 )))
9094 })
95+
96+ g .It ("Cluster scoped load balancer healthcheck port and path should be 10256/healthz" , func () {
97+ exutil .SkipIfNotPlatform (oc , "AWS" )
98+ if strings .HasPrefix (exutil .GetClusterRegion (oc ), "us-iso" ) {
99+ g .Skip ("Skipped: There is no public subnet on AWS C2S/SC2S disconnected clusters!" )
100+ }
101+
102+ g .By ("Create a cluster scope load balancer" )
103+ svcName := "test-lb"
104+ defer oc .WithoutNamespace ().AsAdmin ().Run ("delete" ).Args ("-n" , oc .Namespace (), "service" , "loadbalancer" , svcName , "--ignore-not-found" ).Execute ()
105+ out , err := oc .AsAdmin ().WithoutNamespace ().Run ("create" ).Args ("-n" , oc .Namespace (), "service" , "loadbalancer" , svcName , "--tcp=80:8080" ).Output ()
106+ o .Expect (err ).NotTo (o .HaveOccurred (), "failed to create lb service" )
107+ o .Expect (out ).To (o .ContainSubstring ("service/" + svcName + " created" ))
108+
109+ g .By ("Check External-IP assigned" )
110+ svcExternalIP := getLoadBalancerExternalIP (oc , oc .Namespace (), svcName )
111+ e2e .Logf ("External IP assigned: %s" , svcExternalIP )
112+ o .Expect (svcExternalIP ).NotTo (o .BeEmpty (), "externalIP should not be empty" )
113+ lbName := strings .Split (svcExternalIP , "-" )[0 ]
114+
115+ g .By ("Check healthcheck port and path should be 10256/healthz" )
116+ healthCheckPort := "10256"
117+ healthCheckPath := "/healthz"
118+ exutil .GetAwsCredentialFromCluster (oc )
119+ region := exutil .GetClusterRegion (oc )
120+ sess := exutil .InitAwsSession (region )
121+ elbClient := exutil .NewELBClient (sess )
122+ healthCheck , err := elbClient .GetLBHealthCheckPortPath (lbName )
123+ o .Expect (err ).NotTo (o .HaveOccurred (), "unable to get health check port and path" )
124+ e2e .Logf ("Health check port and path: %v" , healthCheck )
125+ o .Expect (healthCheck ).To (o .Equal (fmt .Sprintf ("HTTP:%s%s" , healthCheckPort , healthCheckPath )))
126+ })
91127})
92128
93129// isPlatformExternal returns true when the platform has an in-tree provider,
@@ -103,3 +139,19 @@ func isPlatformExternal(platformType configv1.PlatformType) bool {
103139 return false
104140 }
105141}
142+
143+ // getLoadBalancerExternalIP get IP address of LB service
144+ func getLoadBalancerExternalIP (oc * exutil.CLI , namespace string , svcName string ) string {
145+ var svcExternalIP string
146+ var cmdErr error
147+ checkErr := wait .Poll (5 * time .Second , 300 * time .Second , func () (bool , error ) {
148+ svcExternalIP , cmdErr = oc .AsAdmin ().WithoutNamespace ().Run ("get" ).Args ("service" , "-n" , namespace , svcName , "-o=jsonpath={.status.loadBalancer.ingress[0].hostname}" ).Output ()
149+ if svcExternalIP == "" || cmdErr != nil {
150+ e2e .Logf ("Waiting for lb service IP assignment. Trying again..." )
151+ return false , nil
152+ }
153+ return true , nil
154+ })
155+ o .Expect (checkErr ).NotTo (o .HaveOccurred ())
156+ return svcExternalIP
157+ }
0 commit comments