forked from open-cluster-management-io/api
/
types.go
260 lines (218 loc) · 10.2 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
package v1
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:subresource:status
// ManifestWork represents a manifests workload that hub wants to deploy on the managed cluster.
// A manifest workload is defined as a set of Kubernetes resources.
// ManifestWork must be created in the cluster namespace on the hub, so that agent on the
// corresponding managed cluster can access this resource and deploy on the managed
// cluster.
type ManifestWork struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec represents a desired configuration of work to be deployed on the managed cluster.
Spec ManifestWorkSpec `json:"spec"`
// Status represents the current status of work.
// +optional
Status ManifestWorkStatus `json:"status,omitempty"`
}
// ManifestWorkSpec represents a desired configuration of manifests to be deployed on the managed cluster.
type ManifestWorkSpec struct {
// Workload represents the manifest workload to be deployed on a managed cluster.
Workload ManifestsTemplate `json:"workload,omitempty"`
}
// Manifest represents a resource to be deployed on managed cluster.
type Manifest struct {
// +kubebuilder:validation:EmbeddedResource
// +kubebuilder:pruning:PreserveUnknownFields
runtime.RawExtension `json:",inline"`
}
// ManifestsTemplate represents the manifest workload to be deployed on a managed cluster.
type ManifestsTemplate struct {
// Manifests represents a list of kuberenetes resources to be deployed on a managed cluster.
// +optional
Manifests []Manifest `json:"manifests,omitempty"`
}
// ManifestResourceMeta represents the group, version, kind, as well as the group, version, resource, name and namespace of a resoure.
type ManifestResourceMeta struct {
// Ordinal represents the index of the manifest on spec.
// +required
Ordinal int32 `json:"ordinal"`
// Group is the API Group of the Kubernetes resource.
// +optional
Group string `json:"group"`
// Version is the version of the Kubernetes resource.
// +optional
Version string `json:"version"`
// Kind is the kind of the Kubernetes resource.
// +optional
Kind string `json:"kind"`
// Resource is the resource name of the Kubernetes resource.
// +optional
Resource string `json:"resource"`
// Name is the name of the Kubernetes resource.
// +optional
Name string `json:"name"`
// Name is the namespace of the Kubernetes resource.
// +optional
Namespace string `json:"namespace"`
}
// AppliedManifestResourceMeta represents the group, version, resource, name and namespace of a resource.
// Since these resources have been created, they must have valid group, version, resource, namespace, and name.
type AppliedManifestResourceMeta struct {
// Group is the API Group of the Kubernetes resource.
// +required
Group string `json:"group"`
// Version is the version of the Kubernetes resource.
// +required
Version string `json:"version"`
// Resource is the resource name of the Kubernetes resource.
// +required
Resource string `json:"resource"`
// Name is the name of the Kubernetes resource.
// +required
Name string `json:"name"`
// Name is the namespace of the Kubernetes resource, empty string indicates
// it is a cluster scoped resource.
// +required
Namespace string `json:"namespace"`
// UID is set on successful deletion of the Kubernetes resource by controller. The
// resource might be still visible on the managed cluster after this field is set.
// It is not directly settable by a client.
// +optional
UID string `json:"uid,omitempty"`
}
// ManifestWorkStatus represents the current status of managed cluster ManifestWork.
type ManifestWorkStatus struct {
// Conditions contains the different condition statuses for this work.
// Valid condition types are:
// 1. Applied represents workload in ManifestWork is applied successfully on managed cluster.
// 2. Progressing represents workload in ManifestWork is being applied on managed cluster.
// 3. Available represents workload in ManifestWork exists on the managed cluster.
// 4. Degraded represents the current state of workload does not match the desired
// state for a certain period.
Conditions []metav1.Condition `json:"conditions,omitempty"`
// ResourceStatus represents the status of each resource in manifestwork deployed on a
// managed cluster. The Klusterlet agent on managed cluster syncs the condition from the managed cluster to the hub.
// +optional
ResourceStatus ManifestResourceStatus `json:"resourceStatus,omitempty"`
}
// ManifestResourceStatus represents the status of each resource in manifest work deployed on
// managed cluster
type ManifestResourceStatus struct {
// Manifests represents the condition of manifests deployed on managed cluster.
// Valid condition types are:
// 1. Progressing represents the resource is being applied on managed cluster.
// 2. Applied represents the resource is applied successfully on managed cluster.
// 3. Available represents the resource exists on the managed cluster.
// 4. Degraded represents the current state of resource does not match the desired
// state for a certain period.
Manifests []ManifestCondition `json:"manifests,omitempty"`
}
const (
// WorkProgressing represents that the work is in the progress to be
// applied on the managed cluster.
WorkProgressing string = "Progressing"
// WorkApplied represents that the workload defined in work is
// succesfully applied on the managed cluster.
WorkApplied string = "Applied"
// WorkAvailable represents that all resources of the work exists on
// the managed cluster.
WorkAvailable string = "Available"
// WorkDegraded represents that the current state of work does not match
// the desired state for a certain period.
WorkDegraded string = "Degraded"
)
// ManifestCondition represents the conditions of the resources deployed on a
// managed cluster.
type ManifestCondition struct {
// ResourceMeta represents the group, version, kind, name and namespace of a resoure.
// +required
ResourceMeta ManifestResourceMeta `json:"resourceMeta"`
// Conditions represents the conditions of this resource on a managed cluster.
// +required
Conditions []metav1.Condition `json:"conditions"`
}
// ManifestConditionType represents the condition type of a single
// resource manifest deployed on the managed cluster.
type ManifestConditionType string
const (
// ManifestProgressing represents that the resource is being applied on the managed cluster
ManifestProgressing ManifestConditionType = "Progressing"
// ManifestApplied represents that the resource object is applied
// on the managed cluster.
ManifestApplied ManifestConditionType = "Applied"
// ManifestAvailable represents that the resource object exists
// on the managed cluster.
ManifestAvailable ManifestConditionType = "Available"
// ManifestDegraded represents that the current state of resource object does not
// match the desired state for a certain period.
ManifestDegraded ManifestConditionType = "Degraded"
)
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// ManifestWorkList is a collection of manifestworks.
type ManifestWorkList 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 manifestworks.
Items []ManifestWork `json:"items"`
}
// +genclient
// +genclient:nonNamespaced
// +kubebuilder:subresource:status
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// AppliedManifestWork represents an applied manifestwork on managed cluster that is placed
// on a managed cluster. An AppliedManifestWork links to a manifestwork on a hub recording resources
// deployed in the managed cluster.
// When the agent is removed from managed cluster, cluster-admin on managed cluster
// can delete appliedmanifestwork to remove resources deployed by the agent.
// The name of the appliedmanifestwork must be in the format of
// {hash of hub's first kube-apiserver url}-{manifestwork name}
type AppliedManifestWork struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
// Spec represents the desired configuration of AppliedManifestWork.
Spec AppliedManifestWorkSpec `json:"spec,omitempty"`
// Status represents the current status of AppliedManifestWork.
// +optional
Status AppliedManifestWorkStatus `json:"status,omitempty"`
}
// AppliedManifestWorkSpec represents the desired configuration of AppliedManifestWork
type AppliedManifestWorkSpec struct {
// HubHash represents the hash of the first hub kube apiserver to identify which hub
// this AppliedManifestWork links to.
// +required
HubHash string `json:"hubHash"`
// ManifestWorkName represents the name of the related manifestwork on the hub.
// +required
ManifestWorkName string `json:"manifestWorkName"`
}
// AppliedManifestWorkStatus represents the current status of AppliedManifestWork
type AppliedManifestWorkStatus struct {
// AppliedResources represents a list of resources defined within the manifestwork that are applied.
// Only resources with valid GroupVersionResource, namespace, and name are suitable.
// An item in this slice is deleted when there is no mapped manifest in manifestwork.Spec or by finalizer.
// The resource relating to the item will also be removed from managed cluster.
// The deleted resource may still be present until the finalizers for that resource are finished.
// However, the resource will not be undeleted, so it can be removed from this list and eventual consistency is preserved.
// +optional
AppliedResources []AppliedManifestResourceMeta `json:"appliedResources,omitempty"`
}
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// AppliedManifestWorkList is a collection of appliedmanifestworks.
type AppliedManifestWorkList 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 appliedmanifestworks.
Items []AppliedManifestWork `json:"items"`
}