-
Notifications
You must be signed in to change notification settings - Fork 81
/
Copy pathtypes.go
369 lines (301 loc) · 15.8 KB
/
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
package v1
import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// ClusterManager configures the controllers on the hub that govern registration and work distribution for attached Klusterlets.
// In Default mode, ClusterManager will only be deployed in open-cluster-management-hub namespace.
// In Detached mode, ClusterManager will be deployed in the namespace with the same name as cluster manager.
type ClusterManager struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec represents a desired deployment configuration of controllers that govern registration and work distribution for attached Klusterlets.
Spec ClusterManagerSpec `json:"spec"`
// Status represents the current status of controllers that govern the lifecycle of managed clusters.
// +optional
Status ClusterManagerStatus `json:"status,omitempty"`
}
// ClusterManagerSpec represents a desired deployment configuration of controllers that govern registration and work distribution for attached Klusterlets.
type ClusterManagerSpec struct {
// RegistrationImagePullSpec represents the desired image of registration controller/webhook installed on hub.
// +optional
// +kubebuilder:default=quay.io/open-cluster-management/registration
RegistrationImagePullSpec string `json:"registrationImagePullSpec,omitempty"`
// WorkImagePullSpec represents the desired image configuration of work controller/webhook installed on hub.
// +optional
// +kubebuilder:default=quay.io/open-cluster-management/work
WorkImagePullSpec string `json:"workImagePullSpec,omitempty"`
// PlacementImagePullSpec represents the desired image configuration of placement controller/webhook installed on hub.
// +optional
// +kubebuilder:default=quay.io/open-cluster-management/placement
PlacementImagePullSpec string `json:"placementImagePullSpec,omitempty"`
// NodePlacement enables explicit control over the scheduling of the deployed pods.
// +optional
NodePlacement NodePlacement `json:"nodePlacement,omitempty"`
// DeployOption contains the options of deploying a cluster-manager
// Default mode is used if DeployOption is not set.
// +optional
DeployOption DeployOption `json:"deployOption,omitempty"`
}
// DetachedClusterManagerConfiguration represents customized configurations we need to set for clustermanager in the detached mode.
type DetachedClusterManagerConfiguration struct {
// RegistrationWebhookConfiguration represents the customized webhook-server configuration of registration.
// +optional
RegistrationWebhookConfiguration WebhookConfiguration `json:"registrationWebhookConfiguration,omitempty"`
// WorkWebhookConfiguration represents the customized webhook-server configuration of work.
// +optional
WorkWebhookConfiguration WebhookConfiguration `json:"workWebhookConfiguration,omitempty"`
}
// WebhookConfiguration has two properties: Address and Port.
type WebhookConfiguration struct {
// Address represents the address of a webhook-server.
// It could be in IP format or fqdn format.
// The Address must be reachable by apiserver of the hub cluster.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])$
Address string `json:"address"`
// Port represents the port of a webhook-server. The default value of Port is 443.
// +optional
// +default=443
// +kubebuilder:default=443
// +kubebuilder:validation:Maximum=65535
Port int32 `json:"port,omitempty"`
}
// DeployOption describes the deploy options for cluster-manager or klusterlet
type DeployOption struct {
// Mode can be Default or Detached.
// For cluster-manager:
// - In Default mode, the Hub is installed as a whole and all parts of Hub are deployed in the same cluster.
// - In Detached mode, only crd and configurations are installed on one cluster(defined as hub-cluster). Controllers run in another cluster (defined as management-cluster) and connect to the hub with the kubeconfig in secret of "external-hub-kubeconfig"(a kubeconfig of hub-cluster with cluster-admin permission).
// For klusterlet:
// - In Default mode, all klusterlet related resources are deployed on the managed cluster.
// - In Detached mode, only crd and configurations are installed on the spoke/managed cluster. Controllers run in another cluster (defined as management-cluster) and connect to the mangaged cluster with the kubeconfig in secret of "external-managed-kubeconfig"(a kubeconfig of managed-cluster with cluster-admin permission).
// The purpose of Detached mode is to give it more flexibility, for example we can install a hub on a cluster with no worker nodes, meanwhile running all deployments on another more powerful cluster.
// And we can also register a managed cluster to the hub that has some firewall rules preventing access from the managed cluster.
//
// Note: Do not modify the Mode field once it's applied.
//
// +required
// +default=Default
// +kubebuilder:validation:Required
// +kubebuilder:default=Default
// +kubebuilder:validation:Enum=Default;Detached
Mode InstallMode `json:"mode"`
// Detached includes configurations we needs for clustermanager in the detached mode.
// +optional
Detached *DetachedClusterManagerConfiguration `json:"detached,omitempty"`
}
// InstallMode represents the mode of deploy cluster-manager or klusterlet
type InstallMode string
const (
// InstallModeDefault is the default deploy mode.
// The cluster-manager will be deployed in the hub-cluster, the klusterlet will be deployed in the managed-cluster.
InstallModeDefault InstallMode = "Default"
// InstallModeDetached means deploying components outside.
// The cluster-manager will be deployed outside of the hub-cluster, the klusterlet will be deployed outside of the managed-cluster.
InstallModeDetached InstallMode = "Detached"
)
// ClusterManagerStatus represents the current status of the registration and work distribution controllers running on the hub.
type ClusterManagerStatus struct {
// ObservedGeneration is the last generation change you've dealt with
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Version represents the version of the compoenents in cluster manager
Version ClusterManagerVersion `json:"version,omitempty"`
// Conditions contain the different condition statuses for this ClusterManager.
// Valid condition types are:
// Applied: Components in hub are applied.
// Available: Components in hub are available and ready to serve.
// Progressing: Components in hub are in a transitioning state.
// Degraded: Components in hub do not match the desired configuration and only provide
// degraded service.
Conditions []metav1.Condition `json:"conditions"`
// Generations are used to determine when an item needs to be reconciled or has changed in a way that needs a reaction.
// +optional
Generations []GenerationStatus `json:"generations,omitempty"`
// RelatedResources are used to track the resources that are related to this ClusterManager.
// +optional
RelatedResources []RelatedResourceMeta `json:"relatedResources,omitempty"`
}
// ClusterManagerVersion represents the version of the compoenents in cluster manager
type ClusterManagerVersion struct {
// ClusterManager is the version of cluster manager operator
ClusterManager string `json:"clusterManager,omitempty"`
// Registration is the version of the registration controller and webhoook
Registration string `json:"registration,omitempty"`
// Work is the version of the work webhook
Work string `json:"work,omitempty"`
// Placement is the version of the placement controller
Placement string `json:"placement,omitempty"`
}
// RelatedResourceMeta represents the resource that is managed by an operator
type RelatedResourceMeta struct {
// group is the group of the resource that you're tracking
// +required
Group string `json:"group"`
// version is the version of the thing you're tracking
// +required
Version string `json:"version"`
// resource is the resource type of the resource that you're tracking
// +required
Resource string `json:"resource"`
// namespace is where the thing you're tracking is
// +optional
Namespace string `json:"namespace"`
// name is the name of the resource that you're tracking
// +required
Name string `json:"name"`
}
// GenerationStatus keeps track of the generation for a given resource so that decisions about forced updates can be made.
// The definition matches the GenerationStatus defined in github.com/openshift/api/v1
type GenerationStatus struct {
// group is the group of the resource that you're tracking
// +required
Group string `json:"group"`
// version is the version of the resource that you're tracking
// +required
Version string `json:"version"`
// resource is the resource type of the resource that you're tracking
// +required
Resource string `json:"resource"`
// namespace is where the resource that you're tracking is
// +optional
Namespace string `json:"namespace"`
// name is the name of the resource that you're tracking
// +required
Name string `json:"name"`
// lastGeneration is the last generation of the resource that controller applies
// +required
LastGeneration int64 `json:"lastGeneration" protobuf:"varint,5,opt,name=lastGeneration"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ClusterManagerList is a collection of deployment configurations for registration and work distribution controllers.
type ClusterManagerList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
// Items is a list of deployment configurations for registration and work distribution controllers.
Items []ClusterManager `json:"items"`
}
// +genclient
// +genclient:nonNamespaced
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Cluster
// Klusterlet represents controllers to install the resources for a managed cluster.
// When configured, the Klusterlet requires a secret named bootstrap-hub-kubeconfig in the
// agent namespace to allow API requests to the hub for the registration protocol.
// In Detached mode, the Klusterlet requires an additional secret named external-managed-kubeconfig
// in the agent namespace to allow API requests to the managed cluster for resources installation.
type Klusterlet struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec represents the desired deployment configuration of Klusterlet agent.
Spec KlusterletSpec `json:"spec,omitempty"`
// Status represents the current status of Klusterlet agent.
Status KlusterletStatus `json:"status,omitempty"`
}
// KlusterletSpec represents the desired deployment configuration of Klusterlet agent.
type KlusterletSpec struct {
// Namespace is the namespace to deploy the agent.
// The namespace must have a prefix of "open-cluster-management-", and if it is not set,
// the namespace of "open-cluster-management-agent" is used to deploy agent.
// Note: in Detach mode, this field will be **ignored**, the agent will be deployed to the
// namespace with the same name as klusterlet.
// +optional
Namespace string `json:"namespace,omitempty"`
// RegistrationImagePullSpec represents the desired image configuration of registration agent.
// +required
// +kubebuilder:default=quay.io/open-cluster-management/registration
RegistrationImagePullSpec string `json:"registrationImagePullSpec"`
// WorkImagePullSpec represents the desired image configuration of work agent.
// +required
// +kubebuilder:default=quay.io/open-cluster-management/work
WorkImagePullSpec string `json:"workImagePullSpec,omitempty"`
// ClusterName is the name of the managed cluster to be created on hub.
// The Klusterlet agent generates a random name if it is not set, or discovers the appropriate cluster name on OpenShift.
// +optional
ClusterName string `json:"clusterName,omitempty"`
// ExternalServerURLs represents the a list of apiserver urls and ca bundles that is accessible externally
// If it is set empty, managed cluster has no externally accessible url that hub cluster can visit.
// +optional
ExternalServerURLs []ServerURL `json:"externalServerURLs,omitempty"`
// NodePlacement enables explicit control over the scheduling of the deployed pods.
// +optional
NodePlacement NodePlacement `json:"nodePlacement,omitempty"`
// DeployOption contains the options of deploying a klusterlet
// +optional
// +kubebuilder:default={mode: Default}
DeployOption DeployOption `json:"deployOption,omitempty"`
}
// ServerURL represents the apiserver url and ca bundle that is accessible externally
type ServerURL struct {
// URL is the url of apiserver endpoint of the managed cluster.
// +required
URL string `json:"url"`
// CABundle is the ca bundle to connect to apiserver of the managed cluster.
// System certs are used if it is not set.
// +optional
CABundle []byte `json:"caBundle,omitempty"`
}
// NodePlacement describes node scheduling configuration for the pods.
type NodePlacement struct {
// NodeSelector defines which Nodes the Pods are scheduled on. The default is an empty list.
// +optional
NodeSelector map[string]string `json:"nodeSelector,omitempty"`
// Tolerations is attached by pods to tolerate any taint that matches
// the triple <key,value,effect> using the matching operator <operator>.
// The default is an empty list.
// +optional
Tolerations []v1.Toleration `json:"tolerations,omitempty"`
}
// KlusterletVersion represents the version of the compoenents in klusterlet
type KlusterletVersion struct {
// Klusterlet is the version of klusterlet operator
Klusterlet string `json:"klusterlet,omitempty"`
// Registration is the version of the registration agent
Registration string `json:"registration,omitempty"`
// Work is the version of the work agent
Work string `json:"work,omitempty"`
}
// KlusterletStatus represents the current status of Klusterlet agent.
type KlusterletStatus struct {
// ObservedGeneration is the last generation change you've dealt with
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// Version represents the version of the compoenents in klusterlet
Version KlusterletVersion `json:"version,omitempty"`
// Conditions contain the different condition statuses for this Klusterlet.
// Valid condition types are:
// Applied: Components have been applied in the managed cluster.
// Available: Components in the managed cluster are available and ready to serve.
// Progressing: Components in the managed cluster are in a transitioning state.
// Degraded: Components in the managed cluster do not match the desired configuration and only provide
// degraded service.
Conditions []metav1.Condition `json:"conditions"`
// Generations are used to determine when an item needs to be reconciled or has changed in a way that needs a reaction.
// +optional
Generations []GenerationStatus `json:"generations,omitempty"`
// RelatedResources are used to track the resources that are related to this Klusterlet.
// +optional
RelatedResources []RelatedResourceMeta `json:"relatedResources,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// KlusterletList is a collection of Klusterlet agents.
type KlusterletList struct {
metav1.TypeMeta `json:",inline"`
// Standard list metadata.
// More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds
// +optional
metav1.ListMeta `json:"metadata,omitempty"`
// Items is a list of Klusterlet agents.
Items []Klusterlet `json:"items"`
}