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

EVEREST-496 Add multi-namespaces support to DBClusters #427

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
ef7a89a
EVEREST-496: add TargetNamespaces to GET monitoring-instances
recharte Jan 28, 2024
f488558
EVEREST-496: add TargetNamespaces to POST monitoring-instances
recharte Jan 28, 2024
1b691a9
EVEREST-496: add TargetNamespaces to PATCH monitoring-instances
recharte Jan 28, 2024
1a2d214
EVEREST-496 autogen API code
recharte Feb 6, 2024
fd06eb1
EVEREST-496 allow managing everest CRs in any namespace
recharte Feb 6, 2024
97e7a8b
EVEREST-496 add username to monitoring secret
recharte Feb 6, 2024
8dbe470
EVEREST-496 prepare secrets management for multi-namespaces
recharte Jan 29, 2024
c7ab016
EVEREST-496 use monitoring resources from the monitoring namespace
recharte Feb 6, 2024
f46cd6f
EVEREST-496 remove check for VMAgent use of monitoring config
recharte Feb 6, 2024
c07fe41
EVEREST-496 remove cluster-monitoring endpoint
recharte Feb 6, 2024
0fafd96
EVEREST-496 autogen API code
recharte Feb 6, 2024
5bb1368
EVEREST-496 add multi-namespaces to POST /database-clusters
recharte Jan 29, 2024
4057821
EVEREST-496 add multi-namespaces to GET /database-clusters
recharte Jan 29, 2024
065df38
EVEREST-496 add multi-namespaces to GET /database-clusters/{name}
recharte Jan 29, 2024
dc0f196
EVEREST-496 prepare GetDatabaseClusters for multi-namespaces
recharte Jan 29, 2024
dee3141
EVEREST-496 prepare ListDatabaseClusters for multi-namespaces
recharte Jan 29, 2024
5bfd56e
EVEREST-496 add multi-namespaces to PUT /database-clusters/{name}
recharte Jan 29, 2024
95abf3e
EVEREST-496 add multi-namespaces to DELETE /database-clusters/{name}
recharte Jan 29, 2024
68ff921
EVEREST-496 add multi-namespaces to GET DBC credentials
recharte Jan 29, 2024
709c969
EVEREST-496 add multi-namespaces to GET DBC PITR
recharte Jan 29, 2024
e86b396
EVEREST-496 fix telemetry for multi-namespaces
recharte Jan 29, 2024
8d76996
EVEREST-496 add multi-namespaces to GET DBC backups
recharte Jan 29, 2024
eee8a9d
EVEREST-496 add multi-namespaces to POST /database-cluster-backups
recharte Jan 29, 2024
10fac5b
EVEREST-496 add multi-namespaces to GET /database-clusters-backups/:name
recharte Jan 29, 2024
e72e04b
EVEREST-496 add multi-namespaces to DELETE /database-clusters-backups
recharte Jan 29, 2024
38c5602
EVEREST-496 add multi-namespaces to GET DBC restores
recharte Jan 29, 2024
27be559
EVEREST-496 add multi-namespaces to POST /database-cluster-restores
recharte Jan 29, 2024
7264a99
EVEREST-496 add multi-namespaces to GET /database-cluster-restores/name
recharte Jan 29, 2024
39dfb2d
EVEREST-496 add multi-namespaces to PUT /database-cluster-restores/name
recharte Jan 29, 2024
aed5245
EVEREST-496 add multi-namespaces to DELETE /database-cluster-restores
recharte Jan 29, 2024
8530130
EVEREST-496 fix deletion of backup storage while in use
recharte Feb 6, 2024
75dbb66
EVEREST-496 autogen API code
recharte Feb 6, 2024
28695af
EVEREST-496 update namespaces env var name
recharte Feb 7, 2024
6d79a33
EVEREST-496 remove unneeded types
recharte Feb 7, 2024
ed6e674
EVEREST-496 Fix getting DB engine from incorrect namespace
recharte Feb 7, 2024
698d2a5
EVEREST-496 reduce set of permissions
recharte Feb 7, 2024
0dce13f
EVEREST-496 remove unused vmagent functions
recharte Feb 7, 2024
ab7f000
EVEREST-496 Update everest-operator go mod
recharte Feb 7, 2024
f5c08af
Merge remote-tracking branch 'origin/EVEREST-495-multi-namespaces' in…
recharte Feb 7, 2024
bae7fd0
EVEREST-496 Update everest-operator go mod
recharte Feb 7, 2024
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
4 changes: 2 additions & 2 deletions api/backup_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ 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
namespaces, err := e.kubeClient.GetWatchedNamespaces(ctx.Request().Context(), e.kubeClient.Namespace())
namespaces, err := e.kubeClient.GetDBNamespaces(ctx.Request().Context(), e.kubeClient.Namespace())
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{
Expand Down Expand Up @@ -258,7 +258,7 @@ func (e *EverestServer) UpdateBackupStorage(ctx echo.Context, backupStorageName
})
}

