-
Notifications
You must be signed in to change notification settings - Fork 25
/
membercluster_types.go
128 lines (103 loc) · 4.86 KB
/
membercluster_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
/*
Copyright (c) Microsoft Corporation.
Licensed under the MIT license.
*/
package v1alpha1
import (
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster,categories={fleet},shortName=mc
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:JSONPath=`.status.conditions[?(@.type=="Joined")].status`,name="Joined",type=string
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
// MemberCluster is a resource created in the hub cluster to represent a member cluster within a fleet.
type MemberCluster struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// The desired state of MemberCluster.
// +required
Spec MemberClusterSpec `json:"spec"`
// The observed status of MemberCluster.
// +optional
Status MemberClusterStatus `json:"status,omitempty"`
}
// MemberClusterSpec defines the desired state of MemberCluster.
type MemberClusterSpec struct {
// +kubebuilder:validation:Required,Enum=Join;Leave
// The desired state of the member cluster. Possible values: Join, Leave.
// +required
State ClusterState `json:"state"`
// The identity used by the member cluster to access the hub cluster.
// The hub agents deployed on the hub cluster will automatically grant the minimal required permissions to this identity for the member agents deployed on the member cluster to access the hub cluster.
// +required
Identity rbacv1.Subject `json:"identity"`
// +kubebuilder:default=60
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=600
// How often (in seconds) for the member cluster to send a heartbeat to the hub cluster. Default: 60 seconds. Min: 1 second. Max: 10 minutes.
// +optional
HeartbeatPeriodSeconds int32 `json:"heartbeatPeriodSeconds,omitempty"`
}
// MemberClusterStatus defines the observed status of MemberCluster.
type MemberClusterStatus struct {
// +patchMergeKey=type
// +patchStrategy=merge
// +listType=map
// +listMapKey=type
// Conditions is an array of current observed conditions for the member cluster.
// +optional
Conditions []metav1.Condition `json:"conditions"`
// The current observed resource usage of the member cluster. It is copied from the corresponding InternalMemberCluster object.
// +optional
ResourceUsage ResourceUsage `json:"resourceUsage,omitempty"`
// AgentStatus is an array of current observed status, each corresponding to one member agent running in the member cluster.
// +optional
AgentStatus []AgentStatus `json:"agentStatus,omitempty"`
}
// MemberClusterConditionType defines a specific condition of a member cluster.
type MemberClusterConditionType string
const (
// ConditionTypeMemberClusterReadyToJoin indicates the readiness condition of the given member cluster for joining the hub cluster.
// Its condition status can be one of the following:
// - "True" means the hub cluster is ready for the member cluster to join.
// - "False" means the hub cluster is not ready for the member cluster to join.
// - "Unknown" means it is unknown whether the hub cluster is ready for the member cluster to join.
ConditionTypeMemberClusterReadyToJoin MemberClusterConditionType = "ReadyToJoin"
// ConditionTypeMemberClusterJoined indicates the join condition of the given member cluster.
// Its condition status can be one of the following:
// - "True" means all the agents on the member cluster have joined.
// - "False" means all the agents on the member cluster have left.
// - "Unknown" means not all the agents have joined or left.
ConditionTypeMemberClusterJoined MemberClusterConditionType = "Joined"
// ConditionTypeMemberClusterHealthy indicates the health condition of the given member cluster.
// Its condition status can be one of the following:
// - "True" means the member cluster is healthy.
// - "False" means the member cluster is unhealthy.
// - "Unknown" means the member cluster has an unknown health status.
// NOTE: This condition type is currently unused.
ConditionTypeMemberClusterHealthy MemberClusterConditionType = "Healthy"
)
//+kubebuilder:object:root=true
// MemberClusterList contains a list of MemberCluster.
type MemberClusterList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []MemberCluster `json:"items"`
}
func (m *MemberCluster) SetConditions(conditions ...metav1.Condition) {
for _, c := range conditions {
meta.SetStatusCondition(&m.Status.Conditions, c)
}
}
func (m *MemberCluster) GetCondition(conditionType string) *metav1.Condition {
return meta.FindStatusCondition(m.Status.Conditions, conditionType)
}
func (m *MemberCluster) RemoveCondition(conditionType string) {
meta.RemoveStatusCondition(&m.Status.Conditions, conditionType)
}
func init() {
SchemeBuilder.Register(&MemberCluster{}, &MemberClusterList{})
}