Merge pull request #104590 from Jiawei0227/anno

Add GA AnnStorageProvisioner annotation to PVC
This commit is contained in:
Kubernetes Prow Robot 2021-09-03 06:09:49 -07:00 committed by GitHub
commit bcd2ffbdc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 84 additions and 42 deletions

View File

@ -401,7 +401,7 @@ func newClaim(name, claimUID, capacity, boundToVolume string, phase v1.Persisten
claim.Annotations = make(map[string]string) claim.Annotations = make(map[string]string)
for _, a := range annotations { for _, a := range annotations {
switch a { switch a {
case pvutil.AnnStorageProvisioner: case pvutil.AnnBetaStorageProvisioner, pvutil.AnnStorageProvisioner:
claim.Annotations[a] = mockPluginName claim.Annotations[a] = mockPluginName
default: default:
claim.Annotations[a] = "yes" claim.Annotations[a] = "yes"

View File

@ -174,7 +174,7 @@ func TestProvisionSync(t *testing.T) {
newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned), newVolumeArray("pvc-uid11-1", "1Gi", "uid11-1", "claim11-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned),
newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold),
// Binding will be completed in the next syncClaim // Binding will be completed in the next syncClaim
newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-1", "uid11-1", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim),
}, },
{ {
@ -193,7 +193,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-3", "uid11-3", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Warning ProvisioningFailed"}, noerrors, []string{"Warning ProvisioningFailed"}, noerrors,
wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim),
}, },
@ -203,7 +203,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-4", "uid11-4", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Warning ProvisioningFailed"}, noerrors, []string{"Warning ProvisioningFailed"}, noerrors,
wrapTestWithProvisionCalls([]provisionCall{provision1Error}, testSyncClaim), wrapTestWithProvisionCalls([]provisionCall{provision1Error}, testSyncClaim),
}, },
@ -227,7 +227,7 @@ func TestProvisionSync(t *testing.T) {
newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned), newVolumeArray("pvc-uid11-7", "1Gi", "uid11-7", "claim11-7", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned),
newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold),
// The claim would be bound in next syncClaim // The claim would be bound in next syncClaim
newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-7", "uid11-7", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
noevents, noerrors, noevents, noerrors,
wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) {
// Create a volume before provisionClaimOperation starts. // Create a volume before provisionClaimOperation starts.
@ -244,7 +244,7 @@ func TestProvisionSync(t *testing.T) {
newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned), newVolumeArray("pvc-uid11-8", "1Gi", "uid11-8", "claim11-8", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned),
newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold),
// Binding will be completed in the next syncClaim // Binding will be completed in the next syncClaim
newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-8", "uid11-8", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Normal ProvisioningSucceeded"}, []string{"Normal ProvisioningSucceeded"},
[]pvtesting.ReactorError{ []pvtesting.ReactorError{
// Inject error to the first // Inject error to the first
@ -261,7 +261,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-9", "uid11-9", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Warning ProvisioningFailed"}, []string{"Warning ProvisioningFailed"},
[]pvtesting.ReactorError{ []pvtesting.ReactorError{
// Inject error to five kubeclient.PersistentVolumes.Create() // Inject error to five kubeclient.PersistentVolumes.Create()
@ -286,7 +286,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-10", "uid11-10", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"},
[]pvtesting.ReactorError{ []pvtesting.ReactorError{
// Inject error to five kubeclient.PersistentVolumes.Create() // Inject error to five kubeclient.PersistentVolumes.Create()
@ -307,7 +307,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-11", "uid11-11", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"}, []string{"Warning ProvisioningFailed", "Warning ProvisioningCleanupFailed"},
[]pvtesting.ReactorError{ []pvtesting.ReactorError{
// Inject error to five kubeclient.PersistentVolumes.Create() // Inject error to five kubeclient.PersistentVolumes.Create()
@ -337,7 +337,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-12", "uid11-12", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Warning ProvisioningFailed"}, []string{"Warning ProvisioningFailed"},
[]pvtesting.ReactorError{ []pvtesting.ReactorError{
// Inject error to five kubeclient.PersistentVolumes.Create() // Inject error to five kubeclient.PersistentVolumes.Create()
@ -365,7 +365,7 @@ func TestProvisionSync(t *testing.T) {
newVolumeArray("pvc-uid11-13", "1Gi", "uid11-13", "claim11-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classSilver, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned), newVolumeArray("pvc-uid11-13", "1Gi", "uid11-13", "claim11-13", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classSilver, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned),
newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver), newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver),
// Binding will be completed in the next syncClaim // Binding will be completed in the next syncClaim
newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver, pvutil.AnnStorageProvisioner), newClaimArray("claim11-13", "uid11-13", "1Gi", "", v1.ClaimPending, &classSilver, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
[]string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision2Success}, testSyncClaim), []string{"Normal ProvisioningSucceeded"}, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision2Success}, testSyncClaim),
}, },
{ {
@ -401,8 +401,9 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal), newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal),
claimWithAnnotation(pvutil.AnnBetaStorageProvisioner, "vendor.com/my-volume",
claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume",
newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal)), newClaimArray("claim11-17", "uid11-17", "1Gi", "", v1.ClaimPending, &classExternal))),
[]string{"Normal ExternalProvisioning"}, []string{"Normal ExternalProvisioning"},
noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim),
}, },
@ -431,7 +432,7 @@ func TestProvisionSync(t *testing.T) {
// end of the test is empty. // end of the test is empty.
novolumes, novolumes,
newClaimArray("claim11-19", "uid11-19", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim11-19", "uid11-19", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim11-19", "uid11-19", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner), newClaimArray("claim11-19", "uid11-19", "1Gi", "", v1.ClaimPending, &classGold, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
noevents, noevents,
[]pvtesting.ReactorError{ []pvtesting.ReactorError{
// Inject errors to simulate crashed API server during // Inject errors to simulate crashed API server during
@ -452,7 +453,7 @@ func TestProvisionSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions), newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions),
newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions, pvutil.AnnStorageProvisioner), newClaimArray("claim11-20", "uid11-20", "1Gi", "", v1.ClaimPending, &classUnsupportedMountOptions, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
// Expect event to be prefixed with "Mount options" because saving PV will fail anyway // Expect event to be prefixed with "Mount options" because saving PV will fail anyway
[]string{"Warning ProvisioningFailed Mount options"}, []string{"Warning ProvisioningFailed Mount options"},
noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), noerrors, wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim),
@ -468,6 +469,7 @@ func TestProvisionSync(t *testing.T) {
newClaim("claim11-21", "uid11-21", "1Gi", "", v1.ClaimPending, &classGold), newClaim("claim11-21", "uid11-21", "1Gi", "", v1.ClaimPending, &classGold),
map[string]string{ map[string]string{
pvutil.AnnStorageProvisioner: "vendor.com/MockCSIDriver", pvutil.AnnStorageProvisioner: "vendor.com/MockCSIDriver",
pvutil.AnnBetaStorageProvisioner: "vendor.com/MockCSIDriver",
pvutil.AnnMigratedTo: "vendor.com/MockCSIDriver", pvutil.AnnMigratedTo: "vendor.com/MockCSIDriver",
}), }),
}, },
@ -496,7 +498,7 @@ func TestProvisionSync(t *testing.T) {
claimWithAnnotation(pvutil.AnnSelectedNode, "node1", claimWithAnnotation(pvutil.AnnSelectedNode, "node1",
newClaimArray("claim11-23", "uid11-23", "1Gi", "", v1.ClaimPending, &classCopper)), newClaimArray("claim11-23", "uid11-23", "1Gi", "", v1.ClaimPending, &classCopper)),
claimWithAnnotation(pvutil.AnnSelectedNode, "node1", claimWithAnnotation(pvutil.AnnSelectedNode, "node1",
newClaimArray("claim11-23", "uid11-23", "1Gi", "", v1.ClaimPending, &classCopper, pvutil.AnnStorageProvisioner)), newClaimArray("claim11-23", "uid11-23", "1Gi", "", v1.ClaimPending, &classCopper, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner)),
[]string{"Normal ProvisioningSucceeded"}, []string{"Normal ProvisioningSucceeded"},
noerrors, noerrors,
wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim),
@ -514,9 +516,10 @@ func TestProvisionSync(t *testing.T) {
newVolumeArray("volume11-24", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classExternalWait), newVolumeArray("volume11-24", "1Gi", "", "", v1.VolumeAvailable, v1.PersistentVolumeReclaimDelete, classExternalWait),
claimWithAnnotation(pvutil.AnnSelectedNode, "node1", claimWithAnnotation(pvutil.AnnSelectedNode, "node1",
newClaimArray("claim11-24", "uid11-24", "1Gi", "", v1.ClaimPending, &classExternalWait)), newClaimArray("claim11-24", "uid11-24", "1Gi", "", v1.ClaimPending, &classExternalWait)),
claimWithAnnotation(pvutil.AnnBetaStorageProvisioner, "vendor.com/my-volume-wait",
claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume-wait", claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume-wait",
claimWithAnnotation(pvutil.AnnSelectedNode, "node1", claimWithAnnotation(pvutil.AnnSelectedNode, "node1",
newClaimArray("claim11-24", "uid11-24", "1Gi", "", v1.ClaimPending, &classExternalWait))), newClaimArray("claim11-24", "uid11-24", "1Gi", "", v1.ClaimPending, &classExternalWait)))),
[]string{"Normal ExternalProvisioning"}, []string{"Normal ExternalProvisioning"},
noerrors, testSyncClaim, noerrors, testSyncClaim,
}, },
@ -570,7 +573,7 @@ func TestProvisionMultiSync(t *testing.T) {
novolumes, novolumes,
newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned), newVolumeArray("pvc-uid12-1", "1Gi", "uid12-1", "claim12-1", v1.VolumeBound, v1.PersistentVolumeReclaimDelete, classGold, pvutil.AnnBoundByController, pvutil.AnnDynamicallyProvisioned),
newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, &classGold), newClaimArray("claim12-1", "uid12-1", "1Gi", "", v1.ClaimPending, &classGold),
newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, &classGold, pvutil.AnnBoundByController, pvutil.AnnBindCompleted, pvutil.AnnStorageProvisioner), newClaimArray("claim12-1", "uid12-1", "1Gi", "pvc-uid12-1", v1.ClaimBound, &classGold, pvutil.AnnBoundByController, pvutil.AnnBindCompleted, pvutil.AnnStorageProvisioner, pvutil.AnnBetaStorageProvisioner),
noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), noevents, noerrors, wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim),
}, },
{ {
@ -579,8 +582,9 @@ func TestProvisionMultiSync(t *testing.T) {
novolumes, novolumes,
newVolumeArray("pvc-uid12-2", "1Gi", "uid12-2", "claim12-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, pvutil.AnnBoundByController), newVolumeArray("pvc-uid12-2", "1Gi", "uid12-2", "claim12-2", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, pvutil.AnnBoundByController),
newClaimArray("claim12-2", "uid12-2", "1Gi", "", v1.ClaimPending, &classExternal), newClaimArray("claim12-2", "uid12-2", "1Gi", "", v1.ClaimPending, &classExternal),
claimWithAnnotation(pvutil.AnnBetaStorageProvisioner, "vendor.com/my-volume",
claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume",
newClaimArray("claim12-2", "uid12-2", "1Gi", "pvc-uid12-2", v1.ClaimBound, &classExternal, pvutil.AnnBoundByController, pvutil.AnnBindCompleted)), newClaimArray("claim12-2", "uid12-2", "1Gi", "pvc-uid12-2", v1.ClaimBound, &classExternal, pvutil.AnnBoundByController, pvutil.AnnBindCompleted))),
[]string{"Normal ExternalProvisioning"}, []string{"Normal ExternalProvisioning"},
noerrors, noerrors,
wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) {
@ -604,8 +608,9 @@ func TestProvisionMultiSync(t *testing.T) {
novolumes, novolumes,
novolumes, novolumes,
newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal), newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal),
claimWithAnnotation(pvutil.AnnBetaStorageProvisioner, "vendor.com/my-volume",
claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume",
newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal)), newClaimArray("claim12-3", "uid12-3", "1Gi", "", v1.ClaimPending, &classExternal))),
[]string{"Normal ExternalProvisioning"}, []string{"Normal ExternalProvisioning"},
noerrors, noerrors,
wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim), wrapTestWithProvisionCalls([]provisionCall{provision1Success}, testSyncClaim),
@ -616,8 +621,9 @@ func TestProvisionMultiSync(t *testing.T) {
novolumes, novolumes,
newVolumeArray("pvc-uid12-4", "1Gi", "uid12-4", "claim12-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, pvutil.AnnBoundByController), newVolumeArray("pvc-uid12-4", "1Gi", "uid12-4", "claim12-4", v1.VolumeBound, v1.PersistentVolumeReclaimRetain, classExternal, pvutil.AnnBoundByController),
newClaimArray("claim12-4", "uid12-4", "1Gi", "", v1.ClaimPending, &classExternal), newClaimArray("claim12-4", "uid12-4", "1Gi", "", v1.ClaimPending, &classExternal),
claimWithAnnotation(pvutil.AnnBetaStorageProvisioner, "vendor.com/my-volume",
claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume", claimWithAnnotation(pvutil.AnnStorageProvisioner, "vendor.com/my-volume",
newClaimArray("claim12-4", "uid12-4", "1Gi", "pvc-uid12-4", v1.ClaimBound, &classExternal, pvutil.AnnBoundByController, pvutil.AnnBindCompleted)), newClaimArray("claim12-4", "uid12-4", "1Gi", "pvc-uid12-4", v1.ClaimBound, &classExternal, pvutil.AnnBoundByController, pvutil.AnnBindCompleted))),
[]string{"Normal ExternalProvisioning"}, []string{"Normal ExternalProvisioning"},
noerrors, noerrors,
wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) { wrapTestWithInjectedOperation(wrapTestWithProvisionCalls([]provisionCall{}, testSyncClaim), func(ctrl *PersistentVolumeController, reactor *pvtesting.VolumeReactor) {

View File

@ -331,7 +331,7 @@ func (ctrl *PersistentVolumeController) updateClaimMigrationAnnotations(claim *v
// when no modifications are required this function could sometimes return a // when no modifications are required this function could sometimes return a
// copy of the volume and sometimes return a ref to the original // copy of the volume and sometimes return a ref to the original
claimClone := claim.DeepCopy() claimClone := claim.DeepCopy()
modified := updateMigrationAnnotations(ctrl.csiMigratedPluginManager, ctrl.translator, claimClone.Annotations, pvutil.AnnStorageProvisioner) modified := updateMigrationAnnotations(ctrl.csiMigratedPluginManager, ctrl.translator, claimClone.Annotations, true)
if !modified { if !modified {
return claimClone, nil return claimClone, nil
} }
@ -348,7 +348,7 @@ func (ctrl *PersistentVolumeController) updateClaimMigrationAnnotations(claim *v
func (ctrl *PersistentVolumeController) updateVolumeMigrationAnnotations(volume *v1.PersistentVolume) (*v1.PersistentVolume, error) { func (ctrl *PersistentVolumeController) updateVolumeMigrationAnnotations(volume *v1.PersistentVolume) (*v1.PersistentVolume, error) {
volumeClone := volume.DeepCopy() volumeClone := volume.DeepCopy()
modified := updateMigrationAnnotations(ctrl.csiMigratedPluginManager, ctrl.translator, volumeClone.Annotations, pvutil.AnnDynamicallyProvisioned) modified := updateMigrationAnnotations(ctrl.csiMigratedPluginManager, ctrl.translator, volumeClone.Annotations, false)
if !modified { if !modified {
return volumeClone, nil return volumeClone, nil
} }
@ -365,12 +365,14 @@ func (ctrl *PersistentVolumeController) updateVolumeMigrationAnnotations(volume
} }
// updateMigrationAnnotations takes an Annotations map and checks for a // updateMigrationAnnotations takes an Annotations map and checks for a
// provisioner name using the provisionerKey. It will then add a // provisioner name depending if the annotation came from a PVC or not.
// "pv.kubernetes.io/migrated-to" annotation if migration with the CSI // It will then add a "pv.kubernetes.io/migrated-to" annotation if migration with
// driver name for that provisioner is "on" based on feature flags, it will also // the CSI driver name for that provisioner is "on" based on feature flags, it will also
// remove the annotation is migration is "off" for that provisioner in rollback // remove the annotation if migration is "off" for that provisioner in rollback
// scenarios. Returns true if the annotations map was modified and false otherwise. // scenarios. Returns true if the annotations map was modified and false otherwise.
func updateMigrationAnnotations(cmpm CSIMigratedPluginManager, translator CSINameTranslator, ann map[string]string, provisionerKey string) bool { // Parameters:
// - claim: true means the ann came from a PVC, false means the ann came from a PV
func updateMigrationAnnotations(cmpm CSIMigratedPluginManager, translator CSINameTranslator, ann map[string]string, claim bool) bool {
var csiDriverName string var csiDriverName string
var err error var err error
@ -379,11 +381,25 @@ func updateMigrationAnnotations(cmpm CSIMigratedPluginManager, translator CSINam
// this is migrated - no change // this is migrated - no change
return false return false
} }
var provisionerKey string
if claim {
provisionerKey = pvutil.AnnStorageProvisioner
} else {
provisionerKey = pvutil.AnnDynamicallyProvisioned
}
provisioner, ok := ann[provisionerKey] provisioner, ok := ann[provisionerKey]
if !ok { if !ok {
if claim {
// Also check beta AnnStorageProvisioner annontation to make sure
provisioner, ok = ann[pvutil.AnnBetaStorageProvisioner]
if !ok {
return false
}
} else {
// Volume not dynamically provisioned. Ignore // Volume not dynamically provisioned. Ignore
return false return false
} }
}
migratedToDriver := ann[pvutil.AnnMigratedTo] migratedToDriver := ann[pvutil.AnnMigratedTo]
if cmpm.IsMigrationEnabledForPlugin(provisioner) { if cmpm.IsMigrationEnabledForPlugin(provisioner) {
@ -547,7 +563,7 @@ func (ctrl *PersistentVolumeController) resync() {
} }
// setClaimProvisioner saves // setClaimProvisioner saves
// claim.Annotations[pvutil.AnnStorageProvisioner] = class.Provisioner // claim.Annotations["volume.kubernetes.io/storage-provisioner"] = class.Provisioner
func (ctrl *PersistentVolumeController) setClaimProvisioner(claim *v1.PersistentVolumeClaim, provisionerName string) (*v1.PersistentVolumeClaim, error) { func (ctrl *PersistentVolumeController) setClaimProvisioner(claim *v1.PersistentVolumeClaim, provisionerName string) (*v1.PersistentVolumeClaim, error) {
if val, ok := claim.Annotations[pvutil.AnnStorageProvisioner]; ok && val == provisionerName { if val, ok := claim.Annotations[pvutil.AnnStorageProvisioner]; ok && val == provisionerName {
// annotation is already set, nothing to do // annotation is already set, nothing to do
@ -557,8 +573,10 @@ func (ctrl *PersistentVolumeController) setClaimProvisioner(claim *v1.Persistent
// The volume from method args can be pointing to watcher cache. We must not // The volume from method args can be pointing to watcher cache. We must not
// modify these, therefore create a copy. // modify these, therefore create a copy.
claimClone := claim.DeepCopy() claimClone := claim.DeepCopy()
// TODO: remove the beta storage provisioner anno after the deprecation period
metav1.SetMetaDataAnnotation(&claimClone.ObjectMeta, pvutil.AnnBetaStorageProvisioner, provisionerName)
metav1.SetMetaDataAnnotation(&claimClone.ObjectMeta, pvutil.AnnStorageProvisioner, provisionerName) metav1.SetMetaDataAnnotation(&claimClone.ObjectMeta, pvutil.AnnStorageProvisioner, provisionerName)
updateMigrationAnnotations(ctrl.csiMigratedPluginManager, ctrl.translator, claimClone.Annotations, pvutil.AnnStorageProvisioner) updateMigrationAnnotations(ctrl.csiMigratedPluginManager, ctrl.translator, claimClone.Annotations, true)
newClaim, err := ctrl.kubeClient.CoreV1().PersistentVolumeClaims(claim.Namespace).Update(context.TODO(), claimClone, metav1.UpdateOptions{}) newClaim, err := ctrl.kubeClient.CoreV1().PersistentVolumeClaims(claim.Namespace).Update(context.TODO(), claimClone, metav1.UpdateOptions{})
if err != nil { if err != nil {
return newClaim, err return newClaim, err

View File

@ -557,6 +557,14 @@ func TestAnnealMigrationAnnotations(t *testing.T) {
expClaimAnnotations: map[string]string{pvutil.AnnStorageProvisioner: gcePlugin, pvutil.AnnMigratedTo: gceDriver}, expClaimAnnotations: map[string]string{pvutil.AnnStorageProvisioner: gcePlugin, pvutil.AnnMigratedTo: gceDriver},
migratedDriverGates: []featuregate.Feature{features.CSIMigrationGCE}, migratedDriverGates: []featuregate.Feature{features.CSIMigrationGCE},
}, },
{
name: "migration on for GCE with Beta storage provisioner annontation",
volumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: gcePlugin},
expVolumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: gcePlugin, pvutil.AnnMigratedTo: gceDriver},
claimAnnotations: map[string]string{pvutil.AnnBetaStorageProvisioner: gcePlugin},
expClaimAnnotations: map[string]string{pvutil.AnnBetaStorageProvisioner: gcePlugin, pvutil.AnnMigratedTo: gceDriver},
migratedDriverGates: []featuregate.Feature{features.CSIMigrationGCE},
},
{ {
name: "migration off for GCE", name: "migration off for GCE",
volumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: gcePlugin}, volumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: gcePlugin},
@ -573,6 +581,14 @@ func TestAnnealMigrationAnnotations(t *testing.T) {
expClaimAnnotations: map[string]string{pvutil.AnnStorageProvisioner: gcePlugin}, expClaimAnnotations: map[string]string{pvutil.AnnStorageProvisioner: gcePlugin},
migratedDriverGates: []featuregate.Feature{}, migratedDriverGates: []featuregate.Feature{},
}, },
{
name: "migration off for GCE removes migrated to (rollback) with Beta storage provisioner annontation",
volumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: gcePlugin, pvutil.AnnMigratedTo: gceDriver},
expVolumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: gcePlugin},
claimAnnotations: map[string]string{pvutil.AnnBetaStorageProvisioner: gcePlugin, pvutil.AnnMigratedTo: gceDriver},
expClaimAnnotations: map[string]string{pvutil.AnnBetaStorageProvisioner: gcePlugin},
migratedDriverGates: []featuregate.Feature{},
},
{ {
name: "migration on for GCE other plugin not affected", name: "migration on for GCE other plugin not affected",
volumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: testPlugin}, volumeAnnotations: map[string]string{pvutil.AnnDynamicallyProvisioned: testPlugin},
@ -625,14 +641,14 @@ func TestAnnealMigrationAnnotations(t *testing.T) {
} }
if tc.volumeAnnotations != nil { if tc.volumeAnnotations != nil {
ann := tc.volumeAnnotations ann := tc.volumeAnnotations
updateMigrationAnnotations(cmpm, translator, ann, pvutil.AnnDynamicallyProvisioned) updateMigrationAnnotations(cmpm, translator, ann, false)
if !reflect.DeepEqual(tc.expVolumeAnnotations, ann) { if !reflect.DeepEqual(tc.expVolumeAnnotations, ann) {
t.Errorf("got volume annoations: %v, but expected: %v", ann, tc.expVolumeAnnotations) t.Errorf("got volume annoations: %v, but expected: %v", ann, tc.expVolumeAnnotations)
} }
} }
if tc.claimAnnotations != nil { if tc.claimAnnotations != nil {
ann := tc.claimAnnotations ann := tc.claimAnnotations
updateMigrationAnnotations(cmpm, translator, ann, pvutil.AnnStorageProvisioner) updateMigrationAnnotations(cmpm, translator, ann, true)
if !reflect.DeepEqual(tc.expClaimAnnotations, ann) { if !reflect.DeepEqual(tc.expClaimAnnotations, ann) {
t.Errorf("got volume annoations: %v, but expected: %v", ann, tc.expVolumeAnnotations) t.Errorf("got volume annoations: %v, but expected: %v", ann, tc.expVolumeAnnotations)
} }

View File

@ -74,7 +74,9 @@ const (
// AnnStorageProvisioner annotation is added to a PVC that is supposed to be dynamically // AnnStorageProvisioner annotation is added to a PVC that is supposed to be dynamically
// provisioned. Its value is name of volume plugin that is supposed to provision // provisioned. Its value is name of volume plugin that is supposed to provision
// a volume for this PVC. // a volume for this PVC.
AnnStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner" // TODO: remove beta anno once deprecation period ends
AnnStorageProvisioner = "volume.kubernetes.io/storage-provisioner"
AnnBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
) )
// IsDelayBindingProvisioning checks if claim provisioning with selected-node annotation // IsDelayBindingProvisioning checks if claim provisioning with selected-node annotation