Skip to content

Commit

Permalink
Add status sub-resource to ResourceExport/Import and ClusterSet (#2367)
Browse files Browse the repository at this point in the history
Status sub-resource for multi cluster CRDs
  • Loading branch information
abhiraut authored and luolanzone committed Dec 13, 2021
1 parent 0a04c20 commit 7f709f6
Show file tree
Hide file tree
Showing 8 changed files with 1,159 additions and 164 deletions.
79 changes: 70 additions & 9 deletions multicluster/apis/multicluster/v1alpha1/clusterset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1alpha1

import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -32,11 +33,8 @@ type MemberCluster struct {
ServiceAccount string `json:"serviceAccount,omitempty"`
}

// ClusterSetSpec defines the desired state of ClusterSet
// ClusterSetSpec defines the desired state of ClusterSet.
type ClusterSetSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Members include member clusters known to the leader clusters.
// Used in leader cluster.
Members []MemberCluster `json:"members,omitempty"`
Expand All @@ -47,16 +45,79 @@ type ClusterSetSpec struct {
Namespace string `json:"namespace,omitempty"`
}

// ClusterSetStatus defines the observed state of ClusterSet
type ClusterSetConditionType string

const (
// ClusterSetReady indicates whether ClusterSet is ready.
ClusterSetReady ClusterSetConditionType = "Ready"
)

// ClusterSetCondition indicates the readiness condition of the clusterSet.
type ClusterSetCondition struct {
Type ClusterSetConditionType `json:"type,omitempty"`
// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status,omitempty"`
// +optional
// Last time the condition transited from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// +optional
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
// +optional
// Unique, one-word, CamelCase reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
}

type ClusterConditionType string

const (
// ClusterReady indicates whether Cluster is ready and connected.
ClusterReady ClusterConditionType = "Ready"
// ClusterIsLeader indicates whether Cluster is leader.
ClusterIsLeader ClusterConditionType = "IsLeader"
)

// ClusterCondition indicates the readiness condition of a cluster.
type ClusterCondition struct {
Type ClusterConditionType `json:"type,omitempty"`
// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status,omitempty"`

// +optional
// Last time the condition transited from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// +optional
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
// +optional
// Unique, one-word, CamelCase reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
}

type ClusterStatus struct {
// ClusterID is the unique identifier of this cluster.
ClusterID string `json:"clusterID,omitempty"`
Conditions []ClusterCondition `json:"conditions,omitempty"`
}

// ClusterSetStatus defines the observed state of ClusterSet.
type ClusterSetStatus struct {
// Important: Run "make" to regenerate code after modifying this file
// TBD
// Total number of member clusters configured in the set.
TotalClusters int32 `json:"totalClusters,omitempty"`
// Total number of clusters ready and connected.
ReadyClusters int32 `json:"readyClusters,omitempty"`
// The overall condition of the cluster set.
Conditions []ClusterSetCondition `json:"conditions,omitempty"`
// The status of individual member clusters.
ClusterStatuses []ClusterStatus `json:"clusterStatuses,omitempty"`
// The generation observed by the controller.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ClusterSet is the Schema for the clustersets API
// ClusterSet is the Schema for the clustersets API.
type ClusterSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -67,7 +128,7 @@ type ClusterSet struct {

//+kubebuilder:object:root=true

// ClusterSetList contains a list of ClusterSet
// ClusterSetList contains a list of ClusterSet.
type ClusterSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
32 changes: 27 additions & 5 deletions multicluster/apis/multicluster/v1alpha1/resourceexport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type RawResourceExport struct {
Data []byte `json:"data,omitempty"`
}

// ResourceExportSpec defines the desired state of ResourceExport
// ResourceExportSpec defines the desired state of ResourceExport.
type ResourceExportSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Expand All @@ -67,15 +67,37 @@ type ResourceExportSpec struct {
Raw RawResourceExport `json:"raw,omitempty"`
}

// ResourceExportStatus defines the observed state of ResourceExport
type ResourceExportConditionType string

const (
ResourceExportSucceeded ResourceExportConditionType = "Succeeded"
)

// ResourceExportCondition indicates the readiness condition of the ResourceExport.
type ResourceExportCondition struct {
Type ResourceExportConditionType `json:"type,omitempty"`
// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status,omitempty"`
// +optional
// Last time the condition transited from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// +optional
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
// +optional
// Unique, one-word, CamelCase reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
}

// ResourceExportStatus defines the observed state of ResourceExport.
type ResourceExportStatus struct {
// TBD
Conditions []ResourceExportCondition `json:"conditions,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ResourceExport is the Schema for the resourceexports API
// ResourceExport is the Schema for the resourceexports API.
type ResourceExport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -86,7 +108,7 @@ type ResourceExport struct {

//+kubebuilder:object:root=true

// ResourceExportList contains a list of ResourceExport
// ResourceExportList contains a list of ResourceExport.
type ResourceExportList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
39 changes: 34 additions & 5 deletions multicluster/apis/multicluster/v1alpha1/resourceimport_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RawResourceImport struct {
Data []byte `json:"data,omitempty"`
}

// ResourceImportSpec defines the desired state of ResourceImport
// ResourceImportSpec defines the desired state of ResourceImport.
type ResourceImportSpec struct {
// ClusterIDs specifies the member clusters this resource to import to.
// When not specified, import to all member clusters.
Expand All @@ -65,15 +65,44 @@ type ResourceImportSpec struct {
Raw *RawResourceImport `json:"raw,omitempty"`
}

// ResourceImportStatus defines the observed state of ResourceImport
type ResourceImportConditionType string

const (
ResourceImportSucceeded ResourceImportConditionType = "Succeeded"
)

// ResourceImportCondition indicates the condition of the ResourceImport in a cluster.
type ResourceImportCondition struct {
Type ResourceImportConditionType `json:"type,omitempty"`
// Status of the condition, one of True, False, Unknown.
Status v1.ConditionStatus `json:"status,omitempty"`
// +optional
// Last time the condition transited from one status to another.
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// +optional
// A human readable message indicating details about the transition.
Message string `json:"message,omitempty"`
// +optional
// Unique, one-word, CamelCase reason for the condition's last transition.
Reason string `json:"reason,omitempty"`
}

// ResourceImportClusterStatus indicates the readiness status of the ResourceImport in clusters.
type ResourceImportClusterStatus struct {
// ClusterID is the unique identifier of this cluster.
ClusterID string `json:"clusterID,omitempty"`
Conditions []ResourceImportCondition `json:"conditions,omitempty"`
}

// ResourceImportStatus defines the observed state of ResourceImport.
type ResourceImportStatus struct {
// TBD
ClusterStatuses []ResourceImportClusterStatus `json:"clusterStatuses,omitempty"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// ResourceImport is the Schema for the resourceimports API
// ResourceImport is the Schema for the resourceimports API.
type ResourceImport struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Expand All @@ -84,7 +113,7 @@ type ResourceImport struct {

//+kubebuilder:object:root=true

// ResourceImportList contains a list of ResourceImport
// ResourceImportList contains a list of ResourceImport.
type ResourceImportList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Expand Down
Loading

0 comments on commit 7f709f6

Please sign in to comment.