Skip to content

Commit

Permalink
Update PkgManifest upon catsrc update
Browse files Browse the repository at this point in the history
The catsrc update sync triggered by the informer does not update pkgmanifest. This commit adds an update mechanism.
  • Loading branch information
bowenislandsong committed May 21, 2020
1 parent 408ca95 commit 675ebe7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 6 deletions.
15 changes: 13 additions & 2 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,7 +189,18 @@ func (p *RegistryProvider) syncCatalogSource(obj interface{}) (syncError error)
Namespace: source.GetNamespace(),
Name: source.GetName(),
}

if sourceMeta := p.sources.GetMeta(key); sourceMeta != nil && sourceMeta.Address == address {
logger.Infof("updating PackageManifest based on CatalogSource changes: %v", key)
timeout, cancel := context.WithTimeout(context.Background(), cacheTimeout)
defer cancel()
client, err := p.registryClient(key)
if err != nil {
syncError = err
return
}
syncError = p.refreshCache(timeout, client)

// If the address hasn't changed, don't bother creating a new source
logger.Debug("catalog address unchanged, skipping source creation")
return
Expand Down
32 changes: 28 additions & 4 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,27 @@ 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")
})

It("updating CatalogSource", func() {

updatedDisplayName := "updated Name"
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(catalogSource.GetNamespace()).Get(context.TODO(), catalogSource.GetName(), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred(), "error getting catalogSource")
catalogSource.Spec.DisplayName = updatedDisplayName

_, err = crc.OperatorsV1alpha1().CatalogSources(catalogSource.GetNamespace()).Update(context.TODO(), catalogSource, metav1.UpdateOptions{})
Expect(err).NotTo(HaveOccurred(), "error updating catalogSource")

pm, err = fetchPackageManifest(pmc, testNamespace, packageName, packageManifestHasStatus)
Expect(err).NotTo(HaveOccurred(), "error getting package manifest after updating catsrc")
Expect(pm.Status.CatalogSourceDisplayName).Should(Equal(updatedDisplayName))
})
})
})

Expand Down

0 comments on commit 675ebe7

Please sign in to comment.