Skip to content

Commit

Permalink
call Run on operator directly instead of manually setting up informers
Browse files Browse the repository at this point in the history
also rewrite metrics to list resources directly rather than listing custom
resources (was causing the unit test to crash, maybe something isn't faked
looking up that way?)
  • Loading branch information
Jeff Peeler committed Oct 12, 2018
1 parent ba84266 commit ec652c6
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 32 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/operators/catalog/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
op.syncCatalogSources,
nil,
"catsrc",
metrics.NewMetricsCatalogSource(op.Operator.OpClient),
metrics.NewMetricsCatalogSource(op.client),
)
for _, informer := range catsrcQueueInformer {
op.RegisterQueueInformer(informer)
Expand All @@ -120,7 +120,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
op.syncInstallPlans,
nil,
"installplan",
metrics.NewMetricsInstallPlan(op.Operator.OpClient),
metrics.NewMetricsInstallPlan(op.client),
)
for _, informer := range ipQueueInformers {
op.RegisterQueueInformer(informer)
Expand All @@ -134,7 +134,7 @@ func NewOperator(kubeconfigPath string, wakeupInterval time.Duration, operatorNa
op.syncSubscriptions,
nil,
"subscription",
metrics.NewMetricsSubscription(op.Operator.OpClient),
metrics.NewMetricsSubscription(op.client),
)
op.subQueue = subscriptionQueue
for _, informer := range subscriptionQueueInformers {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/operators/olm/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func NewOperator(crClient versioned.Interface, opClient operatorclient.ClientInt
op.syncClusterServiceVersion,
nil,
"csv",
metrics.NewMetricsCSV(op.Operator.OpClient),
metrics.NewMetricsCSV(op.client),
)
for _, informer := range queueInformers {
op.RegisterQueueInformer(informer)
Expand Down
13 changes: 3 additions & 10 deletions pkg/controller/operators/olm/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/informers"
k8sfake "k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/tools/cache"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"
apiregistrationfake "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/fake"

Expand Down Expand Up @@ -1245,14 +1243,9 @@ func TestSyncOperatorGroups(t *testing.T) {
require.NoError(t, err)

stopCh := make(chan struct{})
informerFactory := informers.NewSharedInformerFactory(op.OpClient.KubernetesInterface(), 1*time.Second)
deployInformer := informerFactory.Apps().V1().Deployments()
for _, informer := range []cache.SharedIndexInformer{deployInformer.Informer()} {
go informer.Run(stopCh)
}
op.deploymentLister[testNS] = deployInformer.Lister()
informerFactory.Start(stopCh)
informerFactory.WaitForCacheSync(stopCh)
defer func() { stopCh <- struct{}{} }()
ready, _ := op.Run(stopCh)
<-ready

// Could not put this in initialObjs - got "no kind is registered for the type v1alpha2.OperatorGroup"
op.client.OperatorsV1alpha2().OperatorGroups(tc.inputGroup.Namespace).Create(&tc.inputGroup)
Expand Down
35 changes: 17 additions & 18 deletions pkg/metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package metrics

import (
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/lib/operatorclient"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned"
"github.com/prometheus/client_golang/prometheus"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
Expand All @@ -12,15 +11,15 @@ type MetricsProvider interface {
}

type metricsCSV struct {
opClient operatorclient.ClientInterface
client versioned.Interface
}

func NewMetricsCSV(opClient operatorclient.ClientInterface) MetricsProvider {
return &metricsCSV{opClient}
func NewMetricsCSV(client versioned.Interface) MetricsProvider {
return &metricsCSV{client}
}

func (m *metricsCSV) HandleMetrics() error {
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.ClusterServiceVersionKind)
cList, err := m.client.OperatorsV1alpha1().ClusterServiceVersions(metav1.NamespaceAll).List(metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -29,15 +28,15 @@ func (m *metricsCSV) HandleMetrics() error {
}

type metricsInstallPlan struct {
opClient operatorclient.ClientInterface
client versioned.Interface
}

func NewMetricsInstallPlan(opClient operatorclient.ClientInterface) MetricsProvider {
return &metricsInstallPlan{opClient}
func NewMetricsInstallPlan(client versioned.Interface) MetricsProvider {
return &metricsInstallPlan{client}
}

func (m *metricsInstallPlan) HandleMetrics() error {
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.InstallPlanKind)
cList, err := m.client.OperatorsV1alpha1().InstallPlans(metav1.NamespaceAll).List(metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -46,15 +45,15 @@ func (m *metricsInstallPlan) HandleMetrics() error {
}

type metricsSubscription struct {
opClient operatorclient.ClientInterface
client versioned.Interface
}

func NewMetricsSubscription(opClient operatorclient.ClientInterface) MetricsProvider {
return &metricsSubscription{opClient}
func NewMetricsSubscription(client versioned.Interface) MetricsProvider {
return &metricsSubscription{client}
}

func (m *metricsSubscription) HandleMetrics() error {
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.SubscriptionKind)
cList, err := m.client.OperatorsV1alpha1().Subscriptions(metav1.NamespaceAll).List(metav1.ListOptions{})
if err != nil {
return err
}
Expand All @@ -63,16 +62,16 @@ func (m *metricsSubscription) HandleMetrics() error {
}

type metricsCatalogSource struct {
opClient operatorclient.ClientInterface
client versioned.Interface
}

func NewMetricsCatalogSource(opClient operatorclient.ClientInterface) MetricsProvider {
return &metricsCatalogSource{opClient}
func NewMetricsCatalogSource(client versioned.Interface) MetricsProvider {
return &metricsCatalogSource{client}

}

func (m *metricsCatalogSource) HandleMetrics() error {
cList, err := m.opClient.ListCustomResource(v1alpha1.GroupName, v1alpha1.GroupVersion, metav1.NamespaceAll, v1alpha1.CatalogSourceKind)
cList, err := m.client.OperatorsV1alpha1().CatalogSources(metav1.NamespaceAll).List(metav1.ListOptions{})
if err != nil {
return err
}
Expand Down

0 comments on commit ec652c6

Please sign in to comment.