|
5 | 5 | package planner |
6 | 6 |
|
7 | 7 | import ( |
| 8 | + "errors" |
8 | 9 | "fmt" |
9 | 10 | "time" |
10 | 11 |
|
@@ -525,27 +526,42 @@ func getCurrentStepIndex(steps []temporaliov1alpha1.RolloutStep, targetRampPerce |
525 | 526 | return result |
526 | 527 | } |
527 | 528 |
|
| 529 | +// validateGateInputConfig validates that gate input is configured correctly |
| 530 | +func validateGateInputConfig(gate *temporaliov1alpha1.GateWorkflowConfig) error { |
| 531 | + if gate == nil { |
| 532 | + return nil |
| 533 | + } |
| 534 | + // If both are set, return error (webhook should prevent this, but double-check) |
| 535 | + if gate.Input != nil && gate.InputFrom != nil { |
| 536 | + return errors.New("both spec.rollout.gate.input and spec.rollout.gate.inputFrom are set") |
| 537 | + } |
| 538 | + if gate.InputFrom == nil { |
| 539 | + return nil |
| 540 | + } |
| 541 | + // Exactly one of ConfigMapKeyRef or SecretKeyRef should be set |
| 542 | + cmSet := gate.InputFrom.ConfigMapKeyRef != nil |
| 543 | + secSet := gate.InputFrom.SecretKeyRef != nil |
| 544 | + if (cmSet && secSet) || (!cmSet && !secSet) { |
| 545 | + return errors.New("spec.rollout.gate.inputFrom must set exactly one of configMapKeyRef or secretKeyRef") |
| 546 | + } |
| 547 | + return nil |
| 548 | +} |
| 549 | + |
528 | 550 | // ResolveGateInput resolves the gate input from inline JSON or from a referenced ConfigMap/Secret |
529 | 551 | // Returns the input bytes and a boolean indicating whether the input came from a Secret |
530 | 552 | func ResolveGateInput(gate *temporaliov1alpha1.GateWorkflowConfig, namespace string, configMapData map[string]string, configMapBinaryData map[string][]byte, secretData map[string][]byte) ([]byte, bool, error) { |
531 | 553 | if gate == nil { |
532 | 554 | return nil, false, nil |
533 | 555 | } |
534 | | - // If both are set, return error (webhook should prevent this, but double-check) |
535 | | - if gate.Input != nil && gate.InputFrom != nil { |
536 | | - return nil, false, fmt.Errorf("both spec.rollout.gate.input and spec.rollout.gate.inputFrom are set") |
| 556 | + if err := validateGateInputConfig(gate); err != nil { |
| 557 | + return nil, false, err |
537 | 558 | } |
538 | 559 | if gate.Input != nil { |
539 | 560 | return gate.Input.Raw, false, nil |
540 | 561 | } |
541 | 562 | if gate.InputFrom == nil { |
542 | 563 | return nil, false, nil |
543 | 564 | } |
544 | | - // Exactly one of ConfigMapKeyRef or SecretKeyRef should be set |
545 | | - if (gate.InputFrom.ConfigMapKeyRef == nil && gate.InputFrom.SecretKeyRef == nil) || |
546 | | - (gate.InputFrom.ConfigMapKeyRef != nil && gate.InputFrom.SecretKeyRef != nil) { |
547 | | - return nil, false, fmt.Errorf("spec.rollout.gate.inputFrom must set exactly one of configMapKeyRef or secretKeyRef") |
548 | | - } |
549 | 565 | if cmRef := gate.InputFrom.ConfigMapKeyRef; cmRef != nil { |
550 | 566 | if configMapData != nil { |
551 | 567 | if val, ok := configMapData[cmRef.Key]; ok { |
|
0 commit comments