mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-04 01:40:07 +00:00
Fix PVC.Status.Capacity and AccessModes after binding
Also, fix unit tests to have the same claim and volume sizes in most of the tests where we don't test matching based on size and test for a specific size when we do actually test the matching.
This commit is contained in:
parent
40c74be460
commit
3c5364954b
@ -93,7 +93,7 @@ func TestSync(t *testing.T) {
|
|||||||
newVolume("volume1-5_2", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
newVolume("volume1-5_2", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
||||||
},
|
},
|
||||||
newClaimArray("claim1-5", "uid1-5", "1Gi", "", api.ClaimPending),
|
newClaimArray("claim1-5", "uid1-5", "1Gi", "", api.ClaimPending),
|
||||||
newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", api.ClaimBound, annBoundByController, annBindCompleted),
|
withExpectedCapacity("10Gi", newClaimArray("claim1-5", "uid1-5", "1Gi", "volume1-5_1", api.ClaimBound, annBoundByController, annBindCompleted)),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -109,7 +109,7 @@ func TestSync(t *testing.T) {
|
|||||||
newVolume("volume1-6_2", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
newVolume("volume1-6_2", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
||||||
},
|
},
|
||||||
newClaimArray("claim1-6", "uid1-6", "1Gi", "", api.ClaimPending),
|
newClaimArray("claim1-6", "uid1-6", "1Gi", "", api.ClaimPending),
|
||||||
newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", api.ClaimBound, annBoundByController, annBindCompleted),
|
withExpectedCapacity("10Gi", newClaimArray("claim1-6", "uid1-6", "1Gi", "volume1-6_1", api.ClaimBound, annBoundByController, annBindCompleted)),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -199,8 +199,8 @@ func TestSync(t *testing.T) {
|
|||||||
"2-3 - claim prebound to unbound volume",
|
"2-3 - claim prebound to unbound volume",
|
||||||
newVolumeArray("volume2-3", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-3", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", api.VolumeBound, api.PersistentVolumeReclaimRetain, annBoundByController),
|
newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", api.VolumeBound, api.PersistentVolumeReclaimRetain, annBoundByController),
|
||||||
newClaimArray("claim2-3", "uid2-3", "10Gi", "volume2-3", api.ClaimPending),
|
newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", api.ClaimPending),
|
||||||
newClaimArray("claim2-3", "uid2-3", "10Gi", "volume2-3", api.ClaimBound, annBindCompleted),
|
newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", api.ClaimBound, annBindCompleted),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -209,8 +209,8 @@ func TestSync(t *testing.T) {
|
|||||||
"2-4 - claim prebound to prebound volume by name",
|
"2-4 - claim prebound to prebound volume by name",
|
||||||
newVolumeArray("volume2-4", "1Gi", "", "claim2-4", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-4", "1Gi", "", "claim2-4", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume2-4", "1Gi", "uid2-4", "claim2-4", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-4", "1Gi", "uid2-4", "claim2-4", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
newClaimArray("claim2-4", "uid2-4", "10Gi", "volume2-4", api.ClaimPending),
|
newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", api.ClaimPending),
|
||||||
newClaimArray("claim2-4", "uid2-4", "10Gi", "volume2-4", api.ClaimBound, annBindCompleted),
|
newClaimArray("claim2-4", "uid2-4", "1Gi", "volume2-4", api.ClaimBound, annBindCompleted),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -220,8 +220,8 @@ func TestSync(t *testing.T) {
|
|||||||
"2-5 - claim prebound to prebound volume by UID",
|
"2-5 - claim prebound to prebound volume by UID",
|
||||||
newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-5", "1Gi", "uid2-5", "claim2-5", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
newClaimArray("claim2-5", "uid2-5", "10Gi", "volume2-5", api.ClaimPending),
|
newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", api.ClaimPending),
|
||||||
newClaimArray("claim2-5", "uid2-5", "10Gi", "volume2-5", api.ClaimBound, annBindCompleted),
|
newClaimArray("claim2-5", "uid2-5", "1Gi", "volume2-5", api.ClaimBound, annBindCompleted),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -230,8 +230,8 @@ func TestSync(t *testing.T) {
|
|||||||
"2-6 - claim prebound to already bound volume",
|
"2-6 - claim prebound to already bound volume",
|
||||||
newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-6", "1Gi", "uid2-6_1", "claim2-6_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
newClaimArray("claim2-6", "uid2-6", "10Gi", "volume2-6", api.ClaimBound),
|
newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", api.ClaimBound),
|
||||||
newClaimArray("claim2-6", "uid2-6", "10Gi", "volume2-6", api.ClaimPending),
|
newClaimArray("claim2-6", "uid2-6", "1Gi", "volume2-6", api.ClaimPending),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -240,8 +240,8 @@ func TestSync(t *testing.T) {
|
|||||||
"2-7 - claim bound by controller to already bound volume",
|
"2-7 - claim bound by controller to already bound volume",
|
||||||
newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-7", "1Gi", "uid2-7_1", "claim2-7_1", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
newClaimArray("claim2-7", "uid2-7", "10Gi", "volume2-7", api.ClaimBound, annBoundByController),
|
newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", api.ClaimBound, annBoundByController),
|
||||||
newClaimArray("claim2-7", "uid2-7", "10Gi", "volume2-7", api.ClaimBound, annBoundByController),
|
newClaimArray("claim2-7", "uid2-7", "1Gi", "volume2-7", api.ClaimBound, annBoundByController),
|
||||||
noevents, noerrors, testSyncClaimError,
|
noevents, noerrors, testSyncClaimError,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -251,8 +251,8 @@ func TestSync(t *testing.T) {
|
|||||||
"2-8 - claim prebound to unbound volume that does not match the selector",
|
"2-8 - claim prebound to unbound volume that does not match the selector",
|
||||||
newVolumeArray("volume2-3", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume2-3", "1Gi", "", "", api.VolumePending, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", api.VolumeBound, api.PersistentVolumeReclaimRetain, annBoundByController),
|
newVolumeArray("volume2-3", "1Gi", "uid2-3", "claim2-3", api.VolumeBound, api.PersistentVolumeReclaimRetain, annBoundByController),
|
||||||
withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "10Gi", "volume2-3", api.ClaimPending)),
|
withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", api.ClaimPending)),
|
||||||
withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "10Gi", "volume2-3", api.ClaimBound, annBindCompleted)),
|
withLabelSelector(labels, newClaimArray("claim2-3", "uid2-3", "1Gi", "volume2-3", api.ClaimBound, annBindCompleted)),
|
||||||
noevents, noerrors, testSyncClaim,
|
noevents, noerrors, testSyncClaim,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ package persistentvolume
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
@ -215,7 +216,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *api.PersistentVo
|
|||||||
}
|
}
|
||||||
// Mark the claim as Pending and try to find a match in the next
|
// Mark the claim as Pending and try to find a match in the next
|
||||||
// periodic syncClaim
|
// periodic syncClaim
|
||||||
if _, err = ctrl.updateClaimPhase(claim, api.ClaimPending); err != nil {
|
if _, err = ctrl.updateClaimStatus(claim, api.ClaimPending, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -244,7 +245,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *api.PersistentVo
|
|||||||
// OBSERVATION: pvc is "Pending"
|
// OBSERVATION: pvc is "Pending"
|
||||||
// Retry later.
|
// Retry later.
|
||||||
glog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume %q requested and not found, will try again next time", claimToClaimKey(claim), claim.Spec.VolumeName)
|
glog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume %q requested and not found, will try again next time", claimToClaimKey(claim), claim.Spec.VolumeName)
|
||||||
if _, err = ctrl.updateClaimPhase(claim, api.ClaimPending); err != nil {
|
if _, err = ctrl.updateClaimStatus(claim, api.ClaimPending, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -282,7 +283,7 @@ func (ctrl *PersistentVolumeController) syncUnboundClaim(claim *api.PersistentVo
|
|||||||
if !hasAnnotation(claim.ObjectMeta, annBoundByController) {
|
if !hasAnnotation(claim.ObjectMeta, annBoundByController) {
|
||||||
glog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume already bound to different claim by user, will retry later", claimToClaimKey(claim))
|
glog.V(4).Infof("synchronizing unbound PersistentVolumeClaim[%s]: volume already bound to different claim by user, will retry later", claimToClaimKey(claim))
|
||||||
// User asked for a specific PV, retry later
|
// User asked for a specific PV, retry later
|
||||||
if _, err = ctrl.updateClaimPhase(claim, api.ClaimPending); err != nil {
|
if _, err = ctrl.updateClaimStatus(claim, api.ClaimPending, nil); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -306,7 +307,7 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu
|
|||||||
// [Unit test set 3]
|
// [Unit test set 3]
|
||||||
if claim.Spec.VolumeName == "" {
|
if claim.Spec.VolumeName == "" {
|
||||||
// Claim was bound before but not any more.
|
// Claim was bound before but not any more.
|
||||||
if _, err := ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimLost", "Bound claim has lost reference to PersistentVolume. Data on the volume is lost!"); err != nil {
|
if _, err := ctrl.updateClaimStatusWithEvent(claim, api.ClaimLost, nil, api.EventTypeWarning, "ClaimLost", "Bound claim has lost reference to PersistentVolume. Data on the volume is lost!"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -317,7 +318,7 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu
|
|||||||
}
|
}
|
||||||
if !found {
|
if !found {
|
||||||
// Claim is bound to a non-existing volume.
|
// Claim is bound to a non-existing volume.
|
||||||
if _, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimLost", "Bound claim has lost its PersistentVolume. Data on the volume is lost!"); err != nil {
|
if _, err = ctrl.updateClaimStatusWithEvent(claim, api.ClaimLost, nil, api.EventTypeWarning, "ClaimLost", "Bound claim has lost its PersistentVolume. Data on the volume is lost!"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -354,7 +355,7 @@ func (ctrl *PersistentVolumeController) syncBoundClaim(claim *api.PersistentVolu
|
|||||||
// Claim is bound but volume has a different claimant.
|
// Claim is bound but volume has a different claimant.
|
||||||
// Set the claim phase to 'Lost', which is a terminal
|
// Set the claim phase to 'Lost', which is a terminal
|
||||||
// phase.
|
// phase.
|
||||||
if _, err = ctrl.updateClaimPhaseWithEvent(claim, api.ClaimLost, api.EventTypeWarning, "ClaimMisbound", "Two claims are bound to the same volume, this one is bound incorrectly"); err != nil {
|
if _, err = ctrl.updateClaimStatusWithEvent(claim, api.ClaimLost, nil, api.EventTypeWarning, "ClaimMisbound", "Two claims are bound to the same volume, this one is bound incorrectly"); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -517,14 +518,15 @@ func (ctrl *PersistentVolumeController) syncVolume(volume *api.PersistentVolume)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateClaimPhase saves new claim phase to API server.
|
// updateClaimStatus saves new claim.Status to API server.
|
||||||
func (ctrl *PersistentVolumeController) updateClaimPhase(claim *api.PersistentVolumeClaim, phase api.PersistentVolumeClaimPhase) (*api.PersistentVolumeClaim, error) {
|
// Parameters:
|
||||||
glog.V(4).Infof("updating PersistentVolumeClaim[%s]: set phase %s", claimToClaimKey(claim), phase)
|
// claim - claim to update
|
||||||
if claim.Status.Phase == phase {
|
// phasephase - phase to set
|
||||||
// Nothing to do.
|
// volume - volume which Capacity is set into claim.Status.Capacity
|
||||||
glog.V(4).Infof("updating PersistentVolumeClaim[%s]: phase %s already set", claimToClaimKey(claim), phase)
|
func (ctrl *PersistentVolumeController) updateClaimStatus(claim *api.PersistentVolumeClaim, phase api.PersistentVolumeClaimPhase, volume *api.PersistentVolume) (*api.PersistentVolumeClaim, error) {
|
||||||
return claim, nil
|
glog.V(4).Infof("updating PersistentVolumeClaim[%s] status: set phase %s", claimToClaimKey(claim), phase)
|
||||||
}
|
|
||||||
|
dirty := false
|
||||||
|
|
||||||
clone, err := conversion.NewCloner().DeepCopy(claim)
|
clone, err := conversion.NewCloner().DeepCopy(claim)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -535,33 +537,76 @@ func (ctrl *PersistentVolumeController) updateClaimPhase(claim *api.PersistentVo
|
|||||||
return nil, fmt.Errorf("Unexpected claim cast error : %v", claimClone)
|
return nil, fmt.Errorf("Unexpected claim cast error : %v", claimClone)
|
||||||
}
|
}
|
||||||
|
|
||||||
claimClone.Status.Phase = phase
|
if claim.Status.Phase != phase {
|
||||||
|
claimClone.Status.Phase = phase
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
|
||||||
|
if volume == nil {
|
||||||
|
// Need to reset AccessModes and Capacity
|
||||||
|
if claim.Status.AccessModes != nil {
|
||||||
|
claimClone.Status.AccessModes = nil
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
if claim.Status.Capacity != nil {
|
||||||
|
claimClone.Status.Capacity = nil
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Need to update AccessModes and Capacity
|
||||||
|
if !reflect.DeepEqual(claim.Status.AccessModes, volume.Spec.AccessModes) {
|
||||||
|
claimClone.Status.AccessModes = volume.Spec.AccessModes
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
|
||||||
|
volumeCap, ok := volume.Spec.Capacity[api.ResourceStorage]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("PersistentVolume %q is without a storage capacity", volume.Name)
|
||||||
|
}
|
||||||
|
claimCap, ok := claim.Status.Capacity[api.ResourceStorage]
|
||||||
|
if !ok || volumeCap.Cmp(claimCap) != 0 {
|
||||||
|
claimClone.Status.Capacity = volume.Spec.Capacity
|
||||||
|
dirty = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !dirty {
|
||||||
|
// Nothing to do.
|
||||||
|
glog.V(4).Infof("updating PersistentVolumeClaim[%s] status: phase %s already set", claimToClaimKey(claim), phase)
|
||||||
|
return claim, nil
|
||||||
|
}
|
||||||
|
|
||||||
newClaim, err := ctrl.kubeClient.Core().PersistentVolumeClaims(claimClone.Namespace).UpdateStatus(claimClone)
|
newClaim, err := ctrl.kubeClient.Core().PersistentVolumeClaims(claimClone.Namespace).UpdateStatus(claimClone)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("updating PersistentVolumeClaim[%s]: set phase %s failed: %v", claimToClaimKey(claim), phase, err)
|
glog.V(4).Infof("updating PersistentVolumeClaim[%s] status: set phase %s failed: %v", claimToClaimKey(claim), phase, err)
|
||||||
return newClaim, err
|
return newClaim, err
|
||||||
}
|
}
|
||||||
_, err = ctrl.storeClaimUpdate(newClaim)
|
_, err = ctrl.storeClaimUpdate(newClaim)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.V(4).Infof("updating PersistentVolumeClaim[%s]: cannot update internal cache: %v", claimToClaimKey(claim), err)
|
glog.V(4).Infof("updating PersistentVolumeClaim[%s] status: cannot update internal cache: %v", claimToClaimKey(claim), err)
|
||||||
return newClaim, err
|
return newClaim, err
|
||||||
}
|
}
|
||||||
glog.V(2).Infof("claim %q entered phase %q", claimToClaimKey(claim), phase)
|
glog.V(2).Infof("claim %q entered phase %q", claimToClaimKey(claim), phase)
|
||||||
return newClaim, nil
|
return newClaim, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// updateClaimPhaseWithEvent saves new claim phase to API server and emits given
|
// updateClaimStatusWithEvent saves new claim.Status to API server and emits
|
||||||
// event on the claim. It saves the phase and emits the event only when the
|
// given event on the claim. It saves the status and emits the event only when
|
||||||
// phase has actually changed from the version saved in API server.
|
// the status has actually changed from the version saved in API server.
|
||||||
func (ctrl *PersistentVolumeController) updateClaimPhaseWithEvent(claim *api.PersistentVolumeClaim, phase api.PersistentVolumeClaimPhase, eventtype, reason, message string) (*api.PersistentVolumeClaim, error) {
|
// Parameters:
|
||||||
glog.V(4).Infof("updating updateClaimPhaseWithEvent[%s]: set phase %s", claimToClaimKey(claim), phase)
|
// claim - claim to update
|
||||||
|
// phasephase - phase to set
|
||||||
|
// volume - volume which Capacity is set into claim.Status.Capacity
|
||||||
|
// eventtype, reason, message - event to send, see EventRecorder.Event()
|
||||||
|
func (ctrl *PersistentVolumeController) updateClaimStatusWithEvent(claim *api.PersistentVolumeClaim, phase api.PersistentVolumeClaimPhase, volume *api.PersistentVolume, eventtype, reason, message string) (*api.PersistentVolumeClaim, error) {
|
||||||
|
glog.V(4).Infof("updating updateClaimStatusWithEvent[%s]: set phase %s", claimToClaimKey(claim), phase)
|
||||||
if claim.Status.Phase == phase {
|
if claim.Status.Phase == phase {
|
||||||
// Nothing to do.
|
// Nothing to do.
|
||||||
glog.V(4).Infof("updating updateClaimPhaseWithEvent[%s]: phase %s already set", claimToClaimKey(claim), phase)
|
glog.V(4).Infof("updating updateClaimStatusWithEvent[%s]: phase %s already set", claimToClaimKey(claim), phase)
|
||||||
return claim, nil
|
return claim, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
newClaim, err := ctrl.updateClaimPhase(claim, phase)
|
newClaim, err := ctrl.updateClaimStatus(claim, phase, volume)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -791,7 +836,7 @@ func (ctrl *PersistentVolumeController) bind(volume *api.PersistentVolume, claim
|
|||||||
}
|
}
|
||||||
claim = updatedClaim
|
claim = updatedClaim
|
||||||
|
|
||||||
if updatedClaim, err = ctrl.updateClaimPhase(claim, api.ClaimBound); err != nil {
|
if updatedClaim, err = ctrl.updateClaimStatus(claim, api.ClaimBound, volume); err != nil {
|
||||||
glog.V(3).Infof("error binding volume %q to claim %q: failed saving the claim status: %v", volume.Name, claimToClaimKey(claim), err)
|
glog.V(3).Infof("error binding volume %q to claim %q: failed saving the claim status: %v", volume.Name, claimToClaimKey(claim), err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,8 @@ func TestControllerSync(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// addClaim gets a new claim. Check it's bound to a volume.
|
// addClaim gets a new claim. Check it's bound to a volume.
|
||||||
"5-2 - complete bind",
|
"5-2 - complete bind",
|
||||||
newVolumeArray("volume5-2", "10Gi", "", "", api.VolumeAvailable, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume5-2", "1Gi", "", "", api.VolumeAvailable, api.PersistentVolumeReclaimRetain),
|
||||||
newVolumeArray("volume5-2", "10Gi", "uid5-2", "claim5-2", api.VolumeBound, api.PersistentVolumeReclaimRetain, annBoundByController),
|
newVolumeArray("volume5-2", "1Gi", "uid5-2", "claim5-2", api.VolumeBound, api.PersistentVolumeReclaimRetain, annBoundByController),
|
||||||
noclaims, /* added in testAddClaim5_2 */
|
noclaims, /* added in testAddClaim5_2 */
|
||||||
newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", api.ClaimBound, annBoundByController, annBindCompleted),
|
newClaimArray("claim5-2", "uid5-2", "1Gi", "volume5-2", api.ClaimBound, annBoundByController, annBindCompleted),
|
||||||
noevents, noerrors,
|
noevents, noerrors,
|
||||||
@ -73,7 +73,7 @@ func TestControllerSync(t *testing.T) {
|
|||||||
{
|
{
|
||||||
// deleteVolume with a bound volume. Check the claim is Lost.
|
// deleteVolume with a bound volume. Check the claim is Lost.
|
||||||
"5-4 - delete volume",
|
"5-4 - delete volume",
|
||||||
newVolumeArray("volume5-4", "10Gi", "uid5-4", "claim5-4", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
newVolumeArray("volume5-4", "1Gi", "uid5-4", "claim5-4", api.VolumeBound, api.PersistentVolumeReclaimRetain),
|
||||||
novolumes,
|
novolumes,
|
||||||
newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", api.ClaimBound, annBoundByController, annBindCompleted),
|
newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", api.ClaimBound, annBoundByController, annBindCompleted),
|
||||||
newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", api.ClaimLost, annBoundByController, annBindCompleted),
|
newClaimArray("claim5-4", "uid5-4", "1Gi", "volume5-4", api.ClaimLost, annBoundByController, annBindCompleted),
|
||||||
@ -91,13 +91,13 @@ func TestControllerSync(t *testing.T) {
|
|||||||
// is expected - it should stay bound.
|
// is expected - it should stay bound.
|
||||||
"5-5 - add bound volume from 1.2",
|
"5-5 - add bound volume from 1.2",
|
||||||
novolumes,
|
novolumes,
|
||||||
[]*api.PersistentVolume{addVolumeAnnotation(newVolume("volume5-5", "10Gi", "uid5-5", "claim5-5", api.VolumeBound, api.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
|
[]*api.PersistentVolume{addVolumeAnnotation(newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", api.VolumeBound, api.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
|
||||||
newClaimArray("claim5-5", "uid5-5", "1Gi", "", api.ClaimPending),
|
newClaimArray("claim5-5", "uid5-5", "1Gi", "", api.ClaimPending),
|
||||||
newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", api.ClaimBound, annBindCompleted, annBoundByController),
|
newClaimArray("claim5-5", "uid5-5", "1Gi", "volume5-5", api.ClaimBound, annBindCompleted, annBoundByController),
|
||||||
noevents, noerrors,
|
noevents, noerrors,
|
||||||
// Custom test function that generates a add event
|
// Custom test function that generates a add event
|
||||||
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
||||||
volume := newVolume("volume5-5", "10Gi", "uid5-5", "claim5-5", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
volume := newVolume("volume5-5", "1Gi", "uid5-5", "claim5-5", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
||||||
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)
|
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)
|
||||||
reactor.addVolumeEvent(volume)
|
reactor.addVolumeEvent(volume)
|
||||||
return nil
|
return nil
|
||||||
@ -107,14 +107,14 @@ func TestControllerSync(t *testing.T) {
|
|||||||
// updateVolume with provisioned volume from Kubernetes 1.2. No
|
// updateVolume with provisioned volume from Kubernetes 1.2. No
|
||||||
// "action" is expected - it should stay bound.
|
// "action" is expected - it should stay bound.
|
||||||
"5-6 - update bound volume from 1.2",
|
"5-6 - update bound volume from 1.2",
|
||||||
[]*api.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", api.VolumeBound, api.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
|
[]*api.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", api.VolumeBound, api.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
|
||||||
[]*api.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", api.VolumeBound, api.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
|
[]*api.PersistentVolume{addVolumeAnnotation(newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", api.VolumeBound, api.PersistentVolumeReclaimDelete), pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)},
|
||||||
newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", api.ClaimBound),
|
newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", api.ClaimBound),
|
||||||
newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", api.ClaimBound, annBindCompleted),
|
newClaimArray("claim5-6", "uid5-6", "1Gi", "volume5-6", api.ClaimBound, annBindCompleted),
|
||||||
noevents, noerrors,
|
noevents, noerrors,
|
||||||
// Custom test function that generates a add event
|
// Custom test function that generates a add event
|
||||||
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
||||||
volume := newVolume("volume5-6", "10Gi", "uid5-6", "claim5-6", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
volume := newVolume("volume5-6", "1Gi", "uid5-6", "claim5-6", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
||||||
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)
|
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, pvProvisioningCompletedAnnotationValue)
|
||||||
reactor.modifyVolumeEvent(volume)
|
reactor.modifyVolumeEvent(volume)
|
||||||
return nil
|
return nil
|
||||||
@ -131,7 +131,7 @@ func TestControllerSync(t *testing.T) {
|
|||||||
noevents, noerrors,
|
noevents, noerrors,
|
||||||
// Custom test function that generates a add event
|
// Custom test function that generates a add event
|
||||||
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
||||||
volume := newVolume("volume5-7", "10Gi", "uid5-7", "claim5-7", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
volume := newVolume("volume5-7", "1Gi", "uid5-7", "claim5-7", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
||||||
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes")
|
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes")
|
||||||
reactor.addVolumeEvent(volume)
|
reactor.addVolumeEvent(volume)
|
||||||
return nil
|
return nil
|
||||||
@ -148,7 +148,7 @@ func TestControllerSync(t *testing.T) {
|
|||||||
noevents, noerrors,
|
noevents, noerrors,
|
||||||
// Custom test function that generates a add event
|
// Custom test function that generates a add event
|
||||||
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
func(ctrl *PersistentVolumeController, reactor *volumeReactor, test controllerTest) error {
|
||||||
volume := newVolume("volume5-8", "10Gi", "uid5-8", "claim5-8", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
volume := newVolume("volume5-8", "1Gi", "uid5-8", "claim5-8", api.VolumeBound, api.PersistentVolumeReclaimDelete)
|
||||||
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes")
|
volume = addVolumeAnnotation(volume, pvProvisioningRequiredAnnotationKey, "yes")
|
||||||
reactor.modifyVolumeEvent(volume)
|
reactor.modifyVolumeEvent(volume)
|
||||||
return nil
|
return nil
|
||||||
|
@ -694,6 +694,17 @@ func withLabelSelector(labels map[string]string, claims []*api.PersistentVolumeC
|
|||||||
return claims
|
return claims
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// withExpectedCapacity sets the claim.Spec.Capacity of the first claim in the
|
||||||
|
// array to given value and returns the array. Meant to be used to compose
|
||||||
|
// claims specified inline in a test.
|
||||||
|
func withExpectedCapacity(capacity string, claims []*api.PersistentVolumeClaim) []*api.PersistentVolumeClaim {
|
||||||
|
claims[0].Status.Capacity = api.ResourceList{
|
||||||
|
api.ResourceName(api.ResourceStorage): resource.MustParse(capacity),
|
||||||
|
}
|
||||||
|
|
||||||
|
return claims
|
||||||
|
}
|
||||||
|
|
||||||
// withMessage saves given message into volume.Status.Message of the first
|
// withMessage saves given message into volume.Status.Message of the first
|
||||||
// volume in the array and returns the array. Meant to be used to compose
|
// volume in the array and returns the array. Meant to be used to compose
|
||||||
// volumes specified inline in a test.
|
// volumes specified inline in a test.
|
||||||
@ -741,6 +752,15 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase api.Persiste
|
|||||||
claim.Annotations[a] = "yes"
|
claim.Annotations[a] = "yes"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Bound claims must have proper Status.
|
||||||
|
if phase == api.ClaimBound {
|
||||||
|
claim.Status.AccessModes = claim.Spec.AccessModes
|
||||||
|
// For most of the tests it's enough to copy claim's requested capacity,
|
||||||
|
// individual tests can adjust it using withExpectedCapacity()
|
||||||
|
claim.Status.Capacity = claim.Spec.Resources.Requests
|
||||||
|
}
|
||||||
|
|
||||||
return &claim
|
return &claim
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user