-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add volume types filter in resource policies
Signed-off-by: Ming Qiu <[email protected]>
- Loading branch information
1 parent
d3e5bb7
commit f5b03ea
Showing
7 changed files
with
261 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add volume types filter in resource policies |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,207 @@ | ||
/* | ||
Copyright the Velero contributors. | ||
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 resourcepolicies | ||
|
||
import ( | ||
corev1api "k8s.io/api/core/v1" | ||
) | ||
|
||
type volumeTypeCondition struct { | ||
volumeTypes []string | ||
} | ||
|
||
func (v *volumeTypeCondition) match(s *structuredVolume) bool { | ||
if len(v.volumeTypes) == 0 { | ||
return true | ||
} | ||
|
||
for _, vt := range v.volumeTypes { | ||
if vt == s.volumeType { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
|
||
func (s *volumeTypeCondition) validate() error { | ||
// validate by yamlv3 | ||
return nil | ||
} | ||
|
||
func getVolumeTypeFromPV(pv *corev1api.PersistentVolume) string { | ||
if pv == nil { | ||
return "" | ||
} | ||
if pv.Spec.GCEPersistentDisk != nil { | ||
return "gcePersistentDisk" | ||
} | ||
if pv.Spec.AWSElasticBlockStore != nil { | ||
return "awsElasticBlockStore" | ||
} | ||
if pv.Spec.HostPath != nil { | ||
return "hostPath" | ||
} | ||
if pv.Spec.Glusterfs != nil { | ||
return "glusterfs" | ||
} | ||
if pv.Spec.NFS != nil { | ||
return "nfs" | ||
} | ||
if pv.Spec.RBD != nil { | ||
return "rbd" | ||
} | ||
if pv.Spec.ISCSI != nil { | ||
return "iscsi" | ||
} | ||
if pv.Spec.Cinder != nil { | ||
return "cinder" | ||
} | ||
if pv.Spec.CephFS != nil { | ||
return "cephfs" | ||
} | ||
if pv.Spec.FC != nil { | ||
return "fc" | ||
} | ||
if pv.Spec.Flocker != nil { | ||
return "flocker" | ||
} | ||
if pv.Spec.FlexVolume != nil { | ||
return "flexVolume" | ||
} | ||
if pv.Spec.AzureFile != nil { | ||
return "azureFile" | ||
} | ||
if pv.Spec.VsphereVolume != nil { | ||
return "vsphereVolume" | ||
} | ||
if pv.Spec.Quobyte != nil { | ||
return "quobyte" | ||
} | ||
if pv.Spec.AzureDisk != nil { | ||
return "azureDisk" | ||
} | ||
if pv.Spec.PhotonPersistentDisk != nil { | ||
return "photonPersistentDisk" | ||
} | ||
if pv.Spec.PortworxVolume != nil { | ||
return "portworxVolume" | ||
} | ||
if pv.Spec.ScaleIO != nil { | ||
return "scaleIO" | ||
} | ||
if pv.Spec.Local != nil { | ||
return "local" | ||
} | ||
if pv.Spec.StorageOS != nil { | ||
return "storageOS" | ||
} | ||
if pv.Spec.CSI != nil { | ||
return "csi" | ||
} | ||
return "" | ||
} | ||
|
||
func getVolumeTypeFromVolume(vol *corev1api.Volume) string { | ||
if vol == nil { | ||
return "" | ||
} | ||
if vol.HostPath != nil { | ||
return "hostPath" | ||
} | ||
if vol.EmptyDir != nil { | ||
return "emptyDir" | ||
} | ||
if vol.GCEPersistentDisk != nil { | ||
return "gcePersistentDisk" | ||
} | ||
if vol.AWSElasticBlockStore != nil { | ||
return "awsElasticBlockStore" | ||
} | ||
if vol.GitRepo != nil { | ||
return "gitRepo" | ||
} | ||
if vol.Secret != nil { | ||
return "secret" | ||
} | ||
if vol.NFS != nil { | ||
return "nfs" | ||
} | ||
if vol.ISCSI != nil { | ||
return "iscsi" | ||
} | ||
if vol.Glusterfs != nil { | ||
return "glusterfs" | ||
} | ||
if vol.RBD != nil { | ||
return "rbd" | ||
} | ||
if vol.FlexVolume != nil { | ||
return "flexVolume" | ||
} | ||
if vol.Cinder != nil { | ||
return "cinder" | ||
} | ||
if vol.CephFS != nil { | ||
return "cephfs" | ||
} | ||
if vol.Flocker != nil { | ||
return "flocker" | ||
} | ||
if vol.DownwardAPI != nil { | ||
return "downwardAPI" | ||
} | ||
if vol.FC != nil { | ||
return "fc" | ||
} | ||
if vol.AzureFile != nil { | ||
return "azureFile" | ||
} | ||
if vol.ConfigMap != nil { | ||
return "configMap" | ||
} | ||
if vol.VsphereVolume != nil { | ||
return "vsphereVolume" | ||
} | ||
if vol.Quobyte != nil { | ||
return "quobyte" | ||
} | ||
if vol.AzureDisk != nil { | ||
return "azureDisk" | ||
} | ||
if vol.PhotonPersistentDisk != nil { | ||
return "photonPersistentDisk" | ||
} | ||
if vol.Projected != nil { | ||
return "projected" | ||
} | ||
if vol.PortworxVolume != nil { | ||
return "portworxVolume" | ||
} | ||
if vol.ScaleIO != nil { | ||
return "scaleIO" | ||
} | ||
if vol.StorageOS != nil { | ||
return "storageOS" | ||
} | ||
if vol.CSI != nil { | ||
return "csi" | ||
} | ||
if vol.Ephemeral != nil { | ||
return "ephemeral" | ||
} | ||
return "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters