Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,17 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/ghodss/yaml v1.0.0
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9 // indirect
github.com/golang/protobuf v1.3.2
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5
github.com/operator-framework/operator-registry v1.5.3
github.com/operator-framework/operator-registry v1.5.4
github.com/pkg/errors v0.8.1
github.com/sirupsen/logrus v1.4.2
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc
google.golang.org/grpc v1.23.0
k8s.io/api v0.0.0
k8s.io/apiextensions-apiserver v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/client-go v8.0.0+incompatible
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ github.com/mattn/go-sqlite3 v1.10.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsO
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.1/go.mod h1:F9YacGpnZbLQMzuPI0rR6op21YvNu/RjL705LJJpM3k=
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
github.com/mesos/mesos-go v0.0.9/go.mod h1:kPYCMQ9gsOXVAle1OsoY4I1+9kPu8GHkf88aV59fDr4=
github.com/mholt/certmagic v0.6.2-0.20190624175158-6a42ef9fe8c2/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
Expand Down Expand Up @@ -410,8 +411,8 @@ github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJ
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5 h1:rjaihxY50c5C+kbQIK4s36R8zxByATYrgRbua4eiG6o=
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5/go.mod h1:zL34MNy92LPutBH5gQK+gGhtgTUlZZX03I2G12vWHF4=
github.com/operator-framework/operator-registry v1.5.1/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY=
github.com/operator-framework/operator-registry v1.5.3 h1:az83WDwgB+tHsmVn+tFq72yQBbaUAye8e4+KkDQmzLs=
github.com/operator-framework/operator-registry v1.5.3/go.mod h1:agrQlkWOo1q8U1SAaLSS2WQ+Z9vswNT2M2HFib9iuLY=
github.com/operator-framework/operator-registry v1.5.4 h1:ssUAU7CaacYCB6p+CJj9nxXowpD89VLOAY+Aw1w2o8Q=
github.com/operator-framework/operator-registry v1.5.4/go.mod h1:6T3+8vu3N5fpQikSA1Tp91sLxRordtmmvF6ynvBg06g=
github.com/otiai10/copy v1.0.1 h1:gtBjD8aq4nychvRZ2CyJvFWAw0aja+VHazDdruZKGZA=
github.com/otiai10/copy v1.0.1/go.mod h1:8bMCJrAqOtN/d9oyh5HR7HhLQMvcGMpGdwRDYsfOCHc=
github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE=
Expand Down
87 changes: 58 additions & 29 deletions pkg/internal/bundle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ package manifests
import (
"encoding/json"

manifests "github.com/operator-framework/api/pkg/registry/manifests"

"github.com/blang/semver"
operatorsv1alpha1 "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-registry/pkg/registry"
"github.com/operator-framework/operator-registry/pkg/sqlite"
"github.com/pkg/errors"
)

// TODO: use internal version of registry.Bundle/registry.PackageManifest so
// operator-registry can use validation library.

