Skip to content

Commit 0bdd923

Browse files
committed
Fix XR matchLabels validation in composition
Signed-off-by: Omer Aplatony <[email protected]>
1 parent 586bd39 commit 0bdd923

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

cmd/crank/render/cmd.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,22 @@ func (c *Cmd) Run(k *kong.Context, log logging.Logger) error { //nolint:gocognit
150150
return errors.Wrapf(errs.ToAggregate(), "invalid Composition %q", comp.GetName())
151151
}
152152

153+
// check if XR's matchLabels have corresponding label at composition
154+
xrSelector := xr.GetCompositionSelector()
155+
if xrSelector != nil {
156+
for key, value := range xrSelector.MatchLabels {
157+
compValue, exists := comp.Labels[key]
158+
if !exists {
159+
return fmt.Errorf("composition %q is missing required label %q", comp.GetName(), key)
160+
}
161+
fmt.Println("compValue: ", compValue, "value: ", value)
162+
if compValue != value {
163+
return fmt.Errorf("composition %q has incorrect value for label %q: want %q, got %q",
164+
comp.GetName(), key, value, compValue)
165+
}
166+
}
167+
}
168+
153169
if m := comp.Spec.Mode; m == nil || *m != v1.CompositionModePipeline {
154170
return errors.Errorf("render only supports Composition Function pipelines: Composition %q must use spec.mode: Pipeline", comp.GetName())
155171
}

0 commit comments

Comments
 (0)