Skip to content

Commit

Permalink
Fix an error processing storage on k8s; handle storagepool notfound e…
Browse files Browse the repository at this point in the history
…rrors
  • Loading branch information
wallyworld committed Apr 8, 2024
1 parent 1356add commit 430b477
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/juju/juju/core/objectstore"
"github.com/juju/juju/core/resources"
"github.com/juju/juju/core/status"
storageerrors "github.com/juju/juju/domain/storage/errors"
"github.com/juju/juju/environs/config"
"github.com/juju/juju/internal/docker"
"github.com/juju/juju/internal/storage"
Expand Down Expand Up @@ -161,6 +162,9 @@ func (m *mockStoragePoolGetter) GetStoragePoolByName(_ context.Context, name str
if err := m.NextErr(); err != nil {
return nil, err
}
if name == "notpool" {
return nil, storageerrors.PoolNotFoundError
}
return storage.NewConfig(name, k8sconstants.StorageProviderType, map[string]interface{}{"foo": "bar"})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func CharmStorageParams(
}

providerType, attrs, err := poolStorageProvider(ctx, storagePoolGetter, registry, maybePoolName)
if err != nil && (!errors.Is(err, errors.NotFound) || poolName != "") {
if err != nil && (!errors.Is(err, storageerrors.PoolNotFoundError) || poolName != "") {
return nil, errors.Trace(err)
}
if err == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
jujuresource "github.com/juju/juju/core/resources"
"github.com/juju/juju/core/status"
"github.com/juju/juju/core/watcher/eventsource"
envconfig "github.com/juju/juju/environs/config"
"github.com/juju/juju/internal/docker"
"github.com/juju/juju/rpc/params"
"github.com/juju/juju/state"
Expand Down Expand Up @@ -680,3 +681,20 @@ func (s *CAASApplicationProvisionerSuite) TestProvisionerConfig(c *gc.C) {
c.Assert(result.ProvisionerConfig, gc.NotNil)
c.Assert(result.ProvisionerConfig.UnmanagedApplications.Entities, gc.DeepEquals, []params.Entity{{Tag: "application-controller"}})
}

func (s *CAASApplicationProvisionerSuite) TestCharmStorageParamsPoolNotFound(c *gc.C) {
cfg, err := envconfig.New(envconfig.NoDefaults, coretesting.FakeConfig())
c.Assert(err, jc.ErrorIsNil)
p, err := caasapplicationprovisioner.CharmStorageParams(
context.Background(), coretesting.ControllerTag.Id(),
"notpool", cfg, "", s.storagePoolGetter, s.registry,
)
c.Assert(err, jc.ErrorIsNil)
c.Assert(p, jc.DeepEquals, &params.KubernetesFilesystemParams{
StorageName: "charm",
Size: 1024,
Provider: "kubernetes",
Attributes: map[string]any{"storage-class": "notpool"},
Tags: map[string]string{"juju-controller-uuid": coretesting.ControllerTag.Id(), "juju-model-uuid": coretesting.ModelTag.Id()},
})
}

0 comments on commit 430b477

Please sign in to comment.