2017-05-05 06:14:27 +00:00
|
|
|
/*
|
|
|
|
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 (
|
|
|
|
"k8s.io/kubernetes/pkg/api"
|
|
|
|
)
|
|
|
|
|
2017-02-24 15:47:40 +00:00
|
|
|
func getClaimRefNamespace(pv *api.PersistentVolume) string {
|
|
|
|
if pv.Spec.ClaimRef != nil {
|
|
|
|
return pv.Spec.ClaimRef.Namespace
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2017-07-25 16:10:06 +00:00
|
|
|
// Visitor is called with each object's namespace and name, and returns true if visiting should continue
|
|
|
|
type Visitor func(namespace, name string) (shouldContinue bool)
|
|
|
|
|
2017-05-05 06:14:27 +00:00
|
|
|
// 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.
|
2017-07-25 16:10:06 +00:00
|
|
|
func VisitPVSecretNames(pv *api.PersistentVolume, visitor Visitor) bool {
|
2017-05-05 06:14:27 +00:00
|
|
|
source := &pv.Spec.PersistentVolumeSource
|
|
|
|
switch {
|
|
|
|
case source.AzureFile != nil:
|
2017-02-24 15:47:40 +00:00
|
|
|
if len(source.AzureFile.SecretName) > 0 && !visitor(getClaimRefNamespace(pv), source.AzureFile.SecretName) {
|
2017-05-05 06:14:27 +00:00
|
|
|
return false
|
|
|
|
}
|
2017-02-24 15:47:40 +00:00
|
|
|
return true
|
2017-05-05 06:14:27 +00:00
|
|
|
case source.CephFS != nil:
|
2017-02-24 15:47:40 +00:00
|
|
|
if source.CephFS.SecretRef != nil && !visitor(getClaimRefNamespace(pv), source.CephFS.SecretRef.Name) {
|
2017-05-05 06:14:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
case source.FlexVolume != nil:
|
2017-02-24 15:47:40 +00:00
|
|
|
if source.FlexVolume.SecretRef != nil && !visitor(getClaimRefNamespace(pv), source.FlexVolume.SecretRef.Name) {
|
2017-05-05 06:14:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
case source.RBD != nil:
|
2017-02-24 15:47:40 +00:00
|
|
|
if source.RBD.SecretRef != nil && !visitor(getClaimRefNamespace(pv), source.RBD.SecretRef.Name) {
|
2017-05-05 06:14:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
case source.ScaleIO != nil:
|
2017-02-24 15:47:40 +00:00
|
|
|
if source.ScaleIO.SecretRef != nil && !visitor(getClaimRefNamespace(pv), source.ScaleIO.SecretRef.Name) {
|
2017-05-05 06:14:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
case source.ISCSI != nil:
|
2017-02-24 15:47:40 +00:00
|
|
|
if source.ISCSI.SecretRef != nil && !visitor(getClaimRefNamespace(pv), source.ISCSI.SecretRef.Name) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
case source.StorageOS != nil:
|
|
|
|
if source.StorageOS.SecretRef != nil && !visitor(source.StorageOS.SecretRef.Namespace, source.StorageOS.SecretRef.Name) {
|
2017-05-05 06:14:27 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|