Skip to content

Commit 63c22b9

Browse files
dinhxuanvuperdasilva
authored andcommitted
fix(render/diff): Support olm.constraint in opm render/diff cmd (openshift#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]> Upstream-repository: operator-registry Upstream-commit: 4e339285b95dad2e635204ff85826aa6099ee6a3
1 parent d173fd1 commit 63c22b9

File tree

7 files changed

+40
-3
lines changed

7 files changed

+40
-3
lines changed

staging/operator-registry/bundles/etcd.0.9.2/metadata/dependencies.yaml

Lines changed: 5 additions & 0 deletions
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")'

staging/operator-registry/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ require (
3636
github.com/onsi/gomega v1.15.0
3737
github.com/opencontainers/go-digest v1.0.0
3838
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
39-
github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce
39+
github.com/operator-framework/api v0.11.1
4040
github.com/otiai10/copy v1.2.0
4141
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
4242
github.com/pkg/errors v0.9.1

staging/operator-registry/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,8 @@ github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700 h1:e
645645
github.com/opencontainers/runtime-spec v0.1.2-0.20190507144316-5b71a03e2700/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
646646
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
647647
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
648-
github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce h1:+zEJrt6Kw4SnN115WzleIpmw5jAgscrWb9K0WgvjhOc=
649-
github.com/operator-framework/api v0.10.8-0.20211210002341-1eb6c0266cce/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
648+
github.com/operator-framework/api v0.11.1 h1:5eNUMplyL/GZrnBgG4SS2csO3+Fl4F79OqXN6POHQyA=
649+
github.com/operator-framework/api v0.11.1/go.mod h1:FTiYGm11fZQ3cSX+EQHc/UWoGZAwkGfyeHU+wMJ8jmA=
650650
github.com/otiai10/copy v1.2.0 h1:HvG945u96iNadPoG2/Ja2+AUJeW5YuFQMixq9yirC+k=
651651
github.com/otiai10/copy v1.2.0/go.mod h1:rrF5dJ5F0t/EWSYODDu4j9/vEeYHMkc8jt0zJChqQWw=
652652
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=

staging/operator-registry/pkg/registry/populator_test.go

Lines changed: 16 additions & 0 deletions
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{}

staging/operator-registry/pkg/registry/registry_to_model.go

Lines changed: 5 additions & 0 deletions
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

staging/operator-registry/pkg/registry/registry_to_model_test.go

Lines changed: 6 additions & 0 deletions
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
}

vendor/github.com/operator-framework/operator-registry/pkg/registry/registry_to_model.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)