diff --git a/cmd/apiserver/app/server/run_server.go b/cmd/apiserver/app/server/run_server.go index b24581f17d7..dff174a2d39 100644 --- a/cmd/apiserver/app/server/run_server.go +++ b/cmd/apiserver/app/server/run_server.go @@ -47,8 +47,7 @@ func RunServer(opts *ServiceCatalogServerOptions) error { func installTPRsToCore(cl clientset.Interface) func() error { return func() error { - installer := tpr.NewInstaller(cl.Extensions().ThirdPartyResources()) - if err := installer.InstallTypes(); err != nil { + if err := tpr.InstallTypes(cl.Extensions().ThirdPartyResources()); err != nil { glog.Errorf("Failed to install TPR types (%s)", err) return err } @@ -60,6 +59,7 @@ func runTPRServer(opts *ServiceCatalogServerOptions) error { tprOpts := opts.TPROptions glog.Infoln("Installing TPR types to the cluster") if err := tprOpts.InstallTPRsFunc(); err != nil { + glog.V(4).Infof("Installing TPR types failed, continuing anyway (%s)", err) return err } diff --git a/pkg/storage/tpr/install_types.go b/pkg/storage/tpr/install_types.go index bb01bc86fbb..c7eed213d67 100644 --- a/pkg/storage/tpr/install_types.go +++ b/pkg/storage/tpr/install_types.go @@ -42,26 +42,18 @@ type ErrTPRInstall struct { errMsg string } -// Installer takes in a client and exposes method for installing third party resources -type Installer struct { - tprs extensionsv1beta.ThirdPartyResourceInterface -} - -// NewInstaller is used to install third party resources -func NewInstaller(tprs extensionsv1beta.ThirdPartyResourceInterface) *Installer { - return &Installer{ - tprs: tprs, - } +func (e ErrTPRInstall) Error() string { + return e.errMsg } // InstallTypes installs all third party resource types to the cluster -func (i *Installer) InstallTypes() error { +func InstallTypes(cl extensionsv1beta.ThirdPartyResourceInterface) error { var wg sync.WaitGroup errMsg := make(chan string, len(thirdPartyResources)) for _, tpr := range thirdPartyResources { glog.Infof("Checking for existence of %s", tpr.Name) - if _, err := i.tprs.Get(tpr.Name); err == nil { + if _, err := cl.Get(tpr.Name); err == nil { glog.Infof("Found existing TPR %s", tpr.Name) continue } @@ -71,7 +63,7 @@ func (i *Installer) InstallTypes() error { wg.Add(1) go func(tpr v1beta1.ThirdPartyResource, client extensionsv1beta.ThirdPartyResourceInterface) { defer wg.Done() - if _, err := i.tprs.Create(&tpr); err != nil { + if _, err := cl.Create(&tpr); err != nil { errMsg <- fmt.Sprintf("%s: %s", tpr.Name, err) } else { glog.Infof("Created TPR '%s'", tpr.Name) @@ -90,7 +82,7 @@ func (i *Installer) InstallTypes() error { glog.Infof("Error polling for TPR status:", err) } } - }(tpr, i.tprs) + }(tpr, cl) } wg.Wait() @@ -110,7 +102,3 @@ func (i *Installer) InstallTypes() error { return nil } - -func (e ErrTPRInstall) Error() string { - return e.errMsg -} diff --git a/pkg/storage/tpr/install_types_test.go b/pkg/storage/tpr/install_types_test.go index 1bec654043c..73a8aaa8e63 100644 --- a/pkg/storage/tpr/install_types_test.go +++ b/pkg/storage/tpr/install_types_test.go @@ -61,8 +61,9 @@ func TestInstallTypesAllResources(t *testing.T) { }, ) - installer := NewInstaller(fakeClientset.Extensions().ThirdPartyResources()) - installer.InstallTypes() + if err := InstallTypes(fakeClientset.Extensions().ThirdPartyResources()); err != nil { + t.Fatalf("error installing types (%s)", err) + } expectTotal := len(thirdPartyResources) if createCallCount != expectTotal { @@ -96,8 +97,9 @@ func TestInstallTypesResourceExisted(t *testing.T) { }, ) - installer := NewInstaller(fakeClientset.Extensions().ThirdPartyResources()) - installer.InstallTypes() + if err := InstallTypes(fakeClientset.Extensions().ThirdPartyResources()); err != nil { + t.Fatalf("error installing (%s)", err) + } if createCallCount != len(thirdPartyResources)-1 { t.Errorf("Failed to skip 1 installed Third Party Resource") @@ -135,8 +137,7 @@ func TestInstallTypesErrors(t *testing.T) { }, ) - installer := NewInstaller(fakeClientset.Extensions().ThirdPartyResources()) - err := installer.InstallTypes() + err := InstallTypes(fakeClientset.Extensions().ThirdPartyResources()) errStr := err.Error() if !strings.Contains(errStr, "Error 1") && !strings.Contains(errStr, "Error 2") { @@ -170,8 +171,9 @@ func TestInstallTypesPolling(t *testing.T) { }, ) - installer := NewInstaller(fakeClientset.Extensions().ThirdPartyResources()) - installer.InstallTypes() + if err := InstallTypes(fakeClientset.Extensions().ThirdPartyResources()); err == nil { + t.Fatal("InstallTypes was supposed to error but didn't") + } for _, name := range getCallArgs { if name == serviceBrokerTPR.Name || name == serviceInstanceTPR.Name {