namespaces, err := e.kubeClient.GetWatchedNamespaces(ctx.Request().Context(), e.kubeClient.Namespace())
namespaces, err := e.kubeClient.GetDBNamespaces(ctx.Request().Context(), e.kubeClient.Namespace())
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{
Expand Down
38 changes: 19 additions & 19 deletions api/database_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (
)

// CreateDatabaseCluster creates a new db cluster inside the given k8s cluster.
func (e *EverestServer) CreateDatabaseCluster(ctx echo.Context) error {
func (e *EverestServer) CreateDatabaseCluster(ctx echo.Context, namespace string) error {
dbc := &DatabaseCluster{}
if err := e.getBodyFromContext(ctx, dbc); err != nil {
e.l.Error(err)
Expand All @@ -42,30 +42,30 @@ func (e *EverestServer) CreateDatabaseCluster(ctx echo.Context) error {
})
}

if err := e.validateDatabaseClusterCR(ctx, dbc); err != nil {
if err := e.validateDatabaseClusterCR(ctx, namespace, dbc); err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}

return e.proxyKubernetes(ctx, "", databaseClusterKind, "")
return e.proxyKubernetes(ctx, namespace, databaseClusterKind, "")
}

// ListDatabaseClusters lists the created database clusters on the specified kubernetes cluster.
func (e *EverestServer) ListDatabaseClusters(ctx echo.Context) error {
return e.proxyKubernetes(ctx, "", databaseClusterKind, "")
func (e *EverestServer) ListDatabaseClusters(ctx echo.Context, namespace string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterKind, "")
}

// DeleteDatabaseCluster deletes a database cluster on the specified kubernetes cluster.
func (e *EverestServer) DeleteDatabaseCluster(ctx echo.Context, name string) error {
return e.proxyKubernetes(ctx, "", databaseClusterKind, name)
func (e *EverestServer) DeleteDatabaseCluster(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterKind, name)
}

// GetDatabaseCluster retrieves the specified database cluster on the specified kubernetes cluster.
func (e *EverestServer) GetDatabaseCluster(ctx echo.Context, name string) error {
return e.proxyKubernetes(ctx, "", databaseClusterKind, name)
func (e *EverestServer) GetDatabaseCluster(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterKind, name)
}

// UpdateDatabaseCluster replaces the specified database cluster on the specified kubernetes cluster.
func (e *EverestServer) UpdateDatabaseCluster(ctx echo.Context, name string) error {
func (e *EverestServer) UpdateDatabaseCluster(ctx echo.Context, namespace, name string) error {
dbc := &DatabaseCluster{}
if err := e.getBodyFromContext(ctx, dbc); err != nil {
e.l.Error(err)
Expand All @@ -74,29 +74,29 @@ func (e *EverestServer) UpdateDatabaseCluster(ctx echo.Context, name string) err
})
}

if err := e.validateDatabaseClusterCR(ctx, dbc); err != nil {
if err := e.validateDatabaseClusterCR(ctx, namespace, dbc); err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}

oldDB, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), name)
oldDB, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), namespace, name)
if err != nil {
return errors.Join(err, errors.New("could not get old Database Cluster"))
}
if err := validateDatabaseClusterOnUpdate(dbc, oldDB); err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}

return e.proxyKubernetes(ctx, "", databaseClusterKind, name)
return e.proxyKubernetes(ctx, namespace, databaseClusterKind, name)
}

// GetDatabaseClusterCredentials returns credentials for the specified database cluster.
func (e *EverestServer) GetDatabaseClusterCredentials(ctx echo.Context, name string) error {
databaseCluster, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), name)
func (e *EverestServer) GetDatabaseClusterCredentials(ctx echo.Context, namespace, name string) error {
databaseCluster, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), namespace, name)
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString(err.Error())})
}
secret, err := e.kubeClient.GetSecret(ctx.Request().Context(), "percona-everest", databaseCluster.Spec.Engine.UserSecretsName)
secret, err := e.kubeClient.GetSecret(ctx.Request().Context(), namespace, databaseCluster.Spec.Engine.UserSecretsName)
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString(err.Error())})
Expand All @@ -120,8 +120,8 @@ func (e *EverestServer) GetDatabaseClusterCredentials(ctx echo.Context, name str
}

