|
6 | 6 | "time" |
7 | 7 |
|
8 | 8 | "github.com/stretchr/testify/require" |
| 9 | + "k8s.io/apimachinery/pkg/api/meta" |
9 | 10 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
10 | 11 | "k8s.io/apimachinery/pkg/runtime" |
11 | 12 | "k8s.io/apimachinery/pkg/runtime/schema" |
@@ -235,3 +236,88 @@ func (m *mockTrackingCacheInternal) Watch(ctx context.Context, user client.Objec |
235 | 236 | func (m *mockTrackingCacheInternal) Source(h handler.EventHandler, predicates ...predicate.Predicate) source.Source { |
236 | 237 | return nil |
237 | 238 | } |
| 239 | + |
| 240 | +func Test_markAsProgressing_doesNotOverwriteProgressDeadlineExceeded(t *testing.T) { |
| 241 | + for _, tc := range []struct { |
| 242 | + name string |
| 243 | + existingConditions []metav1.Condition |
| 244 | + reason string |
| 245 | + expectProgressing metav1.ConditionStatus |
| 246 | + expectReason string |
| 247 | + }{ |
| 248 | + { |
| 249 | + name: "sets Progressing when no condition exists", |
| 250 | + existingConditions: nil, |
| 251 | + reason: ocv1.ReasonRollingOut, |
| 252 | + expectProgressing: metav1.ConditionTrue, |
| 253 | + expectReason: ocv1.ReasonRollingOut, |
| 254 | + }, |
| 255 | + { |
| 256 | + name: "sets Progressing when currently RollingOut", |
| 257 | + existingConditions: []metav1.Condition{ |
| 258 | + { |
| 259 | + Type: ocv1.ClusterObjectSetTypeProgressing, |
| 260 | + Status: metav1.ConditionTrue, |
| 261 | + Reason: ocv1.ReasonRollingOut, |
| 262 | + }, |
| 263 | + }, |
| 264 | + reason: ocv1.ReasonSucceeded, |
| 265 | + expectProgressing: metav1.ConditionTrue, |
| 266 | + expectReason: ocv1.ReasonSucceeded, |
| 267 | + }, |
| 268 | + { |
| 269 | + name: "does not overwrite ProgressDeadlineExceeded with RollingOut", |
| 270 | + existingConditions: []metav1.Condition{ |
| 271 | + { |
| 272 | + Type: ocv1.ClusterObjectSetTypeProgressing, |
| 273 | + Status: metav1.ConditionFalse, |
| 274 | + Reason: ocv1.ReasonProgressDeadlineExceeded, |
| 275 | + }, |
| 276 | + }, |
| 277 | + reason: ocv1.ReasonRollingOut, |
| 278 | + expectProgressing: metav1.ConditionFalse, |
| 279 | + expectReason: ocv1.ReasonProgressDeadlineExceeded, |
| 280 | + }, |
| 281 | + { |
| 282 | + name: "allows Succeeded to overwrite ProgressDeadlineExceeded", |
| 283 | + existingConditions: []metav1.Condition{ |
| 284 | + { |
| 285 | + Type: ocv1.ClusterObjectSetTypeProgressing, |
| 286 | + Status: metav1.ConditionFalse, |
| 287 | + Reason: ocv1.ReasonProgressDeadlineExceeded, |
| 288 | + }, |
| 289 | + }, |
| 290 | + reason: ocv1.ReasonSucceeded, |
| 291 | + expectProgressing: metav1.ConditionTrue, |
| 292 | + expectReason: ocv1.ReasonSucceeded, |
| 293 | + }, |
| 294 | + { |
| 295 | + name: "does not overwrite ProgressDeadlineExceeded with Retrying", |
| 296 | + existingConditions: []metav1.Condition{ |
| 297 | + { |
| 298 | + Type: ocv1.ClusterObjectSetTypeProgressing, |
| 299 | + Status: metav1.ConditionFalse, |
| 300 | + Reason: ocv1.ReasonProgressDeadlineExceeded, |
| 301 | + }, |
| 302 | + }, |
| 303 | + reason: ocv1.ClusterObjectSetReasonRetrying, |
| 304 | + expectProgressing: metav1.ConditionFalse, |
| 305 | + expectReason: ocv1.ReasonProgressDeadlineExceeded, |
| 306 | + }, |
| 307 | + } { |
| 308 | + t.Run(tc.name, func(t *testing.T) { |
| 309 | + cos := &ocv1.ClusterObjectSet{ |
| 310 | + ObjectMeta: metav1.ObjectMeta{Generation: 1}, |
| 311 | + Status: ocv1.ClusterObjectSetStatus{ |
| 312 | + Conditions: tc.existingConditions, |
| 313 | + }, |
| 314 | + } |
| 315 | + markAsProgressing(cos, tc.reason, "test message") |
| 316 | + |
| 317 | + cnd := meta.FindStatusCondition(cos.Status.Conditions, ocv1.ClusterObjectSetTypeProgressing) |
| 318 | + require.NotNil(t, cnd) |
| 319 | + require.Equal(t, tc.expectProgressing, cnd.Status) |
| 320 | + require.Equal(t, tc.expectReason, cnd.Reason) |
| 321 | + }) |
| 322 | + } |
| 323 | +} |
0 commit comments