cluster_types.go 5.9 KB
Newer Older
Z
zryfish 已提交
1 2 3 4 5 6 7 8 9 10 11
package v1alpha1

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

const (
	ResourceKindCluster      = "Cluster"
	ResourcesSingularCluster = "cluster"
	ResourcesPluralCluster   = "clusters"
Z
zryfish 已提交
12 13

	IsHostCluster = "cluster.kubesphere.io/is-host-cluster"
Z
zryfish 已提交
14 15 16 17 18 19
	// Description of which region the cluster been placed
	ClusterRegion = "cluster.kubesphere.io/region"
	// Name of the cluster group
	ClusterGroup = "cluster.kubesphere.io/group"

	Finalizer = "finalizer.cluster.kubesphere.io"
Z
zryfish 已提交
20 21 22 23
)

type ClusterSpec struct {

Z
zryfish 已提交
24
	// Join cluster as a kubefed cluster
Z
zryfish 已提交
25
	JoinFederation bool `json:"joinFederation,omitempty"`
Z
zryfish 已提交
26 27

	// Desired state of the cluster
Z
zryfish 已提交
28
	Enable bool `json:"enable,omitempty"`
Z
zryfish 已提交
29 30 31

	// Provider of the cluster, this field is just for description
	Provider string `json:"provider,omitempty"`
Z
zryfish 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78

	// Connection holds info to connect to the member cluster
	Connection Connection `json:"connection,omitempty"`
}

type ConnectionType string

const (
	ConnectionTypeDirect ConnectionType = "direct"
	ConnectionTypeProxy  ConnectionType = "proxy"
)

type Connection struct {

	// type defines how host cluster will connect to host cluster
	// ConnectionTypeDirect means direct connection, this requires
	//   kubeconfig and kubesphere apiserver endpoint provided
	// ConnectionTypeProxy means using kubesphere proxy, no kubeconfig
	//   or kubesphere apiserver endpoint required
	Type ConnectionType `json:"type,omitempty"`

	// KubeSphere API Server endpoint. Example: http://10.10.0.11:8080
	// Should provide this field explicitly if connection type is direct.
	// Will be populated by ks-apiserver if connection type is proxy.
	KubeSphereAPIEndpoint string `json:"kubesphereAPIEndpoint,omitempty"`

	// Kubernetes API Server endpoint. Example: https://10.10.0.1:6443
	// Should provide this field explicitly if connection type is direct.
	// Will be populated by ks-apiserver if connection type is proxy.
	KubernetesAPIEndpoint string `json:"kubernetesAPIEndpoint,omitempty"`

	// KubeConfig content used to connect to cluster api server
	// Should provide this field explicitly if connection type is direct.
	// Will be populated by ks-proxy if connection type is proxy.
	KubeConfig []byte `json:"kubeconfig,omitempty"`

	// Token used by agents of member cluster to connect to host cluster proxy.
	// This field is populated by apiserver only if connection type is proxy.
	Token string `json:"token,omitempty"`

	// KubeAPIServerPort is the port which listens for forwarding kube-apiserver traffic
	// Only applicable when connection type is proxy.
	KubernetesAPIServerPort uint16 `json:"kubernetesAPIServerPort,omitempty"`

	// KubeSphereAPIServerPort is the port which listens for forwarding kubesphere apigateway traffic
	// Only applicable when connection type is proxy.
	KubeSphereAPIServerPort uint16 `json:"kubesphereAPIServerPort,omitempty"`
Z
zryfish 已提交
79 80 81 82 83 84
}

type ClusterConditionType string

const (
	// Cluster agent is initialized and waiting for connecting
Z
zryfish 已提交
85
	ClusterInitialized ClusterConditionType = "Initialized"
Z
zryfish 已提交
86 87 88 89

	// Cluster agent is available
	ClusterAgentAvailable ClusterConditionType = "AgentAvailable"

Z
zryfish 已提交
90 91
	// Cluster has been one of federated clusters
	ClusterFederated ClusterConditionType = "Federated"
Z
zryfish 已提交
92 93 94

	// Cluster is all available for requests
	ClusterReady ClusterConditionType = "Ready"
Z
zryfish 已提交
95 96
)

Z
zryfish 已提交
97
type ClusterCondition struct {
Z
zryfish 已提交
98 99 100 101 102 103 104 105 106 107 108 109 110 111
	// Type of the condition
	Type ClusterConditionType `json:"type"`
	// Status of the condition, one of True, False, Unknown.
	Status v1.ConditionStatus `json:"status"`
	// The last time this condition was updated.
	LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"`
	// Last time the condition transitioned from one status to another.
	LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
	// The reason for the condition's last transition.
	Reason string `json:"reason,omitempty"`
	// A human readable message indicating details about the transition.
	Message string `json:"message,omitempty"`
}

Z
zryfish 已提交
112 113 114 115 116
type ClusterStatus struct {

	// Represents the latest available observations of a cluster's current state.
	Conditions []ClusterCondition `json:"conditions,omitempty"`

Z
zryfish 已提交
117
	// GitVersion of the kubernetes cluster, this field is populated by cluster controller
Z
zryfish 已提交
118
	KubernetesVersion string `json:"kubernetesVersion,omitempty"`
Z
zryfish 已提交
119

Z
zryfish 已提交
120
	// Count of the kubernetes cluster nodes
Z
zryfish 已提交
121
	// This field may not reflect the instant status of the cluster.
Z
zryfish 已提交
122
	NodeCount int `json:"nodeCount,omitempty"`
Z
zryfish 已提交
123 124 125 126 127 128 129 130

	// Zones are the names of availability zones in which the nodes of the cluster exist, e.g. 'us-east1-a'.
	// +optional
	Zones []string `json:"zones,omitempty"`

	// Region is the name of the region in which all of the nodes in the cluster exist.  e.g. 'us-east1'.
	// +optional
	Region *string `json:"region,omitempty"`
131 132 133 134 135

	// Configz is status of components enabled in the member cluster. This is synchronized with member cluster
	// every amount of time, like 5 minutes.
	// +optional
	Configz map[string]bool `json:"configz,omitempty"`
Z
zryfish 已提交
136 137
}

Z
zryfish 已提交
138 139 140 141
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +k8s:openapi-gen=true
// +genclient:nonNamespaced
Z
zryfish 已提交
142
// +kubebuilder:printcolumn:name="Federated",type="boolean",JSONPath=".spec.joinFederation"
Z
zryfish 已提交
143
// +kubebuilder:printcolumn:name="Provider",type="string",JSONPath=".spec.provider"
Z
zryfish 已提交
144
// +kubebuilder:printcolumn:name="Active",type="boolean",JSONPath=".spec.enable"
Z
zryfish 已提交
145
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".status.kubernetesVersion"
Z
zryfish 已提交
146
// +kubebuilder:resource:scope=Cluster
Z
zryfish 已提交
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167

// Cluster is the schema for the clusters API
type Cluster struct {
	metav1.TypeMeta   `json:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty"`

	Spec   ClusterSpec   `json:"spec,omitempty"`
	Status ClusterStatus `json:"status,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type ClusterList struct {
	metav1.TypeMeta `json:",inline"`
	metav1.ListMeta `json:"metadata,omitempty"`
	Items           []Cluster `json:"items"`
}

func init() {
	SchemeBuilder.Register(&Cluster{}, &ClusterList{})
}