Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update managedClusterSet tableDefinition #347

Merged
merged 1 commit into from
Nov 20, 2024
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
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ require (
k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0
kmodules.xyz/apiversion v0.2.0
kmodules.xyz/authorizer v0.29.1
kmodules.xyz/client-go v0.30.38
kmodules.xyz/client-go v0.30.39
kmodules.xyz/custom-resources v0.30.0
kmodules.xyz/go-containerregistry v0.0.12
kmodules.xyz/monitoring-agent-api v0.30.4
kmodules.xyz/offshoot-api v0.30.1
kmodules.xyz/resource-metadata v0.22.6-0.20241120021225-d78d324ddc82
kmodules.xyz/resource-metadata v0.22.6-0.20241120050054-2941d5e23943
kmodules.xyz/resource-metrics v0.30.5
kmodules.xyz/resource-metrics/utils v0.30.4
kmodules.xyz/sets v0.29.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,8 @@ kmodules.xyz/apiversion v0.2.0 h1:vAQYqZFm4xu4pbB1cAdHbFEPES6EQkcR4wc06xdTOWk=
kmodules.xyz/apiversion v0.2.0/go.mod h1:oPX8g8LvlPdPX3Yc5YvCzJHQnw3YF/X4/jdW0b1am80=
kmodules.xyz/authorizer v0.29.1 h1:uByGGoryKbZcfiEAhjcK/Y345I9mygNQP7DVpkMbNQQ=
kmodules.xyz/authorizer v0.29.1/go.mod h1:kZRhclL8twzyt2bQuJQJbpYww2sc+qFr8I5PPoq/sWY=
kmodules.xyz/client-go v0.30.38 h1:kAQ3FdgX2HbkmfFGEoeKz7fmJYWo1Ndgdum50aaHyI0=
kmodules.xyz/client-go v0.30.38/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/client-go v0.30.39 h1:/GjcgKLY1WdsHRK+956FXQdqDkJg/voJASo+IFyH0xA=
kmodules.xyz/client-go v0.30.39/go.mod h1:CAu+JlA8RVGtj6LQHu0Q1w2mnFUajuti49c7T1AvGdM=
kmodules.xyz/crd-schema-fuzz v0.29.1 h1:zJTlWYOrT5dsVVHW8HGcnR/vaWfxQfNh11QwTtkYpcs=
kmodules.xyz/crd-schema-fuzz v0.29.1/go.mod h1:n708z9YQqLMP2KNLQVgBcRJw1QpSWLvpNCEi+KJDOYE=
kmodules.xyz/custom-resources v0.30.0 h1:vR3CbseHMLwR4GvtcJJuRuwIV8voKqFqNii27rMcm1o=
Expand All @@ -939,8 +939,8 @@ kmodules.xyz/monitoring-agent-api v0.30.4 h1:6CTKxYJKpWDsDYb0WRBHGFoW3xQof05d+W8
kmodules.xyz/monitoring-agent-api v0.30.4/go.mod h1:ZuTQ5uGi6H80QLsOTuuC7m58dfXDGUv0YB+s059gnr4=
kmodules.xyz/offshoot-api v0.30.1 h1:TrulAYO+oBsXe9sZZGTmNWIuI8qD2izMpgcTSPvgAmI=
kmodules.xyz/offshoot-api v0.30.1/go.mod h1:T3mpjR6fui0QzOcmQvIuANytW48fe9ytmy/1cgx6D4g=
kmodules.xyz/resource-metadata v0.22.6-0.20241120021225-d78d324ddc82 h1:CM+e645F76PpWFqSzB+L1j2ViygurqRRvhpj4Armj/4=
kmodules.xyz/resource-metadata v0.22.6-0.20241120021225-d78d324ddc82/go.mod h1:zq0gtycDR21iPzhhqrbOGF4lwffIgQ9xiS8T34aJqjk=
kmodules.xyz/resource-metadata v0.22.6-0.20241120050054-2941d5e23943 h1:rgU3sUx8rgiTxX/Kj0BHBDgBiLHwpOka5/molIuW+RQ=
kmodules.xyz/resource-metadata v0.22.6-0.20241120050054-2941d5e23943/go.mod h1:zq27dG0YA8WEdOOoyfsLn4TQK5Xxox13dwJKtr66eqU=
kmodules.xyz/resource-metrics v0.30.5 h1:ZhpGeR9DCz1HTrKUg/mWhr95wlFzCPRdgVAqwaggy1o=
kmodules.xyz/resource-metrics v0.30.5/go.mod h1:w9+rz7/s/kGP1GWzYSuRdCn+l7EwpesmESSEHkLBnIQ=
kmodules.xyz/resource-metrics/utils v0.30.4 h1:bJS/x0Qr7N1FFdxugFbzZ/Es6HVs4ptsFlhkmgj3jac=
Expand Down
1 change: 1 addition & 0 deletions vendor/kmodules.xyz/client-go/api/v1/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ const (
ClusterNameKey string = "cluster.appscode.com/name"
ClusterDisplayNameKey string = "cluster.appscode.com/display-name"
ClusterProviderNameKey string = "cluster.appscode.com/provider"
ClusterProfileLabel string = "cluster.appscode.com/profile"

AceOrgIDKey string = "ace.appscode.com/org-id"
ClientOrgKey string = "ace.appscode.com/client-org"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,27 @@ spec:
version: v1beta2
validation:
openAPIV3Schema:
description: ManagedClusterSetBinding projects a ManagedClusterSet into a certain
namespace. You can create a ManagedClusterSetBinding in a namespace and bind
it to a ManagedClusterSet if both have a RBAC rules to CREATE on the virtual
subresource of managedclustersets/bind. Workloads that you create in the same
namespace can only be distributed to ManagedClusters in ManagedClusterSets
that are bound in this namespace by higher-level controllers.
description: |-
ManagedClusterSetBinding projects a ManagedClusterSet into a certain namespace.
You can create a ManagedClusterSetBinding in a namespace and bind it to a
ManagedClusterSet if both have a RBAC rules to CREATE on the virtual subresource of managedclustersets/bind.
Workloads that you create in the same namespace can only be distributed to ManagedClusters
in ManagedClusterSets that are bound in this namespace by higher-level controllers.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
properties:
Expand Down Expand Up @@ -80,10 +85,11 @@ spec:
description: Spec defines the attributes of ManagedClusterSetBinding.
properties:
clusterSet:
description: ClusterSet is the name of the ManagedClusterSet to bind.
It must match the instance name of the ManagedClusterSetBinding and
cannot change once created. User is allowed to set this field if they
have an RBAC rule to CREATE on the virtual subresource of managedclustersets/bind.
description: |-
ClusterSet is the name of the ManagedClusterSet to bind. It must match the
instance name of the ManagedClusterSetBinding and cannot change once created.
User is allowed to set this field if they have an RBAC rule to CREATE on the
virtual subresource of managedclustersets/bind.
minLength: 1
type: string
type: object
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,35 @@ spec:
version: v1beta2
validation:
openAPIV3Schema:
description: "ManagedClusterSet defines a group of ManagedClusters that user's
workload can run on. A workload can be defined to deployed on a ManagedClusterSet,
which mean: 1. The workload can run on any ManagedCluster in the ManagedClusterSet
2. The workload cannot run on any ManagedCluster outside the ManagedClusterSet
3. The service exposed by the workload can be shared in any ManagedCluster
in the ManagedClusterSet \n In order to assign a ManagedCluster to a certian
ManagedClusterSet, add a label with name `cluster.open-cluster-management.io/clusterset`
on the ManagedCluster to refers to the ManagedClusterSet. User is not allow
to add/remove this label on a ManagedCluster unless they have a RBAC rule
to CREATE on a virtual subresource of managedclustersets/join. In order to
update this label, user must have the permission on both the old and new ManagedClusterSet."
description: |-
ManagedClusterSet defines a group of ManagedClusters that you can run
workloads on. You can define a workload to be deployed on a ManagedClusterSet. See the following options for the workload:
- The workload can run on any ManagedCluster in the ManagedClusterSet
- The workload cannot run on any ManagedCluster outside the ManagedClusterSet
- The service exposed by the workload can be shared in any ManagedCluster in the ManagedClusterSet


To assign a ManagedCluster to a certain ManagedClusterSet, add a label with the name cluster.open-cluster-management.io/clusterset
on the ManagedCluster to refer to the ManagedClusterSet. You are not
allowed to add or remove this label on a ManagedCluster unless you have an
RBAC rule to CREATE on a virtual subresource of managedclustersets/join.
To update this label, you must have the permission on both
the old and new ManagedClusterSet.
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
description: |-
APIVersion defines the versioned schema of this representation of an object.
Servers should convert recognized schemas to the latest internal value, and
may reject unrecognized values.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
description: |-
Kind is a string value representing the REST resource this object represents.
Servers may infer this from the endpoint the client submits requests to.
Cannot be updated.
In CamelCase.
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
type: string
metadata:
properties:
Expand Down Expand Up @@ -93,51 +101,51 @@ spec:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the
key and values.
description: |-
A label selector requirement is a selector that contains values, a key, and an operator that
relates the key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship
to a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
description: |-
operator represents a key's relationship to a set of values.
Valid operators are In, NotIn, Exists and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a
strategic merge patch.
description: |-
values is an array of string values. If the operator is In or NotIn,
the values array must be non-empty. If the operator is Exists or DoesNotExist,
the values array must be empty. This array is replaced during a strategic
merge patch.
items:
type: string
type: array
x-kubernetes-list-type: atomic
required:
- key
- operator
type: object
type: array
x-kubernetes-list-type: atomic
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
description: |-
matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels
map is equivalent to an element of matchExpressions, whose key field is "key", the
operator is "In", and the values array contains only "value". The requirements are ANDed.
type: object
type: object
x-kubernetes-map-type: atomic
selectorType:
default: ExclusiveClusterSetLabel
description: SelectorType could only be "ExclusiveClusterSetLabel"
or "LabelSelector" "ExclusiveClusterSetLabel" means to use label
"cluster.open-cluster-management.io/clusterset:<ManagedClusterSet
Name>"" to select target clusters. "LabelSelector" means use labelSelector
to select target managedClusters
description: |-
SelectorType could only be "ExclusiveClusterSetLabel" or "LabelSelector"
"ExclusiveClusterSetLabel" means to use label "cluster.open-cluster-management.io/clusterset:<ManagedClusterSet Name>"" to select target clusters.
"LabelSelector" means use labelSelector to select target managedClusters
enum:
- ExclusiveClusterSetLabel
- LabelSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,12 @@ spec:
pathTemplate: '{{ .metadata.labels | toRawJson }}'
priority: 3
type: object
- name: Hub Accepted
pathTemplate: '{{ jp `{.spec.hubAcceptsClient}` . }}'
priority: 3
type: boolean
- name: Managed Cluster URLs
pathTemplate: '{{ jp `{.spec.managedClusterClientConfigs[*].url}` . }}'
priority: 3
type: string
- name: Joined
pathTemplate: '{{ jp `{.status.conditions[?(@.type=="ManagedClusterJoined")].status}` . }}'
- name: Managed Clusters
pathTemplate: '{{ jp `{.status.conditions[?(@.type=="ClusterSetEmpty")]}` . | count_managed_clusters }}'
priority: 3
type: string
- name: Available
pathTemplate: '{{ jp `{.status.conditions[?(@.type=="ManagedClusterConditionAvailable")].status}` . }}'
- name: Profile
pathTemplate: '{{ .metadata.labels | get_cluster_profile }}'
priority: 3
type: string
- name: Age
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"text/template"
"time"

kmapi "kmodules.xyz/client-go/api/v1"
meta_util "kmodules.xyz/client-go/meta"
"kmodules.xyz/resource-metadata/pkg/tableconvertor/lib"
"kmodules.xyz/resource-metadata/pkg/tableconvertor/printers"
Expand Down Expand Up @@ -63,6 +64,8 @@ func init() {
templateFns["cert_validity"] = certificateValidity
templateFns["k8s_fmt_resource_cpu"] = formatResourceCPUFn
templateFns["k8s_fmt_resource_memory"] = formatResourceMemoryFn
templateFns["count_managed_clusters"] = managedClusterSetFn
templateFns["get_cluster_profile"] = getClusterProfile
// ref: https://github.com/kmodules/resource-metrics/blob/bf6b257f8922a5572ccd20bf1cbab6bbedf4fcb4/template.go#L26-L36
for name, fn := range resourcemetrics.TxtFuncMap() {
templateFns[name] = fn
Expand Down Expand Up @@ -509,3 +512,45 @@ func formatResourceMemoryFn(data interface{}) (string, error) {
}
return fmt.Sprintf("%.1fGi", mem/1024.0/1024.0/1024.0), nil
}

func managedClusterSetFn(data interface{}) (string, error) {
conditionStr, ok := data.(string)
if !ok {
return "", fmt.Errorf("expected string input, got %T", data)
}

var condition map[string]interface{}
if err := json.Unmarshal([]byte(conditionStr), &condition); err != nil {
return "", fmt.Errorf("failed to unmarshal condition data: %v", err)
}

status, _ := condition["status"].(string)
message, _ := condition["message"].(string)

// Return "0" if status is "True"
if status == "True" {
return "0", nil
}

// Split the message and return the first word
words := strings.Split(message, " ")
if len(words) > 0 {
return words[0], nil
}

return "", fmt.Errorf("message is empty or invalid")
}

func getClusterProfile(data interface{}) (string, error) {
labels, ok := data.(map[string]interface{})
if !ok {
return "", nil
}

if profile, exists := labels[kmapi.ClusterProfileLabel]; exists {
if profileStr, ok := profile.(string); ok {
return profileStr, nil
}
}
return "", nil
}
4 changes: 2 additions & 2 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,7 @@ kmodules.xyz/authorizer/apiserver
kmodules.xyz/authorizer/rbac
kmodules.xyz/authorizer/rbac/helpers
kmodules.xyz/authorizer/rbac/validation
# kmodules.xyz/client-go v0.30.38
# kmodules.xyz/client-go v0.30.39
## explicit; go 1.22.0
kmodules.xyz/client-go
kmodules.xyz/client-go/api/v1
Expand Down Expand Up @@ -2052,7 +2052,7 @@ kmodules.xyz/monitoring-agent-api/client
kmodules.xyz/offshoot-api/api/v1
kmodules.xyz/offshoot-api/api/v2
kmodules.xyz/offshoot-api/util
# kmodules.xyz/resource-metadata v0.22.6-0.20241120021225-d78d324ddc82
# kmodules.xyz/resource-metadata v0.22.6-0.20241120050054-2941d5e23943
## explicit; go 1.22.1
kmodules.xyz/resource-metadata/apis/core/install
kmodules.xyz/resource-metadata/apis/core/v1alpha1
Expand Down
Loading