Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref(mode): optimize service catalog lookup construction #232

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 0 additions & 40 deletions mode/utils/mode_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/deis/steward/mode/helm"
"google.golang.org/grpc"
"k8s.io/client-go/1.4/kubernetes"
"k8s.io/client-go/1.4/pkg/api"
"k8s.io/client-go/1.4/pkg/api/errors"
"k8s.io/client-go/1.4/rest"
)
Expand Down Expand Up @@ -102,42 +101,3 @@ func Run(

return cleanupFunc, nil
}

// Does the following:
//
// 1. fetches the service catalog from the backing broker
// 2. checks the 3pr for already-existing entries, and errors if one already exists
// 3. if none error-ed in #2, publishes 3prs for all of the catalog entries
//
// returns all of the entries it wrote into the catalog, or an error
func publishCatalog(
brokerName string,
cataloger mode.Cataloger,
catalogEntries k8s.ServiceCatalogInteractor,
) ([]*k8s.ServiceCatalogEntry, error) {

services, err := cataloger.List()
if err != nil {
return nil, errGettingServiceCatalog{Original: err}
}

published := []*k8s.ServiceCatalogEntry{}
// Write all entries from cf catalog to 3prs
for _, service := range services {
for _, plan := range service.Plans {
entry := k8s.NewServiceCatalogEntry(brokerName, api.ObjectMeta{}, service.ServiceInfo, plan)
if _, err := catalogEntries.Create(entry); err != nil {
logger.Errorf(
"error publishing catalog entry (svc_name, plan_name) = (%s, %s) (%s), continuing",
entry.Info.Name,
entry.Plan.Name,
err,
)
continue
}
published = append(published, entry)
}
}

return published, nil
}
46 changes: 46 additions & 0 deletions mode/utils/publish_catalog.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package utils

import (
"github.com/deis/steward/k8s"
"github.com/deis/steward/mode"
"k8s.io/client-go/1.4/pkg/api"
)

// Does the following:
//
// 1. fetches the service catalog from the backing broker
// 2. checks the 3pr for already-existing entries, and errors if one already exists
// 3. if none error-ed in #2, publishes 3prs for all of the catalog entries
//
// returns all of the entries it wrote into the catalog, or an error
func publishCatalog(
brokerName string,
cataloger mode.Cataloger,
catalogEntries k8s.ServiceCatalogInteractor,
) ([]*k8s.ServiceCatalogEntry, error) {

services, err := cataloger.List()
if err != nil {
return nil, errGettingServiceCatalog{Original: err}
}

published := []*k8s.ServiceCatalogEntry{}
// Write all entries from cf catalog to 3prs
for _, service := range services {
for _, plan := range service.Plans {
entry := k8s.NewServiceCatalogEntry(brokerName, api.ObjectMeta{}, service.ServiceInfo, plan)
if _, err := catalogEntries.Create(entry); err != nil {
logger.Errorf(
"error publishing catalog entry (svc_name, plan_name) = (%s, %s) (%s), continuing",
entry.Info.Name,
entry.Plan.Name,
err,
)
continue
}
published = append(published, entry)
}
}

return published, nil
}