Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify conditional nature of restore in log #1153

Merged
merged 1 commit into from Feb 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/1153-daved
@@ -0,0 +1 @@
Clarify restore log when object unchanged
16 changes: 9 additions & 7 deletions pkg/restore/restore.go
Expand Up @@ -793,7 +793,7 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a
// and which backup they came from
addRestoreLabels(obj, ctx.restore.Name, ctx.restore.Spec.BackupName)

ctx.log.Infof("Restoring %s: %v", obj.GroupVersionKind().Kind, name)
ctx.log.Infof("Attempting to restore %s: %v", obj.GroupVersionKind().Kind, name)
createdObj, restoreErr := resourceClient.Create(obj)
if apierrors.IsAlreadyExists(restoreErr) {
fromCluster, err := resourceClient.Get(name, metav1.GetOptions{})
Expand All @@ -815,34 +815,36 @@ func (ctx *context) restoreResource(resource, namespace, resourcePath string) (a
labels := obj.GetLabels()
addRestoreLabels(fromCluster, labels[api.RestoreNameLabel], labels[api.BackupNameLabel])

if !equality.Semantic.DeepEqual(fromCluster, obj) {
if equality.Semantic.DeepEqual(fromCluster, obj) {
ctx.log.Infof("Skipping restore of %s: %v because it already exists in the cluster and is unchanged from the backed up version", obj.GroupVersionKind().Kind, name)
} else {
switch groupResource {
case kuberesource.ServiceAccounts:
desired, err := mergeServiceAccounts(fromCluster, obj)
if err != nil {
ctx.log.Infof("error merging secrets for ServiceAccount %s: %v", kube.NamespaceAndName(obj), err)
addToResult(&warnings, namespace, err)
continue
break
}

patchBytes, err := generatePatch(fromCluster, desired)
if err != nil {
ctx.log.Infof("error generating patch for ServiceAccount %s: %v", kube.NamespaceAndName(obj), err)
addToResult(&warnings, namespace, err)
continue
break
}

if patchBytes == nil {
// In-cluster and desired state are the same, so move on to the next item
continue
break
}

_, err = resourceClient.Patch(name, patchBytes)
if err != nil {
addToResult(&warnings, namespace, err)
} else {
ctx.log.Infof("ServiceAccount %s successfully updated", kube.NamespaceAndName(obj))
break
}
ctx.log.Infof("ServiceAccount %s successfully updated", kube.NamespaceAndName(obj))
default:
e := errors.Errorf("not restored: %s and is different from backed up version.", restoreErr)
addToResult(&warnings, namespace, e)
Expand Down