Skip to content

Commit

Permalink
Update tests and code for new grpc library
Browse files Browse the repository at this point in the history
Signed-off-by: perdasilva <perdasilva@redhat.com>
  • Loading branch information
perdasilva committed Jun 9, 2022
1 parent dd45eb1 commit 60959e5
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 10 deletions.
2 changes: 2 additions & 0 deletions pkg/controller/operators/catalog/operator.go
Expand Up @@ -474,6 +474,8 @@ func (o *Operator) syncSourceState(state grpc.SourceState) {
metrics.RegisterCatalogSourceState(state.Key.Name, state.Key.Namespace, state.State)

switch state.State {
case connectivity.Idle:
fallthrough
case connectivity.Ready:
o.resolverSourceProvider.Invalidate(resolvercache.SourceKey(state.Key))
if o.namespace == state.Key.Namespace {
Expand Down
3 changes: 3 additions & 0 deletions pkg/controller/registry/grpc/source_test.go
Expand Up @@ -134,6 +134,7 @@ func TestConnectionEvents(t *testing.T) {
{Name: "test", Namespace: "test"}: {
connectivity.Connecting,
connectivity.Ready,
connectivity.Idle,
},
},
},
Expand All @@ -143,10 +144,12 @@ func TestConnectionEvents(t *testing.T) {
{Name: "test", Namespace: "test"}: {
connectivity.Connecting,
connectivity.Ready,
connectivity.Idle,
},
{Name: "test2", Namespace: "test2"}: {
connectivity.Connecting,
connectivity.Ready,
connectivity.Idle,
},
},
},
Expand Down
75 changes: 75 additions & 0 deletions pkg/fakes/fake_registry_store.go

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

2 changes: 2 additions & 0 deletions pkg/package-server/provider/registry.go
Expand Up @@ -226,6 +226,8 @@ func (p *RegistryProvider) syncSourceState(state registrygrpc.SourceState) {

var err error
switch state.State {
case connectivity.Idle:
fallthrough
case connectivity.Ready:
var client *registryClient
client, err = p.registryClient(key)
Expand Down
11 changes: 8 additions & 3 deletions test/e2e/catalog_e2e_test.go
Expand Up @@ -441,9 +441,14 @@ var _ = Describe("Starting CatalogSource e2e tests", func() {
Expect(err).ShouldNot(HaveOccurred())

// Check pod created
initialPods, err := c.KubernetesInterface().CoreV1().Pods(ns.GetName()).List(context.Background(), metav1.ListOptions{LabelSelector: "olm.configMapResourceVersion=" + configMap.ResourceVersion})
Expect(err).ShouldNot(HaveOccurred())
Expect(initialPods.Items).To(HaveLen(1))
Eventually(func() int {
initialPods, err := c.KubernetesInterface().CoreV1().Pods(ns.GetName()).List(context.Background(), metav1.ListOptions{LabelSelector: "olm.configMapResourceVersion=" + configMap.ResourceVersion})
if err != nil {
GinkgoWriter.Printf("warning: error listing pods: %s", err)
return -1
}
return len(initialPods.Items)
}).Should(Equal(1))

// delete the first catalog
cleanupSource()
Expand Down
4 changes: 2 additions & 2 deletions test/e2e/magic_catalog.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"google.golang.org/grpc/connectivity"
corev1 "k8s.io/api/core/v1"
k8serror "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
Expand All @@ -18,7 +19,6 @@ const (
olmCatalogLabel string = "olm.catalogSource"
catalogMountPath string = "/opt/olm"
catalogServicePort int32 = 50051
catalogReadyState string = "READY"
)

type MagicCatalog interface {
Expand Down Expand Up @@ -80,7 +80,7 @@ func catalogSourceIsReady(ctx context.Context, c k8scontrollerclient.Client, cs
return false, err
}
state := cs.Status.GRPCConnectionState.LastObservedState
if state != catalogReadyState {
if state != connectivity.Ready.String() && state != connectivity.Idle.String() {
return false, nil
}
return true, nil
Expand Down
4 changes: 3 additions & 1 deletion test/e2e/subscription_e2e_test.go
Expand Up @@ -16,6 +16,7 @@ import (
configv1 "github.com/openshift/api/config/v1"
configv1client "github.com/openshift/client-go/config/clientset/versioned/typed/config/v1"
"github.com/stretchr/testify/require"
"google.golang.org/grpc/connectivity"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
Expand Down Expand Up @@ -2920,8 +2921,9 @@ func updateInternalCatalog(t GinkgoTInterface, c operatorclient.ClientInterface,
_, err = fetchCatalogSourceOnStatus(crc, catalogSourceName, namespace, func(catalog *operatorsv1alpha1.CatalogSource) bool {
before := fetchedInitialCatalog.Status.ConfigMapResource
after := catalog.Status.ConfigMapResource
lastObservedState := catalog.Status.GRPCConnectionState.LastObservedState
if after != nil && after.LastUpdateTime.After(before.LastUpdateTime.Time) && after.ResourceVersion != before.ResourceVersion &&
catalog.Status.GRPCConnectionState.LastConnectTime.After(after.LastUpdateTime.Time) && catalog.Status.GRPCConnectionState.LastObservedState == "READY" {
catalog.Status.GRPCConnectionState.LastConnectTime.After(after.LastUpdateTime.Time) && (lastObservedState == connectivity.Ready.String() || lastObservedState == connectivity.Idle.String()) {
fmt.Println("catalog updated")
return true
}
Expand Down
14 changes: 10 additions & 4 deletions test/e2e/util.go
Expand Up @@ -13,6 +13,7 @@ import (
. "github.com/onsi/gomega"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
Expand Down Expand Up @@ -337,11 +338,11 @@ func registryPodHealthy(address string) bool {
}

func catalogSourceRegistryPodSynced(catalog *operatorsv1alpha1.CatalogSource) bool {
registry := catalog.Status.RegistryServiceStatus
registryStatus := catalog.Status.RegistryServiceStatus
connState := catalog.Status.GRPCConnectionState
if registry != nil && connState != nil && !connState.LastConnectTime.IsZero() && connState.LastObservedState == "READY" {
fmt.Printf("catalog %s pod with address %s\n", catalog.GetName(), registry.Address())
return registryPodHealthy(registry.Address())
if registryStatus != nil && connState != nil && !connState.LastConnectTime.IsZero() && (connState.LastObservedState == connectivity.Ready.String() || connState.LastObservedState == connectivity.Idle.String()) {
fmt.Printf("catalog %s pod with address %s\n", catalog.GetName(), registryStatus.Address())
return registryPodHealthy(registryStatus.Address())
}
state := "NO_CONNECTION"
if connState != nil {
Expand Down Expand Up @@ -616,6 +617,11 @@ func createInternalCatalogSource(
Spec: operatorsv1alpha1.CatalogSourceSpec{
SourceType: "internal",
ConfigMap: configMap.GetName(),
UpdateStrategy: &operatorsv1alpha1.UpdateStrategy{
RegistryPoll: &operatorsv1alpha1.RegistryPoll{
RawInterval: "10s",
},
},
},
}

Expand Down

0 comments on commit 60959e5

Please sign in to comment.