Skip to content

Commit 283f615

Browse files
committed
Drop lxd-storage feature flag
Tidy up the lxd storage provider, and drop the feature flag. Using the "lxd" storage pool (i.e. without configuration), storage will be allocated from the LXD storage pool called "juju", using the driver "dir". The provider also predefines a "lxd-zfs" storage pool, which maps to the LXD storage pool called "juju-zfs", using a zfs pool of the same name. Juju will create the LXD storage pools as necessary, and will ensure that they have the same configuration before use.
1 parent d83b61a commit 283f615

File tree

11 files changed

+451
-156
lines changed

11 files changed

+451
-156
lines changed

feature/flags.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,6 @@ const DeveloperMode = "developer-mode"
3737
// CrossModelRelations allows cross model relations functionality.
3838
const CrossModelRelations = "cross-model"
3939

40-
// LXDStorage enables the LXD storage provider.
41-
const LXDStorage = "lxd-storage"
42-
4340
// StrictMigration will cause migration to error if there are unexported
4441
// values for annotations, status, status history, or settings.
4542
const StrictMigration = "strict-migration"

provider/common/destroy.go

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ func destroyInstances(env environs.Environ) error {
4747
}
4848
}
4949

50+
// TODO(axw) we should just make it Environ.Destroy's responsibility
51+
// to destroy persistent storage. Trying to include it in the storage
52+
// source abstraction doesn't work well with dynamic, non-persistent
53+
// storage like tmpfs, rootfs, etc.
5054
func destroyStorage(env environs.Environ) error {
5155
logger.Infof("destroying storage")
5256
storageProviderTypes, err := env.StorageProviderTypes()
@@ -64,36 +68,28 @@ func destroyStorage(env environs.Environ) error {
6468
if storageProvider.Scope() != storage.ScopeEnviron {
6569
continue
6670
}
67-
if err := destroyVolumes(storageProviderType, storageProvider); err != nil {
71+
storageConfig, err := storage.NewConfig(
72+
string(storageProviderType),
73+
storageProviderType,
74+
map[string]interface{}{},
75+
)
76+
if err != nil {
6877
return errors.Trace(err)
6978
}
70-
// TODO(axw) destroy env-level filesystems when we have them.
79+
if storageProvider.Supports(storage.StorageKindBlock) {
80+
volumeSource, err := storageProvider.VolumeSource(storageConfig)
81+
if err != nil {
82+
return errors.Annotate(err, "getting volume source")
83+
}
84+
if err := destroyVolumes(volumeSource); err != nil {
85+
return errors.Trace(err)
86+
}
87+
}
7188
}
7289
return nil
7390
}
7491

75-
func destroyVolumes(
76-
storageProviderType storage.ProviderType,
77-
storageProvider storage.Provider,
78-
) error {
79-
if !storageProvider.Supports(storage.StorageKindBlock) {
80-
return nil
81-
}
82-
83-
storageConfig, err := storage.NewConfig(
84-
string(storageProviderType),
85-
storageProviderType,
86-
map[string]interface{}{},
87-
)
88-
if err != nil {
89-
return errors.Trace(err)
90-
}
91-
92-
volumeSource, err := storageProvider.VolumeSource(storageConfig)
93-
if err != nil {
94-
return errors.Annotate(err, "getting volume source")
95-
}
96-
92+
func destroyVolumes(volumeSource storage.VolumeSource) error {
9793
volumeIds, err := volumeSource.ListVolumes()
9894
if err != nil {
9995
return errors.Annotate(err, "listing volumes")

provider/lxd/environ.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,11 @@ func (env *environ) Destroy() error {
168168
if err := env.base.DestroyEnv(); err != nil {
169169
return errors.Trace(err)
170170
}
171+
if env.storageSupported() {
172+
if err := destroyModelFilesystems(env); err != nil {
173+
return errors.Annotate(err, "destroying LXD filesystems for model")
174+
}
175+
}
171176
return nil
172177
}
173178

@@ -179,6 +184,11 @@ func (env *environ) DestroyController(controllerUUID string) error {
179184
if err := env.destroyHostedModelResources(controllerUUID); err != nil {
180185
return errors.Trace(err)
181186
}
187+
if env.storageSupported() {
188+
if err := destroyControllerFilesystems(env, controllerUUID); err != nil {
189+
return errors.Annotate(err, "destroying LXD filesystems for controller")
190+
}
191+
}
182192
return nil
183193
}
184194

provider/lxd/environ_raw.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ type lxdImages interface {
6161

6262
type lxdStorage interface {
6363
StorageSupported() bool
64+
65+
StoragePool(name string) (lxdapi.StoragePool, error)
66+
StoragePools() ([]lxdapi.StoragePool, error)
67+
CreateStoragePool(name, driver string, attrs map[string]string) error
68+
6469
VolumeCreate(pool, volume string, config map[string]string) error
6570
VolumeDelete(pool, volume string) error
6671
VolumeList(pool string) ([]lxdapi.StorageVolume, error)

provider/lxd/environ_test.go

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/juju/cmd/cmdtesting"
1010
gitjujutesting "github.com/juju/testing"
1111
jc "github.com/juju/testing/checkers"
12+
"github.com/lxc/lxd/shared/api"
1213
gc "gopkg.in/check.v1"
1314

1415
"github.com/juju/juju/cloudconfig/instancecfg"
@@ -101,33 +102,63 @@ func (s *environSuite) TestBootstrapAPI(c *gc.C) {
101102
}
102103

103104
func (s *environSuite) TestDestroy(c *gc.C) {
104-
err := s.Env.Destroy()
105-
106-
c.Check(err, jc.ErrorIsNil)
107-
}
105+
s.Client.Volumes = map[string][]api.StorageVolume{
106+
"juju": []api.StorageVolume{{
107+
StorageVolumePut: api.StorageVolumePut{
108+
Name: "not-ours",
109+
Config: map[string]string{
110+
"user.juju-model-uuid": "other",
111+
},
112+
},
113+
}, {
114+
StorageVolumePut: api.StorageVolumePut{
115+
Name: "ours",
116+
Config: map[string]string{
117+
"user.juju-model-uuid": s.Config.UUID(),
118+
},
119+
},
120+
}},
121+
}
108122

109-
func (s *environSuite) TestDestroyAPI(c *gc.C) {
110123
err := s.Env.Destroy()
111124
c.Assert(err, jc.ErrorIsNil)
112125

113126
fwname := common.EnvFullName(s.Env.Config().UUID())
114-
s.Stub.CheckCalls(c, []gitjujutesting.StubCall{{
115-
FuncName: "Ports",
116-
Args: []interface{}{
117-
fwname,
118-
},
119-
}, {
120-
FuncName: "Destroy",
121-
Args: nil,
122-
}})
127+
s.Stub.CheckCalls(c, []gitjujutesting.StubCall{
128+
{"Ports", []interface{}{fwname}},
129+
{"Destroy", nil},
130+
{"StorageSupported", nil},
131+
{"StoragePools", nil},
132+
{"VolumeList", []interface{}{"juju"}},
133+
{"VolumeDelete", []interface{}{"juju", "ours"}},
134+
{"VolumeList", []interface{}{"juju-zfs"}},
135+
})
123136
}
124137

125-
func (s *environSuite) TestDestroyHostedModels(c *gc.C) {
138+
func (s *environSuite) TestDestroyController(c *gc.C) {
126139
s.UpdateConfig(c, map[string]interface{}{
127140
"controller-uuid": s.Config.UUID(),
128141
})
129142
s.Stub.ResetCalls()
130143

144+
s.Client.Volumes = map[string][]api.StorageVolume{
145+
"juju": []api.StorageVolume{{
146+
StorageVolumePut: api.StorageVolumePut{
147+
Name: "not-ours",
148+
Config: map[string]string{
149+
"user.juju-controller-uuid": "other",
150+
},
151+
},
152+
}, {
153+
StorageVolumePut: api.StorageVolumePut{
154+
Name: "ours",
155+
Config: map[string]string{
156+
"user.juju-controller-uuid": s.Config.UUID(),
157+
},
158+
},
159+
}},
160+
}
161+
131162
// machine0 is in the controller model.
132163
machine0 := s.NewRawInstance(c, "juju-controller-machine-0")
133164
machine0.InstanceSummary.Metadata["juju-model-uuid"] = s.Config.UUID()
@@ -150,7 +181,16 @@ func (s *environSuite) TestDestroyHostedModels(c *gc.C) {
150181
s.Stub.CheckCalls(c, []gitjujutesting.StubCall{
151182
{"Ports", []interface{}{fwname}},
152183
{"Destroy", nil},
184+
{"StorageSupported", nil},
185+
{"StoragePools", nil},
186+
{"VolumeList", []interface{}{"juju"}},
187+
{"VolumeList", []interface{}{"juju-zfs"}},
153188
{"Instances", []interface{}{"juju-", lxdclient.AliveStatuses}},
154189
{"RemoveInstances", []interface{}{"juju-", []string{machine1.Name}}},
190+
{"StorageSupported", nil},
191+
{"StoragePools", nil},
192+
{"VolumeList", []interface{}{"juju"}},
193+
{"VolumeDelete", []interface{}{"juju", "ours"}},
194+
{"VolumeList", []interface{}{"juju-zfs"}},
155195
})
156196
}

0 commit comments

Comments
 (0)