From 0bdd92314bde718c5398e143ad8554544f8083de Mon Sep 17 00:00:00 2001 From: Omer Aplatony Date: Thu, 7 Nov 2024 20:52:34 +0200 Subject: [PATCH 1/2] Fix XR matchLabels validation in composition Signed-off-by: Omer Aplatony --- cmd/crank/render/cmd.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/cmd/crank/render/cmd.go b/cmd/crank/render/cmd.go index ccec299ac0d..038e0b0301b 100644 --- a/cmd/crank/render/cmd.go +++ b/cmd/crank/render/cmd.go @@ -150,6 +150,22 @@ 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) + } + fmt.Println("compValue: ", compValue, "value: ", value) + 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()) } From ba56c07296a7840e061603d9151b46a1f2d7cfa6 Mon Sep 17 00:00:00 2001 From: Omer Aplatony Date: Fri, 8 Nov 2024 15:40:27 +0200 Subject: [PATCH 2/2] remove redub log Co-authored-by: Philippe Scorsolini Signed-off-by: Omer Aplatony --- cmd/crank/render/cmd.go | 1 - 1 file changed, 1 deletion(-) diff --git a/cmd/crank/render/cmd.go b/cmd/crank/render/cmd.go index 038e0b0301b..fa04f34e996 100644 --- a/cmd/crank/render/cmd.go +++ b/cmd/crank/render/cmd.go @@ -158,7 +158,6 @@ func (c *Cmd) Run(k *kong.Context, log logging.Logger) error { //nolint:gocognit if !exists { return fmt.Errorf("composition %q is missing required label %q", comp.GetName(), key) } - fmt.Println("compValue: ", compValue, "value: ", value) if compValue != value { return fmt.Errorf("composition %q has incorrect value for label %q: want %q, got %q", comp.GetName(), key, value, compValue)