Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 1823714: Update PkgManifest upon catsrc update #1482

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 12 additions & 4 deletions pkg/package-server/provider/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"sync"
"time"

utillabels "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/labels"
"github.com/operator-framework/operator-registry/pkg/api"
"github.com/sirupsen/logrus"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
Expand All @@ -26,9 +24,11 @@ import (
operatorslisters "github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/listers/operators/v1alpha1"
registrygrpc "github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/grpc"
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/registry/resolver"
utillabels "github.com/operator-framework/operator-lifecycle-manager/pkg/lib/kubernetes/pkg/util/labels"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/queueinformer"
"github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/apis/operators"
pkglisters "github.com/operator-framework/operator-lifecycle-manager/pkg/package-server/client/listers/operators/internalversion"
"github.com/operator-framework/operator-registry/pkg/api"
)

const (
Expand Down Expand Up @@ -189,9 +189,17 @@ func (p *RegistryProvider) syncCatalogSource(obj interface{}) (syncError error)
Namespace: source.GetNamespace(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You commit message has misspelled words: triggred andaddes. You should consider enabling spellcheck in VIM or whichever editor you use to create your commit messages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat! did not know that's an option

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funny, i went and looked. turns out i had it on. Somehow i dont see notifiations. I'll check what was wrong with that.

Name: source.GetName(),
}

if sourceMeta := p.sources.GetMeta(key); sourceMeta != nil && sourceMeta.Address == address {
// If the address hasn't changed, don't bother creating a new source
logger.Debug("catalog address unchanged, skipping source creation")
dinhxuanvu marked this conversation as resolved.
Show resolved Hide resolved
logger.Infof("updating PackageManifest based on CatalogSource changes: %v", key)
timeout, cancel := context.WithTimeout(context.Background(), cacheTimeout)
defer cancel()
var client *registryClient
client, syncError = p.registryClient(key)
if syncError != nil {
return
}
syncError = p.refreshCache(timeout, client)
return
}

Expand Down
42 changes: 37 additions & 5 deletions test/e2e/packagemanifest_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package e2e
import (
"context"
"encoding/json"

"github.com/blang/semver"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
Expand Down Expand Up @@ -145,12 +146,13 @@ var _ = Describe("Package Manifest API lists available Operators from Catalog So

Context("Given a CatalogSource created using gRPC catalog source type", func() {
var (
packageName string
catalogSource *v1alpha1.CatalogSource
packageName, displayName string
catalogSource *v1alpha1.CatalogSource
)
BeforeEach(func() {
sourceName := genName("catalog-")
packageName = "etcd-test"
displayName = "etcd test catalog"
image := "quay.io/olmtest/catsrc-update-test:related"

catalogSource = &v1alpha1.CatalogSource{
Expand All @@ -164,8 +166,9 @@ var _ = Describe("Package Manifest API lists available Operators from Catalog So
Labels: map[string]string{"olm.catalogSource": sourceName},
},
Spec: v1alpha1.CatalogSourceSpec{
SourceType: v1alpha1.SourceTypeGrpc,
Image: image,
SourceType: v1alpha1.SourceTypeGrpc,
Image: image,
DisplayName: displayName,
},
}

Expand Down Expand Up @@ -195,6 +198,36 @@ var _ = Describe("Package Manifest API lists available Operators from Catalog So
"quay.io/coreos/etcd-operator@sha256:c0301e4686c3ed4206e370b42de5a3bd2229b9fb4906cf85f3f30650424abec2",
}), "Expected images to exist in the related images list\n")
})

When("the display name for catalog source is updated", func() {

BeforeEach(func() {

pm, err := fetchPackageManifest(pmc, testNamespace, packageName, packageManifestHasStatus)
Expect(err).NotTo(HaveOccurred(), "error getting package manifest")
Expect(pm).ShouldNot(BeNil())
Expect(pm.GetName()).Should(Equal(packageName))
Expect(pm.Status.CatalogSourceDisplayName).Should(Equal(displayName))

catalogSource, err = crc.OperatorsV1alpha1().CatalogSources(testNamespace).Get(context.TODO(), catalogSource.GetName(), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred(), "error getting catalogSource")

displayName = "updated Name"
catalogSource.Spec.DisplayName = displayName
catalogSource, err = crc.OperatorsV1alpha1().CatalogSources(testNamespace).Update(context.TODO(), catalogSource, metav1.UpdateOptions{})
Expect(err).NotTo(HaveOccurred(), "error updating catalogSource")
Expect(catalogSource.Spec.DisplayName).Should(Equal(displayName))
})
It("should successfully update the CatalogSource field", func() {

Eventually(func() string {
pm, err := fetchPackageManifest(pmc, testNamespace, packageName,
packageManifestHasStatus)
Expect(err).NotTo(HaveOccurred(), "error getting package manifest after updating catsrc")
return pm.Status.CatalogSourceDisplayName
}).Should(Equal(displayName))
})
})
})
})

Expand All @@ -203,7 +236,6 @@ type packageManifestCheckFunc func(*packagev1.PackageManifest) bool
func packageManifestHasStatus(pm *packagev1.PackageManifest) bool {
// as long as it has a package name we consider the status non-empty
return pm != nil && pm.Status.PackageName != ""

}

func fetchPackageManifest(pmc pmversioned.Interface, namespace, name string, check packageManifestCheckFunc) (*packagev1.PackageManifest, error) {
Expand Down