Skip to content

Commit

Permalink
feat(registry): remove in-mem registry implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
ecordell committed Jan 8, 2019
1 parent d22f8b4 commit 8224b04
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 2,103 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ setup-bare: clean e2e.namespace
. ./scripts/install_bare.sh $(shell cat ./e2e.namespace) test/e2e/resources

e2e:
go test -v -timeout 30m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager
go test -v -timeout 50m ./test/e2e/... -namespace=openshift-operators -kubeconfig=${KUBECONFIG} -olmNamespace=openshift-operator-lifecycle-manager

e2e-local:
. ./scripts/build_local.sh
Expand Down
2 changes: 1 addition & 1 deletion pkg/api/apis/operators/v1alpha1/catalogsource_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package v1alpha1

import (
"fmt"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

Expand Down
77 changes: 44 additions & 33 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,16 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca
}

// Sync any dependent Subscriptions
o.syncDependentSubscriptions(logger, out.GetName(), out.GetNamespace())

return nil
}

func (o *Operator) syncDependentSubscriptions(logger *logrus.Entry, catalogSource, catalogSourceNamespace string) {
subs, err := o.lister.OperatorsV1alpha1().SubscriptionLister().List(labels.Everything())
if err != nil {
logger.Warnf("could not list Subscriptions")
return nil
return
}

for _, sub := range subs {
Expand All @@ -391,13 +397,11 @@ func (o *Operator) syncConfigMapSource(logger *logrus.Entry, catsrc *v1alpha1.Ca
catalogNamespace = o.namespace
}
logger.Debug("checking subscription")
if sub.Spec.CatalogSource == out.GetName() && catalogNamespace == out.GetNamespace() {
if sub.Spec.CatalogSource == catalogSource && catalogNamespace == catalogSourceNamespace {
logger.Debug("requeueing subscription because catalog changed")
o.requeueSubscription(sub.GetName(), sub.GetNamespace())
}
}

return nil
}

func (o *Operator) syncSubscriptions(obj interface{}) error {
Expand Down Expand Up @@ -427,6 +431,37 @@ func (o *Operator) syncSubscriptions(obj interface{}) error {
return nil
}

// get the set of sources that should be used for resolution and best-effort get their connections working
resolverSources := o.ensureResolverSources(logger, namespace)

// resolve a set of steps to apply to a cluster, a set of subscriptions to create/update, and any errors
steps, subs, err := o.resolver.ResolveSteps(namespace, resolver.NewNamespaceSourceQuerier(resolverSources))
if err != nil {
return err
}

// any subscription in the namespace with manual approval will force generated installplans to be manual
// TODO: this is an odd artifact of the older resolver, and will probably confuse users. approval mode could be on the operatorgroup?
installPlanApproval := v1alpha1.ApprovalAutomatic
for _, sub := range subs {
if sub.Spec.InstallPlanApproval == v1alpha1.ApprovalManual {
installPlanApproval = v1alpha1.ApprovalManual
break
}
}

installplanReference, err := o.createInstallPlan(namespace, subs, installPlanApproval, steps)
if err != nil {
return err
}

if err := o.ensureSubscriptionInstallPlanState(namespace, subs, installplanReference); err != nil {
return err
}
return nil
}

func (o *Operator) ensureResolverSources(logger *logrus.Entry, namespace string) map[resolver.CatalogKey]registryclient.Interface {
// TODO: record connection status onto an object
resolverSources := make(map[resolver.CatalogKey]registryclient.Interface, 0)
func() {
Expand All @@ -449,42 +484,18 @@ func (o *Operator) syncSubscriptions(obj interface{}) error {
logger = logger.WithField("resolverSource", k)
logger.WithField("clientState", client.Conn.GetState()).Debug("source")
if client.Conn.GetState() == connectivity.TransientFailure {
logger.WithField("clientState", client.Conn.GetState()).Debug("resetting connection")
client.Conn.ResetConnectBackoff()
logger.WithField("clientState", client.Conn.GetState()).Debug("waiting for connection")
ctx, _ := context.WithTimeout(context.TODO(), 5*time.Second)
changed := client.Conn.WaitForStateChange(ctx, connectivity.TransientFailure)
if !changed {
logger.WithField("clientState", client.Conn.GetState()).Debug("source in transient failure and didn't recover")
client.Conn.ResetConnectBackoff()
} else {
logger.WithField("clientState", client.Conn.GetState()).Debug("connection re-established")
}
logger.WithField("clientState", client.Conn.GetState()).Debug("connection successfully reset")
}
}

// resolve a set of steps to apply to a cluster, a set of subscriptions to create/update, and any errors
steps, subs, err := o.resolver.ResolveSteps(sub.GetNamespace(), resolver.NewNamespaceSourceQuerier(resolverSources))
if err != nil {
return err
}

// any subscription in the namespace with manual approval will force generated installplans to be manual
// TODO: this is an odd artifact of the older resolver, and will probably confuse users. approval mode could be on the operatorgroup?
installPlanApproval := v1alpha1.ApprovalAutomatic
for _, sub := range subs {
if sub.Spec.InstallPlanApproval == v1alpha1.ApprovalManual {
installPlanApproval = v1alpha1.ApprovalManual
break
}
}

installplanReference, err := o.createInstallPlan(namespace, subs, installPlanApproval, steps)
if err != nil {
return err
}

if err := o.ensureSubscriptionInstallPlanState(namespace, subs, installplanReference); err != nil {
return err
}
return nil
return resolverSources
}

func (o *Operator) nothingToUpdate(logger *logrus.Entry, sub *v1alpha1.Subscription) bool {
Expand Down
100 changes: 50 additions & 50 deletions pkg/controller/operators/catalog/subscriptions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ func TestSyncSubscriptions(t *testing.T) {
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.1",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.1",
Manifest: "{}",
},
},
},
Expand Down Expand Up @@ -150,11 +150,11 @@ func TestSyncSubscriptions(t *testing.T) {
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.1",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.1",
Manifest: "{}",
},
},
},
Expand Down Expand Up @@ -195,11 +195,11 @@ func TestSyncSubscriptions(t *testing.T) {
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
},
},
},
Expand Down Expand Up @@ -279,11 +279,11 @@ func TestSyncSubscriptions(t *testing.T) {
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
},
},
},
Expand Down Expand Up @@ -324,35 +324,35 @@ func TestSyncSubscriptions(t *testing.T) {
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
},
},
{
Resolving: "csv.v.2",
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "dep.v.1",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "dep.v.1",
Manifest: "{}",
},
},
{
Resolving: "csv.v.2",
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.SubscriptionKind,
Name: "sub-dep",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.SubscriptionKind,
Name: "sub-dep",
Manifest: "{}",
},
},
},
Expand Down Expand Up @@ -433,35 +433,35 @@ func TestSyncSubscriptions(t *testing.T) {
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "csv.v.2",
Manifest: "{}",
},
},
{
Resolving: "csv.v.2",
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "dep.v.1",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
Name: "dep.v.1",
Manifest: "{}",
},
},
{
Resolving: "csv.v.2",
Resource: v1alpha1.StepResource{
CatalogSource: "src",
CatalogSourceNamespace: testNamespace,
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.SubscriptionKind,
Name: "sub-dep",
Manifest: "{}",
Group: v1alpha1.GroupName,
Version: v1alpha1.GroupVersion,
Kind: v1alpha1.SubscriptionKind,
Name: "sub-dep",
Manifest: "{}",
},
},
},
Expand Down
Loading

0 comments on commit 8224b04

Please sign in to comment.