Skip to content

Commit

Permalink
Merge pull request crossplane#6080 from omerap12/render-check-matchLa…
Browse files Browse the repository at this point in the history
…bels

crank render: fix XR matchLabels validation in composition
  • Loading branch information
phisco authored Dec 11, 2024
2 parents d07c08b + ba56c07 commit fe31b2d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/crank/render/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,21 @@ func (c *Cmd) Run(k *kong.Context, log logging.Logger) error { //nolint:gocognit
return errors.Wrapf(errs.ToAggregate(), "invalid Composition %q", comp.GetName())
}

// check if XR's matchLabels have corresponding label at composition
xrSelector := xr.GetCompositionSelector()
if xrSelector != nil {
for key, value := range xrSelector.MatchLabels {
compValue, exists := comp.Labels[key]
if !exists {
return fmt.Errorf("composition %q is missing required label %q", comp.GetName(), key)
}
if compValue != value {
return fmt.Errorf("composition %q has incorrect value for label %q: want %q, got %q",
comp.GetName(), key, value, compValue)
}
}
}

if m := comp.Spec.Mode; m == nil || *m != v1.CompositionModePipeline {
return errors.Errorf("render only supports Composition Function pipelines: Composition %q must use spec.mode: Pipeline", comp.GetName())
}
Expand Down

0 comments on commit fe31b2d

Please sign in to comment.