Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 2c33532

Browse files
committedJul 28, 2020
feat(registry): Add label dependency constraint and property
1. Introduce a new type of dependency constraint named `olm.label` which represents the constraints that are based on CSV labels. 2. The new label property is parsed from CSV labels. Signed-off-by: Vu Dinh <[email protected]>
1 parent b2ceacc commit 2c33532

15 files changed

+499
-20
lines changed
 

‎docs/design/operator-bundle.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -69,21 +69,24 @@ annotations:
6969

7070
The dependencies of an operator are listed as a list in `dependencies.yaml` file inside `/metadata` folder of a bundle. This file is optional and only used to specify explicit operator version dependencies at first. Eventually, operator authors can migrate the API-based dependencies into `dependencies.yaml` as well in the future. The ultimate goal is to have `dependencies.yaml` as a centralized metadata for operator dependencies and moving the dependency information away from CSV.
7171

72-
The dependency list will contain a `type` field for each item to specify what kind of dependency this is. There are two supported `type` of operator dependencies. It can be a package type (`olm.package`) meaning this is a dependency for a specific operator version. For `olm.package` type, the dependency information should include the `package` name and the `version` of the package in semver format. We use `blang/semver` library for semver parsing (https://github.com/blang/semver). For example, you can specify an exact version such as `0.5.2` or a range of version such as `>0.5.1` (https://github.com/blang/semver#ranges). In addition, the author can specify dependency that is similiar to existing CRD/API-based using `olm.gvk` type and then specify GVK information as how it is done in CSV. This is a path to enable operator authors to consolidate all dependencies (API or explicit version) to be in the same place.
72+
The dependency list will contain a `type` field for each item to specify what kind of dependency this is. There are two supported `type` of operator dependencies. It can be a package type (`olm.package`) meaning this is a dependency for a specific operator version. For `olm.package` type, the dependency information should include the `package` name and the `version` of the package in semver format. We use `blang/semver` library for semver parsing (https://github.com/blang/semver). For example, you can specify an exact version such as `0.5.2` or a range of version such as `>0.5.1` (https://github.com/blang/semver#ranges). In addition, the author can specify dependency that is similar to existing CRD/API-based using `olm.gvk` type and then specify GVK information as how it is done in CSV. The author can also specify CSV labels as dependency constraints using `olm.label` type. The value of `olm.label` type will be matched against labels in CSV with the key starting with the phrase `olm.label`. This is a path to enable operator authors to consolidate all dependencies (API or explicit version) to be in the same place.
7373

7474
An example of a `dependencies.yaml` that specifies Prometheus operator and etcd CRD dependencies:
7575

7676
```
7777
dependencies:
7878
- type: olm.package
79-
value:
79+
value:
8080
packageName: prometheus
8181
version: >0.27.0
8282
- type: olm.gvk
8383
value:
8484
group: etcd.database.coreos.com
8585
kind: EtcdCluster
8686
version: v1beta2
87+
- type: olm.gvk
88+
value:
89+
label: lts
8790
```
8891

8992
### Bundle Dockerfile

‎manifests/etcd/0.9.2/etcdoperator.v0.9.2.clusterserviceversion.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ kind: ClusterServiceVersion
44
metadata:
55
name: etcdoperator.v0.9.2
66
namespace: placeholder
7+
labels:
8+
olm.label: testlabel
9+
olm.label.1: testlabel1
710
annotations:
811
tectonic-visibility: ocs
912
olm.skipRange: "< 0.6.0"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: etcdbackups.etcd.database.coreos.com
5+
spec:
6+
group: etcd.database.coreos.com
7+
names:
8+
kind: EtcdBackup
9+
listKind: EtcdBackupList
10+
plural: etcdbackups
11+
singular: etcdbackup
12+
scope: Namespaced
13+
version: v1beta2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: etcdclusters.etcd.database.coreos.com
5+
spec:
6+
group: etcd.database.coreos.com
7+
names:
8+
kind: EtcdCluster
9+
listKind: EtcdClusterList
10+
plural: etcdclusters
11+
shortNames:
12+
- etcdclus
13+
- etcd
14+
singular: etcdcluster
15+
scope: Namespaced
16+
version: v1beta2

‎pkg/lib/bundle/testdata/validate/invalid_dependencies_bundle/invalid_label_dependency/manifests/etcdoperator.v0.9.4.clusterserviceversion.yaml

+309
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: etcdrestores.etcd.database.coreos.com
5+
spec:
6+
group: etcd.database.coreos.com
7+
names:
8+
kind: EtcdRestore
9+
listKind: EtcdRestoreList
10+
plural: etcdrestores
11+
singular: etcdrestore
12+
scope: Namespaced
13+
version: v1beta2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
annotations:
2+
operators.operatorframework.io.bundle.channel.default.v1: stable
3+
operators.operatorframework.io.bundle.channels.v1: stable,beta
4+
operators.operatorframework.io.bundle.manifests.v1: manifests/
5+
operators.operatorframework.io.bundle.mediatype.v1: registry+v1
6+
operators.operatorframework.io.bundle.metadata.v1: metadata/
7+
operators.operatorframework.io.bundle.package.v1: etcd
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dependencies:
2+
- type: olm.label

‎pkg/lib/bundle/testdata/validate/valid_bundle/metadata/dependencies.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ dependencies:
77
group: test.coreos.com
88
kind: testapi
99
version: v1
10+
- type: olm.label
11+
label: testlabel

‎pkg/lib/bundle/validate.go

+2
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ func validateDependencies(dependenciesFile *registry.DependenciesFile) []error {
232232
errs = dp.Validate()
233233
case registry.PackageDependency:
234234
errs = dp.Validate()
235+
case registry.LabelDependency:
236+
errs = dp.Validate()
235237
default:
236238
errs = append(errs, fmt.Errorf("unsupported dependency type %s", d.GetType()))
237239
}

‎pkg/lib/bundle/validate_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,14 @@ func TestValidateBundleDependencies(t *testing.T) {
6161
fmt.Errorf("couldn't parse dependency of type olm.crd"),
6262
},
6363
},
64+
{
65+
description: "registryv1 bundle/invalid label type",
66+
mediaType: RegistryV1Type,
67+
directory: "./testdata/validate/invalid_dependencies_bundle/invalid_label_dependency/",
68+
errs: []error{
69+
fmt.Errorf("couldn't parse dependency of type olm.label"),
70+
},
71+
},
6472
}
6573

