@@ -12,7 +12,6 @@ import (
12
12
corev1 "k8s.io/api/core/v1"
13
13
"k8s.io/apimachinery/pkg/api/errors"
14
14
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
15
- "k8s.io/apimachinery/pkg/util/wait"
16
15
appsclientv1 "k8s.io/client-go/kubernetes/typed/apps/v1"
17
16
"k8s.io/client-go/rest"
18
17
"k8s.io/klog"
@@ -113,103 +112,72 @@ func (b *deploymentBuilder) Do(ctx context.Context) error {
113
112
}
114
113
}
115
114
116
- _ , updated , err := resourceapply .ApplyDeployment (ctx , b .client , deployment )
117
- if err != nil {
115
+ if _ , _ , err := resourceapply .ApplyDeployment (ctx , b .client , deployment ); err != nil {
118
116
return err
119
117
}
120
- if updated && b .mode != InitializingMode {
121
- return waitForDeploymentCompletion (ctx , b .client , deployment )
118
+
119
+ if b .mode != InitializingMode {
120
+ return checkDeploymentHealth (ctx , b .client , deployment )
122
121
}
123
122
return nil
124
123
}
125
124
126
- func waitForDeploymentCompletion (ctx context.Context , client appsclientv1.DeploymentsGetter , deployment * appsv1.Deployment ) error {
125
+ func checkDeploymentHealth (ctx context.Context , client appsclientv1.DeploymentsGetter , deployment * appsv1.Deployment ) error {
127
126
iden := fmt .Sprintf ("%s/%s" , deployment .Namespace , deployment .Name )
128
- var lastErr error
129
- err := wait .PollImmediateUntil (defaultObjectPollInterval , func () (bool , error ) {
130
- d , err := client .Deployments (deployment .Namespace ).Get (ctx , deployment .Name , metav1.GetOptions {})
131
- if errors .IsNotFound (err ) {
132
- // exit early to recreate the deployment.
133
- return false , err
134
- }
135
- if err != nil {
136
- // Do not return error here, as we could be updating the API Server itself, in which case we
137
- // want to continue waiting.
138
- lastErr = & payload.UpdateError {
139
- Nested : err ,
140
- Reason : "WorkloadNotAvailable" ,
141
- Message : fmt .Sprintf ("could not find the deployment %s during rollout" , iden ),
142
- Name : iden ,
143
- }
144
- return false , nil
145
- }
146
-
147
- if d .DeletionTimestamp != nil {
148
- return false , fmt .Errorf ("Deployment %s is being deleted" , iden )
149
- }
150
-
151
- if d .Generation <= d .Status .ObservedGeneration && d .Status .UpdatedReplicas == d .Status .Replicas && d .Status .UnavailableReplicas == 0 {
152
- return true , nil
153
- }
127
+ d , err := client .Deployments (deployment .Namespace ).Get (ctx , deployment .Name , metav1.GetOptions {})
128
+ if err != nil {
129
+ return err
130
+ }
154
131
155
- var availableCondition * appsv1.DeploymentCondition
156
- var progressingCondition * appsv1.DeploymentCondition
157
- var replicafailureCondition * appsv1.DeploymentCondition
158
- for idx , dc := range d .Status .Conditions {
159
- switch dc .Type {
160
- case appsv1 .DeploymentProgressing :
161
- progressingCondition = & d .Status .Conditions [idx ]
162
- case appsv1 .DeploymentAvailable :
163
- availableCondition = & d .Status .Conditions [idx ]
164
- case appsv1 .DeploymentReplicaFailure :
165
- replicafailureCondition = & d .Status .Conditions [idx ]
166
- }
167
- }
132
+ if d .DeletionTimestamp != nil {
133
+ return fmt .Errorf ("deployment %s is being deleted" , iden )
134
+ }
168
135
169
- if replicafailureCondition != nil && replicafailureCondition .Status == corev1 .ConditionTrue {
170
- lastErr = & payload.UpdateError {
171
- Nested : fmt .Errorf ("deployment %s has some pods failing; unavailable replicas=%d" , iden , d .Status .UnavailableReplicas ),
172
- Reason : "WorkloadNotProgressing" ,
173
- Message : fmt .Sprintf ("deployment %s has a replica failure %s: %s" , iden , replicafailureCondition .Reason , replicafailureCondition .Message ),
174
- Name : iden ,
175
- }
176
- return false , nil
136
+ var availableCondition * appsv1.DeploymentCondition
137
+ var progressingCondition * appsv1.DeploymentCondition
138
+ var replicaFailureCondition * appsv1.DeploymentCondition
139
+ for idx , dc := range d .Status .Conditions {
140
+ switch dc .Type {
141
+ case appsv1 .DeploymentProgressing :
142
+ progressingCondition = & d .Status .Conditions [idx ]
143
+ case appsv1 .DeploymentAvailable :
144
+ availableCondition = & d .Status .Conditions [idx ]
145
+ case appsv1 .DeploymentReplicaFailure :
146
+ replicaFailureCondition = & d .Status .Conditions [idx ]
177
147
}
148
+ }
178
149
179
- if availableCondition != nil && availableCondition .Status == corev1 .ConditionFalse {
180
- lastErr = & payload.UpdateError {
181
- Nested : fmt .Errorf ("deployment %s is not available; updated replicas=%d of %d, available replicas=%d of %d" , iden , d .Status .UpdatedReplicas , d .Status .Replicas , d .Status .AvailableReplicas , d .Status .Replicas ),
182
- Reason : "WorkloadNotAvailable" ,
183
- Message : fmt .Sprintf ("deployment %s is not available %s: %s" , iden , availableCondition .Reason , availableCondition .Message ),
184
- Name : iden ,
185
- }
186
- return false , nil
150
+ if replicaFailureCondition != nil && replicaFailureCondition .Status == corev1 .ConditionTrue {
151
+ return & payload.UpdateError {
152
+ Nested : fmt .Errorf ("deployment %s has some pods failing; unavailable replicas=%d" , iden , d .Status .UnavailableReplicas ),
153
+ Reason : "WorkloadNotProgressing" ,
154
+ Message : fmt .Sprintf ("deployment %s has a replica failure %s: %s" , iden , replicaFailureCondition .Reason , replicaFailureCondition .Message ),
155
+ Name : iden ,
187
156
}
157
+ }
188
158
189
- if progressingCondition != nil && progressingCondition .Status == corev1 .ConditionFalse && progressingCondition .Reason == "ProgressDeadlineExceeded" {
190
- lastErr = & payload.UpdateError {
191
- Nested : fmt .Errorf ("deployment %s is not progressing; updated replicas=%d of %d, available replicas=%d of %d" , iden , d .Status .UpdatedReplicas , d .Status .Replicas , d .Status .AvailableReplicas , d .Status .Replicas ),
192
- Reason : "WorkloadNotAvailable" ,
193
- Message : fmt .Sprintf ("deployment %s is not progressing %s: %s" , iden , progressingCondition .Reason , progressingCondition .Message ),
194
- Name : iden ,
195
- }
196
- return false , nil
159
+ if availableCondition != nil && availableCondition .Status == corev1 .ConditionFalse {
160
+ return & payload.UpdateError {
161
+ Nested : fmt .Errorf ("deployment %s is not available; updated replicas=%d of %d, available replicas=%d of %d" , iden , d .Status .UpdatedReplicas , d .Status .Replicas , d .Status .AvailableReplicas , d .Status .Replicas ),
162
+ Reason : "WorkloadNotAvailable" ,
163
+ Message : fmt .Sprintf ("deployment %s is not available %s: %s" , iden , availableCondition .Reason , availableCondition .Message ),
164
+ Name : iden ,
197
165
}
166
+ }
198
167
199
- if progressingCondition != nil && progressingCondition .Status == corev1 .ConditionTrue {
200
- klog .V (4 ).Infof ("deployment %s is progressing" , iden )
201
- return false , nil
168
+ if progressingCondition != nil && progressingCondition .Status == corev1 .ConditionFalse {
169
+ return & payload.UpdateError {
170
+ Nested : fmt .Errorf ("deployment %s is not progressing; updated replicas=%d of %d, available replicas=%d of %d" , iden , d .Status .UpdatedReplicas , d .Status .Replicas , d .Status .AvailableReplicas , d .Status .Replicas ),
171
+ Reason : "WorkloadNotAvailable" ,
172
+ Message : fmt .Sprintf ("deployment %s is not progressing %s: %s" , iden , progressingCondition .Reason , progressingCondition .Message ),
173
+ Name : iden ,
202
174
}
175
+ }
203
176
204
- klog .Errorf ("deployment %s is in unknown state" , iden )
205
- return false , nil
206
- }, ctx .Done ())
207
- if err != nil {
208
- if err == wait .ErrWaitTimeout && lastErr != nil {
209
- return lastErr
210
- }
211
- return err
177
+ if availableCondition == nil && progressingCondition == nil && replicaFailureCondition == nil {
178
+ klog .Warningf ("deployment %s is not setting any expected conditions, and is therefore in an unknown state" , iden )
212
179
}
180
+
213
181
return nil
214
182
}
215
183
@@ -264,52 +232,28 @@ func (b *daemonsetBuilder) Do(ctx context.Context) error {
264
232
}
265
233
}
266
234
267
- _ , updated , err := resourceapply .ApplyDaemonSet (ctx , b .client , daemonset )
268
- if err != nil {
235
+ if _ , _ , err := resourceapply .ApplyDaemonSet (ctx , b .client , daemonset ); err != nil {
269
236
return err
270
237
}
271
- if updated && b .mode != InitializingMode {
272
- return waitForDaemonsetRollout (ctx , b .client , daemonset )
238
+
239
+ if b .mode != InitializingMode {
240
+ return checkDaemonSetHealth (ctx , b .client , daemonset )
273
241
}
242
+
274
243
return nil
275
244
}
276
245
277
- func waitForDaemonsetRollout (ctx context.Context , client appsclientv1.DaemonSetsGetter , daemonset * appsv1.DaemonSet ) error {
246
+ func checkDaemonSetHealth (ctx context.Context , client appsclientv1.DaemonSetsGetter , daemonset * appsv1.DaemonSet ) error {
278
247
iden := fmt .Sprintf ("%s/%s" , daemonset .Namespace , daemonset .Name )
279
- var lastErr error
280
- err := wait .PollImmediateUntil (defaultObjectPollInterval , func () (bool , error ) {
281
- d , err := client .DaemonSets (daemonset .Namespace ).Get (ctx , daemonset .Name , metav1.GetOptions {})
282
- if errors .IsNotFound (err ) {
283
- // exit early to recreate the daemonset.
284
- return false , err
285
- }
286
- if err != nil {
287
- // Do not return error here, as we could be updating the API Server itself, in which case we
288
- // want to continue waiting.
289
- lastErr = & payload.UpdateError {
290
- Nested : err ,
291
- Reason : "WorkloadNotAvailable" ,
292
- Message : fmt .Sprintf ("could not find the daemonset %s during rollout" , iden ),
293
- Name : iden ,
294
- }
295
- return false , nil
296
- }
297
-
298
- if d .DeletionTimestamp != nil {
299
- return false , fmt .Errorf ("Daemonset %s is being deleted" , daemonset .Name )
300
- }
301
-
302
- if d .Generation <= d .Status .ObservedGeneration && d .Status .UpdatedNumberScheduled == d .Status .DesiredNumberScheduled && d .Status .NumberUnavailable == 0 {
303
- return true , nil
304
- }
305
- klog .V (4 ).Infof ("daemonset %s is progressing" , iden )
306
- return false , nil
307
- }, ctx .Done ())
248
+ d , err := client .DaemonSets (daemonset .Namespace ).Get (ctx , daemonset .Name , metav1.GetOptions {})
308
249
if err != nil {
309
- if err == wait .ErrWaitTimeout && lastErr != nil {
310
- return lastErr
311
- }
312
250
return err
313
251
}
252
+
253
+ if d .DeletionTimestamp != nil {
254
+ return fmt .Errorf ("daemonset %s is being deleted" , iden )
255
+ }
256
+
257
+ // Kubernetes DaemonSet controller doesn't set status conditions yet (v1.18.0), so nothing more to check.
314
258
return nil
315
259
}
0 commit comments