add member cluster api

Signed-off-by: Kevin Wang <kevinwzf0126@gmail.com>
This commit is contained in:
Kevin Wang 2020-11-10 20:23:52 +08:00
parent edbfad18cb
commit 23c812744a
4 changed files with 178 additions and 0 deletions

View File

@ -0,0 +1,6 @@
package membercluster
// GroupName is the group name used in this package
const (
GroupName = "membercluster.karmada.io"
)

View File

@ -0,0 +1,5 @@
// +k8s:deepcopy-gen=package
// +groupName=membercluster.karmada.io
// Package v1alpha1 is the v1alpha1 version of the API.
package v1alpha1

View File

@ -0,0 +1,39 @@
package v1alpha1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"github.com/huawei-cloudnative/karmada/pkg/apis/membercluster"
)
// SchemeGroupVersion is group version used to register these objects
var SchemeGroupVersion = schema.GroupVersion{Group: membercluster.GroupName, Version: "v1alpha1"}
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
func Kind(kind string) schema.GroupKind {
return SchemeGroupVersion.WithKind(kind).GroupKind()
}
// Resource takes an unqualified resource and returns a Group qualified GroupResource
func Resource(resource string) schema.GroupResource {
return SchemeGroupVersion.WithResource(resource).GroupResource()
}
var (
// SchemeBuilder initializes a scheme builder
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
// AddToScheme is a global function that registers this API group & version to a scheme
AddToScheme = SchemeBuilder.AddToScheme
)
// Adds the list of known types to Scheme.
func addKnownTypes(scheme *runtime.Scheme) error {
scheme.AddKnownTypes(SchemeGroupVersion,
&MemberCluster{},
&MemberClusterList{},
)
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}

View File

@ -0,0 +1,128 @@
package v1alpha1
import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// MemberCluster represents the desire state and status of a member cluster.
type MemberCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec represents the specification of the desired behavior of member cluster.
Spec MemberClusterSpec `json:"spec"`
// Status represents the status of member cluster.
// +optional
Status MemberClusterStatus `json:"status,omitempty"`
}
// MemberClusterSpec defines the desired state of a member cluster.
type MemberClusterSpec struct {
// ManageMode specifies the relationship between control plane and member cluster,
// the mode determines how to reach each other.
// +optional
ManageMode ClusterManageMode `json:"manageMode,omitempty"`
// Accepted represents if the member cluster has been accepted by control plane.
// Default value is false.
// If member cluster working in 'Delegation' mode, this always be true.
// If member cluster working in 'SelfManagement' mode, this will turn to true only after administrator
// accepted the request from member cluster.
// +optional
Accepted bool `json:"accepted,omitempty"`
// The API endpoint of the member cluster. This can be a hostname,
// hostname:port, IP or IP:port.
// +optional
APIEndpoint string `json:"apiEndpoint,omitempty"`
// SecretRef represents the secret contains mandatory credentials to access the member cluster.
// The secret should hold credentials as follows:
// - secret.data.token
// - secret.data.caBundle
// +optional
SecretRef *LocalSecretReference `json:"secretRef,omitempty"`
// Provider represents the cloud provider name of the member cluster.
// +optional
Provider string `json:"provider,omitempty"`
// Region represents the region of the member cluster locate in.
// +optional
Region string `json:"region,omitempty"`
// Zone represents the zone of the member cluster locate in.
// +optional
Zone string `json:"zone,omitempty"`
// Taints attached to the member cluster.
// Taints on the cluster have the "effect" on
// any resource that does not tolerate the Taint.
// +optional
Taints []corev1.Taint `json:"taints,omitempty"`
}
// ClusterManageMode presents member clusters working mode.
type ClusterManageMode string
const (
// Delegation represents a member cluster will be managed directly by control plane.
Delegation ClusterManageMode = "Delegation"
// SelfManagement represents a member cluster will be managed by itself.
SelfManagement ClusterManageMode = "SelfManagement"
)
// LocalSecretReference is a reference to a secret within the enclosing
// namespace.
type LocalSecretReference struct {
// Namespace is the namespace for the resource being referenced.
Namespace string `json:"namespace"`
// Name is the name of resource being referenced.
Name string `json:"name"`
}
// MemberClusterStatus contains information about the current status of a
// cluster updated periodically by cluster controller.
type MemberClusterStatus struct {
// KubernetesVersion represents version of the member cluster.
// +optional
KubernetesVersion string `json:"kubernetesVersion,omitempty"`
// APIEnablement represents the list of APIs installed in the member cluster.
// +optional
APIEnablement []schema.GroupVersionKind `json:"apiEnablement,omitempty"`
// Conditions is an array of current cluster conditions.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// NodeSummary represents the summary of nodes status in the member cluster.
NodeSummary NodeSummary `json:"nodeSummary,omitempty"`
}
// NodeSummary represents the summary of nodes status in a specific cluster.
type NodeSummary struct {
// TotalNum is the total number of nodes in the cluster.
TotalNum int `json:"totalNum,omitempty"`
// ReadyNum is the number of ready nodes in the cluster.
ReadyNum int `json:"readyNum,omitempty"`
// Allocatable represents the allocatable resources across all nodes.
Allocatable corev1.ResourceList `json:"allocatable,omitempty"`
// Used represents the resources have been used across all nodes.
Used corev1.ResourceList `json:"used,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// MemberClusterList contains a list of member cluster
type MemberClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MemberCluster `json:"items"`
}