// GetDatabaseClusterPitr returns the point-in-time recovery related information for the specified database cluster.
func (e *EverestServer) GetDatabaseClusterPitr(ctx echo.Context, name string) error {
databaseCluster, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), name)
func (e *EverestServer) GetDatabaseClusterPitr(ctx echo.Context, namespace, name string) error {
databaseCluster, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), namespace, name)
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString(err.Error())})
Expand All @@ -139,7 +139,7 @@ func (e *EverestServer) GetDatabaseClusterPitr(ctx echo.Context, name string) er
},
}),
}
backups, err := e.kubeClient.ListDatabaseClusterBackups(ctx.Request().Context(), options)
backups, err := e.kubeClient.ListDatabaseClusterBackups(ctx.Request().Context(), namespace, options)
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{Message: pointer.ToString(err.Error())})
Expand Down
18 changes: 9 additions & 9 deletions api/database_cluster_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
)

// ListDatabaseClusterBackups returns list of the created database cluster backups on the specified kubernetes cluster.
func (e *EverestServer) ListDatabaseClusterBackups(ctx echo.Context, name string) error {
func (e *EverestServer) ListDatabaseClusterBackups(ctx echo.Context, namespace, name string) error {
req := ctx.Request()
if err := validateRFC1035(name, "name"); err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
Expand All @@ -46,11 +46,11 @@ func (e *EverestServer) ListDatabaseClusterBackups(ctx echo.Context, name string
path = strings.TrimSuffix(path, name)
path = strings.ReplaceAll(path, "database-clusters", "database-cluster-backups")
req.URL.Path = path
return e.proxyKubernetes(ctx, "", databaseClusterBackupKind, "")
return e.proxyKubernetes(ctx, namespace, databaseClusterBackupKind, "")
}

// CreateDatabaseClusterBackup creates a database cluster backup on the specified kubernetes cluster.
func (e *EverestServer) CreateDatabaseClusterBackup(ctx echo.Context) error {
func (e *EverestServer) CreateDatabaseClusterBackup(ctx echo.Context, namespace string) error {
dbb := &DatabaseClusterBackup{}
if err := e.getBodyFromContext(ctx, dbb); err != nil {
e.l.Error(err)
Expand All @@ -59,19 +59,19 @@ func (e *EverestServer) CreateDatabaseClusterBackup(ctx echo.Context) error {
})
}
// TODO: Improve returns status code in EVEREST-616
if err := validateDatabaseClusterBackup(ctx.Request().Context(), dbb, e.kubeClient); err != nil {
if err := validateDatabaseClusterBackup(ctx.Request().Context(), namespace, dbb, e.kubeClient); err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
}
return e.proxyKubernetes(ctx, "", databaseClusterBackupKind, "")
return e.proxyKubernetes(ctx, namespace, databaseClusterBackupKind, "")
}

// DeleteDatabaseClusterBackup deletes the specified cluster backup on the specified kubernetes cluster.
func (e *EverestServer) DeleteDatabaseClusterBackup(ctx echo.Context, name string) error {
return e.proxyKubernetes(ctx, "", databaseClusterBackupKind, name)
func (e *EverestServer) DeleteDatabaseClusterBackup(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterBackupKind, name)
}

// GetDatabaseClusterBackup returns the specified cluster backup on the specified kubernetes cluster.
func (e *EverestServer) GetDatabaseClusterBackup(ctx echo.Context, name string) error {
return e.proxyKubernetes(ctx, "", databaseClusterBackupKind, name)
func (e *EverestServer) GetDatabaseClusterBackup(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterBackupKind, name)
}
26 changes: 13 additions & 13 deletions api/database_cluster_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
)

// ListDatabaseClusterRestores List of the created database cluster restores on the specified kubernetes cluster.
func (e *EverestServer) ListDatabaseClusterRestores(ctx echo.Context, name string) error {
func (e *EverestServer) ListDatabaseClusterRestores(ctx echo.Context, namespace, name string) error {
req := ctx.Request()
if err := validateRFC1035(name, "name"); err != nil {
return ctx.JSON(http.StatusBadRequest, Error{Message: pointer.ToString(err.Error())})
Expand All @@ -47,25 +47,25 @@ func (e *EverestServer) ListDatabaseClusterRestores(ctx echo.Context, name strin
path = strings.TrimSuffix(path, name)
path = strings.ReplaceAll(path, "database-clusters", "database-cluster-restores")
req.URL.Path = path
return e.proxyKubernetes(ctx, "", databaseClusterRestoreKind, "")
return e.proxyKubernetes(ctx, namespace, databaseClusterRestoreKind, "")
}

// CreateDatabaseClusterRestore Create a database cluster restore on the specified kubernetes cluster.
func (e *EverestServer) CreateDatabaseClusterRestore(ctx echo.Context) error {
func (e *EverestServer) CreateDatabaseClusterRestore(ctx echo.Context, namespace string) error {
restore := &DatabaseClusterRestore{}
if err := e.getBodyFromContext(ctx, restore); err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString("Could not get DatabaseClusterRestore from the request body"),
})
}
if err := validateDatabaseClusterRestore(ctx.Request().Context(), restore, e.kubeClient); err != nil {
if err := validateDatabaseClusterRestore(ctx.Request().Context(), namespace, restore, e.kubeClient); err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString(err.Error()),
})
}
dbCluster, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), restore.Spec.DbClusterName)
dbCluster, err := e.kubeClient.GetDatabaseCluster(ctx.Request().Context(), namespace, restore.Spec.DbClusterName)
if err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusInternalServerError, Error{
Expand All @@ -79,33 +79,33 @@ func (e *EverestServer) CreateDatabaseClusterRestore(ctx echo.Context) error {
})
}

