Skip to content

Commit 418108d

Browse files
committedApr 9, 2020
Codegen for registry API changes
Signed-off-by: Vu Dinh <[email protected]>
1 parent b443c0c commit 418108d

File tree

8 files changed

+876
-272
lines changed

8 files changed

+876
-272
lines changed
 

‎docs/design/operator-bundle.md

+1-2
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,9 @@ An example of a `dependencies.yaml` that specifies Prometheus operator and etcd
7676
```
7777
dependencies:
7878
- type: olm.package
79-
name: prometheus
79+
packgeName: prometheus
8080
version: >0.27.0
8181
- type: olm.gvk
82-
name: etcdclusters.etcd.database.coreos.com
8382
group: etcd.database.coreos.com
8483
kind: EtcdCluster
8584
version: v1beta2

‎pkg/api/grpc_health_v1/health.pb.go

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

‎pkg/api/registry.pb.go

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

‎pkg/registry/empty.go

+8
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ func (EmptyQuery) GetCurrentCSVNameForChannel(ctx context.Context, pkgName, chan
9696
return "", errors.New("empty querier: cannot get csv name for package and channel")
9797
}
9898

99+
func (EmptyQuery) ListBundles(ctx context.Context) ([]*api.Bundle, error) {
100+
return nil, errors.New("empty querier: cannot list bundles")
101+
}
102+
103+
func (EmptyQuery) GetDependenciesForBundle(ctx context.Context, name, version, path string) (dependencies []*api.Dependency, err error) {
104+
return nil, errors.New("empty querier: cannot get dependencies for bundle")
105+
}
106+
99107
var _ Query = &EmptyQuery{}
100108

101109
func NewEmptyQuerier() *EmptyQuery {

‎pkg/registry/populator.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import (
1616
"github.com/operator-framework/operator-registry/pkg/image"
1717
)
1818

19+
const (
20+
DependenciesFileName = "dependencies.yaml"
21+
)
22+
1923
// DirectoryPopulator loads an unpacked operator bundle from a directory into the database.
2024
type DirectoryPopulator struct {
2125
loader Load
@@ -46,30 +50,41 @@ func (i *DirectoryPopulator) Populate(mode Mode) error {
4650
return fmt.Errorf("unable to read directory %s: %s", metadata, err)
4751
}
4852

49-
// Look for the metadata and manifests sub-directories to find the annotations.yaml file that will inform how the
50-
// manifests of the bundle should be loaded into the database.
53+
// Look for the metadata and manifests sub-directories to find the annotations.yaml
54+
// file that will inform how the manifests of the bundle should be loaded into the database.
55+
// If dependencies.yaml which contains operator dependencies in metadata directory
56+
// exists, parse and load it into the DB
5157
annotationsFile := &AnnotationsFile{}
58+
dependenciesFile := &DependenciesFile{}
5259
for _, f := range files {
5360
err = decodeFile(filepath.Join(metadata, f.Name()), annotationsFile)
5461
if err != nil || *annotationsFile == (AnnotationsFile{}) {
62+
log.Info("found annotations file searching for csv")
5563
continue
5664
}
57-
log.Info("found annotations file searching for csv")
65+
if f.Name() == DependenciesFileName {
66+
err = decodeFile(filepath.Join(metadata, f.Name()), dependenciesFile)
67+
if err != nil {
68+
log.Info("found dependencies file searching for csv")
69+
} else {
70+
log.Info("unable to parse dependencies.yaml file")
71+
}
72+
}
5873
}
5974

6075
if *annotationsFile == (AnnotationsFile{}) {
6176
return fmt.Errorf("Could not find annotations.yaml file")
6277
}
6378

64-
err = i.loadManifests(manifests, annotationsFile, mode)
79+
err = i.loadManifests(manifests, annotationsFile, dependenciesFile, mode)
6580
if err != nil {
6681
return err
6782
}
6883

6984
return nil
7085
}
7186

72-
func (i *DirectoryPopulator) loadManifests(manifests string, annotationsFile *AnnotationsFile, mode Mode) error {
87+
func (i *DirectoryPopulator) loadManifests(manifests string, annotationsFile *AnnotationsFile, dependenciesFile *DependenciesFile, mode Mode) error {
7388
log := logrus.WithFields(logrus.Fields{"dir": i.from, "file": manifests, "load": "bundle"})
7489

7590
csv, err := i.findCSV(manifests)
@@ -96,6 +111,8 @@ func (i *DirectoryPopulator) loadManifests(manifests string, annotationsFile *An
96111

97112
// set the bundleimage on the bundle
98113
bundle.BundleImage = i.to.String()
114+
// set the dependencies on the bundle
115+
bundle.Dependencies = dependenciesFile.Dependencies
99116

100117
bundle.Name = csvName
101118
bundle.Package = annotationsFile.Annotations.PackageName

‎pkg/registry/types.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -126,14 +126,14 @@ type Dependency struct {
126126
// dependency or `olm.gvk` for gvk based dependency. This field is required.
127127
Type string `json:"type" yaml:"type"`
128128

129-
// The name of dependency such as 'etcd'. This field is required.
130-
Name string `json:"name" yaml:"name"`
129+
// The name of dependency such as 'etcd'
130+
Name string `json:"name" yaml:"packgeName"`
131131

132-
// The group of GVK based dependency.
133-
Group string `json:"group,omitempty" yaml:"group"`
132+
// The group of GVK based dependency
133+
Group string `json:"group" yaml:"group"`
134134

135-
// The kind of GVK based dependency.
136-
Kind string `json:"kind,omitempty" yaml:"kind"`
135+
// The kind of GVK based dependency
136+
Kind string `json:"kind" yaml:"kind"`
137137

138138
// The version of dependency in semver format
139139
Version string `json:"version" yaml:"version"`

‎pkg/sqlite/load.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ func (s *SQLLoader) addDependencies(tx *sql.Tx, bundle *registry.Bundle) error {
763763
tx.Rollback()
764764
}()
765765

766-
addDep, err := tx.Prepare("insert into dependencies_list(type, package_name, group_name, version, kind, operatorbundle_name, operatorbundle_version, operatorbundle_path) values(?, ?, ?, ?, ?, ?, ?, ?)")
766+
addDep, err := tx.Prepare("insert into dependencies(type, package_name, group_name, version, kind, operatorbundle_name, operatorbundle_version, operatorbundle_path) values(?, ?, ?, ?, ?, ?, ?, ?)")
767767
if err != nil {
768768
return err
769769
}

‎pkg/sqlite/query.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ func (s *SQLQuerier) GetBundlePathsForPackage(ctx context.Context, pkgName strin
688688
}
689689

690690
func (s *SQLQuerier) GetBundlesForPackage(ctx context.Context, pkgName string) (map[registry.BundleKey]struct{}, error) {
691-
query := `SELECT DISTINCT name, bundlepath, version FROM operatorbundle
691+
query := `SELECT DISTINCT name, bundlepath, version FROM operatorbundle
692692
INNER JOIN channel_entry ON operatorbundle.name=channel_entry.operatorbundle_name
693693
WHERE channel_entry.package_name=?`
694694
rows, err := s.db.QueryContext(ctx, query, pkgName)
@@ -850,7 +850,7 @@ func (s *SQLQuerier) GetDependenciesForBundle(ctx context.Context, name, version
850850

851851
rows, err := s.db.QueryContext(ctx, depQuery, name, version, path)
852852
if err != nil {
853-
return nil, nil, err
853+
return nil, err
854854
}
855855
dependencies = []*api.Dependency{}
856856
for rows.Next() {

0 commit comments

Comments
 (0)
Please sign in to comment.