6674
for _, tt := range table {

‎pkg/registry/types.go

+27
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func (e PackageVersionAlreadyAddedErr) Error() string {
3535
const (
3636
GVKType = "olm.gvk"
3737
PackageType = "olm.package"
38+
LabelType = "olm.label"
3839
)
3940

4041
// APIKey stores GroupVersionKind for use as map keys
@@ -185,6 +186,11 @@ type PackageDependency struct {
185186
Version string `json:"version" yaml:"version"`
186187
}
187188

189+
type LabelDependency struct {
190+
// The version range of dependency in semver range format
191+
Label string `json:"label" yaml:"label"`
192+
}
193+
188194
type GVKProperty struct {
189195
// The group of GVK based property
190196
Group string `json:"group" yaml:"group"`
@@ -204,6 +210,11 @@ type PackageProperty struct {
204210
Version string `json:"version" yaml:"version"`
205211
}
206212

213+
type LabelProperty struct {
214+
// The version range of dependency in semver range format
215+
Label string `json:"label" yaml:"label"`
216+
}
217+
207218
// Validate will validate GVK dependency type and return error(s)
208219
func (gd *GVKDependency) Validate() []error {
209220
errs := []error{}
@@ -219,6 +230,15 @@ func (gd *GVKDependency) Validate() []error {
219230
return errs
220231
}
221232

233+
// Validate will validate GVK dependency type and return error(s)
234+
func (ld *LabelDependency) Validate() []error {
235+
errs := []error{}
236+
if ld.Label == "" {
237+
errs = append(errs, fmt.Errorf("Label information is empty"))
238+
}
239+
return errs
240+
}
241+
222242
// Validate will validate package dependency type and return error(s)
223243
func (pd *PackageDependency) Validate() []error {
224244
errs := []error{}
@@ -269,6 +289,13 @@ func (e *Dependency) GetTypeValue() interface{} {
269289
return nil
270290
}
271291
return dep
292+
case LabelType:
293+
dep := LabelDependency{}
294+
err := json.Unmarshal([]byte(e.GetValue()), &dep)
295+
if err != nil {
296+
return nil
297+
}
298+
return dep
272299
}
273300
return nil
274301
}

‎pkg/server/server_test.go

+64-16
Large diffs are not rendered by default.

‎pkg/sqlite/directory_test.go

+10-2
Large diffs are not rendered by default.

‎pkg/sqlite/load.go

+18
Original file line numberDiff line numberDiff line change
@@ -803,5 +803,23 @@ func (s *sqlLoader) addBundleProperties(tx *sql.Tx, bundle *registry.Bundle) err
803803
}
804804
}
805805

806+
// Add label properties
807+
if csv, err := bundle.ClusterServiceVersion(); err == nil {
808+
for k, v := range csv.GetLabels() {
809+
if strings.HasPrefix(k, registry.LabelType) {
810+
prop := registry.LabelProperty{
811+
Label: v,
812+
}
813+
value, err := json.Marshal(prop)
814+
if err != nil {
815+
continue
816+
}
817+
if err := s.addProperty(tx, registry.LabelType, string(value), bundle.Name, bundleVersion, bundle.BundleImage); err != nil {
818+
continue
819+
}
820+
}
821+
}
822+
}
823+
806824
return nil
807825
}

0 commit comments

Comments
 (0)
Please sign in to comment.