@@ -277,15 +277,18 @@ func capiCRDHandler(gvk *schema.GroupVersionKind, action crd.ChangeType) {
277277 if action == crd .Modify {
278278 return
279279 }
280- if gvk .Group == clusterv1 .GroupVersion .Group {
280+ if gvk .Group == clusterv1 .GroupVersion .Group && gvk .Version == clusterv1 .GroupVersion .Version {
281+ setupLog .V (logs .LogInfo ).Info ("Initiating graceful restart due to CAPI CRD update" ,
282+ "GVK" , gvk .String (), "Action" , string (action ))
283+
281284 if killErr := syscall .Kill (syscall .Getpid (), syscall .SIGTERM ); killErr != nil {
282285 panic ("kill -TERM failed" )
283286 }
284287 }
285288}
286289
287- // isCAPIInstalled returns true if CAPI is installed, false otherwise
288- func isCAPIInstalled (ctx context.Context , c client.Client ) (bool , error ) {
290+ // isCAPIInstalled returns true if CAPI is installed with v1beta2 served , false otherwise
291+ func isCAPIInstalled (ctx context.Context , c client.Client , logger logr. Logger ) (bool , error ) {
289292 clusterCRD := & apiextensionsv1.CustomResourceDefinition {}
290293
291294 err := c .Get (ctx , types.NamespacedName {Name : "clusters.cluster.x-k8s.io" }, clusterCRD )
@@ -296,7 +299,14 @@ func isCAPIInstalled(ctx context.Context, c client.Client) (bool, error) {
296299 return false , err
297300 }
298301
299- return true , nil
302+ for _ , version := range clusterCRD .Spec .Versions {
303+ if version .Name == clusterv1 .GroupVersion .Version && version .Served {
304+ return true , nil
305+ }
306+ }
307+
308+ logger .V (logs .LogInfo ).Info ("clusterCRD CRD present but v1beta2 not served" )
309+ return false , nil
300310}
301311
302312func capiWatchers (ctx context.Context , mgr ctrl.Manager ,
@@ -306,7 +316,7 @@ func capiWatchers(ctx context.Context, mgr ctrl.Manager,
306316 const maxRetries = 20
307317 retries := 0
308318 for {
309- capiPresent , err := isCAPIInstalled (ctx , mgr .GetClient ())
319+ capiPresent , err := isCAPIInstalled (ctx , mgr .GetClient (), logger )
310320 if err != nil {
311321 if retries < maxRetries {
312322 logger .Info (fmt .Sprintf ("failed to verify if CAPI is present: %v" , err ))
0 commit comments