toRevision is a non-negative integer, with 0 being reserved to indicate rolling back to previous configuration
(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRunStrategy cmdutil.DryRunStrategy)
| 352 | |
| 353 | // toRevision is a non-negative integer, with 0 being reserved to indicate rolling back to previous configuration |
| 354 | func (r *StatefulSetRollbacker) Rollback(obj runtime.Object, updatedAnnotations map[string]string, toRevision int64, dryRunStrategy cmdutil.DryRunStrategy) (string, error) { |
| 355 | if toRevision < 0 { |
| 356 | return "", revisionNotFoundErr(toRevision) |
| 357 | } |
| 358 | accessor, err := meta.Accessor(obj) |
| 359 | if err != nil { |
| 360 | return "", fmt.Errorf("failed to create accessor for kind %v: %s", obj.GetObjectKind(), err.Error()) |
| 361 | } |
| 362 | sts, history, err := statefulSetHistory(r.c.AppsV1(), accessor.GetNamespace(), accessor.GetName()) |
| 363 | if err != nil { |
| 364 | return "", err |
| 365 | } |
| 366 | if toRevision == 0 && len(history) <= 1 { |
| 367 | return "", fmt.Errorf("no last revision to roll back to") |
| 368 | } |
| 369 | |
| 370 | toHistory := findHistory(toRevision, history) |
| 371 | if toHistory == nil { |
| 372 | return "", revisionNotFoundErr(toRevision) |
| 373 | } |
| 374 | |
| 375 | if dryRunStrategy == cmdutil.DryRunClient { |
| 376 | appliedSS, err := applyRevision(sts, toHistory) |
| 377 | if err != nil { |
| 378 | return "", err |
| 379 | } |
| 380 | return printPodTemplate(&appliedSS.Spec.Template) |
| 381 | } |
| 382 | |
| 383 | // Skip if the revision already matches current StatefulSet |
| 384 | done, err := statefulsetMatch(sts, toHistory) |
| 385 | if err != nil { |
| 386 | return "", err |
| 387 | } |
| 388 | if done { |
| 389 | return fmt.Sprintf("%s (current template already matches revision %d)", rollbackSkipped, toRevision), nil |
| 390 | } |
| 391 | |
| 392 | patchOptions := metav1.PatchOptions{} |
| 393 | if dryRunStrategy == cmdutil.DryRunServer { |
| 394 | patchOptions.DryRun = []string{metav1.DryRunAll} |
| 395 | } |
| 396 | // Restore revision |
| 397 | if _, err = r.c.AppsV1().StatefulSets(sts.Namespace).Patch(context.TODO(), sts.Name, types.StrategicMergePatchType, toHistory.Data.Raw, patchOptions); err != nil { |
| 398 | return "", fmt.Errorf("failed restoring revision %d: %v", toRevision, err) |
| 399 | } |
| 400 | |
| 401 | return rollbackSuccess, nil |
| 402 | } |
| 403 | |
| 404 | var appsCodec = scheme.Codecs.LegacyCodec(appsv1.SchemeGroupVersion) |
| 405 |
nothing calls this directly
no test coverage detected