Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Commit

Permalink
removing the TPR installer (#543)
Browse files Browse the repository at this point in the history
  • Loading branch information
arschles authored and pmorie committed Mar 28, 2017
1 parent 622d930 commit 2f0aebc
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 28 deletions.
4 changes: 2 additions & 2 deletions cmd/apiserver/app/server/run_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}

Expand Down
24 changes: 6 additions & 18 deletions pkg/storage/tpr/install_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand All @@ -90,7 +82,7 @@ func (i *Installer) InstallTypes() error {
glog.Infof("Error polling for TPR status:", err)
}
}
}(tpr, i.tprs)
}(tpr, cl)
}

wg.Wait()
Expand All @@ -110,7 +102,3 @@ func (i *Installer) InstallTypes() error {

return nil
}

func (e ErrTPRInstall) Error() string {
return e.errMsg
}
18 changes: 10 additions & 8 deletions pkg/storage/tpr/install_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 2f0aebc

Please sign in to comment.