Skip to content

Commit 8fc3d5e

Browse files
committed
Use presence of klusterlet objects to identify ocm spoke
Signed-off-by: Tamal Saha <[email protected]>
1 parent 058da18 commit 8fc3d5e

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

cluster/lib.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ func DetectClusterManager(kc client.Client, mappers ...meta.RESTMapper) kmapi.Cl
237237
if IsOpenClusterHub(mapper) {
238238
result |= kmapi.ClusterManagerOCMHub
239239
}
240-
if IsOpenClusterSpoke(mapper) {
240+
if IsOpenClusterSpoke(kc) {
241241
result |= kmapi.ClusterManagerOCMSpoke
242242
}
243243
if IsOpenClusterMulticlusterControlplane(mapper) {

cluster/ocm.go

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,12 @@ limitations under the License.
1717
package cluster
1818

1919
import (
20+
"context"
21+
2022
"k8s.io/apimachinery/pkg/api/meta"
23+
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2124
"k8s.io/apimachinery/pkg/runtime/schema"
25+
"sigs.k8s.io/controller-runtime/pkg/client"
2226
)
2327

2428
func IsOpenClusterHub(mapper meta.RESTMapper) bool {
@@ -31,14 +35,12 @@ func IsOpenClusterHub(mapper meta.RESTMapper) bool {
3135
return false
3236
}
3337

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

4446
func IsOpenClusterMulticlusterControlplane(mapper meta.RESTMapper) bool {

0 commit comments

Comments
 (0)