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
17 changes: 12 additions & 5 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ 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))

Expand All @@ -353,8 +353,8 @@ func capiCRDHandler(gvk *schema.GroupVersionKind, action crd.ChangeType) {
}
}

// 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 @@ -365,7 +365,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
}

// fluxCRDHandler restarts process if a Flux CRD is updated
Expand Down Expand Up @@ -404,7 +411,7 @@ func capiWatchers(ctx context.Context, mgr ctrl.Manager, watchersForCAPI []watch
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
3 changes: 3 additions & 0 deletions controllers/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,9 @@ func deplAssociatedClusterExist(ctx context.Context, c client.Client, depl *apps
if apierrors.IsNotFound(err) {
return false, clusterNamespace, clusterName, clusterType
}
if clusterType == libsveltosv1beta1.ClusterTypeCapi && meta.IsNoMatchError(err) {
return true, clusterNamespace, clusterName, clusterType
}
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to get cluster %s:%s/%s: %v",
clusterNamespace, clusterName, clusterTypeString, err))
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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.20260422123949-ee3c3d0f960e
github.com/prometheus/client_golang v1.23.2
github.com/robfig/cron v1.2.0
github.com/spf13/pflag v1.0.10
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY=
github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg=
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.20260422123949-ee3c3d0f960e h1:6U0OrYtquxjcuHLROBpcva1fofBae9c+nGhRg6xqgRI=
github.com/projectsveltos/libsveltos v1.8.1-0.20260422123949-ee3c3d0f960e/go.mod h1:0K9ZLuYL/g0OonfhRVkHMyDYWuFt24EhvTtjTbUu3+Y=
github.com/projectsveltos/lua-utils/glua-json v0.0.0-20251212200258-2b3cdcb7c0f5 h1:khnc+994UszxZYu69J+R5FKiLA/Nk1JQj0EYAkwTWz0=
github.com/projectsveltos/lua-utils/glua-json v0.0.0-20251212200258-2b3cdcb7c0f5/go.mod h1:yVL8KQFa9tmcxgwl9nwIMtKgtmIVC1zaFRSCfOwYvPY=
github.com/projectsveltos/lua-utils/glua-runes v0.0.0-20251212200258-2b3cdcb7c0f5 h1:YbsebwRwTRhV8QacvEAdFqxcxHdeu7JTVtsBovbkgos=
Expand Down