2017-08-02 17:27:17 +00:00
|
|
|
/*
|
2017-11-21 17:24:43 +00:00
|
|
|
Copyright 2017 the Heptio Ark contributors.
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2017-11-21 17:24:43 +00:00
|
|
|
package restore
|
2017-08-02 17:27:17 +00:00
|
|
|
|
|
|
|
import (
|
2017-09-14 21:27:31 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-08-02 17:27:17 +00:00
|
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
|
|
|
2019-01-25 03:33:07 +00:00
|
|
|
api "github.com/heptio/velero/pkg/apis/velero/v1"
|
|
|
|
"github.com/heptio/velero/pkg/util/collections"
|
2017-08-02 17:27:17 +00:00
|
|
|
)
|
|
|
|
|
2017-11-21 17:24:43 +00:00
|
|
|
type jobAction struct {
|
|
|
|
logger logrus.FieldLogger
|
2017-09-14 21:27:31 +00:00
|
|
|
}
|
2017-08-02 17:27:17 +00:00
|
|
|
|
2017-11-21 17:24:43 +00:00
|
|
|
func NewJobAction(logger logrus.FieldLogger) ItemAction {
|
2018-05-13 13:28:09 +00:00
|
|
|
return &jobAction{logger: logger}
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 17:24:43 +00:00
|
|
|
func (a *jobAction) AppliesTo() (ResourceSelector, error) {
|
|
|
|
return ResourceSelector{
|
|
|
|
IncludedResources: []string{"jobs"},
|
|
|
|
}, nil
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 17:24:43 +00:00
|
|
|
func (a *jobAction) Execute(obj runtime.Unstructured, restore *api.Restore) (runtime.Unstructured, error, error) {
|
2017-09-14 21:27:31 +00:00
|
|
|
fieldDeletions := map[string]string{
|
|
|
|
"spec.selector.matchLabels": "controller-uid",
|
|
|
|
"spec.template.metadata.labels": "controller-uid",
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-09-14 21:27:31 +00:00
|
|
|
for k, v := range fieldDeletions {
|
2017-11-21 17:24:43 +00:00
|
|
|
a.logger.Debugf("Getting %s", k)
|
2017-09-14 21:27:31 +00:00
|
|
|
labels, err := collections.GetMap(obj.UnstructuredContent(), k)
|
|
|
|
if err != nil {
|
2017-11-21 17:24:43 +00:00
|
|
|
a.logger.WithError(err).Debugf("Unable to get %s", k)
|
2017-09-14 21:27:31 +00:00
|
|
|
} else {
|
|
|
|
delete(labels, v)
|
|
|
|
}
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|
|
|
|
|
2017-08-18 22:11:42 +00:00
|
|
|
return obj, nil, nil
|
2017-08-02 17:27:17 +00:00
|
|
|
}
|