return e.proxyKubernetes(ctx, "", databaseClusterRestoreKind, "")
return e.proxyKubernetes(ctx, namespace, databaseClusterRestoreKind, "")
}

// DeleteDatabaseClusterRestore Delete the specified cluster restore on the specified kubernetes cluster.
func (e *EverestServer) DeleteDatabaseClusterRestore(ctx echo.Context, name string) error {
return e.proxyKubernetes(ctx, "", databaseClusterRestoreKind, name)
func (e *EverestServer) DeleteDatabaseClusterRestore(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterRestoreKind, name)
}

// GetDatabaseClusterRestore Returns the specified cluster restore on the specified kubernetes cluster.
func (e *EverestServer) GetDatabaseClusterRestore(ctx echo.Context, name string) error {
return e.proxyKubernetes(ctx, "", databaseClusterRestoreKind, name)
func (e *EverestServer) GetDatabaseClusterRestore(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseClusterRestoreKind, name)
}

// UpdateDatabaseClusterRestore Replace the specified cluster restore on the specified kubernetes cluster.
func (e *EverestServer) UpdateDatabaseClusterRestore(ctx echo.Context, name string) error {
func (e *EverestServer) UpdateDatabaseClusterRestore(ctx echo.Context, namespace, name string) error {
restore := &DatabaseClusterRestore{}
if err := e.getBodyFromContext(ctx, restore); err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString("Could not get DatabaseClusterRestore from the request body"),
})
}
if err := validateDatabaseClusterRestore(ctx.Request().Context(), restore, e.kubeClient); err != nil {
if err := validateDatabaseClusterRestore(ctx.Request().Context(), namespace, restore, e.kubeClient); err != nil {
e.l.Error(err)
return ctx.JSON(http.StatusBadRequest, Error{
Message: pointer.ToString(err.Error()),
})
}
return e.proxyKubernetes(ctx, "", databaseClusterRestoreKind, name)
return e.proxyKubernetes(ctx, namespace, databaseClusterRestoreKind, name)
}
4 changes: 2 additions & 2 deletions api/database_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ func (e *EverestServer) ListDatabaseEngines(ctx echo.Context, namespace string)
}

// GetDatabaseEngine Get the specified database engine on the specified namespace.
func (e *EverestServer) GetDatabaseEngine(ctx echo.Context, namespace string, name string) error {
func (e *EverestServer) GetDatabaseEngine(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseEngineKind, name)
}

// UpdateDatabaseEngine Update the specified database engine on the specified namespace.
func (e *EverestServer) UpdateDatabaseEngine(ctx echo.Context, namespace string, name string) error {
func (e *EverestServer) UpdateDatabaseEngine(ctx echo.Context, namespace, name string) error {
return e.proxyKubernetes(ctx, namespace, databaseEngineKind, name)
}
Loading
Loading