util for external pv

prune unused pv utils and its test
pull/8/head
yue9944882 2018-08-09 21:26:53 +08:00
parent 3e205cadcc
commit b497570e50
6 changed files with 280 additions and 220 deletions

View File

@ -24,6 +24,7 @@ filegroup(
"//pkg/api/testing:all-srcs", "//pkg/api/testing:all-srcs",
"//pkg/api/v1/endpoints:all-srcs", "//pkg/api/v1/endpoints:all-srcs",
"//pkg/api/v1/node:all-srcs", "//pkg/api/v1/node:all-srcs",
"//pkg/api/v1/persistentvolume:all-srcs",
"//pkg/api/v1/pod:all-srcs", "//pkg/api/v1/pod:all-srcs",
"//pkg/api/v1/resource:all-srcs", "//pkg/api/v1/resource:all-srcs",
"//pkg/api/v1/service:all-srcs", "//pkg/api/v1/service:all-srcs",

View File

@ -3,7 +3,6 @@ package(default_visibility = ["//visibility:public"])
load( load(
"@io_bazel_rules_go//go:def.bzl", "@io_bazel_rules_go//go:def.bzl",
"go_library", "go_library",
"go_test",
) )
go_library( go_library(
@ -29,16 +28,3 @@ filegroup(
srcs = [":package-srcs"], srcs = [":package-srcs"],
tags = ["automanaged"], tags = ["automanaged"],
) )
go_test(
name = "go_default_test",
srcs = ["util_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/features:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
],
)

View File

@ -22,119 +22,6 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
) )
func getClaimRefNamespace(pv *api.PersistentVolume) string {
if pv.Spec.ClaimRef != nil {
return pv.Spec.ClaimRef.Namespace
}
return ""
}
// Visitor is called with each object's namespace and name, and returns true if visiting should continue
type Visitor func(namespace, name string, kubeletVisible bool) (shouldContinue bool)
// VisitPVSecretNames invokes the visitor function with the name of every secret
// referenced by the PV spec. If visitor returns false, visiting is short-circuited.
// Returns true if visiting completed, false if visiting was short-circuited.
func VisitPVSecretNames(pv *api.PersistentVolume, visitor Visitor) bool {
source := &pv.Spec.PersistentVolumeSource
switch {
case source.AzureFile != nil:
if source.AzureFile.SecretNamespace != nil && len(*source.AzureFile.SecretNamespace) > 0 {
if len(source.AzureFile.SecretName) > 0 && !visitor(*source.AzureFile.SecretNamespace, source.AzureFile.SecretName, true /* kubeletVisible */) {
return false
}
} else {
if len(source.AzureFile.SecretName) > 0 && !visitor(getClaimRefNamespace(pv), source.AzureFile.SecretName, true /* kubeletVisible */) {
return false
}
}
return true
case source.CephFS != nil:
if source.CephFS.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.CephFS.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.CephFS.SecretRef.Namespace
}
if !visitor(ns, source.CephFS.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.Cinder != nil:
if source.Cinder.SecretRef != nil && !visitor(source.Cinder.SecretRef.Namespace, source.Cinder.SecretRef.Name, true /* kubeletVisible */) {
return false
}
case source.FlexVolume != nil:
if source.FlexVolume.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.FlexVolume.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.FlexVolume.SecretRef.Namespace
}
if !visitor(ns, source.FlexVolume.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.RBD != nil:
if source.RBD.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.RBD.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.RBD.SecretRef.Namespace
}
if !visitor(ns, source.RBD.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.ScaleIO != nil:
if source.ScaleIO.SecretRef != nil {
ns := getClaimRefNamespace(pv)
if source.ScaleIO.SecretRef != nil && len(source.ScaleIO.SecretRef.Namespace) > 0 {
ns = source.ScaleIO.SecretRef.Namespace
}
if !visitor(ns, source.ScaleIO.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.ISCSI != nil:
if source.ISCSI.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.ISCSI.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.ISCSI.SecretRef.Namespace
}
if !visitor(ns, source.ISCSI.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.StorageOS != nil:
if source.StorageOS.SecretRef != nil && !visitor(source.StorageOS.SecretRef.Namespace, source.StorageOS.SecretRef.Name, true /* kubeletVisible */) {
return false
}
case source.CSI != nil:
if source.CSI.ControllerPublishSecretRef != nil {
if !visitor(source.CSI.ControllerPublishSecretRef.Namespace, source.CSI.ControllerPublishSecretRef.Name, false /* kubeletVisible */) {
return false
}
}
if source.CSI.NodePublishSecretRef != nil {
if !visitor(source.CSI.NodePublishSecretRef.Namespace, source.CSI.NodePublishSecretRef.Name, true /* kubeletVisible */) {
return false
}
}
if source.CSI.NodeStageSecretRef != nil {
if !visitor(source.CSI.NodeStageSecretRef.Namespace, source.CSI.NodeStageSecretRef.Name, true /* kubeletVisible */) {
return false
}
}
}
return true
}
// DropDisabledAlphaFields removes disabled fields from the pv spec. // DropDisabledAlphaFields removes disabled fields from the pv spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec. // This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec.
func DropDisabledAlphaFields(pvSpec *api.PersistentVolumeSpec) { func DropDisabledAlphaFields(pvSpec *api.PersistentVolumeSpec) {

View File

@ -0,0 +1,41 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["util.go"],
importpath = "k8s.io/kubernetes/pkg/api/v1/persistentvolume",
visibility = ["//visibility:public"],
deps = [
"//pkg/features:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["util_test.go"],
embed = [":go_default_library"],
deps = [
"//pkg/apis/core:go_default_library",
"//pkg/features:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/sets:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
"//staging/src/k8s.io/apiserver/pkg/util/feature:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,144 @@
/*
Copyright 2017 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package persistentvolume
import (
corev1 "k8s.io/api/core/v1"
utilfeature "k8s.io/apiserver/pkg/util/feature"
"k8s.io/kubernetes/pkg/features"
)
func getClaimRefNamespace(pv *corev1.PersistentVolume) string {
if pv.Spec.ClaimRef != nil {
return pv.Spec.ClaimRef.Namespace
}
return ""
}
// Visitor is called with each object's namespace and name, and returns true if visiting should continue
type Visitor func(namespace, name string, kubeletVisible bool) (shouldContinue bool)
// VisitPVSecretNames invokes the visitor function with the name of every secret
// referenced by the PV spec. If visitor returns false, visiting is short-circuited.
// Returns true if visiting completed, false if visiting was short-circuited.
func VisitPVSecretNames(pv *corev1.PersistentVolume, visitor Visitor) bool {
source := &pv.Spec.PersistentVolumeSource
switch {
case source.AzureFile != nil:
if source.AzureFile.SecretNamespace != nil && len(*source.AzureFile.SecretNamespace) > 0 {
if len(source.AzureFile.SecretName) > 0 && !visitor(*source.AzureFile.SecretNamespace, source.AzureFile.SecretName, true /* kubeletVisible */) {
return false
}
} else {
if len(source.AzureFile.SecretName) > 0 && !visitor(getClaimRefNamespace(pv), source.AzureFile.SecretName, true /* kubeletVisible */) {
return false
}
}
return true
case source.CephFS != nil:
if source.CephFS.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.CephFS.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.CephFS.SecretRef.Namespace
}
if !visitor(ns, source.CephFS.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.Cinder != nil:
if source.Cinder.SecretRef != nil && !visitor(source.Cinder.SecretRef.Namespace, source.Cinder.SecretRef.Name, true /* kubeletVisible */) {
return false
}
case source.FlexVolume != nil:
if source.FlexVolume.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.FlexVolume.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.FlexVolume.SecretRef.Namespace
}
if !visitor(ns, source.FlexVolume.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.RBD != nil:
if source.RBD.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.RBD.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.RBD.SecretRef.Namespace
}
if !visitor(ns, source.RBD.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.ScaleIO != nil:
if source.ScaleIO.SecretRef != nil {
ns := getClaimRefNamespace(pv)
if source.ScaleIO.SecretRef != nil && len(source.ScaleIO.SecretRef.Namespace) > 0 {
ns = source.ScaleIO.SecretRef.Namespace
}
if !visitor(ns, source.ScaleIO.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.ISCSI != nil:
if source.ISCSI.SecretRef != nil {
// previously persisted PV objects use claimRef namespace
ns := getClaimRefNamespace(pv)
if len(source.ISCSI.SecretRef.Namespace) > 0 {
// use the secret namespace if namespace is set
ns = source.ISCSI.SecretRef.Namespace
}
if !visitor(ns, source.ISCSI.SecretRef.Name, true /* kubeletVisible */) {
return false
}
}
case source.StorageOS != nil:
if source.StorageOS.SecretRef != nil && !visitor(source.StorageOS.SecretRef.Namespace, source.StorageOS.SecretRef.Name, true /* kubeletVisible */) {
return false
}
case source.CSI != nil:
if source.CSI.ControllerPublishSecretRef != nil {
if !visitor(source.CSI.ControllerPublishSecretRef.Namespace, source.CSI.ControllerPublishSecretRef.Name, false /* kubeletVisible */) {
return false
}
}
if source.CSI.NodePublishSecretRef != nil {
if !visitor(source.CSI.NodePublishSecretRef.Namespace, source.CSI.NodePublishSecretRef.Name, true /* kubeletVisible */) {
return false
}
}
if source.CSI.NodeStageSecretRef != nil {
if !visitor(source.CSI.NodeStageSecretRef.Namespace, source.CSI.NodeStageSecretRef.Name, true /* kubeletVisible */) {
return false
}
}
}
return true
}
// DropDisabledAlphaFields removes disabled fields from the pv spec.
// This should be called from PrepareForCreate/PrepareForUpdate for all resources containing a pv spec.
func DropDisabledAlphaFields(pvSpec *corev1.PersistentVolumeSpec) {
if !utilfeature.DefaultFeatureGate.Enabled(features.BlockVolume) {
pvSpec.VolumeMode = nil
}
}

View File

@ -22,6 +22,7 @@ import (
"strings" "strings"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/validation/field" "k8s.io/apimachinery/pkg/util/validation/field"
utilfeature "k8s.io/apiserver/pkg/util/feature" utilfeature "k8s.io/apiserver/pkg/util/feature"
@ -33,115 +34,115 @@ func TestPVSecrets(t *testing.T) {
// Stub containing all possible secret references in a PV. // Stub containing all possible secret references in a PV.
// The names of the referenced secrets match struct paths detected by reflection. // The names of the referenced secrets match struct paths detected by reflection.
secretNamespace := "Spec.PersistentVolumeSource.AzureFile.SecretNamespace" secretNamespace := "Spec.PersistentVolumeSource.AzureFile.SecretNamespace"
pvs := []*api.PersistentVolume{ pvs := []*corev1.PersistentVolume{
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
AzureFile: &api.AzureFilePersistentVolumeSource{ AzureFile: &corev1.AzureFilePersistentVolumeSource{
SecretName: "Spec.PersistentVolumeSource.AzureFile.SecretName"}}}}, SecretName: "Spec.PersistentVolumeSource.AzureFile.SecretName"}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
AzureFile: &api.AzureFilePersistentVolumeSource{ AzureFile: &corev1.AzureFilePersistentVolumeSource{
SecretName: "Spec.PersistentVolumeSource.AzureFile.SecretName", SecretName: "Spec.PersistentVolumeSource.AzureFile.SecretName",
SecretNamespace: &secretNamespace}}}}, SecretNamespace: &secretNamespace}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
CephFS: &api.CephFSPersistentVolumeSource{ CephFS: &corev1.CephFSPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.CephFS.SecretRef", Name: "Spec.PersistentVolumeSource.CephFS.SecretRef",
Namespace: "cephfs"}}}}}, Namespace: "cephfs"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
CephFS: &api.CephFSPersistentVolumeSource{ CephFS: &corev1.CephFSPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.CephFS.SecretRef"}}}}}, Name: "Spec.PersistentVolumeSource.CephFS.SecretRef"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
Cinder: &api.CinderPersistentVolumeSource{ Cinder: &corev1.CinderPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.Cinder.SecretRef", Name: "Spec.PersistentVolumeSource.Cinder.SecretRef",
Namespace: "cinder"}}}}}, Namespace: "cinder"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
FlexVolume: &api.FlexPersistentVolumeSource{ FlexVolume: &corev1.FlexPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.FlexVolume.SecretRef", Name: "Spec.PersistentVolumeSource.FlexVolume.SecretRef",
Namespace: "flexns"}}}}}, Namespace: "flexns"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
FlexVolume: &api.FlexPersistentVolumeSource{ FlexVolume: &corev1.FlexPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.FlexVolume.SecretRef"}}}}}, Name: "Spec.PersistentVolumeSource.FlexVolume.SecretRef"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
RBD: &api.RBDPersistentVolumeSource{ RBD: &corev1.RBDPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.RBD.SecretRef"}}}}}, Name: "Spec.PersistentVolumeSource.RBD.SecretRef"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
RBD: &api.RBDPersistentVolumeSource{ RBD: &corev1.RBDPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.RBD.SecretRef", Name: "Spec.PersistentVolumeSource.RBD.SecretRef",
Namespace: "rbdns"}}}}}, Namespace: "rbdns"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
ScaleIO: &api.ScaleIOPersistentVolumeSource{ ScaleIO: &corev1.ScaleIOPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.ScaleIO.SecretRef"}}}}}, Name: "Spec.PersistentVolumeSource.ScaleIO.SecretRef"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
ScaleIO: &api.ScaleIOPersistentVolumeSource{ ScaleIO: &corev1.ScaleIOPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.ScaleIO.SecretRef", Name: "Spec.PersistentVolumeSource.ScaleIO.SecretRef",
Namespace: "scaleions"}}}}}, Namespace: "scaleions"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
ISCSI: &api.ISCSIPersistentVolumeSource{ ISCSI: &corev1.ISCSIPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.ISCSI.SecretRef", Name: "Spec.PersistentVolumeSource.ISCSI.SecretRef",
Namespace: "iscsi"}}}}}, Namespace: "iscsi"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
ISCSI: &api.ISCSIPersistentVolumeSource{ ISCSI: &corev1.ISCSIPersistentVolumeSource{
SecretRef: &api.SecretReference{ SecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.ISCSI.SecretRef"}}}}}, Name: "Spec.PersistentVolumeSource.ISCSI.SecretRef"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
StorageOS: &api.StorageOSPersistentVolumeSource{ StorageOS: &corev1.StorageOSPersistentVolumeSource{
SecretRef: &api.ObjectReference{ SecretRef: &corev1.ObjectReference{
Name: "Spec.PersistentVolumeSource.StorageOS.SecretRef", Name: "Spec.PersistentVolumeSource.StorageOS.SecretRef",
Namespace: "storageosns"}}}}}, Namespace: "storageosns"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
CSI: &api.CSIPersistentVolumeSource{ CSI: &corev1.CSIPersistentVolumeSource{
ControllerPublishSecretRef: &api.SecretReference{ ControllerPublishSecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.CSI.ControllerPublishSecretRef", Name: "Spec.PersistentVolumeSource.CSI.ControllerPublishSecretRef",
Namespace: "csi"}}}}}, Namespace: "csi"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
CSI: &api.CSIPersistentVolumeSource{ CSI: &corev1.CSIPersistentVolumeSource{
NodePublishSecretRef: &api.SecretReference{ NodePublishSecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.CSI.NodePublishSecretRef", Name: "Spec.PersistentVolumeSource.CSI.NodePublishSecretRef",
Namespace: "csi"}}}}}, Namespace: "csi"}}}}},
{Spec: api.PersistentVolumeSpec{ {Spec: corev1.PersistentVolumeSpec{
ClaimRef: &api.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"}, ClaimRef: &corev1.ObjectReference{Namespace: "claimrefns", Name: "claimrefname"},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
CSI: &api.CSIPersistentVolumeSource{ CSI: &corev1.CSIPersistentVolumeSource{
NodeStageSecretRef: &api.SecretReference{ NodeStageSecretRef: &corev1.SecretReference{
Name: "Spec.PersistentVolumeSource.CSI.NodeStageSecretRef", Name: "Spec.PersistentVolumeSource.CSI.NodeStageSecretRef",
Namespace: "csi"}}}}}, Namespace: "csi"}}}}},
} }
@ -266,23 +267,23 @@ func collectSecretPaths(t *testing.T, path *field.Path, name string, tp reflect.
return secretPaths return secretPaths
} }
func newHostPathType(pathType string) *api.HostPathType { func newHostPathType(pathType string) *corev1.HostPathType {
hostPathType := new(api.HostPathType) hostPathType := new(corev1.HostPathType)
*hostPathType = api.HostPathType(pathType) *hostPathType = corev1.HostPathType(pathType)
return hostPathType return hostPathType
} }
func TestDropAlphaPVVolumeMode(t *testing.T) { func TestDropAlphaPVVolumeMode(t *testing.T) {
vmode := api.PersistentVolumeFilesystem vmode := corev1.PersistentVolumeFilesystem
// PersistentVolume with VolumeMode set // PersistentVolume with VolumeMode set
pv := api.PersistentVolume{ pv := corev1.PersistentVolume{
Spec: api.PersistentVolumeSpec{ Spec: corev1.PersistentVolumeSpec{
AccessModes: []api.PersistentVolumeAccessMode{api.ReadWriteOnce}, AccessModes: []corev1.PersistentVolumeAccessMode{corev1.ReadWriteOnce},
PersistentVolumeSource: api.PersistentVolumeSource{ PersistentVolumeSource: corev1.PersistentVolumeSource{
HostPath: &api.HostPathVolumeSource{ HostPath: &corev1.HostPathVolumeSource{
Path: "/foo", Path: "/foo",
Type: newHostPathType(string(api.HostPathDirectory)), Type: newHostPathType(string(corev1.HostPathDirectory)),
}, },
}, },
StorageClassName: "test-storage-class", StorageClassName: "test-storage-class",