Skip to content

Commit

Permalink
Use presence of klusterlet objects to identify ocm spoke
Browse files Browse the repository at this point in the history
Signed-off-by: Tamal Saha <[email protected]>
  • Loading branch information
tamalsaha committed Oct 10, 2024
1 parent 058da18 commit 8fc3d5e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cluster/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ func DetectClusterManager(kc client.Client, mappers ...meta.RESTMapper) kmapi.Cl
if IsOpenClusterHub(mapper) {
result |= kmapi.ClusterManagerOCMHub
}
if IsOpenClusterSpoke(mapper) {
if IsOpenClusterSpoke(kc) {
result |= kmapi.ClusterManagerOCMSpoke
}
if IsOpenClusterMulticlusterControlplane(mapper) {
Expand Down
18 changes: 10 additions & 8 deletions cluster/ocm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ limitations under the License.
package cluster

import (
"context"

"k8s.io/apimachinery/pkg/api/meta"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func IsOpenClusterHub(mapper meta.RESTMapper) bool {
Expand All @@ -31,14 +35,12 @@ func IsOpenClusterHub(mapper meta.RESTMapper) bool {
return false
}

func IsOpenClusterSpoke(mapper meta.RESTMapper) bool {
if _, err := mapper.RESTMappings(schema.GroupKind{
Group: "operator.open-cluster-management.io",
Kind: "Klusterlet",
}); err == nil {
return true
}
return false
func IsOpenClusterSpoke(kc client.Client) bool {
var list unstructured.UnstructuredList
list.SetAPIVersion("operator.open-cluster-management.io/v1")
list.SetKind("Klusterlet")
err := kc.List(context.TODO(), &list)
return err == nil && len(list.Items) > 0
}

func IsOpenClusterMulticlusterControlplane(mapper meta.RESTMapper) bool {
Expand Down

0 comments on commit 8fc3d5e

Please sign in to comment.