/
clusterset_types.go
146 lines (124 loc) · 5.16 KB
/
clusterset_types.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
Copyright 2021 Antrea Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package v1alpha1
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// MemberCluster defines member cluster information.
type MemberCluster struct {
// Identify member cluster in ClusterSet.
ClusterID string `json:"clusterID,omitempty"`
// API server of the destination cluster.
Server string `json:"server,omitempty"`
// Secret name to access API server of the member from the leader cluster.
Secret string `json:"secret,omitempty"`
// ServiceAccount used by the member cluster to access into leader cluster.
ServiceAccount string `json:"serviceAccount,omitempty"`
}
// ClusterSetSpec defines the desired state of ClusterSet.
type ClusterSetSpec struct {
// Members include member clusters known to the leader clusters.
// Used in leader cluster.
Members []MemberCluster `json:"members,omitempty"`
// Leaders include leader clusters known to the member clusters.
Leaders []MemberCluster `json:"leaders,omitempty"`
// Namespace to connect to in leader clusters.
// Used in member cluster.
Namespace string `json:"namespace,omitempty"`
}
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"
// ClusterIsElectedLeader indicates whether the leader cluster is the elected leader.
// Used in Member clusters only.
ClusterIsElectedLeader ClusterConditionType = "IsElectedLeader"
// ClusterImportsResources indicates whether the member cluster has elected the
// local cluster as the elected leader and imports resources from it.
// Used in Leader clusters only.
ClusterImportsResources ClusterConditionType = "ImportsResources"
)
// 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 {
// 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"`
}
// +genclient
//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
// ClusterSet is the Schema for the clustersets API.
type ClusterSet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec ClusterSetSpec `json:"spec,omitempty"`
Status ClusterSetStatus `json:"status,omitempty"`
}
//+kubebuilder:object:root=true
// ClusterSetList contains a list of ClusterSet.
type ClusterSetList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []ClusterSet `json:"items"`
}
func init() {
SchemeBuilder.Register(&ClusterSet{}, &ClusterSetList{})
}