Skip to content

Commit 8afbebc

Browse files
committed
remove helm template, reduce cognitive complexity, and add more informative comments and secrets
1 parent 219ef7f commit 8afbebc

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

api/v1alpha1/worker_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -275,10 +275,12 @@ const (
275275
type GateWorkflowConfig struct {
276276
WorkflowType string `json:"workflowType"`
277277
// Input is an arbitrary JSON object passed as the first parameter to the gate workflow.
278+
// For inputs with secrets use SecretKeyRef in InputFrom to omit from logs.
278279
// +optional
279280
Input *apiextensionsv1.JSON `json:"input,omitempty"`
280281
// InputFrom references a key in a ConfigMap or Secret whose contents are passed
281282
// as the first parameter to the gate workflow. The referenced value should be a JSON document.
283+
// For inputs with secrets use SecretKeyRef to omit from logs.
282284
// +optional
283285
InputFrom *GateInputSource `json:"inputFrom,omitempty"`
284286
}

helm/temporal-worker-controller/templates/temporal_connection.yaml

Lines changed: 0 additions & 9 deletions
This file was deleted.

internal/planner/planner.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package planner
66

77
import (
8+
"errors"
89
"fmt"
910
"time"
1011

@@ -525,27 +526,42 @@ func getCurrentStepIndex(steps []temporaliov1alpha1.RolloutStep, targetRampPerce
525526
return result
526527
}
527528

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+
528550
// ResolveGateInput resolves the gate input from inline JSON or from a referenced ConfigMap/Secret
529551
// Returns the input bytes and a boolean indicating whether the input came from a Secret
530552
func ResolveGateInput(gate *temporaliov1alpha1.GateWorkflowConfig, namespace string, configMapData map[string]string, configMapBinaryData map[string][]byte, secretData map[string][]byte) ([]byte, bool, error) {
531553
if gate == nil {
532554
return nil, false, nil
533555
}
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
537558
}
538559
if gate.Input != nil {
539560
return gate.Input.Raw, false, nil
540561
}
541562
if gate.InputFrom == nil {
542563
return nil, false, nil
543564
}
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-
}
549565
if cmRef := gate.InputFrom.ConfigMapKeyRef; cmRef != nil {
550566
if configMapData != nil {
551567
if val, ok := configMapData[cmRef.Key]; ok {

0 commit comments

Comments
 (0)