Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Commit

Permalink
Move Catalog into store package, and minor catalog changes
Browse files Browse the repository at this point in the history
  • Loading branch information
James Haggerty committed Feb 14, 2018
1 parent 7a84366 commit 136fc0a
Show file tree
Hide file tree
Showing 11 changed files with 80 additions and 79 deletions.
2 changes: 1 addition & 1 deletion cmd/smith/app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/apis/smith/v1:go_default_library",
"//pkg/catalog:go_default_library",
"//pkg/cleanup:go_default_library",
"//pkg/cleanup/types:go_default_library",
"//pkg/client:go_default_library",
Expand All @@ -22,6 +21,7 @@ go_library(
"//pkg/store:go_default_library",
"//vendor/github.com/ash2k/stager:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/informers_generated/externalversions/servicecatalog/v1beta1:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/go.uber.org/zap:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
Expand Down
34 changes: 20 additions & 14 deletions cmd/smith/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/atlassian/smith/pkg/catalog"
"github.com/atlassian/smith/pkg/cleanup"
clean_types "github.com/atlassian/smith/pkg/cleanup/types"
"github.com/atlassian/smith/pkg/client"
Expand All @@ -26,6 +25,7 @@ import (

"github.com/ash2k/stager"
scClientset "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset"
sc_v1b1inf "github.com/kubernetes-incubator/service-catalog/pkg/client/informers_generated/externalversions/servicecatalog/v1beta1"
"github.com/pkg/errors"
"go.uber.org/zap"
core_v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -112,15 +112,22 @@ func (a *App) Run(ctx context.Context) error {
}

// Informers
var infs []cache.SharedIndexInformer
// We don't add these to 'infs' because they're added later as part of
// resourceInfs processing.
bundleInf := client.BundleInformer(bundleClient.SmithV1(), a.Namespace, a.ResyncPeriod)
crdInf := apiext_v1b1inf.NewCustomResourceDefinitionInformer(crdClient, a.ResyncPeriod, cache.Indexers{})
crdStore, err := store.NewCrd(crdInf)
if err != nil {
return err
}
var catalogger *catalog.Catalog
var catalog *store.Catalog
if a.ServiceCatalogSupport {
catalogger = catalog.NewCatalog(scClient, a.ResyncPeriod)
serviceClassInf := sc_v1b1inf.NewClusterServiceClassInformer(scClient, a.ResyncPeriod, cache.Indexers{})
infs = append(infs, serviceClassInf)
servicePlanInf := sc_v1b1inf.NewClusterServicePlanInformer(scClient, a.ResyncPeriod, cache.Indexers{})
infs = append(infs, servicePlanInf)
catalog = store.NewCatalog(serviceClassInf, servicePlanInf)
}

// Ready Checker
Expand Down Expand Up @@ -192,7 +199,7 @@ func (a *App) Run(ctx context.Context) error {
Namespace: a.Namespace,
PluginContainers: pluginContainers,
Scheme: scheme,
Catalog: catalogger,
Catalog: catalog,
}
cntrlr.Prepare(ctx, crdInf, resourceInfs)

Expand All @@ -204,21 +211,20 @@ func (a *App) Run(ctx context.Context) error {
defer stgr.Shutdown()
stage := stgr.NextStage()

infs := make([]cache.InformerSynced, 0)
// Add all informers to Multi store and start them
// Add resource informers to Multi store (not ServiceClass/Plan informers, ...)
for gvk, inf := range resourceInfs {
multiStore.AddInformer(gvk, inf)
stage.StartWithChannel(inf.Run) // Must be after AddInformer()
infs = append(infs, inf.HasSynced)
infs = append(infs, inf)
}
if catalogger != nil {
for _, inf := range catalogger.InformersToRegister() {
stage.StartWithChannel(inf.Run)
infs = append(infs, inf.HasSynced)
}

// Start all informers then wait on them
infCacheSyncs := make([]cache.InformerSynced, len(infs))
for i, inf := range infs {
stage.StartWithChannel(inf.Run) // Must be after AddInformer()
infCacheSyncs[i] = inf.HasSynced
}
a.Logger.Info("Waiting for informers to sync")
if !cache.WaitForCacheSync(ctx.Done(), infs...) {
if !cache.WaitForCacheSync(ctx.Done(), infCacheSyncs...) {
return ctx.Err()
}

Expand Down
15 changes: 0 additions & 15 deletions pkg/catalog/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,15 +0,0 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")

go_library(
name = "go_default_library",
srcs = ["catalog.go"],
importpath = "github.com/atlassian/smith/pkg/catalog",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/informers_generated/externalversions/servicecatalog/v1beta1:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/client-go/tools/cache:go_default_library",
],
)
2 changes: 1 addition & 1 deletion pkg/controller/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ go_library(
deps = [
"//:go_default_library",
"//pkg/apis/smith/v1:go_default_library",
"//pkg/catalog:go_default_library",
"//pkg/client/clientset_generated/clientset/typed/smith/v1:go_default_library",
"//pkg/plugin:go_default_library",
"//pkg/resources:go_default_library",
"//pkg/store:go_default_library",
"//pkg/util:go_default_library",
"//pkg/util/graph:go_default_library",
"//pkg/util/logz:go_default_library",
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/bundle_sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (
"fmt"

smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/atlassian/smith/pkg/catalog"
smithClient_v1 "github.com/atlassian/smith/pkg/client/clientset_generated/clientset/typed/smith/v1"
"github.com/atlassian/smith/pkg/plugin"
"github.com/atlassian/smith/pkg/store"
"github.com/atlassian/smith/pkg/util/graph"
"github.com/atlassian/smith/pkg/util/logz"

Expand All @@ -31,7 +31,7 @@ type bundleSyncTask struct {
processedResources map[smith_v1.ResourceName]*resourceInfo
pluginContainers map[smith_v1.PluginName]plugin.PluginContainer
scheme *runtime.Scheme
catalog *catalog.Catalog
catalog *store.Catalog
}

// Parse bundle, build resource graph, traverse graph, assert each resource exists.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"time"

smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/atlassian/smith/pkg/catalog"
smithClient_v1 "github.com/atlassian/smith/pkg/client/clientset_generated/clientset/typed/smith/v1"
"github.com/atlassian/smith/pkg/plugin"
"github.com/atlassian/smith/pkg/store"
"github.com/atlassian/smith/pkg/util/logz"

"github.com/ash2k/stager/wait"
Expand Down Expand Up @@ -55,7 +55,7 @@ type BundleController struct {
PluginContainers map[smith_v1.PluginName]plugin.PluginContainer
Scheme *runtime.Scheme

Catalog *catalog.Catalog
Catalog *store.Catalog
}

// Prepare prepares the controller to be run.
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/resource_sync_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package controller
import (
"github.com/atlassian/smith"
smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/atlassian/smith/pkg/catalog"
"github.com/atlassian/smith/pkg/plugin"
"github.com/atlassian/smith/pkg/store"
"github.com/atlassian/smith/pkg/util"
"github.com/atlassian/smith/pkg/util/logz"

Expand Down Expand Up @@ -74,7 +74,7 @@ type resourceSyncTask struct {
processedResources map[smith_v1.ResourceName]*resourceInfo
pluginContainers map[smith_v1.PluginName]plugin.PluginContainer
scheme *runtime.Scheme
catalog *catalog.Catalog
catalog *store.Catalog
}

func (st *resourceSyncTask) processResource(res *smith_v1.Resource) resourceInfo {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller_test/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ go_test(
"//examples/sleeper:go_default_library",
"//examples/sleeper/pkg/apis/sleeper/v1:go_default_library",
"//pkg/apis/smith/v1:go_default_library",
"//pkg/catalog:go_default_library",
"//pkg/cleanup:go_default_library",
"//pkg/cleanup/types:go_default_library",
"//pkg/client:go_default_library",
Expand All @@ -44,6 +43,7 @@ go_test(
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset/fake:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/client/informers_generated/externalversions/servicecatalog/v1beta1:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/github.com/stretchr/testify/assert:go_default_library",
"//vendor/github.com/stretchr/testify/require:go_default_library",
Expand Down
35 changes: 22 additions & 13 deletions pkg/controller_test/zz_plumbing_for_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/atlassian/smith/examples/sleeper"
sleeper_v1 "github.com/atlassian/smith/examples/sleeper/pkg/apis/sleeper/v1"
smith_v1 "github.com/atlassian/smith/pkg/apis/smith/v1"
"github.com/atlassian/smith/pkg/catalog"
"github.com/atlassian/smith/pkg/cleanup"
clean_types "github.com/atlassian/smith/pkg/cleanup/types"
"github.com/atlassian/smith/pkg/client"
Expand All @@ -32,6 +31,7 @@ import (
sc_v1b1 "github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
scClientset "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset"
scFake "github.com/kubernetes-incubator/service-catalog/pkg/client/clientset_generated/clientset/fake"
sc_v1b1inf "github.com/kubernetes-incubator/service-catalog/pkg/client/informers_generated/externalversions/servicecatalog/v1beta1"
"github.com/pkg/errors"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -162,8 +162,12 @@ func (tc *testCase) run(t *testing.T) {
for _, reactor := range tc.crdReactors {
crdClient.AddReactor(reactor.verb, reactor.resource, reactor.reactor(t))
}

// Informers
var infs []cache.SharedIndexInformer

var scClient scClientset.Interface
var catalogger *catalog.Catalog
var catalog *store.Catalog
if tc.enableServiceCatalog {
scClientFake := scFake.NewSimpleClientset(append(
tc.scClientObjects,
Expand Down Expand Up @@ -205,7 +209,11 @@ func (tc *testCase) run(t *testing.T) {
for _, reactor := range tc.scReactors {
scClientFake.AddReactor(reactor.verb, reactor.resource, reactor.reactor(t))
}
catalogger = catalog.NewCatalog(scClient, 0)
serviceClassInf := sc_v1b1inf.NewClusterServiceClassInformer(scClient, 0, cache.Indexers{})
infs = append(infs, serviceClassInf)
servicePlanInf := sc_v1b1inf.NewClusterServicePlanInformer(scClient, 0, cache.Indexers{})
infs = append(infs, servicePlanInf)
catalog = store.NewCatalog(serviceClassInf, servicePlanInf)
}

crdInf := apiext_v1b1inf.NewCustomResourceDefinitionInformer(crdClient, 0, cache.Indexers{})
Expand Down Expand Up @@ -298,27 +306,28 @@ func (tc *testCase) run(t *testing.T) {
Namespace: tc.namespace,
PluginContainers: pluginContainers,
Scheme: scheme,
Catalog: catalogger,
Catalog: catalog,
}
prepare := func(ctx context.Context) {
cntrlr.Prepare(ctx, crdInf, resourceInfs)

resourceInfs[apiext_v1b1.SchemeGroupVersion.WithKind("CustomResourceDefinition")] = crdInf
resourceInfs[smith_v1.BundleGVK] = bundleInf
infs := make([]cache.InformerSynced, 0, len(resourceInfs))
stage := stgr.NextStage()

// Add resource informers to Multi store (not ServiceClass/Plan informers, ...)
for gvk, inf := range resourceInfs {
multiStore.AddInformer(gvk, inf)
stage.StartWithChannel(inf.Run)
infs = append(infs, inf.HasSynced)
infs = append(infs, inf)
}
if catalogger != nil {
for _, inf := range catalogger.InformersToRegister() {
stage.StartWithChannel(inf.Run)
infs = append(infs, inf.HasSynced)
}

// Start all informers then wait on them
infCacheSyncs := make([]cache.InformerSynced, len(infs))
for i, inf := range infs {
stage.StartWithChannel(inf.Run) // Must be after AddInformer()
infCacheSyncs[i] = inf.HasSynced
}
require.True(t, cache.WaitForCacheSync(ctx.Done(), infs...))
require.True(t, cache.WaitForCacheSync(ctx.Done(), infCacheSyncs...))
}

defer tc.verifyActions(t)
Expand Down
2 changes: 2 additions & 0 deletions pkg/store/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
srcs = [
"bundle.go",
"catalog.go",
"crd.go",
"multi.go",
],
Expand All @@ -12,6 +13,7 @@ go_library(
deps = [
"//pkg/apis/smith/v1:go_default_library",
"//pkg/plugin:go_default_library",
"//vendor/github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
Expand Down
Loading

0 comments on commit 136fc0a

Please sign in to comment.