Skip to content

✨ [WIP] Adding managed namespace field in the managedclusterset #390

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ spec:
- type: string
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: Allocatable represents the total allocatable resources
description: allocatable represents the total allocatable resources
on the managed cluster.
type: object
capacity:
Expand All @@ -176,12 +176,12 @@ spec:
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
x-kubernetes-int-or-string: true
description: |-
Capacity represents the total resource capacity from all nodeStatuses
capacity represents the total resource capacity from all nodeStatuses
on the managed cluster.
type: object
clusterClaims:
description: |-
ClusterClaims represents cluster information that a managed cluster claims,
clusterClaims represents cluster information that a managed cluster claims,
for example a unique cluster identifier (id.k8s.io) and kubernetes version
(kubeversion.open-cluster-management.io). They are written from the managed
cluster. The set of claims is not uniform across a fleet, some claims can be
Expand All @@ -205,7 +205,7 @@ spec:
type: object
type: array
conditions:
description: Conditions contains the different condition statuses
description: conditions contains the different condition statuses
for this managed cluster.
items:
description: Condition contains details for one aspect of the current
Expand Down Expand Up @@ -262,8 +262,90 @@ spec:
- type
type: object
type: array
managedNamespaces:
description: |-
managedNamespaces are a list of namespaces managed by the clustersets the
cluster belongs to.
items:
properties:
clusterSet:
description: clusterSet represents the name of the cluster set.
type: string
conditions:
description: conditions are the status conditions of the managed
namespace
items:
description: Condition contains details for one aspect of
the current state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False,
Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
name:
description: name is the name of the namespace.
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
- clusterSet
- name
type: object
type: array
x-kubernetes-list-map-keys:
- clusterSet
- name
x-kubernetes-list-type: map
version:
description: Version represents the kubernetes version of the managed
description: version represents the kubernetes version of the managed
cluster.
properties:
kubernetes:
Expand Down
39 changes: 34 additions & 5 deletions cluster/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,26 +144,34 @@ const (

// ManagedClusterStatus represents the current status of joined managed cluster.
type ManagedClusterStatus struct {
// Conditions contains the different condition statuses for this managed cluster.
// conditions contains the different condition statuses for this managed cluster.
Conditions []metav1.Condition `json:"conditions"`

// Capacity represents the total resource capacity from all nodeStatuses
// capacity represents the total resource capacity from all nodeStatuses
// on the managed cluster.
Capacity ResourceList `json:"capacity,omitempty"`

// Allocatable represents the total allocatable resources on the managed cluster.
// allocatable represents the total allocatable resources on the managed cluster.
Allocatable ResourceList `json:"allocatable,omitempty"`

// Version represents the kubernetes version of the managed cluster.
// version represents the kubernetes version of the managed cluster.
Version ManagedClusterVersion `json:"version,omitempty"`

// ClusterClaims represents cluster information that a managed cluster claims,
// clusterClaims represents cluster information that a managed cluster claims,
// for example a unique cluster identifier (id.k8s.io) and kubernetes version
// (kubeversion.open-cluster-management.io). They are written from the managed
// cluster. The set of claims is not uniform across a fleet, some claims can be
// vendor or version specific and may not be included from all managed clusters.
// +optional
ClusterClaims []ManagedClusterClaim `json:"clusterClaims,omitempty"`

// managedNamespaces are a list of namespaces managed by the clustersets the
// cluster belongs to.
// +optional
// +listType=map
// +listMapKey=clusterSet
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the 'clusterSet' is the key of the map, does that mean for each clusterset only one item is allowed in the list? in another world, only one managed namespace is allowed for a clusterset in the 'managedNamespaces' list?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correct, add name is another key

// +listMapKey=name
ManagedNamespaces []ClusterSetManagedNamespaceConfig `json:"managedNamespaces,omitempty"`
}

// ManagedClusterVersion represents version information about the managed cluster.
Expand All @@ -188,6 +196,27 @@ type ManagedClusterClaim struct {
Value string `json:"value,omitempty"`
}

// managedNamespaces defines a namespace on the managedclusters across the
// clusterset to be managed by this clusterset.
type ManagedNamespaceConfig struct {
// name is the name of the namespace.
// +required
// +kubebuilder:validation:MaxLength=63
// +kubebuilder:validation:Pattern=^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
Name string `json:"name"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any restriction on the name? for example, it cannot be one of 'kube-system', 'kube-public' and 'default'

}

type ClusterSetManagedNamespaceConfig struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has this struct been used anywhere?

Copy link
Member Author

@qiujian16 qiujian16 Aug 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated, should be in the cluster status

ManagedNamespaceConfig `json:",inline"`

// clusterSet represents the name of the cluster set.
// +required
ClusterSet string `json:"clusterSet"`

// conditions are the status conditions of the managed namespace
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

const (
// ManagedClusterConditionJoined means the managed cluster has successfully joined the hub.
ManagedClusterConditionJoined string = "ManagedClusterJoined"
Expand Down
47 changes: 47 additions & 0 deletions cluster/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,27 @@ spec:
required:
- selectorType
type: object
managedNamespaces:
description: |-
managedNamespaces defines the list of namespace on the managedclusters
across the clusterset to be managed.
items:
description: |-
managedNamespaces defines a namespace on the managedclusters across the
clusterset to be managed by this clusterset.
properties:
name:
description: name is the name of the namespace.
maxLength: 63
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$
type: string
required:
- name
type: object
type: array
x-kubernetes-list-map-keys:
- name
x-kubernetes-list-type: map
type: object
status:
description: Status represents the current status of the ManagedClusterSet
Expand Down
8 changes: 8 additions & 0 deletions cluster/v1beta2/types_managedclusterset.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v1beta2

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "open-cluster-management.io/api/cluster/v1"
)

// ExclusiveClusterSetLabel LabelKey
Expand Down Expand Up @@ -48,6 +49,13 @@ type ManagedClusterSetSpec struct {
// +optional
// +kubebuilder:default:={selectorType: ExclusiveClusterSetLabel}
ClusterSelector ManagedClusterSelector `json:"clusterSelector,omitempty"`

// managedNamespaces defines the list of namespace on the managedclusters
// across the clusterset to be managed.
// +optional
// +listType=map
// +listMapKey=name
ManagedNamespaces []v1.ManagedNamespaceConfig `json:"managedNamespaces,omitempty"`
}

// ManagedClusterSelector represents a selector of ManagedClusters
Expand Down
6 changes: 6 additions & 0 deletions cluster/v1beta2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions hack/update-copyright.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ fi

COMMUNITY_COPY_HEADER_STRING=$(cat $COMMUNITY_COPY_HEADER_FILE | sed 's#^// ##')

echo "Desired copyright header is: $COMMUNITY_COPY_HEADER_STRING"

# NOTE: Only use one newline or javascript and typescript linter/prettier will complain about the extra blank lines
NEWLINE="\n"

Expand Down