Skip to content

Commit

Permalink
Merge pull request #667 from Jiawei0227/anno
Browse files Browse the repository at this point in the history
Support accepting GA annStorageProvisioner annotation
  • Loading branch information
k8s-ci-robot authored Aug 26, 2021
2 parents 1c82e2d + 731e1cd commit d686130
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
21 changes: 15 additions & 6 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,11 @@ const (

deleteVolumeRetryCount = 5

annMigratedTo = "pv.kubernetes.io/migrated-to"
annStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
annSelectedNode = "volume.kubernetes.io/selected-node"
annMigratedTo = "pv.kubernetes.io/migrated-to"
// TODO: Beta will be deprecated and removed in a later release
annBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
annStorageProvisioner = "volume.kubernetes.io/storage-provisioner"
annSelectedNode = "volume.kubernetes.io/selected-node"

snapshotNotBound = "snapshot %s not bound"

Expand Down Expand Up @@ -698,13 +700,17 @@ func (p *csiProvisioner) prepareProvision(ctx context.Context, claim *v1.Persist

func (p *csiProvisioner) Provision(ctx context.Context, options controller.ProvisionOptions) (*v1.PersistentVolume, controller.ProvisioningState, error) {
claim := options.PVC
if claim.Annotations[annStorageProvisioner] != p.driverName && claim.Annotations[annMigratedTo] != p.driverName {
provisioner, ok := claim.Annotations[annStorageProvisioner]
if !ok {
provisioner = claim.Annotations[annBetaStorageProvisioner]
}
if provisioner != p.driverName && claim.Annotations[annMigratedTo] != p.driverName {
// The storage provisioner annotation may not equal driver name but the
// PVC could have annotation "migrated-to" which is the new way to
// signal a PVC is migrated (k8s v1.17+)
return nil, controller.ProvisioningFinished, &controller.IgnoredError{
Reason: fmt.Sprintf("PVC annotated with external-provisioner name %s does not match provisioner driver name %s. This could mean the PVC is not migrated",
claim.Annotations[annStorageProvisioner],
provisioner,
p.driverName),
}

Expand Down Expand Up @@ -1229,7 +1235,10 @@ func (p *csiProvisioner) SupportsBlock(ctx context.Context) bool {
}

func (p *csiProvisioner) ShouldProvision(ctx context.Context, claim *v1.PersistentVolumeClaim) bool {
provisioner := claim.Annotations[annStorageProvisioner]
provisioner, ok := claim.Annotations[annStorageProvisioner]
if !ok {
provisioner = claim.Annotations[annBetaStorageProvisioner]
}
migratedTo := claim.Annotations[annMigratedTo]
if provisioner != p.driverName && migratedTo != p.driverName {
// Non-migrated in-tree volume is requested.
Expand Down
26 changes: 19 additions & 7 deletions pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var (
volumeModeFileSystem = v1.PersistentVolumeFilesystem
volumeModeBlock = v1.PersistentVolumeBlock

driverNameAnnotation = map[string]string{annStorageProvisioner: driverName}
driverNameAnnotation = map[string]string{annBetaStorageProvisioner: driverName}
translatedKey = "translated"
defaultfsType = "ext4"
)
Expand Down Expand Up @@ -503,7 +503,7 @@ func provisionFromPVCCapabilities() (rpc.PluginCapabilitySet, rpc.ControllerCapa
var fakeSCName = "fake-test-sc"

func createFakeNamedPVC(requestBytes int64, name string, userAnnotations map[string]string) *v1.PersistentVolumeClaim {
annotations := map[string]string{annStorageProvisioner: driverName}
annotations := map[string]string{annBetaStorageProvisioner: driverName}
for k, v := range userAnnotations {
annotations[k] = v
}
Expand Down Expand Up @@ -4503,43 +4503,55 @@ func TestProvisionWithMigration(t *testing.T) {
{
name: "provision with migration on",
scProvisioner: inTreePluginName,
annotation: map[string]string{annBetaStorageProvisioner: driverName},
expectTranslation: true,
},
{
name: "provision with migration on with GA annStorageProvisioner annontation",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: driverName},
expectTranslation: true,
},
{
name: "provision without migration for native CSI",
scProvisioner: driverName,
annotation: map[string]string{annBetaStorageProvisioner: driverName},
expectTranslation: false,
},
{
name: "provision without migration for native CSI with GA annStorageProvisioner annontation",
scProvisioner: driverName,
annotation: map[string]string{annStorageProvisioner: driverName},
expectTranslation: false,
},
{
name: "provision with migration for migrated-to CSI",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: inTreePluginName, annMigratedTo: driverName},
annotation: map[string]string{annBetaStorageProvisioner: inTreePluginName, annMigratedTo: driverName},
expectTranslation: true,
},
{
name: "provision with migration-to some random driver",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: inTreePluginName, annMigratedTo: "foo"},
annotation: map[string]string{annBetaStorageProvisioner: inTreePluginName, annMigratedTo: "foo"},
expectErr: true,
},
{
name: "provision with migration-to some random driver with random storageProvisioner",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: "foo", annMigratedTo: "foo"},
annotation: map[string]string{annBetaStorageProvisioner: "foo", annMigratedTo: "foo"},
expectErr: true,
},
{
name: "provision with migration for migrated-to CSI with CSI Provisioner",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: driverName, annMigratedTo: driverName},
annotation: map[string]string{annBetaStorageProvisioner: driverName, annMigratedTo: driverName},
expectTranslation: true,
},
{
name: "ignore in-tree PVC when provisioned by in-tree",
scProvisioner: inTreePluginName,
annotation: map[string]string{annStorageProvisioner: inTreePluginName},
annotation: map[string]string{annBetaStorageProvisioner: inTreePluginName},
expectErr: true,
},
}
Expand Down

0 comments on commit d686130

Please sign in to comment.