-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactors storage code for localConfigProvider.
- Loading branch information
Showing
20 changed files
with
1,022 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,84 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/openshift/odo/pkg/localConfigProvider" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// StorageCreate sets the storage related information in the local configuration | ||
func (lci *LocalConfigInfo) StorageCreate(name, size, path string) (ComponentStorageSettings, error) { | ||
storage := ComponentStorageSettings{ | ||
Name: name, | ||
Size: size, | ||
Path: path, | ||
// GetStorage gets the storage with the given name | ||
func (lci *LocalConfigInfo) GetStorage(storageName string) *localConfigProvider.LocalStorage { | ||
for _, storage := range lci.ListStorage() { | ||
if storageName == storage.Name { | ||
return &storage | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
// CreateStorage sets the storage related information in the local configuration | ||
func (lci *LocalConfigInfo) CreateStorage(storage localConfigProvider.LocalStorage) error { | ||
err := lci.SetConfiguration("storage", storage) | ||
if err != nil { | ||
return ComponentStorageSettings{}, err | ||
return err | ||
} | ||
return storage, err | ||
return err | ||
} | ||
|
||
func (lci *LocalConfigInfo) StorageExists(storageName string) bool { | ||
for _, storage := range lci.GetStorage() { | ||
if storageName == storage.Name { | ||
return true | ||
} | ||
// ListStorage gets all the storage from the config | ||
func (lci *LocalConfigInfo) ListStorage() []localConfigProvider.LocalStorage { | ||
if lci.componentSettings.Storage == nil { | ||
return []localConfigProvider.LocalStorage{} | ||
} | ||
return false | ||
} | ||
|
||
func (lci *LocalConfigInfo) StorageList() ([]ComponentStorageSettings, error) { | ||
storageConfigList := lci.GetStorage() | ||
var storageList []ComponentStorageSettings | ||
for _, storage := range storageConfigList { | ||
storageList = append(storageList, ComponentStorageSettings{ | ||
var storageList []localConfigProvider.LocalStorage | ||
for _, storage := range *lci.componentSettings.Storage { | ||
storageList = append(storageList, localConfigProvider.LocalStorage{ | ||
Name: storage.Name, | ||
Path: storage.Path, | ||
Size: storage.Size, | ||
}) | ||
} | ||
return storageList, nil | ||
return storageList | ||
} | ||
|
||
func (lci *LocalConfigInfo) ValidateStorage(storageName, storagePath string) error { | ||
for _, storage := range lci.GetStorage() { | ||
if storage.Name == storageName { | ||
return errors.Errorf("there already is a storage with the name %s", storageName) | ||
} | ||
if storage.Path == storagePath { | ||
return errors.Errorf("there already is a storage mounted at %s", storagePath) | ||
} | ||
// DeleteStorage deletes the storage with the given name | ||
func (lci *LocalConfigInfo) DeleteStorage(name string) error { | ||
storage := lci.GetStorage(name) | ||
if storage == nil { | ||
return errors.Errorf("storage named %s doesn't exists", name) | ||
} | ||
return nil | ||
return lci.DeleteFromConfigurationList("storage", name) | ||
} | ||
|
||
func (lci *LocalConfigInfo) StorageDelete(name string) error { | ||
exists := lci.StorageExists(name) | ||
if !exists { | ||
return errors.Errorf("storage named %s doesn't exists", name) | ||
// CompleteStorage completes the given storage | ||
func (lci *LocalConfigInfo) CompleteStorage(storage *localConfigProvider.LocalStorage) {} | ||
|
||
// ValidateStorage validates the given storage | ||
func (lci *LocalConfigInfo) ValidateStorage(storage localConfigProvider.LocalStorage) error { | ||
if storage.Size == "" || storage.Path == "" { | ||
return fmt.Errorf("\"size\" and \"path\" flags are required for s2i components") | ||
} | ||
return lci.DeleteFromConfigurationList("storage", name) | ||
|
||
for _, store := range lci.ListStorage() { | ||
if store.Name == storage.Name { | ||
return errors.Errorf("there already is a storage with the name %s", storage.Name) | ||
} | ||
if store.Path == storage.Path { | ||
return errors.Errorf("there already is a storage mounted at %s", storage.Path) | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (lci *LocalConfigInfo) GetMountPath(storageName string) string { | ||
// GetStorageMountPath gets the mount path of the storage with the given storage name | ||
func (lci *LocalConfigInfo) GetStorageMountPath(storageName string) (string, error) { | ||
var mPath string | ||
storageList, _ := lci.StorageList() | ||
for _, storage := range storageList { | ||
for _, storage := range lci.ListStorage() { | ||
if storage.Name == storageName { | ||
mPath = storage.Path | ||
} | ||
} | ||
return mPath | ||
return mPath, nil | ||
} |
Oops, something went wrong.