Skip to content

Commit

Permalink
feat(ec): improved disaster recovery - take multiple backups (#5028)
Browse files Browse the repository at this point in the history
* feat(ec): improved disaster recovery

* app version record restore spec

* fix tests

* refactor

* refactor

* refactor

* refactor

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* f

* rename function

* feat(ec): use label for backup name, use common terminology (#5031)

* rename to hasAppBackupSpec

* type legacy

* dont render app spec for improved dr

* dont render app spec for improved dr

* rename to hasAppBackup

* disable GetInstanceBackupType check in list handler

* remove backup detail from ci

* fix tests

* remove todo comment

* dont add new annotations and labels if not improved dr
  • Loading branch information
emosbaugh authored Dec 9, 2024
1 parent 83d142f commit 2393c2e
Show file tree
Hide file tree
Showing 15 changed files with 2,756 additions and 323 deletions.
2 changes: 2 additions & 0 deletions migrations/tables/app_version.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ spec:
type: text
- name: backup_spec
type: text
- name: restore_spec
type: text
- name: identity_spec
type: text
- name: branding_archive
Expand Down
4 changes: 2 additions & 2 deletions pkg/handlers/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (h *Handler) CreateInstanceBackup(w http.ResponseWriter, r *http.Request) {
}
c := clusters[0]

backup, err := snapshot.CreateInstanceBackup(context.TODO(), c, false)
backupName, err := snapshot.CreateInstanceBackup(context.TODO(), c, false)
if err != nil {
logger.Error(errors.Wrap(err, "failed to create instance snapshot"))
createInstanceBackupResponse.Error = "failed to create instance backup"
Expand All @@ -215,7 +215,7 @@ func (h *Handler) CreateInstanceBackup(w http.ResponseWriter, r *http.Request) {
}

createInstanceBackupResponse.Success = true
createInstanceBackupResponse.BackupName = backup.ObjectMeta.Name
createInstanceBackupResponse.BackupName = backupName

JSON(w, http.StatusOK, createInstanceBackupResponse)
}
12 changes: 10 additions & 2 deletions pkg/handlers/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ func (h *Handler) CreateApplicationRestore(w http.ResponseWriter, r *http.Reques
return
}

if snapshot.IsInstanceBackup(*backup) && snapshot.GetInstanceBackupType(*backup) != snapshottypes.InstanceBackupTypeLegacy {
err := errors.New("only legacy type instance backups are restorable")
logger.Error(err)
createRestoreResponse.Error = err.Error()
JSON(w, http.StatusInternalServerError, createRestoreResponse)
return
}

appID := backup.Annotations["kots.io/app-id"]
sequence, err := strconv.ParseInt(backup.Annotations["kots.io/app-sequence"], 10, 64)
if err != nil {
Expand Down Expand Up @@ -149,7 +157,7 @@ func (h *Handler) RestoreApps(w http.ResponseWriter, r *http.Request) {
return
}

if backup.Annotations["kots.io/instance"] != "true" {
if backup.Annotations[snapshottypes.InstanceBackupAnnotation] != "true" {
err := errors.Errorf("backup %s is not an instance backup", backup.ObjectMeta.Name)
logger.Error(err)
restoreResponse.Error = err.Error()
Expand Down Expand Up @@ -244,7 +252,7 @@ func (h *Handler) GetRestoreAppsStatus(w http.ResponseWriter, r *http.Request) {
return
}

if backup.Annotations["kots.io/instance"] != "true" {
if backup.Annotations[snapshottypes.InstanceBackupAnnotation] != "true" {
err := errors.Errorf("backup %s is not an instance backup", backup.ObjectMeta.Name)
logger.Error(err)
response.Error = err.Error()
Expand Down
7 changes: 1 addition & 6 deletions pkg/k8sutil/kotsadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ const (
KotsadmIDConfigMapName = "kotsadm-id"
)

func FindKotsadmImage(namespace string) (string, error) {
clientset, err := GetClientset()
if err != nil {
return "", errors.Wrap(err, "failed to get k8s client set")
}

func FindKotsadmImage(clientset kubernetes.Interface, namespace string) (string, error) {
var containers []corev1.Container
if os.Getenv("POD_OWNER_KIND") == "deployment" {
kotsadmDeployment, err := clientset.AppsV1().Deployments(namespace).Get(context.TODO(), "kotsadm", metav1.GetOptions{})
Expand Down
Loading

0 comments on commit 2393c2e

Please sign in to comment.