// manifestsLoad loads a manifests directory from disk.
type manifestsLoad struct {
dir string
Expand Down Expand Up @@ -70,63 +69,93 @@ func (l *manifestsLoad) ClearNonDefaultBundles(packageName string) error {
return nil
}

// ManifestsStore knows how to query for an operator's package manifest and
// ManifestsStorer knows how to query for an operator's package manifest and
// related bundles.
type ManifestsStore interface {
// GetPackageManifest returns the ManifestsStore's registry.PackageManifest.
type ManifestsStorer interface {
// GetPackageManifest returns the ManifestsStorer's registry.PackageManifest.
// The returned object is assumed to be valid.
GetPackageManifest() registry.PackageManifest
// GetBundles returns the ManifestsStore's set of registry.Bundle. These
// bundles are unique by CSV version, since only one operator type should
// exist in one manifests dir.
GetPackageManifest() manifests.PackageManifest
// GetBundles returns the ManifestsStorer's set of Bundles. These bundles
// are unique by CSV version, since only one operator type should exist
// in one manifests dir.
// The returned objects are assumed to be valid.
GetBundles() []*registry.Bundle
// GetBundleForVersion returns the ManifestsStore's registry.Bundle for a
// given version string. An error should be returned if the passed version
GetBundles() []*manifests.Bundle
// GetBundleForVersion returns the ManifestsStorer's Bundle for a given
// version string. An error should be returned if the passed version
// does not exist in the store.
// The returned object is assumed to be valid.
GetBundleForVersion(string) (*registry.Bundle, error)
GetBundleForVersion(string) (*manifests.Bundle, error)
}

// manifests implements ManifestsStore
type manifests struct {
pkg registry.PackageManifest
bundles map[string]*registry.Bundle
// manifestsStore implements ManifestsStorer
type manifestsStore struct {
pkg manifests.PackageManifest
bundles map[string]*manifests.Bundle
}

// ManifestsStoreForDir populates a ManifestsStore from the metadata in dir.
// ManifestsStoreForDir populates a ManifestsStorer from the metadata in dir.
// Each bundle and the package manifest are statically validated, and will
// return an error if any are not valid.
func ManifestsStoreForDir(dir string) (ManifestsStore, error) {
func ManifestsStoreForDir(dir string) (ManifestsStorer, error) {
load := &manifestsLoad{
dir: dir,
bundles: map[string]*registry.Bundle{},
}
if err := load.populate(); err != nil {
return nil, err
}
return &manifests{
pkg: load.pkg,
bundles: load.bundles,
// TODO(estroz): remove when operator-registry migrates to api types.
pkg, bundles := convertRegistryToAPITypes(load.pkg, load.bundles)
return &manifestsStore{
pkg: pkg,
bundles: bundles,
}, nil
}

func (l manifests) GetPackageManifest() registry.PackageManifest {
return l.pkg
// TODO(estroz): remove when operator-registry migrates to api types.
func convertRegistryToAPITypes(pkgR registry.PackageManifest, bundlesR map[string]*registry.Bundle) (manifests.PackageManifest, map[string]*manifests.Bundle) {
pkgA := manifests.PackageManifest{
PackageName: pkgR.PackageName,
DefaultChannelName: pkgR.DefaultChannelName,
}
for _, channel := range pkgR.Channels {
pkgA.Channels = append(pkgA.Channels, manifests.PackageChannel{
Name: channel.Name,
CurrentCSVName: channel.CurrentCSVName,
})
}
bundlesA := map[string]*manifests.Bundle{}
for key, bundle := range bundlesR {
b := manifests.Bundle{
Name: bundle.Name,
Package: bundle.Package,
Channel: bundle.Channel,
BundleImage: bundle.BundleImage,
}
for _, obj := range bundle.Objects {
b.Add(obj.DeepCopy())
}
bundlesA[key] = &b
}
return pkgA, bundlesA
}

func (s manifestsStore) GetPackageManifest() manifests.PackageManifest {
return s.pkg
}

func (l manifests) GetBundles() (bundles []*registry.Bundle) {
for _, bundle := range l.bundles {
func (s manifestsStore) GetBundles() (bundles []*manifests.Bundle) {
for _, bundle := range s.bundles {
bundles = append(bundles, bundle)
}
return bundles
}

func (l manifests) GetBundleForVersion(version string) (*registry.Bundle, error) {
func (s manifestsStore) GetBundleForVersion(version string) (*manifests.Bundle, error) {
if _, err := semver.Parse(version); err != nil {
return nil, errors.Wrapf(err, "error getting bundle for version %q", version)
}
bundle, ok := l.bundles[version]
bundle, ok := s.bundles[version]
if !ok {
return nil, errors.Errorf("bundle for version %q does not exist", version)
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/manifests/directory.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@ import (
"fmt"

internal "github.com/operator-framework/api/pkg/internal"
manifests "github.com/operator-framework/api/pkg/registry/manifests"
"github.com/operator-framework/api/pkg/validation"
"github.com/operator-framework/api/pkg/validation/errors"

"github.com/operator-framework/operator-registry/pkg/registry"
)

// GetManifestsDir parses all bundles and a package manifest from dir, which
// are returned if found along with any errors or warnings encountered while
// parsing/validating found manifests.
func GetManifestsDir(dir string) (registry.PackageManifest, []*registry.Bundle, []errors.ManifestResult) {
manifests, err := internal.ManifestsStoreForDir(dir)
func GetManifestsDir(dir string) (manifests.PackageManifest, []*manifests.Bundle, []errors.ManifestResult) {
store, err := internal.ManifestsStoreForDir(dir)
if err != nil {
result := errors.ManifestResult{}
result.Add(errors.ErrInvalidParse(fmt.Sprintf("parse manifests from %q", dir), err))
return registry.PackageManifest{}, nil, []errors.ManifestResult{result}
return manifests.PackageManifest{}, nil, []errors.ManifestResult{result}
}
pkg := manifests.GetPackageManifest()
bundles := manifests.GetBundles()
pkg := store.GetPackageManifest()
bundles := store.GetBundles()
objs := []interface{}{}
for _, obj := range bundles {
objs = append(objs, obj)
Expand Down
190 changes: 190 additions & 0 deletions pkg/registry/api/grpc_health_v1/health.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading