From 5a6c5b07a23ecbc22abd19aa7a286c09aeac6f77 Mon Sep 17 00:00:00 2001 From: Xing Yang Date: Fri, 24 Aug 2018 12:46:32 -0700 Subject: [PATCH] Address Tim's comments --- api/openapi-spec/swagger.json | 2 +- api/swagger-spec/apps_v1.json | 2 +- api/swagger-spec/apps_v1beta1.json | 2 +- api/swagger-spec/apps_v1beta2.json | 2 +- api/swagger-spec/v1.json | 2 +- docs/api-reference/apps/v1/definitions.html | 2 +- docs/api-reference/apps/v1beta1/definitions.html | 2 +- docs/api-reference/apps/v1beta2/definitions.html | 2 +- docs/api-reference/v1/definitions.html | 2 +- pkg/apis/core/types.go | 4 +++- pkg/apis/core/validation/validation.go | 16 ++++++++-------- staging/src/k8s.io/api/core/v1/generated.proto | 4 +++- staging/src/k8s.io/api/core/v1/types.go | 4 +++- .../api/core/v1/types_swagger_doc_generated.go | 2 +- 14 files changed, 27 insertions(+), 21 deletions(-) diff --git a/api/openapi-spec/swagger.json b/api/openapi-spec/swagger.json index 61dd3e69369..5cc50c33bac 100644 --- a/api/openapi-spec/swagger.json +++ b/api/openapi-spec/swagger.json @@ -82490,7 +82490,7 @@ } }, "dataSource": { - "description": "If specified, volume will be prepopulated with data from the DataSource.", + "description": "If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume.", "$ref": "#/definitions/io.k8s.api.core.v1.TypedLocalObjectReference" }, "resources": { diff --git a/api/swagger-spec/apps_v1.json b/api/swagger-spec/apps_v1.json index 24b755e9461..4a4f6cdb316 100644 --- a/api/swagger-spec/apps_v1.json +++ b/api/swagger-spec/apps_v1.json @@ -9516,7 +9516,7 @@ }, "dataSource": { "$ref": "v1.TypedLocalObjectReference", - "description": "If specified, volume will be prepopulated with data from the DataSource." + "description": "If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume." } } }, diff --git a/api/swagger-spec/apps_v1beta1.json b/api/swagger-spec/apps_v1beta1.json index e244271ec71..89f226baa51 100644 --- a/api/swagger-spec/apps_v1beta1.json +++ b/api/swagger-spec/apps_v1beta1.json @@ -6798,7 +6798,7 @@ }, "dataSource": { "$ref": "v1.TypedLocalObjectReference", - "description": "If specified, volume will be prepopulated with data from the DataSource." + "description": "If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume." } } }, diff --git a/api/swagger-spec/apps_v1beta2.json b/api/swagger-spec/apps_v1beta2.json index 88eedb7a87f..516b7f7d32f 100644 --- a/api/swagger-spec/apps_v1beta2.json +++ b/api/swagger-spec/apps_v1beta2.json @@ -9520,7 +9520,7 @@ }, "dataSource": { "$ref": "v1.TypedLocalObjectReference", - "description": "If specified, volume will be prepopulated with data from the DataSource." + "description": "If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume." } } }, diff --git a/api/swagger-spec/v1.json b/api/swagger-spec/v1.json index fc7ff35e277..8b3867a65d2 100644 --- a/api/swagger-spec/v1.json +++ b/api/swagger-spec/v1.json @@ -19311,7 +19311,7 @@ }, "dataSource": { "$ref": "v1.TypedLocalObjectReference", - "description": "If specified, volume will be prepopulated with data from the DataSource." + "description": "If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume." } } }, diff --git a/docs/api-reference/apps/v1/definitions.html b/docs/api-reference/apps/v1/definitions.html index 68f95e2d517..9d5eab6638e 100755 --- a/docs/api-reference/apps/v1/definitions.html +++ b/docs/api-reference/apps/v1/definitions.html @@ -1019,7 +1019,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }

