61 lines
1.7 KiB
Go
61 lines
1.7 KiB
Go
/*
|
|
Copyright 2017 the Heptio Ark 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 restore
|
|
|
|
import (
|
|
"github.com/pkg/errors"
|
|
"github.com/sirupsen/logrus"
|
|
batchv1api "k8s.io/api/batch/v1"
|
|
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
velerov1api "github.com/heptio/velero/pkg/apis/velero/v1"
|
|
)
|
|
|
|
type jobAction struct {
|
|
logger logrus.FieldLogger
|
|
}
|
|
|
|
func NewJobAction(logger logrus.FieldLogger) ItemAction {
|
|
return &jobAction{logger: logger}
|
|
}
|
|
|
|
func (a *jobAction) AppliesTo() (ResourceSelector, error) {
|
|
return ResourceSelector{
|
|
IncludedResources: []string{"jobs"},
|
|
}, nil
|
|
}
|
|
|
|
func (a *jobAction) Execute(obj runtime.Unstructured, restore *velerov1api.Restore) (runtime.Unstructured, error, error) {
|
|
job := new(batchv1api.Job)
|
|
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.UnstructuredContent(), job); err != nil {
|
|
return nil, nil, errors.WithStack(err)
|
|
}
|
|
|
|
if job.Spec.Selector != nil {
|
|
delete(job.Spec.Selector.MatchLabels, "controller-uid")
|
|
}
|
|
delete(job.Spec.Template.ObjectMeta.Labels, "controller-uid")
|
|
|
|
res, err := runtime.DefaultUnstructuredConverter.ToUnstructured(job)
|
|
if err != nil {
|
|
return nil, nil, errors.WithStack(err)
|
|
}
|
|
|
|
return &unstructured.Unstructured{Object: res}, nil, nil
|
|
}
|