Skip to content
This repository has been archived by the owner on Mar 4, 2024. It is now read-only.

Commit

Permalink
EVEREST-496 Add target namespaces to backup storages (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
recharte authored Feb 6, 2024
1 parent 24f4d72 commit 9152e62
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 343 deletions.
80 changes: 53 additions & 27 deletions api/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ func (e *EverestServer) ListBackupStorages(ctx echo.Context) error {
for _, bs := range backupList.Items {
s := bs
result = append(result, BackupStorage{
Type: BackupStorageType(bs.Spec.Type),
Name: s.Name,
Description: &s.Spec.Description,
BucketName: s.Spec.Bucket,
Region: s.Spec.Region,
Url: &s.Spec.EndpointURL,
Type: BackupStorageType(bs.Spec.Type),
Name: s.Name,
Description: &s.Spec.Description,
BucketName: s.Spec.Bucket,
Region: s.Spec.Region,
Url: &s.Spec.EndpointURL,
TargetNamespaces: s.Spec.TargetNamespaces,
})
}

Expand All @@ -55,7 +56,15 @@ func (e *EverestServer) ListBackupStorages(ctx echo.Context) error {

// CreateBackupStorage creates a new backup storage object.
func (e *EverestServer) CreateBackupStorage(ctx echo.Context) error { //nolint:funlen
params, err := validateCreateBackupStorageRequest(ctx, e.l)
namespaces, err := e.kubeClient.GetWatchedNamespaces(ctx.Request().Context(), e.kubeClient.Namespace())
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{
Message: pointer.ToString("Failed getting watched namespaces"),
})
}

params, err := validateCreateBackupStorageRequest(ctx, namespaces, e.l)
if err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}
Expand Down Expand Up @@ -111,6 +120,7 @@ func (e *EverestServer) CreateBackupStorage(ctx echo.Context) error { //nolint:f
Bucket: params.BucketName,
Region: params.Region,
CredentialsSecretName: params.Name,
TargetNamespaces: params.TargetNamespaces,
},
}
if params.Url != nil {
Expand All @@ -134,12 +144,13 @@ func (e *EverestServer) CreateBackupStorage(ctx echo.Context) error { //nolint:f
})
}
result := BackupStorage{
Type: BackupStorageType(params.Type),
Name: params.Name,
Description: params.Description,
BucketName: params.BucketName,
Region: params.Region,
Url: params.Url,
Type: BackupStorageType(params.Type),
Name: params.Name,
Description: params.Description,
BucketName: params.BucketName,
Region: params.Region,
Url: params.Url,
TargetNamespaces: params.TargetNamespaces,
}

return ctx.JSON(http.StatusOK, result)
Expand Down Expand Up @@ -208,17 +219,18 @@ func (e *EverestServer) GetBackupStorage(ctx echo.Context, backupStorageName str
})
}
return ctx.JSON(http.StatusOK, BackupStorage{
Type: BackupStorageType(s.Spec.Type),
Name: s.Name,
Description: &s.Spec.Description,
BucketName: s.Spec.Bucket,
Region: s.Spec.Region,
Url: &s.Spec.EndpointURL,
Type: BackupStorageType(s.Spec.Type),
Name: s.Name,
Description: &s.Spec.Description,
BucketName: s.Spec.Bucket,
Region: s.Spec.Region,
Url: &s.Spec.EndpointURL,
TargetNamespaces: s.Spec.TargetNamespaces,
})
}

// UpdateBackupStorage updates of the specified backup storage.
func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName string) error { //nolint:funlen
func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName string) error { //nolint:funlen,cyclop
c := ctx.Request().Context()
bs, err := e.kubeClient.GetBackupStorage(c, backupStorageName)
if err != nil {
Expand All @@ -232,6 +244,7 @@ func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName
Message: pointer.ToString("Failed getting backup storage"),
})
}

secret, err := e.kubeClient.GetSecret(c, backupStorageName)
if err != nil {
if k8serrors.IsNotFound(err) {
Expand All @@ -244,7 +257,16 @@ func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName
Message: pointer.ToString("Failed getting secret"),
})
}
params, err := validateUpdateBackupStorageRequest(ctx, bs, secret, e.l)

namespaces, err := e.kubeClient.GetWatchedNamespaces(ctx.Request().Context(), e.kubeClient.Namespace())
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{
Message: pointer.ToString("Failed getting watched namespaces"),
})
}

params, err := validateUpdateBackupStorageRequest(ctx, bs, secret, namespaces, e.l)
if err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}
Expand Down Expand Up @@ -276,6 +298,9 @@ func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName
if params.Description != nil {
bs.Spec.Description = *params.Description
}
if params.TargetNamespaces != nil {
bs.Spec.TargetNamespaces = *params.TargetNamespaces
}

err = e.kubeClient.UpdateBackupStorage(c, bs)
if err != nil {
Expand All @@ -285,12 +310,13 @@ func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName
})
}
result := BackupStorage{
Type: BackupStorageType(bs.Spec.Type),
Name: bs.Name,
Description: params.Description,
BucketName: bs.Spec.Bucket,
Region: bs.Spec.Region,
Url: &bs.Spec.EndpointURL,
Type: BackupStorageType(bs.Spec.Type),
Name: bs.Name,
Description: params.Description,
BucketName: bs.Spec.Bucket,
Region: bs.Spec.Region,
Url: &bs.Spec.EndpointURL,
TargetNamespaces: bs.Spec.TargetNamespaces,
}

return ctx.JSON(http.StatusOK, result)
Expand Down
Loading

0 comments on commit 9152e62

Please sign in to comment.