Skip to content

Commit

Permalink
Merge pull request #110 from Jiawei0227/anno
Browse files Browse the repository at this point in the history
Update annStorageProvisioner to GA version
  • Loading branch information
k8s-ci-robot authored Oct 11, 2021
2 parents 853cdd7 + de4a43e commit f863560
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
10 changes: 8 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ const annDynamicallyProvisioned = "pv.kubernetes.io/provisioned-by"
// Deletion.
const annMigratedTo = "pv.kubernetes.io/migrated-to"

const annStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
const annBetaStorageProvisioner = "volume.beta.kubernetes.io/storage-provisioner"
const annStorageProvisioner = "volume.kubernetes.io/storage-provisioner"

// This annotation is added to a PVC that has been triggered by scheduler to
// be dynamically provisioned. Its value is the name of the selected node.
Expand Down Expand Up @@ -1134,7 +1135,12 @@ func (ctrl *ProvisionController) shouldProvision(ctx context.Context, claim *v1.
}
}

if provisioner, found := claim.Annotations[annStorageProvisioner]; found {
provisioner, found := claim.Annotations[annStorageProvisioner]
if !found {
provisioner, found = claim.Annotations[annBetaStorageProvisioner]
}

if found {
if ctrl.knownProvisioner(provisioner) {
claimClass := util.GetPersistentVolumeClaimClass(claim)
class, err := ctrl.getStorageClass(claimClass)
Expand Down
44 changes: 31 additions & 13 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,13 @@ func TestController(t *testing.T) {
name: "remove selectedNode and claim on reschedule",
objs: []runtime.Object{
newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-1"}),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-1"}),
newNode("node-1"),
},
provisionerName: "foo.bar/baz",
provisioner: newRescheduleTestProvisioner(),
expectedClaims: []v1.PersistentVolumeClaim{
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz"}),
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz"}),
},
expectedClaimsInProgress: nil, // not in progress anymore
expectedMetrics: testMetrics{
Expand All @@ -542,12 +542,12 @@ func TestController(t *testing.T) {
name: "do not remove selectedNode after final error, only the claim",
objs: []runtime.Object{
newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
},
provisionerName: "foo.bar/baz",
provisioner: newBadTestProvisioner(),
expectedClaims: []v1.PersistentVolumeClaim{
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
},
expectedClaimsInProgress: nil, // not in progress anymore
expectedMetrics: testMetrics{
Expand All @@ -560,12 +560,12 @@ func TestController(t *testing.T) {
name: "do not remove selectedNode if nothing changes",
objs: []runtime.Object{
newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
},
provisionerName: "foo.bar/baz",
provisioner: newNoChangeTestProvisioner(),
expectedClaims: []v1.PersistentVolumeClaim{
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-wrong"}),
},
expectedMetrics: testMetrics{
provisioned: counts{
Expand All @@ -577,13 +577,13 @@ func TestController(t *testing.T) {
name: "do not remove selectedNode while in progress",
objs: []runtime.Object{
newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-1"}),
newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-1"}),
newNode("node-1"),
},
provisionerName: "foo.bar/baz",
provisioner: newTemporaryTestProvisioner(),
expectedClaims: []v1.PersistentVolumeClaim{
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-1"}),
*newClaim("claim-1", "uid-1-1", "class-1", "foo.bar/baz", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node-1"}),
},
expectedClaimsInProgress: []string{"uid-1-1"},
expectedMetrics: testMetrics{
Expand Down Expand Up @@ -837,25 +837,35 @@ func TestShouldProvision(t *testing.T) {
claim: newClaim("claim-1", "1-1", "class-1", "abc.def/ghi", "", nil),
expectedShould: false,
},
// Kubernetes 1.5 provisioning - annStorageProvisioner is set
// Kubernetes 1.5 provisioning - annBetaStorageProvisioner is set
// and only this annotation is evaluated
{
name: "unknown provisioner annotation 1.5",
provisionerName: "foo.bar/baz",
provisioner: newTestProvisioner(),
class: newStorageClass("class-1", "foo.bar/baz"),
claim: newClaim("claim-1", "1-1", "class-1", "", "",
map[string]string{annStorageProvisioner: "abc.def/ghi"}),
map[string]string{annBetaStorageProvisioner: "abc.def/ghi"}),
expectedShould: false,
},
// Kubernetes 1.5 provisioning - annStorageProvisioner is not set
// Kubernetes 1.5 provisioning - annBetaStorageProvisioner is not set
{
name: "no provisioner annotation 1.5",
provisionerName: "foo.bar/baz",
class: newStorageClass("class-1", "foo.bar/baz"),
claim: newClaim("claim-1", "1-1", "class-1", "", "", nil),
expectedShould: false,
},
// Kubernetes 1.23 provisioning - annStorageProvisioner is set
{
name: "unknown provisioner annotation 1.23",
provisionerName: "foo.bar/baz",
provisioner: newTestProvisioner(),
class: newStorageClass("class-1", "foo.bar/baz"),
claim: newClaim("claim-1", "1-1", "class-1", "", "",
map[string]string{annStorageProvisioner: "abc.def/ghi"}),
expectedShould: false,
},
{
name: "qualifier says no",
provisionerName: "foo.bar/baz",
Expand All @@ -877,14 +887,22 @@ func TestShouldProvision(t *testing.T) {
provisionerName: "foo.bar/baz",
provisioner: newTestProvisioner(),
class: newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
claim: newClaim("claim-1", "1-1", "class-1", "", "", map[string]string{annStorageProvisioner: "foo.bar/baz"}),
claim: newClaim("claim-1", "1-1", "class-1", "", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz"}),
expectedShould: false,
},
{
name: "if PVC is in delay binding mode, should provision if annSelectedNode is set",
provisionerName: "foo.bar/baz",
provisioner: newTestProvisioner(),
class: newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
claim: newClaim("claim-1", "1-1", "class-1", "", "", map[string]string{annBetaStorageProvisioner: "foo.bar/baz", annSelectedNode: "node1"}),
expectedShould: true,
},
{
name: "if PVC is in delay binding mode, should provision if annSelectedNode is set with annStorageProvisioner",
provisionerName: "foo.bar/baz",
provisioner: newTestProvisioner(),
class: newStorageClassWithVolumeBindingMode("class-1", "foo.bar/baz", &modeWait),
claim: newClaim("claim-1", "1-1", "class-1", "", "", map[string]string{annStorageProvisioner: "foo.bar/baz", annSelectedNode: "node1"}),
expectedShould: true,
},
Expand Down Expand Up @@ -1355,7 +1373,7 @@ func newClaim(name, claimUID, class, provisioner, volumeName string, annotations
},
}
if provisioner != "" {
claim.Annotations[annStorageProvisioner] = provisioner
claim.Annotations[annBetaStorageProvisioner] = provisioner
}
// Allow overwriting of above annotations
for k, v := range annotations {
Expand Down

0 comments on commit f863560

Please sign in to comment.