Skip to content

Commit

Permalink
Implement glusterfs resizing and add populator loop
Browse files Browse the repository at this point in the history
Also change resizing mechanism for picking pvcs.
Also add unit tests for the same.
  • Loading branch information
gnufied committed Aug 31, 2017
1 parent 6ccda81 commit 54375e8
Show file tree
Hide file tree
Showing 23 changed files with 584 additions and 298 deletions.
2 changes: 1 addition & 1 deletion cmd/kube-controller-manager/app/controllermanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ func NewControllerInitializers() map[string]InitFunc {
controllers["route"] = startRouteController
controllers["persistentvolume-binder"] = startPersistentVolumeBinderController
controllers["attachdetach"] = startAttachDetachController
controllers["volume-expand"] = startVolumeExpandController
controllers["persistentvolume-expander"] = startVolumeExpandController

return controllers
}
Expand Down
23 changes: 13 additions & 10 deletions cmd/kube-controller-manager/app/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,18 +190,21 @@ func startAttachDetachController(ctx ControllerContext) (bool, error) {
}

func startVolumeExpandController(ctx ControllerContext) (bool, error) {
expandController, expandControllerErr := expand.NewExpandController(
ctx.ClientBuilder.ClientOrDie("expand-controller"),
ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
ctx.InformerFactory.Core().V1().PersistentVolumes(),
ctx.Cloud,
ProbeAttachableVolumePlugins(ctx.Options.VolumeConfiguration))
if utilfeature.DefaultFeatureGate.Enabled(features.ExpandPersistentVolumes) {
expandController, expandControllerErr := expand.NewExpandController(
ctx.ClientBuilder.ClientOrDie("expand-controller"),
ctx.InformerFactory.Core().V1().PersistentVolumeClaims(),
ctx.InformerFactory.Core().V1().PersistentVolumes(),
ctx.Cloud,
ProbeExpandableVolumePlugins(ctx.Options.VolumeConfiguration))

if expandControllerErr != nil {
return true, fmt.Errorf("Failed to start volume expand controller : %v", expandControllerErr)
if expandControllerErr != nil {
return true, fmt.Errorf("Failed to start volume expand controller : %v", expandControllerErr)
}
go expandController.Run(ctx.Stop)
return true, nil
}
go expandController.Run(ctx.Stop)
return true, nil
return false, nil
}

func startEndpointController(ctx ControllerContext) (bool, error) {
Expand Down
19 changes: 19 additions & 0 deletions cmd/kube-controller-manager/app/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,25 @@ func GetDynamicPluginProber(config componentconfig.VolumeConfiguration) volume.D
return flexvolume.GetDynamicPluginProber(config.FlexVolumePluginDir)
}

// ProbeExpandableVolumePlugins returns volume plugins which are expandable
func ProbeExpandableVolumePlugins(config componentconfig.VolumeConfiguration) []volume.VolumePlugin {
allPlugins := []volume.VolumePlugin{}

allPlugins = append(allPlugins, aws_ebs.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, gce_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, cinder.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, portworx.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, vsphere_volume.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, glusterfs.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, rbd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, azure_dd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, photon_pd.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, scaleio.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, storageos.ProbeVolumePlugins()...)
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
return allPlugins
}

// ProbeControllerVolumePlugins collects all persistent volume plugins into an
// easy to use list. Only volume plugins that implement any of
// provisioner/recycler/deleter interface should be returned.
Expand Down
14 changes: 5 additions & 9 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,20 +547,16 @@ type PersistentVolumeClaimSpec struct {
StorageClassName *string
}

type PvcConditionType string
type PersistentVolumeClaimConditionType string

// These are valid conditions of Pvc
const (
// An user trigger resize of pvc has been started
PvcResizeStarted PvcConditionType = "ResizeStarted"
// PvcReady means an operation in progress on PVC is finished successfuly
PvcReady PvcConditionType = "Ready"
// PvcResizeFailed means user trigged resize of PVC has failed
PvcResizeFailed PvcConditionType = "ResizeFailed"
PersistentVolumeClaimResizeStarted PersistentVolumeClaimConditionType = "ResizeStarted"
)

type PvcCondition struct {
Type PvcConditionType
type PersistentVolumeClaimCondition struct {
Type PersistentVolumeClaimConditionType
Status ConditionStatus
// +optional
LastProbeTime metav1.Time
Expand All @@ -583,7 +579,7 @@ type PersistentVolumeClaimStatus struct {
// +optional
Capacity ResourceList
// +optional
Conditions []PvcCondition
Conditions []PersistentVolumeClaimCondition
}

type PersistentVolumeAccessMode string
Expand Down
6 changes: 5 additions & 1 deletion pkg/api/validation/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -1558,8 +1558,12 @@ func ValidatePersistentVolumeClaimUpdate(newPvc, oldPvc *api.PersistentVolumeCla
oldSize := oldPvc.Spec.Resources.Requests["storage"]
newSize := newPvc.Spec.Resources.Requests["storage"]

if (newPvc.Status.Phase != api.ClaimBound) && (newSize.Cmp(oldSize) != 0) {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "resources", "requests", "storage"), "field can only be changed for bound claims"))
}

if newSize.Cmp(oldSize) < 0 {
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "resources", "requests", "storage"), "field can not be lesser than previous value"))
allErrs = append(allErrs, field.Forbidden(field.NewPath("spec", "resources", "requests", "storage"), "field can not be less than previous value"))
}

