Skip to content

Commit 2e30704

Browse files
committedJul 30, 2020
Update label property extraction from CSV
The label properties are now specified in CSV annotations. Signed-off-by: Vu Dinh <[email protected]>
1 parent eb48f76 commit 2e30704

File tree

5 files changed

+40
-30
lines changed

5 files changed

+40
-30
lines changed
 

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

+1-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,8 @@ kind: ClusterServiceVersion
44
metadata:
55
name: etcdoperator.v0.9.2
66
namespace: placeholder
7-
labels:
8-
olm.label: testlabel
9-
olm.label.1: testlabel1
107
annotations:
8+
olm.properties: '[{"type":"olm.label","value":{"label":"testlabel"}},{"type":"olm.label","value":{"label":"testlabel1"}}]'
119
tectonic-visibility: ocs
1210
olm.skipRange: "< 0.6.0"
1311
alm-examples: '[{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdCluster","metadata":{"name":"example","namespace":"default"},"spec":{"size":3,"version":"3.2.13"}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdRestore","metadata":{"name":"example-etcd-cluster"},"spec":{"etcdCluster":{"name":"example-etcd-cluster"},"backupStorageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}},{"apiVersion":"etcd.database.coreos.com/v1beta2","kind":"EtcdBackup","metadata":{"name":"example-etcd-cluster-backup"},"spec":{"etcdEndpoints":["<etcd-cluster-endpoints>"],"storageType":"S3","s3":{"path":"<full-s3-path>","awsSecret":"<aws-secret>"}}}]'

‎pkg/registry/types.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ const (
4444
PackageType = "olm.package"
4545
DeprecatedType = "olm.deprecated"
4646
LabelType = "olm.label"
47+
PropertyKey = "olm.properties"
4748
)
4849

4950
// APIKey stores GroupVersionKind for use as map keys
@@ -172,7 +173,7 @@ type Property struct {
172173
Type string `json:"type" yaml:"type"`
173174

174175
// The serialized value of the propertuy
175-
Value string `json:"value" yaml:"value"`
176+
Value json.RawMessage `json:"value" yaml:"value"`
176177
}
177178

178179
type GVKDependency struct {

‎pkg/server/server_test.go

+12-12
Large diffs are not rendered by default.

‎pkg/sqlite/directory_test.go

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

‎pkg/sqlite/load.go

+23-12
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,8 @@ func (s *sqlLoader) addBundleProperties(tx *sql.Tx, bundle *registry.Bundle) err
777777
}
778778

779779
for _, prop := range bundle.Properties {
780-
if err := s.addProperty(tx, prop.Type, prop.Value, bundle.Name, bundleVersion, bundle.BundleImage); err != nil {
780+
value, _ := json.Marshal(prop.Value)
781+
if err := s.addProperty(tx, prop.Type, string(value), bundle.Name, bundleVersion, bundle.BundleImage); err != nil {
781782
return err
782783
}
783784
}
@@ -805,17 +806,27 @@ func (s *sqlLoader) addBundleProperties(tx *sql.Tx, bundle *registry.Bundle) err
805806

806807
// Add label properties
807808
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
809+
annotations := csv.ObjectMeta.GetAnnotations()
810+
if v, ok := annotations[registry.PropertyKey]; ok {
811+
var props []registry.Property
812+
if err := json.Unmarshal([]byte(v), &props); err == nil {
813+
for _, prop := range props {
814+
// Only add label type from the list
815+
// TODO: Support more types such as GVK and package
816+
if prop.Type == registry.LabelType {
817+
var label registry.LabelProperty
818+
err := json.Unmarshal(prop.Value, &label)
819+
if err != nil {
820+
continue
821+
}
822+
value, err := json.Marshal(label)
823+
if err != nil {
824+
continue
825+
}
826+
if err := s.addProperty(tx, registry.LabelType, string(value), bundle.Name, bundleVersion, bundle.BundleImage); err != nil {
827+
continue
828+
}
829+
}
819830
}
820831
}
821832
}

0 commit comments

Comments
 (0)
Please sign in to comment.