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

EVEREST-496 Add target namespaces to backup storages #415

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
This conversation was marked as resolved.
Show resolved Hide resolved
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
Loading