if !apiequality.Semantic.DeepEqual(newPvc.Spec.AccessModes, oldPvc.Spec.AccessModes) {
Expand Down
19 changes: 14 additions & 5 deletions pkg/api/validation/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ func TestValidatePersistentVolumeClaim(t *testing.T) {
}

func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
validClaim := testVolumeClaim("foo", "ns", api.PersistentVolumeClaimSpec{
validClaim := testVolumeClaimWithStatus("foo", "ns", api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
Expand All @@ -749,7 +749,10 @@ func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
api.ResourceName(api.ResourceStorage): resource.MustParse("10G"),
},
},
}, api.PersistentVolumeClaimStatus{
Phase: api.ClaimBound,
})

validClaimStorageClass := testVolumeClaimStorageClass("foo", "ns", "fast", api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadOnlyMany,
Expand Down Expand Up @@ -839,7 +842,7 @@ func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
},
VolumeName: "volume",
})
validSizeUpdate := testVolumeClaim("foo", "ns", api.PersistentVolumeClaimSpec{
validSizeUpdate := testVolumeClaimWithStatus("foo", "ns", api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
Expand All @@ -849,8 +852,11 @@ func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
api.ResourceName(api.ResourceStorage): resource.MustParse("15G"),
},
},
}, api.PersistentVolumeClaimStatus{
Phase: api.ClaimBound,
})
invalidSizeUpdate := testVolumeClaim("foo", "ns", api.PersistentVolumeClaimSpec{

invalidSizeUpdate := testVolumeClaimWithStatus("foo", "ns", api.PersistentVolumeClaimSpec{
AccessModes: []api.PersistentVolumeAccessMode{
api.ReadWriteOnce,
api.ReadOnlyMany,
Expand All @@ -860,7 +866,10 @@ func TestValidatePersistentVolumeClaimUpdate(t *testing.T) {
api.ResourceName(api.ResourceStorage): resource.MustParse("5G"),
},
},
}, api.PersistentVolumeClaimStatus{
Phase: api.ClaimBound,
})

scenarios := map[string]struct {
isExpectedFailure bool
oldClaim *api.PersistentVolumeClaim
Expand Down Expand Up @@ -9111,8 +9120,8 @@ func TestValidatePersistentVolumeClaimStatusUpdate(t *testing.T) {
},
}, api.PersistentVolumeClaimStatus{
Phase: api.ClaimPending,
Conditions: []api.PvcCondition{
{Type: api.PvcResizeStarted, Status: api.ConditionTrue},
Conditions: []api.PersistentVolumeClaimCondition{
{Type: api.PersistentVolumeClaimResizeStarted, Status: api.ConditionTrue},
},
})
scenarios := map[string]struct {
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/volume/expand/OWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
approvers:
- saad-ali
- jsafrane
- gnufied
Loading

0 comments on commit 54375e8

Please sign in to comment.