99 "github.com/spf13/cobra"
1010 rbacv1 "k8s.io/api/rbac/v1"
1111 "k8s.io/apimachinery/pkg/runtime"
12+ "k8s.io/apimachinery/pkg/util/wait"
1213 "sigs.k8s.io/controller-runtime/pkg/client"
1314
1415 ctrlutils "github.com/openmcp-project/controller-utils/pkg/controller"
@@ -17,11 +18,13 @@ import (
1718 clustersv1alpha1 "github.com/openmcp-project/openmcp-operator/api/clusters/v1alpha1"
1819 openmcpconst "github.com/openmcp-project/openmcp-operator/api/constants"
1920 "github.com/openmcp-project/openmcp-operator/lib/clusteraccess"
21+ libutils "github.com/openmcp-project/openmcp-operator/lib/utils"
2022
2123 pwv1alpha1 "github.com/openmcp-project/project-workspace-operator/api/core/v1alpha1"
2224 "github.com/openmcp-project/project-workspace-operator/api/crds"
2325 providerscheme "github.com/openmcp-project/project-workspace-operator/api/install"
2426 "github.com/openmcp-project/project-workspace-operator/internal/controller/core"
27+ "github.com/openmcp-project/project-workspace-operator/internal/dns"
2528)
2629
2730func NewInitCommand (so * SharedOptions ) * cobra.Command {
@@ -140,8 +143,70 @@ func (o *InitOptions) Run(ctx context.Context) error {
140143
141144 suffix := "-webhook"
142145 whServiceName := ctrlutils .ShortenToXCharactersUnsafe (o .ProviderName , ctrlutils .K8sMaxNameLength - len (suffix )) + suffix
143- suffix = "-webhook-tls"
144- whSecretName := ctrlutils .ShortenToXCharactersUnsafe (o .ProviderName , ctrlutils .K8sMaxNameLength - len (suffix )) + suffix
146+ whSecretName , err := libutils .WebhookSecretName (o .ProviderName )
147+ if err != nil {
148+ return fmt .Errorf ("unable to determine webhook secret name: %w" , err )
149+ }
150+
151+ webhookPort , err := resolveWebhookPort (ctx , o .PlatformCluster .Client (), * pwc .Spec .Webhook .TargetPort )
152+ if err != nil {
153+ return err
154+ }
155+
156+ // setup gateway for webhooks
157+ dnsInstance := & dns.Instance {
158+ Name : whServiceName ,
159+ Namespace : providerSystemNamespace ,
160+ SubDomainPrefix : "pwo-webhooks" ,
161+ BackendName : whServiceName ,
162+ BackendPort : int32 (webhookPort ),
163+ }
164+ dnsReconciler := dns .NewReconciler ()
165+ timeout := 3 * time .Minute
166+ log .Info ("Verifying default Gateway is available" , "timeout" , timeout .String ())
167+ waitCtx , cancelCtx := context .WithTimeout (ctx , timeout )
168+ defer cancelCtx ()
169+ var gatewayResult dns.GatewayReconcileResult
170+ err = wait .PollUntilContextTimeout (waitCtx , 10 * time .Second , timeout , true , func (ctx context.Context ) (bool , error ) {
171+ gatewayResult , err = dnsReconciler .ReconcileGateway (ctx , dnsInstance , o .PlatformCluster )
172+ if err != nil {
173+ log .Error (err , "Error reconciling Gateway, retrying..." )
174+ return false , nil
175+ }
176+ if gatewayResult .RequeueAfter > 0 {
177+ log .Debug ("Default Gateway is not yet available, retrying..." )
178+ return false , nil
179+ }
180+ return true , nil
181+ })
182+ if err != nil {
183+ return fmt .Errorf ("default Gateway did not become available within %s: %w" , timeout .String (), err )
184+ }
185+ log .Info ("Default Gateway is available" , "hostName" , gatewayResult .HostName )
186+
187+ log .Info ("Waiting for TLS route to become ready" , "timeout" , timeout .String ())
188+ waitCtx , cancelCtx = context .WithTimeout (ctx , timeout )
189+ defer cancelCtx ()
190+ err = wait .PollUntilContextTimeout (waitCtx , 10 * time .Second , timeout , true , func (ctx context.Context ) (bool , error ) {
191+ if err := dnsReconciler .ReconcileTLSRoute (ctx , dnsInstance , o .PlatformCluster ); err != nil {
192+ log .Error (err , "Error reconciling TLS route, retrying..." )
193+ return false , nil
194+ }
195+ tlsReady , err := dnsReconciler .IsTLSRouteReady (ctx , dnsInstance , o .PlatformCluster )
196+ if err != nil {
197+ log .Error (err , "Error checking TLS route readiness, retrying..." )
198+ return false , nil
199+ }
200+ if ! tlsReady {
201+ log .Debug ("TLS route is not yet ready, retrying..." )
202+ return false , nil
203+ }
204+ return true , nil
205+ })
206+ if err != nil {
207+ return fmt .Errorf ("TLS route did not become ready within %s: %w" , timeout .String (), err )
208+ }
209+ log .Info ("TLS route is ready" )
145210
146211 opts := []webhooks.InstallOption {
147212 webhooks.WithWebhookService {Name : whServiceName , Namespace : providerSystemNamespace },
0 commit comments