Skip to content

Commit fe31b2d

Browse files
authored
Merge pull request crossplane#6080 from omerap12/render-check-matchLabels
crank render: fix XR matchLabels validation in composition
2 parents d07c08b + ba56c07 commit fe31b2d

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

cmd/crank/render/cmd.go

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

162+
// check if XR's matchLabels have corresponding label at composition
163+
xrSelector := xr.GetCompositionSelector()
164+
if xrSelector != nil {
165+
for key, value := range xrSelector.MatchLabels {
166+
compValue, exists := comp.Labels[key]
167+
if !exists {
168+
return fmt.Errorf("composition %q is missing required label %q", comp.GetName(), key)
169+
}
170+
if compValue != value {
171+
return fmt.Errorf("composition %q has incorrect value for label %q: want %q, got %q",
172+
comp.GetName(), key, value, compValue)
173+
}
174+
}
175+
}
176+
162177
if m := comp.Spec.Mode; m == nil || *m != v1.CompositionModePipeline {
163178
return errors.Errorf("render only supports Composition Function pipelines: Composition %q must use spec.mode: Pipeline", comp.GetName())
164179
}

0 commit comments

Comments
 (0)