dataSource

-

If specified, volume will be prepopulated with data from the DataSource.

+

If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume.

true

v1.TypedLocalObjectReference

diff --git a/docs/api-reference/apps/v1beta1/definitions.html b/docs/api-reference/apps/v1beta1/definitions.html index c1a9dc896f0..24436962182 100755 --- a/docs/api-reference/apps/v1beta1/definitions.html +++ b/docs/api-reference/apps/v1beta1/definitions.html @@ -1047,7 +1047,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }

dataSource

-

If specified, volume will be prepopulated with data from the DataSource.

+

If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume.

true

v1.TypedLocalObjectReference

diff --git a/docs/api-reference/apps/v1beta2/definitions.html b/docs/api-reference/apps/v1beta2/definitions.html index 73383a8f21f..e9f4c03d4a0 100755 --- a/docs/api-reference/apps/v1beta2/definitions.html +++ b/docs/api-reference/apps/v1beta2/definitions.html @@ -994,7 +994,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }

dataSource

-

If specified, volume will be prepopulated with data from the DataSource.

+

If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume.

true

v1.TypedLocalObjectReference

diff --git a/docs/api-reference/v1/definitions.html b/docs/api-reference/v1/definitions.html index acd4fbd57fb..c2a40768551 100755 --- a/docs/api-reference/v1/definitions.html +++ b/docs/api-reference/v1/definitions.html @@ -696,7 +696,7 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }

dataSource

-

If specified, volume will be prepopulated with data from the DataSource.

+

If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume.

true

v1.TypedLocalObjectReference

diff --git a/pkg/apis/core/types.go b/pkg/apis/core/types.go index 698e182ae61..5697328e7d1 100644 --- a/pkg/apis/core/types.go +++ b/pkg/apis/core/types.go @@ -413,7 +413,9 @@ type PersistentVolumeClaimSpec struct { // This is an alpha feature and may change in the future. // +optional VolumeMode *PersistentVolumeMode - // If specified, volume will be prepopulated with data from the DataSource. + // If specified, volume will be prepopulated with data from the specified data source. + // This depends on the provisioner for this volume being able to use the specified source. + // If the provisioner does not support it, it will fail to provision the volume. // +optional DataSource *TypedLocalObjectReference } diff --git a/pkg/apis/core/validation/validation.go b/pkg/apis/core/validation/validation.go index eb22aee1899..4c5a7aefa06 100644 --- a/pkg/apis/core/validation/validation.go +++ b/pkg/apis/core/validation/validation.go @@ -1501,6 +1501,9 @@ var supportedReclaimPolicy = sets.NewString(string(core.PersistentVolumeReclaimD var supportedVolumeModes = sets.NewString(string(core.PersistentVolumeBlock), string(core.PersistentVolumeFilesystem)) +var supportedDataSourceKinds = sets.NewString(string("VolumeSnapshot")) +var supportedDataSourceAPIGroups = sets.NewString(string("snapshot.storage.k8s.io")) + func ValidatePersistentVolume(pv *core.PersistentVolume) field.ErrorList { metaPath := field.NewPath("metadata") allErrs := ValidateObjectMeta(&pv.ObjectMeta, false, ValidatePersistentVolumeName, metaPath) @@ -1827,16 +1830,13 @@ func ValidatePersistentVolumeClaimSpec(spec *core.PersistentVolumeClaimSpec, fld if spec.DataSource != nil && !utilfeature.DefaultFeatureGate.Enabled(features.VolumeSnapshotDataSource) { allErrs = append(allErrs, field.Forbidden(fldPath.Child("dataSource"), "VolumeSnapshotDataSource is disabled by feature-gate")) - spec.DataSource = nil } else if spec.DataSource != nil { if len(spec.DataSource.Name) == 0 { - allErrs = append(allErrs, field.Required(fldPath.Child("dataSource").Key(string("Name")), "VolumeSnapshotDataSource Name cannot be empty")) - } - if spec.DataSource.Kind != "VolumeSnapshot" { - allErrs = append(allErrs, field.Invalid(fldPath.Child("dataSource"), spec.DataSource.Kind, "expected DataSource Kind is VolumeSnapshot")) - } - if spec.DataSource.APIGroup != "snapshot.storage.k8s.io" { - allErrs = append(allErrs, field.Invalid(fldPath.Child("dataSource"), spec.DataSource.APIGroup, "expected DataSource APIGroup is snapshot.storage.k8s.io")) + allErrs = append(allErrs, field.Required(fldPath.Child("dataSource", "name"), "")) + } else if !supportedDataSourceKinds.Has(string(spec.DataSource.Kind)) { + allErrs = append(allErrs, field.NotSupported(fldPath.Child("dataSource"), spec.DataSource.Kind, supportedDataSourceKinds.List())) + } else if !supportedDataSourceAPIGroups.Has(string(spec.DataSource.APIGroup)) { + allErrs = append(allErrs, field.NotSupported(fldPath.Child("dataSource"), spec.DataSource.APIGroup, supportedDataSourceAPIGroups.List())) } } diff --git a/staging/src/k8s.io/api/core/v1/generated.proto b/staging/src/k8s.io/api/core/v1/generated.proto index 7ee1355f9d6..888b318ddc0 100644 --- a/staging/src/k8s.io/api/core/v1/generated.proto +++ b/staging/src/k8s.io/api/core/v1/generated.proto @@ -2293,7 +2293,9 @@ message PersistentVolumeClaimSpec { // +optional optional string volumeMode = 6; - // If specified, volume will be prepopulated with data from the DataSource. + // If specified, volume will be prepopulated with data from the specified data source. + // This depends on the provisioner for this volume being able to use the specified source. + // If the provisioner does not support it, it will fail to provision the volume. // +optional optional TypedLocalObjectReference dataSource = 7; } diff --git a/staging/src/k8s.io/api/core/v1/types.go b/staging/src/k8s.io/api/core/v1/types.go index 7c97f0a6dd8..3d086c97c7f 100644 --- a/staging/src/k8s.io/api/core/v1/types.go +++ b/staging/src/k8s.io/api/core/v1/types.go @@ -458,7 +458,9 @@ type PersistentVolumeClaimSpec struct { // This is an alpha feature and may change in the future. // +optional VolumeMode *PersistentVolumeMode `json:"volumeMode,omitempty" protobuf:"bytes,6,opt,name=volumeMode,casttype=PersistentVolumeMode"` - // If specified, volume will be prepopulated with data from the DataSource. + // If specified, volume will be prepopulated with data from the specified data source. + // This depends on the provisioner for this volume being able to use the specified source. + // If the provisioner does not support it, it will fail to provision the volume. // +optional DataSource *TypedLocalObjectReference `json:"dataSource" protobuf:"bytes,7,opt,name=dataSource"` } diff --git a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go index ed4bfbeef07..eb380564bf8 100644 --- a/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go +++ b/staging/src/k8s.io/api/core/v1/types_swagger_doc_generated.go @@ -1210,7 +1210,7 @@ var map_PersistentVolumeClaimSpec = map[string]string{ "volumeName": "VolumeName is the binding reference to the PersistentVolume backing this claim.", "storageClassName": "Name of the StorageClass required by the claim. More info: https://kubernetes.io/docs/concepts/storage/persistent-volumes#class-1", "volumeMode": "volumeMode defines what type of volume is required by the claim. Value of Filesystem is implied when not included in claim spec. This is an alpha feature and may change in the future.", - "dataSource": "If specified, volume will be prepopulated with data from the DataSource.", + "dataSource": "If specified, volume will be prepopulated with data from the specified data source. This depends on the provisioner for this volume being able to use the specified source. If the provisioner does not support it, it will fail to provision the volume.", } func (PersistentVolumeClaimSpec) SwaggerDoc() map[string]string {