Skip to content

Commit 4e33928

Browse files
authoredJan 24, 2022
fix(render/diff): Support olm.constraint in opm render/diff cmd (#901)
* fix(render/diff): Support olm.constraint in opm render/diff cmd Currently, the olm.constraint type is ignored and not recognized in render and diff cmd. This commit is to add supoprt for constraint type. Signed-off-by: Vu Dinh <[email protected]> * Accept any non-specific dependency as property Clean up test code Signed-off-by: Vu Dinh <[email protected]>
1 parent 354cd38 commit 4e33928

File tree

11 files changed

+69
-10
lines changed

11 files changed

+69
-10
lines changed
 

‎bundles/etcd.0.9.2/metadata/dependencies.yaml

+5
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,8 @@ dependencies:
44
group: testapi.coreos.com
55
kind: testapi
66
version: v1
7+
- type: olm.constraint
8+
value:
9+
failureMessage: 'require to have "certified"'
10+
cel:
11+
rule: 'properties.exists(p, p.type == "certified")'

‎go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ require (
3737
github.com/onsi/gomega v1.15.0
3838
github.com/opencontainers/go-digest v1.0.0
3939
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
40-
github.com/operator-framework/api v0.11.0
40+
github.com/operator-framework/api v0.11.1
4141
github.com/otiai10/copy v1.2.0
4242
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
4343
github.com/pkg/errors v0.9.1

‎go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -652,8 +652,8 @@ github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:e
652652
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
653653
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
654654
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
655-
github.com/operator-framework/api v0.11.0 h1:W9V1NNwl3LWPQL9S1pDaFONCarJLl8Xu6gdF9w54hTE=
656-
github.com/operator-framework/api v0.11.0/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
655+
github.com/operator-framework/api v0.11.1 h1:5eNUMplyL/GZrnBgG4SS2csO3+Fl4F79OqXN6POHQyA=
656+
github.com/operator-framework/api v0.11.1/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
657657
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
658658
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
659659
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=

‎pkg/registry/populator_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ func TestQuerierForImage(t *testing.T) {
151151
Type: "olm.gvk",
152152
Value: `{"group":"etcd.database.coreos.com","kind":"EtcdCluster","version":"v1beta2"}`,
153153
},
154+
{
155+
Type: "olm.constraint",
156+
Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`,
157+
},
154158
},
155159
Properties: []*api.Property{
156160
{
@@ -572,6 +576,10 @@ func TestQuerierForDependencies(t *testing.T) {
572576
Type: "olm.gvk",
573577
Value: `{"group":"testprometheus.coreos.com","kind":"testtestprometheus","version":"v1"}`,
574578
},
579+
{
580+
Type: "olm.constraint",
581+
Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`,
582+
},
575583
}
576584

577585
type operatorbundle struct {
@@ -635,6 +643,14 @@ func TestListBundles(t *testing.T) {
635643
Type: "olm.gvk",
636644
Value: `{"group":"etcd.database.coreos.com","kind":"EtcdCluster","version":"v1beta2"}`,
637645
},
646+
{
647+
Type: "olm.constraint",
648+
Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`,
649+
},
650+
{
651+
Type: "olm.constraint",
652+
Value: `{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`,
653+
},
638654
}
639655

640656
dependencies := []*api.Dependency{}

‎pkg/registry/registry_to_model.go

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func ObjectsAndPropertiesFromBundle(b *Bundle) ([]string, []property.Property, e
5555
return nil, nil, property.ParseError{Idx: i, Typ: p.Type, Err: err}
5656
}
5757
packageRequiredProps = append(packageRequiredProps, property.MustBuildPackageRequired(v.PackageName, v.Version))
58+
default:
59+
otherProps = append(otherProps, property.Property{
60+
Type: p.Type,
61+
Value: p.Value,
62+
})
5863
}
5964
}
6065

‎pkg/registry/registry_to_model_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package registry
22

33
import (
4+
"encoding/json"
45
"testing"
56

67
"github.com/stretchr/testify/assert"
@@ -44,7 +45,12 @@ func testExpectedProperties() []property.Property {
4445
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdCluster"),
4546
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdBackup"),
4647
property.MustBuildGVK("etcd.database.coreos.com", "v1beta2", "EtcdRestore"),
48+
property.Property{
49+
Type: "olm.constraint",
50+
Value: json.RawMessage(`{"cel":{"rule":"properties.exists(p, p.type == \"certified\")"},"failureMessage":"require to have \"certified\""}`),
51+
},
4752
}
53+
4854
for _, obj := range testExpectedObjects() {
4955
props = append(props, property.MustBuildBundleObjectData([]byte(obj)))
5056
}

‎pkg/registry/types.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ type LabelDependency struct {
223223
}
224224

225225
type CelConstraint struct {
226-
// Constraint message that surfaces in resolution
226+
// Constraint failure message that surfaces in resolution
227227
// This field is optional
228-
Message string `json:"message" yaml:"message"`
228+
FailureMessage string `json:"failureMessage" yaml:"failureMessage"`
229229

230230
// The cel struct that contraints CEL expression
231231
// This field is required

‎vendor/github.com/operator-framework/api/pkg/constraints/constraint.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/operator-framework/api/pkg/validation/internal/csv.go

+27
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/github.com/operator-framework/api/pkg/validation/internal/good_practices.go

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎vendor/modules.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ github.com/opencontainers/go-digest
420420
## explicit
421421
github.com/opencontainers/image-spec/specs-go
422422
github.com/opencontainers/image-spec/specs-go/v1
423-
# github.com/operator-framework/api v0.11.0
423+
# github.com/operator-framework/api v0.11.1
424424
## explicit
425425
github.com/operator-framework/api/pkg/constraints
426426
github.com/operator-framework/api/pkg/lib/version

0 commit comments

Comments
 (0)
Please sign in to comment.