forked from openshift/velero
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR implements the internal ItemBlockAction plugins needed for pod, PVC, and SA. Signed-off-by: Scott Seago <[email protected]>
- Loading branch information
Showing
16 changed files
with
1,461 additions
and
147 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 @@ | ||
Internal ItemBlockAction plugins |
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,53 @@ | ||
/* | ||
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 actionhelpers | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
corev1api "k8s.io/api/core/v1" | ||
|
||
"github.com/vmware-tanzu/velero/pkg/kuberesource" | ||
"github.com/vmware-tanzu/velero/pkg/plugin/velero" | ||
) | ||
|
||
func RelatedItemsForPod(pod *corev1api.Pod, log logrus.FieldLogger) []velero.ResourceIdentifier { | ||
var additionalItems []velero.ResourceIdentifier | ||
if pod.Spec.PriorityClassName != "" { | ||
log.Infof("Adding priorityclass %s to additionalItems", pod.Spec.PriorityClassName) | ||
additionalItems = append(additionalItems, velero.ResourceIdentifier{ | ||
GroupResource: kuberesource.PriorityClasses, | ||
Name: pod.Spec.PriorityClassName, | ||
}) | ||
} | ||
|
||
if len(pod.Spec.Volumes) == 0 { | ||
log.Info("pod has no volumes") | ||
} | ||
|
||
for _, volume := range pod.Spec.Volumes { | ||
if volume.PersistentVolumeClaim != nil && volume.PersistentVolumeClaim.ClaimName != "" { | ||
log.Infof("Adding pvc %s to additionalItems", volume.PersistentVolumeClaim.ClaimName) | ||
|
||
additionalItems = append(additionalItems, velero.ResourceIdentifier{ | ||
GroupResource: kuberesource.PersistentVolumeClaims, | ||
Namespace: pod.Namespace, | ||
Name: volume.PersistentVolumeClaim.ClaimName, | ||
}) | ||
} | ||
} | ||
return additionalItems | ||
} |
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,35 @@ | ||
/* | ||
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 actionhelpers | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
corev1api "k8s.io/api/core/v1" | ||
|
||
"github.com/vmware-tanzu/velero/pkg/kuberesource" | ||
"github.com/vmware-tanzu/velero/pkg/plugin/velero" | ||
) | ||
|
||
func RelatedItemsForPVC(pvc *corev1api.PersistentVolumeClaim, log logrus.FieldLogger) []velero.ResourceIdentifier { | ||
return []velero.ResourceIdentifier{ | ||
{ | ||
GroupResource: kuberesource.PersistentVolumes, | ||
Name: pvc.Spec.VolumeName, | ||
}, | ||
} | ||
} | ||
|
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,85 @@ | ||
/* | ||
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 actionhelpers | ||
|
||
import ( | ||
"github.com/sirupsen/logrus" | ||
rbac "k8s.io/api/rbac/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/util/sets" | ||
|
||
"github.com/vmware-tanzu/velero/pkg/kuberesource" | ||
velerodiscovery "github.com/vmware-tanzu/velero/pkg/discovery" | ||
"github.com/vmware-tanzu/velero/pkg/plugin/velero" | ||
) | ||
|
||
func ClusterRoleBindingsForAction(clusterRoleBindingListers map[string]ClusterRoleBindingLister, discoveryHelper velerodiscovery.Helper) ([]ClusterRoleBinding, error) { | ||
// Look up the supported RBAC version | ||
var supportedAPI metav1.GroupVersionForDiscovery | ||
for _, ag := range discoveryHelper.APIGroups() { | ||
if ag.Name == rbac.GroupName { | ||
supportedAPI = ag.PreferredVersion | ||
break | ||
} | ||
} | ||
|
||
crbLister := clusterRoleBindingListers[supportedAPI.Version] | ||
|
||
// This should be safe because the List call will return a 0-item slice | ||
// if there's no matching API version. | ||
return crbLister.List() | ||
} | ||
|
||
func RelatedItemsForServiceAccount(objectMeta metav1.Object, clusterRoleBindings []ClusterRoleBinding, log logrus.FieldLogger) []velero.ResourceIdentifier { | ||
|
||
var ( | ||
namespace = objectMeta.GetNamespace() | ||
name = objectMeta.GetName() | ||
bindings = sets.NewString() | ||
roles = sets.NewString() | ||
) | ||
|
||
for _, crb := range clusterRoleBindings { | ||
for _, s := range crb.ServiceAccountSubjects(namespace) { | ||
if s == name { | ||
log.Infof("Adding clusterrole %s and clusterrolebinding %s to relatedItems since serviceaccount %s/%s is a subject", | ||
crb.RoleRefName(), crb.Name(), namespace, name) | ||
|
||
bindings.Insert(crb.Name()) | ||
roles.Insert(crb.RoleRefName()) | ||
break | ||
} | ||
} | ||
} | ||
|
||
var relatedItems []velero.ResourceIdentifier | ||
for binding := range bindings { | ||
relatedItems = append(relatedItems, velero.ResourceIdentifier{ | ||
GroupResource: kuberesource.ClusterRoleBindings, | ||
Name: binding, | ||
}) | ||
} | ||
|
||
for role := range roles { | ||
relatedItems = append(relatedItems, velero.ResourceIdentifier{ | ||
GroupResource: kuberesource.ClusterRoles, | ||
Name: role, | ||
}) | ||
} | ||
|
||
return relatedItems | ||
} |
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
Oops, something went wrong.