kubesphere.io/api@v0.0.0-20231107125330-c9a03957060c/cluster/v1alpha1/cluster_types.go (about) 1 /* 2 Copyright 2020 KubeSphere Authors 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package v1alpha1 18 19 import ( 20 v1 "k8s.io/api/core/v1" 21 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 "k8s.io/apimachinery/pkg/types" 23 ) 24 25 const ( 26 ResourceKindCluster = "Cluster" 27 ResourcesSingularCluster = "cluster" 28 ResourcesPluralCluster = "clusters" 29 30 HostCluster = "cluster-role.kubesphere.io/host" 31 // Description of which region the cluster been placed 32 ClusterRegion = "cluster.kubesphere.io/region" 33 // Name of the cluster group 34 ClusterGroup = "cluster.kubesphere.io/group" 35 36 Finalizer = "finalizer.cluster.kubesphere.io" 37 ) 38 39 type ClusterSpec struct { 40 41 // Join cluster as a kubefed cluster 42 JoinFederation bool `json:"joinFederation,omitempty"` 43 44 // Desired state of the cluster 45 Enable bool `json:"enable,omitempty"` 46 47 // Provider of the cluster, this field is just for description 48 Provider string `json:"provider,omitempty"` 49 50 // Connection holds info to connect to the member cluster 51 Connection Connection `json:"connection,omitempty"` 52 53 // ExternalKubeAPIEnabled export kubeapiserver to public use a lb type service if connection type is proxy 54 ExternalKubeAPIEnabled bool `json:"externalKubeAPIEnabled,omitempty"` 55 } 56 57 type ConnectionType string 58 59 const ( 60 ConnectionTypeDirect ConnectionType = "direct" 61 ConnectionTypeProxy ConnectionType = "proxy" 62 ) 63 64 type Connection struct { 65 66 // type defines how host cluster will connect to host cluster 67 // ConnectionTypeDirect means direct connection, this requires 68 // kubeconfig and kubesphere apiserver endpoint provided 69 // ConnectionTypeProxy means using kubesphere proxy, no kubeconfig 70 // or kubesphere apiserver endpoint required 71 Type ConnectionType `json:"type,omitempty"` 72 73 // KubeSphere API Server endpoint. Example: http://10.10.0.11:8080 74 // Should provide this field explicitly if connection type is direct. 75 // Will be populated by ks-apiserver if connection type is proxy. 76 KubeSphereAPIEndpoint string `json:"kubesphereAPIEndpoint,omitempty"` 77 78 // Kubernetes API Server endpoint. Example: https://10.10.0.1:6443 79 // Should provide this field explicitly if connection type is direct. 80 // Will be populated by ks-apiserver if connection type is proxy. 81 KubernetesAPIEndpoint string `json:"kubernetesAPIEndpoint,omitempty"` 82 83 // External Kubernetes API Server endpoint 84 // Will be populated by ks-apiserver if connection type is proxy and ExternalKubeAPIEnabled is true. 85 ExternalKubernetesAPIEndpoint string `json:"externalKubernetesAPIEndpoint,omitempty"` 86 87 // KubeConfig content used to connect to cluster api server 88 // Should provide this field explicitly if connection type is direct. 89 // Will be populated by ks-proxy if connection type is proxy. 90 KubeConfig []byte `json:"kubeconfig,omitempty"` 91 92 // Token used by agents of member cluster to connect to host cluster proxy. 93 // This field is populated by apiserver only if connection type is proxy. 94 Token string `json:"token,omitempty"` 95 96 // KubeAPIServerPort is the port which listens for forwarding kube-apiserver traffic 97 // Only applicable when connection type is proxy. 98 KubernetesAPIServerPort uint16 `json:"kubernetesAPIServerPort,omitempty"` 99 100 // KubeSphereAPIServerPort is the port which listens for forwarding kubesphere apigateway traffic 101 // Only applicable when connection type is proxy. 102 KubeSphereAPIServerPort uint16 `json:"kubesphereAPIServerPort,omitempty"` 103 } 104 105 type ClusterConditionType string 106 107 const ( 108 // Cluster agent is initialized and waiting for connecting 109 ClusterInitialized ClusterConditionType = "Initialized" 110 111 // Cluster agent is available 112 ClusterAgentAvailable ClusterConditionType = "AgentAvailable" 113 114 // Cluster has been one of federated clusters 115 ClusterFederated ClusterConditionType = "Federated" 116 117 // Cluster external access ready 118 ClusterExternalAccessReady ClusterConditionType = "ExternalAccessReady" 119 120 // Cluster is all available for requests 121 ClusterReady ClusterConditionType = "Ready" 122 123 // Openpitrix runtime is created 124 ClusterOpenPitrixRuntimeReady ClusterConditionType = "OpenPitrixRuntimeReady" 125 126 // ClusterKubeConfigCertExpiresInSevenDays indicates that the cluster certificate is about to expire. 127 ClusterKubeConfigCertExpiresInSevenDays ClusterConditionType = "KubeConfigCertExpiresInSevenDays" 128 ) 129 130 type ClusterCondition struct { 131 // Type of the condition 132 Type ClusterConditionType `json:"type"` 133 // Status of the condition, one of True, False, Unknown. 134 Status v1.ConditionStatus `json:"status"` 135 // The last time this condition was updated. 136 LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty"` 137 // Last time the condition transitioned from one status to another. 138 LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"` 139 // The reason for the condition's last transition. 140 Reason string `json:"reason,omitempty"` 141 // A human readable message indicating details about the transition. 142 Message string `json:"message,omitempty"` 143 } 144 145 type ClusterStatus struct { 146 147 // Represents the latest available observations of a cluster's current state. 148 Conditions []ClusterCondition `json:"conditions,omitempty"` 149 150 // GitVersion of the kubernetes cluster, this field is populated by cluster controller 151 KubernetesVersion string `json:"kubernetesVersion,omitempty"` 152 153 // GitVersion of the /kapis/version api response, this field is populated by cluster controller 154 KubeSphereVersion string `json:"kubeSphereVersion,omitempty"` 155 156 // Count of the kubernetes cluster nodes 157 // This field may not reflect the instant status of the cluster. 158 NodeCount int `json:"nodeCount,omitempty"` 159 160 // Zones are the names of availability zones in which the nodes of the cluster exist, e.g. 'us-east1-a'. 161 // +optional 162 Zones []string `json:"zones,omitempty"` 163 164 // Region is the name of the region in which all of the nodes in the cluster exist. e.g. 'us-east1'. 165 // +optional 166 Region *string `json:"region,omitempty"` 167 168 // Configz is status of components enabled in the member cluster. This is synchronized with member cluster 169 // every amount of time, like 5 minutes. 170 // +optional 171 Configz map[string]bool `json:"configz,omitempty"` 172 173 // UID is the kube-system namespace UID of the cluster, which represents the unique ID of the cluster. 174 UID types.UID `json:"uid,omitempty"` 175 } 176 177 // +genclient 178 // +kubebuilder:object:root=true 179 // +k8s:openapi-gen=true 180 // +genclient:nonNamespaced 181 // +kubebuilder:printcolumn:name="Federated",type="boolean",JSONPath=".spec.joinFederation" 182 // +kubebuilder:printcolumn:name="Provider",type="string",JSONPath=".spec.provider" 183 // +kubebuilder:printcolumn:name="Active",type="boolean",JSONPath=".spec.enable" 184 // +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".status.kubernetesVersion" 185 // +kubebuilder:resource:scope=Cluster 186 187 // Cluster is the schema for the clusters API 188 type Cluster struct { 189 metav1.TypeMeta `json:",inline"` 190 metav1.ObjectMeta `json:"metadata,omitempty"` 191 192 Spec ClusterSpec `json:"spec,omitempty"` 193 Status ClusterStatus `json:"status,omitempty"` 194 } 195 196 // +kubebuilder:object:root=true 197 198 type ClusterList struct { 199 metav1.TypeMeta `json:",inline"` 200 metav1.ListMeta `json:"metadata,omitempty"` 201 Items []Cluster `json:"items"` 202 } 203 204 func init() { 205 SchemeBuilder.Register(&Cluster{}, &ClusterList{}) 206 }