Skip to content

Commit

Permalink
Remove storage status when storage is removed
Browse files Browse the repository at this point in the history
  • Loading branch information
dmage committed Feb 28, 2020
1 parent 6d953d3 commit 31a2e03
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 27 deletions.
26 changes: 12 additions & 14 deletions pkg/resource/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ func (g *Generator) syncStorage(cr *imageregistryv1.Config) error {
var runCreate bool
// Create a driver with the current configuration
driver, err := storage.NewDriver(&cr.Spec.Storage, g.kubeconfig, g.listers)
if err == storage.ErrStorageNotConfigured {
cr.Spec.Storage, err = storage.GetPlatformStorage(g.listers)
if err != nil {
return fmt.Errorf("unable to get storage configuration from cluster install config: %s", err)
}
driver, err = storage.NewDriver(&cr.Spec.Storage, g.kubeconfig, g.listers)
}
if err != nil {
return err
}
Expand All @@ -149,19 +156,6 @@ func (g *Generator) syncStorage(cr *imageregistryv1.Config) error {
}
}

// XXX BZ 1722878
// This is a workaround for a bug that affected OCP 4.2 and earlier. We
// may have multiple storage engines set on Status, that is not a valid
// situation. Here we check if this is the case and if yes we fix it by
// copying what we have on the Spec into the Status.
_, err = storage.NewDriver(
&cr.Status.Storage, g.kubeconfig, g.listers,
)
if _, ok := err.(*storage.MultiStoragesError); ok {
specCopy := cr.Spec.Storage.DeepCopy()
cr.Status.Storage = *specCopy
}

return nil
}

Expand Down Expand Up @@ -275,7 +269,9 @@ func (g *Generator) Remove(cr *imageregistryv1.Config) error {
}

driver, err := storage.NewDriver(&cr.Status.Storage, g.kubeconfig, g.listers)
if err != nil {
if err == storage.ErrStorageNotConfigured {
return nil
} else if err != nil {
return err
}

Expand All @@ -295,5 +291,7 @@ func (g *Generator) Remove(cr *imageregistryv1.Config) error {
return fmt.Errorf("unable to remove storage: %s, %s", err, derr)
}

cr.Status.Storage = imageregistryv1.ImageRegistryConfigStorage{}

return nil
}
14 changes: 1 addition & 13 deletions pkg/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Driver interface {
ID() string
}

func newDriver(cfg *imageregistryv1.ImageRegistryConfigStorage, kubeconfig *rest.Config, listers *regopclient.Listers) (Driver, error) {
func NewDriver(cfg *imageregistryv1.ImageRegistryConfigStorage, kubeconfig *rest.Config, listers *regopclient.Listers) (Driver, error) {
var names []string
var drivers []Driver

Expand Down Expand Up @@ -104,18 +104,6 @@ func newDriver(cfg *imageregistryv1.ImageRegistryConfigStorage, kubeconfig *rest
return nil, &MultiStoragesError{names}
}

func NewDriver(cfg *imageregistryv1.ImageRegistryConfigStorage, kubeconfig *rest.Config, listers *regopclient.Listers) (Driver, error) {
drv, err := newDriver(cfg, kubeconfig, listers)
if err == ErrStorageNotConfigured {
*cfg, err = GetPlatformStorage(listers)
if err != nil {
return nil, fmt.Errorf("unable to get storage configuration from cluster install config: %s", err)
}
drv, err = newDriver(cfg, kubeconfig, listers)
}
return drv, err
}

// GetPlatformStorage returns the storage configuration that should be used
// based on the cloudplatform we are running on, as determined from the
// infrastructure configuration.
Expand Down

0 comments on commit 31a2e03

Please sign in to comment.