-
Notifications
You must be signed in to change notification settings - Fork 0
/
nodeimage_types.go
198 lines (160 loc) · 7.57 KB
/
nodeimage_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
/*
Copyright 2020 The Kruise 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"
)
// NodeImageSpec defines the desired state of NodeImage
type NodeImageSpec struct {
// Specifies images to be pulled on this node
Images map[string]ImageSpec `json:"images,omitempty"`
}
// ImageSpec defines the pulling spec of an image
type ImageSpec struct {
// PullSecrets is an optional list of references to secrets in the same namespace to use for pulling the image.
// If specified, these secrets will be passed to individual puller implementations for them to use. For example,
// in the case of docker, only DockerConfig type secrets are honored.
// +optional
PullSecrets []ReferenceObject `json:"pullSecrets,omitempty"`
// Tags is a list of versions of this image
Tags []ImageTagSpec `json:"tags"`
}
// ReferenceObject comprises a resource name, with a mandatory namespace,
// rendered as "<namespace>/<name>".
type ReferenceObject struct {
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
}
// ImageTagSpec defines the pulling spec of an image tag
type ImageTagSpec struct {
// Specifies the image tag
Tag string `json:"tag"`
// Specifies the create time of this tag
// +optional
CreatedAt *metav1.Time `json:"createdAt,omitempty"`
// PullPolicy is an optional field to set parameters of the pulling task. If not specified,
// the system will use the default values.
// +optional
PullPolicy *ImageTagPullPolicy `json:"pullPolicy,omitempty"`
// List of objects depended by this object. If this image is managed by a controller,
// then an entry in this list will point to this controller.
// +optional
OwnerReferences []v1.ObjectReference `json:"ownerReferences,omitempty"`
}
// ImageTagPullPolicy defines the policy of the pulling task
type ImageTagPullPolicy struct {
// Specifies the timeout of the pulling task.
// Defaults to 600
// +optional
TimeoutSeconds *int32 `json:"timeoutSeconds,omitempty"`
// Specifies the number of retries before marking the pulling task failed.
// Defaults to 3
// +optional
BackoffLimit *int32 `json:"backoffLimit,omitempty"`
// TTLSecondsAfterFinished limits the lifetime of a pulling task that has finished execution (either Complete or Failed).
// If this field is set, ttlSecondsAfterFinished after the task finishes, it is eligible to be automatically deleted.
// If this field is unset, the task won't be automatically deleted.
// If this field is set to zero, the task becomes eligible to be deleted immediately after it finishes.
// +optional
TTLSecondsAfterFinished *int32 `json:"ttlSecondsAfterFinished,omitempty"`
// ActiveDeadlineSeconds specifies the duration in seconds relative to the startTime that the task may be active
// before the system tries to terminate it; value must be positive integer.
// if not specified, the system will never terminate it.
// +optional
ActiveDeadlineSeconds *int64 `json:"activeDeadlineSeconds,omitempty"`
}
// NodeImageStatus defines the observed state of NodeImage
type NodeImageStatus struct {
// ObservedGeneration is the most recent generation observed for this Node.
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// The desired number of pulling tasks, this is typically equal to the number of images in spec.
Desired int32 `json:"desired"`
// The number of pulling tasks which reached phase Succeeded.
// +optional
Succeeded int32 `json:"succeeded"`
// The number of pulling tasks which reached phase Failed.
// +optional
Failed int32 `json:"failed"`
// The number of pulling tasks which are not finished.
// +optional
Pulling int32 `json:"pulling"`
// all statuses of active image pulling tasks
ImageStatuses map[string]ImageStatus `json:"imageStatuses,omitempty"`
}
// ImageStatus defines the pulling status of an image
type ImageStatus struct {
// Represents statuses of pulling tasks on this node
Tags []ImageTagStatus `json:"tags"`
}
// ImageTagStatus defines the pulling status of an image tag
type ImageTagStatus struct {
// Represents the image tag.
Tag string `json:"tag"`
// Represents the image pulling task phase.
Phase ImagePullPhase `json:"phase"`
// Represents the pulling progress of this tag, which is beetween 0-100. There is no guarantee
// of monotonic consistency, and it may be a rollback due to retry during pulling.
Progress int32 `json:"progress,omitempty"`
// Represents time when the pulling task was acknowledged by the image puller.
// It is not guaranteed to be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
// +optional
StartTime *metav1.Time `json:"startTime,omitempty"`
// Represents time when the pulling task was completed. It is not guaranteed to
// be set in happens-before order across separate operations.
// It is represented in RFC3339 form and is in UTC.
// +optional
CompletionTime *metav1.Time `json:"completionTime,omitempty"`
// Represents the summary informations of this node
// +optional
Message string `json:"message,omitempty"`
}
// ImagePullPhase defines the tasks status
type ImagePullPhase string
const (
// ImagePhaseWaiting means the task has not started
ImagePhaseWaiting ImagePullPhase = "Waiting"
// ImagePhasePulling means the task has been started, but not completed
ImagePhasePulling ImagePullPhase = "Pulling"
// ImagePhaseSucceeded means the task has been completed
ImagePhaseSucceeded ImagePullPhase = "Succeeded"
// ImagePhaseFailed means the task has failed
ImagePhaseFailed ImagePullPhase = "Failed"
)
// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:resource:scope=Cluster
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="DESIRED",type="integer",JSONPath=".status.desired",description="Number of all images on this node"
// +kubebuilder:printcolumn:name="PULLING",type="integer",JSONPath=".status.pulling",description="Number of image pull task active"
// +kubebuilder:printcolumn:name="SUCCEED",type="integer",JSONPath=".status.succeeded",description="Number of image pull task succeeded"
// +kubebuilder:printcolumn:name="FAILED",type="integer",JSONPath=".status.failed",description="Number of image pull tasks failed"
// +kubebuilder:printcolumn:name="AGE",type="date",JSONPath=".metadata.creationTimestamp",description="CreationTimestamp is a timestamp representing the server time when this object was created. It is not guaranteed to be set in happens-before order across separate operations. Clients may not set this value. It is represented in RFC3339 form and is in UTC."
// NodeImage is the Schema for the nodeimages API
type NodeImage struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec NodeImageSpec `json:"spec,omitempty"`
Status NodeImageStatus `json:"status,omitempty"`
}
// +kubebuilder:object:root=true
// NodeImageList contains a list of NodeImage
type NodeImageList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []NodeImage `json:"items"`
}
func init() {
SchemeBuilder.Register(&NodeImage{}, &NodeImageList{})
}