@@ -18,16 +18,20 @@ package openstack
1818
1919import (
2020 "context"
21+ "errors"
2122 "fmt"
2223
24+ routev1 "github.com/openshift/api/route/v1"
2325 "github.com/openstack-k8s-operators/lib-common/modules/certmanager"
2426 "github.com/openstack-k8s-operators/lib-common/modules/common/clusterdns"
2527 "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
2628 "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
29+ "github.com/openstack-k8s-operators/lib-common/modules/common/object"
2730 "github.com/openstack-k8s-operators/lib-common/modules/common/service"
2831 "github.com/openstack-k8s-operators/lib-common/modules/common/tls"
2932 "github.com/openstack-k8s-operators/lib-common/modules/common/util"
3033
34+ "sigs.k8s.io/controller-runtime/pkg/client"
3135 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
3236
3337 certmgrv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
@@ -40,6 +44,70 @@ import (
4044 ctrl "sigs.k8s.io/controller-runtime"
4145)
4246
47+ func deleteUndefinedNoVNCProxyCertsByCellName (
48+ ctx context.Context ,
49+ instance * corev1beta1.OpenStackControlPlane ,
50+ helper * helper.Helper ,
51+ ) (ctrl.Result , error ) {
52+
53+ log := GetLogger (ctx )
54+ // Fetch the list of certificates
55+ allCerts := & certmgrv1.CertificateList {}
56+ listOpts := []client.ListOption {
57+ client .InNamespace (instance .GetNamespace ()),
58+ }
59+ err := helper .GetClient ().List (ctx , allCerts , listOpts ... )
60+ if err != nil {
61+ return ctrl.Result {}, fmt .Errorf ("could not get certs %w" , err )
62+ }
63+
64+ allRoutes := & routev1.RouteList {}
65+ listOpts = []client.ListOption {
66+ client .InNamespace (instance .GetNamespace ()),
67+ }
68+ err = helper .GetClient ().List (ctx , allRoutes , listOpts ... )
69+ if err != nil {
70+ return ctrl.Result {}, fmt .Errorf ("could not get routes %w" , err )
71+ }
72+
73+ novncproxyPrefix := "nova-novncproxy-cell"
74+
75+ var delErrs []error
76+ for _ , cert := range allCerts .Items {
77+ shouldDelete := ShouldCertRouteBeDeleted (cert .Name , novncproxyPrefix , instance )
78+ if shouldDelete {
79+ if object .CheckOwnerRefExist (instance .GetUID (), cert .OwnerReferences ) {
80+ log .Info ("Deleting novncproxy cert %s" , "" , cert .Name )
81+ err = DeleteCertificate (ctx , helper , instance .Namespace , cert .Name )
82+ if err != nil {
83+ delErrs = append (delErrs , fmt .Errorf ("novncproxy cert deletion for '%s' failed, because: %w" , cert .Name , err ))
84+ }
85+ }
86+
87+ }
88+ }
89+
90+ for _ , route := range allRoutes .Items {
91+ shouldDelete := ShouldCertRouteBeDeleted (route .Name , novncproxyPrefix , instance )
92+ if shouldDelete {
93+ if object .CheckOwnerRefExist (instance .GetUID (), route .OwnerReferences ) {
94+ log .Info ("Deleting novncproxy route for %s" , "" , route .Name )
95+ _ , err := EnsureDeleted (ctx , helper , & route )
96+ if err != nil {
97+ delErrs = append (delErrs , fmt .Errorf ("novncproxy route deletion for '%s' failed, because: %w" , route .Name , err ))
98+ }
99+ }
100+ }
101+ }
102+
103+ if len (delErrs ) > 0 {
104+ delErrs := errors .Join (delErrs ... )
105+ return ctrl.Result {}, delErrs
106+ }
107+
108+ return ctrl.Result {}, nil
109+ }
110+
43111// ReconcileNova -
44112func ReconcileNova (ctx context.Context , instance * corev1beta1.OpenStackControlPlane , version * corev1beta1.OpenStackVersion , helper * helper.Helper ) (ctrl.Result , error ) {
45113 nova := & novav1.Nova {
@@ -209,6 +277,7 @@ func ReconcileNova(ctx context.Context, instance *corev1beta1.OpenStackControlPl
209277 }
210278
211279 // cell Metadata and NoVNCProxy
280+ Log .Info ("" , "" , "XXX ReconcileNova iterating cells" )
212281 for cellName , cellTemplate := range instance .Spec .Nova .Template .CellTemplates {
213282 // create certificate for Metadata agend if internal TLS and Metadata per cell is enabled
214283 if instance .Spec .TLS .PodLevel .Enabled &&
@@ -232,6 +301,7 @@ func ReconcileNova(ctx context.Context, instance *corev1beta1.OpenStackControlPl
232301
233302 // NoVNCProxy check for/creating route if service is enabled
234303 if noVNCProxyEnabled (cellTemplate .NoVNCProxyServiceTemplate ) {
304+ Log .Info ("" , "XXX ReconcileNova VNC enabled cell name" , cellName )
235305 if cellTemplate .NoVNCProxyServiceTemplate .Override .Service == nil {
236306 cellTemplate .NoVNCProxyServiceTemplate .Override .Service = & service.RoutedOverrideSpec {}
237307 }
@@ -247,6 +317,7 @@ func ReconcileNova(ctx context.Context, instance *corev1beta1.OpenStackControlPl
247317 }
248318
249319 // make sure to get to EndpointConfig when all service got created
320+ Log .Info ("" , "XXX vnc services" , svcs .Items )
250321 if len (svcs .Items ) == 1 {
251322 endpointDetails , ctrlResult , err := EnsureEndpointConfig (
252323 ctx ,
@@ -394,6 +465,17 @@ func ReconcileNova(ctx context.Context, instance *corev1beta1.OpenStackControlPl
394465 corev1beta1 .OpenStackControlPlaneNovaReadyRunningMessage ))
395466 }
396467
468+ _ , errs := deleteUndefinedNoVNCProxyCertsByCellName (ctx , instance , helper )
469+ if errs != nil {
470+ instance .Status .Conditions .Set (condition .FalseCondition (
471+ corev1beta1 .OpenStackControlPlaneNovaReadyCondition ,
472+ condition .ErrorReason ,
473+ condition .SeverityWarning ,
474+ corev1beta1 .OpenStackControlPlaneNovaReadyErrorMessage ,
475+ errs ))
476+ return ctrl.Result {}, errs
477+ }
478+
397479 return ctrl.Result {}, nil
398480}
399481
0 commit comments