Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/onsi/ginkgo/v2 v2.28.1
github.com/onsi/gomega v1.39.1
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v1.8.0
github.com/projectsveltos/libsveltos v1.8.1-0.20260422193357-a670bbae8df8
github.com/prometheus/client_golang v1.23.2
github.com/spf13/pflag v1.0.10
golang.org/x/text v0.36.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/projectsveltos/libsveltos v1.8.0 h1:yBHmiYpBbpPS6aNJOx+uOAvvBOQPkHE8cU4VKsXoAao=
github.com/projectsveltos/libsveltos v1.8.0/go.mod h1:0K9ZLuYL/g0OonfhRVkHMyDYWuFt24EhvTtjTbUu3+Y=
github.com/projectsveltos/libsveltos v1.8.1-0.20260422193357-a670bbae8df8 h1:XR0ebx6/L4q+GvYlmvNEhyrF5ALMMVSySgkJ5bW6iAw=
github.com/projectsveltos/libsveltos v1.8.1-0.20260422193357-a670bbae8df8/go.mod h1:0K9ZLuYL/g0OonfhRVkHMyDYWuFt24EhvTtjTbUu3+Y=
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
Expand Down
20 changes: 15 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,15 +277,18 @@ func capiCRDHandler(gvk *schema.GroupVersionKind, action crd.ChangeType) {
if action == crd.Modify {
return
}
if gvk.Group == clusterv1.GroupVersion.Group {
if gvk.Group == clusterv1.GroupVersion.Group && gvk.Version == clusterv1.GroupVersion.Version {
setupLog.V(logs.LogInfo).Info("Initiating graceful restart due to CAPI CRD update",
"GVK", gvk.String(), "Action", string(action))

if killErr := syscall.Kill(syscall.Getpid(), syscall.SIGTERM); killErr != nil {
panic("kill -TERM failed")
}
}
}

// isCAPIInstalled returns true if CAPI is installed, false otherwise
func isCAPIInstalled(ctx context.Context, c client.Client) (bool, error) {
// isCAPIInstalled returns true if CAPI is installed with v1beta2 served, false otherwise
func isCAPIInstalled(ctx context.Context, c client.Client, logger logr.Logger) (bool, error) {
clusterCRD := &apiextensionsv1.CustomResourceDefinition{}

err := c.Get(ctx, types.NamespacedName{Name: "clusters.cluster.x-k8s.io"}, clusterCRD)
Expand All @@ -296,7 +299,14 @@ func isCAPIInstalled(ctx context.Context, c client.Client) (bool, error) {
return false, err
}

return true, nil
for _, version := range clusterCRD.Spec.Versions {
if version.Name == clusterv1.GroupVersion.Version && version.Served {
return true, nil
}
}

logger.V(logs.LogInfo).Info("clusterCRD CRD present but v1beta2 not served")
return false, nil
}

func capiWatchers(ctx context.Context, mgr ctrl.Manager,
Expand All @@ -306,7 +316,7 @@ func capiWatchers(ctx context.Context, mgr ctrl.Manager,
const maxRetries = 20
retries := 0
for {
capiPresent, err := isCAPIInstalled(ctx, mgr.GetClient())
capiPresent, err := isCAPIInstalled(ctx, mgr.GetClient(), logger)
if err != nil {
if retries < maxRetries {
logger.Info(fmt.Sprintf("failed to verify if CAPI is present: %v", err))
Expand Down