@@ -24,12 +24,37 @@ import (
2424 "k8s.io/client-go/kubernetes"
2525 "k8s.io/client-go/tools/clientcmd"
2626
27+ "github.com/hetznercloud/hcloud-cloud-controller-manager/internal/annotation"
2728 "github.com/hetznercloud/hcloud-cloud-controller-manager/internal/hcops"
2829 "github.com/hetznercloud/hcloud-cloud-controller-manager/internal/testsupport"
2930 "github.com/hetznercloud/hcloud-cloud-controller-manager/internal/utils"
3031 "github.com/hetznercloud/hcloud-go/v2/hcloud"
3132)
3233
34+ // Load Balancer creation timeouts. Services that involve certificate
35+ // provisioning take longer to become ready.
36+ const (
37+ lbCreateTimeoutDefault = 8 * time .Minute
38+ lbCreateTimeoutCert = 16 * time .Minute
39+ )
40+
41+ // lbCreateTimeoutFor returns the timeout to use when waiting for the given
42+ // Load Balancer service to become ready.
43+ func lbCreateTimeoutFor (svc * corev1.Service ) time.Duration {
44+ certAnnotations := []annotation.Name {
45+ annotation .LBSvcHTTPCertificates ,
46+ annotation .LBSvcHTTPCertificateType ,
47+ annotation .LBSvcHTTPManagedCertificateName ,
48+ annotation .LBSvcHTTPManagedCertificateDomains ,
49+ }
50+ for _ , a := range certAnnotations {
51+ if _ , ok := svc .Annotations [string (a )]; ok {
52+ return lbCreateTimeoutCert
53+ }
54+ }
55+ return lbCreateTimeoutDefault
56+ }
57+
3358var rng * rand.Rand
3459
3560func init () {
@@ -291,10 +316,13 @@ func (l *lbTestHelper) ServiceDefinition(pod *corev1.Pod, annotations map[string
291316}
292317
293318// CreateService creates a k8s service based on the given service definition
294- // and waits until it is "ready".
295- func (l * lbTestHelper ) CreateService (lbSvc * corev1.Service , timeout time.Duration ) (* corev1.Service , error ) {
319+ // and waits until it is "ready". The wait timeout is derived from the service
320+ // annotations: services that provision certificates get a longer timeout.
321+ func (l * lbTestHelper ) CreateService (lbSvc * corev1.Service ) (* corev1.Service , error ) {
296322 l .t .Helper ()
297323
324+ timeout := lbCreateTimeoutFor (lbSvc )
325+
298326 lbSvc , err := testCluster .k8sClient .CoreV1 ().Services (l .namespace ).Create (l .t .Context (), lbSvc , metav1.CreateOptions {})
299327 if err != nil {
300328 return nil , fmt .Errorf ("could not create service: %w" , err )
0 commit comments