This repository was archived by the owner on Mar 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
EVEREST-838 Fix uninstall command (#295)
* EVEREST-838 remove unused operators namespace * EVEREST-838 Rename olm namespace to everest-olm * EVEREST-838 import custom resources client from percona-everest-backend * EVEREST-838 delete DBs during uninstall * EVEREST-838 delete DB namespaces during uninstall * EVEREST-838 make backup storage kubernetes functions namespaced * EVEREST-838 delete BackupStorages during uninstall * EVEREST-838 fix delete monitoring stack during uninstall * EVEREST-838 delete everest system during uninstall * EVEREST-838 delete OLM namespace during uninstall * EVEREST-838 refactor uninstall waiting mechanism * EVEREST-838 fix uninstall stuck deleting DB namespace * EVEREST-838 Import MonitoringConfig client from BE repo * EVEREST-838 fix uninstall stuck deleting monitoring namespace * EVEREST-838 fix uninstall stuck deleting OLM namespace * EVEREST-838 Update everest-operator go mod * EVEREST-838 fix incorrect namespace for GetPackageManifest * EVEREST-838 fix unit tests * EVEREST-838 fix linter * EVEREST-838 fix wrong namespace for packageserver CSV * EVEREST-838 remove unneeded conditional
- Loading branch information
Showing
32 changed files
with
2,140 additions
and
235 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// everest | ||
// Copyright (C) 2023 Percona LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package kubernetes ... | ||
package kubernetes | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
everestv1alpha1 "github.com/percona/everest-operator/api/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
const ( | ||
backupStorageNameLabelTmpl = "backupStorage-%s" | ||
backupStorageLabelValue = "used" | ||
) | ||
|
||
// ListBackupStorages returns list of managed backup storages. | ||
func (k *Kubernetes) ListBackupStorages(ctx context.Context, namespace string) (*everestv1alpha1.BackupStorageList, error) { | ||
return k.client.ListBackupStorages(ctx, namespace, metav1.ListOptions{}) | ||
} | ||
|
||
// GetBackupStorage returns backup storages by provided name. | ||
func (k *Kubernetes) GetBackupStorage(ctx context.Context, namespace, name string) (*everestv1alpha1.BackupStorage, error) { | ||
return k.client.GetBackupStorage(ctx, namespace, name) | ||
} | ||
|
||
// CreateBackupStorage returns backup storages by provided name. | ||
func (k *Kubernetes) CreateBackupStorage(ctx context.Context, storage *everestv1alpha1.BackupStorage) error { | ||
return k.client.CreateBackupStorage(ctx, storage) | ||
} | ||
|
||
// UpdateBackupStorage returns backup storages by provided name. | ||
func (k *Kubernetes) UpdateBackupStorage(ctx context.Context, storage *everestv1alpha1.BackupStorage) error { | ||
return k.client.UpdateBackupStorage(ctx, storage) | ||
} | ||
|
||
// DeleteBackupStorage returns backup storages by provided name. | ||
func (k *Kubernetes) DeleteBackupStorage(ctx context.Context, namespace, name string) error { | ||
return k.client.DeleteBackupStorage(ctx, namespace, name) | ||
} | ||
|
||
// IsBackupStorageUsed checks that a backup storage by provided name is used across k8s cluster. | ||
func (k *Kubernetes) IsBackupStorageUsed(ctx context.Context, namespace, backupStorageName string) (bool, error) { | ||
_, err := k.client.GetBackupStorage(ctx, namespace, backupStorageName) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
namespaces, err := k.GetDBNamespaces(ctx, namespace) | ||
if err != nil { | ||
return false, err | ||
} | ||
|
||
options := metav1.ListOptions{ | ||
LabelSelector: metav1.FormatLabelSelector(&metav1.LabelSelector{ | ||
MatchLabels: map[string]string{ | ||
fmt.Sprintf(backupStorageNameLabelTmpl, backupStorageName): backupStorageLabelValue, | ||
}, | ||
}), | ||
} | ||
|
||
for _, namespace := range namespaces { | ||
list, err := k.client.ListDatabaseClusters(ctx, namespace, options) | ||
if err != nil { | ||
return false, err | ||
} | ||
if len(list.Items) > 0 { | ||
return true, nil | ||
} | ||
bList, err := k.client.ListDatabaseClusterBackups(ctx, namespace, options) | ||
if err != nil { | ||
return false, err | ||
} | ||
if len(bList.Items) > 0 { | ||
return true, nil | ||
} | ||
rList, err := k.client.ListDatabaseClusterRestores(ctx, namespace, options) | ||
if err != nil { | ||
return false, err | ||
} | ||
if len(rList.Items) > 0 { | ||
return true, nil | ||
} | ||
} | ||
|
||
return false, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// everest | ||
// Copyright (C) 2023 Percona LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package client ... | ||
package client | ||
|
||
import ( | ||
"context" | ||
|
||
everestv1alpha1 "github.com/percona/everest-operator/api/v1alpha1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
// CreateBackupStorage creates an backupStorage. | ||
func (c *Client) CreateBackupStorage(ctx context.Context, storage *everestv1alpha1.BackupStorage) error { | ||
_, err := c.customClientSet.BackupStorage(storage.Namespace).Create(ctx, storage, metav1.CreateOptions{}) | ||
return err | ||
} | ||
|
||
// UpdateBackupStorage updates an backupStorage. | ||
func (c *Client) UpdateBackupStorage(ctx context.Context, storage *everestv1alpha1.BackupStorage) error { | ||
_, err := c.customClientSet.BackupStorage(storage.Namespace).Update(ctx, storage, metav1.UpdateOptions{}) | ||
return err | ||
} | ||
|
||
// GetBackupStorage returns the backupStorage. | ||
func (c *Client) GetBackupStorage(ctx context.Context, namespace, name string) (*everestv1alpha1.BackupStorage, error) { | ||
return c.customClientSet.BackupStorage(namespace).Get(ctx, name, metav1.GetOptions{}) | ||
} | ||
|
||
// ListBackupStorages returns the backupStorage. | ||
func (c *Client) ListBackupStorages(ctx context.Context, namespace string, options metav1.ListOptions) (*everestv1alpha1.BackupStorageList, error) { | ||
return c.customClientSet.BackupStorage(namespace).List(ctx, options) | ||
} | ||
|
||
// DeleteBackupStorage deletes the backupStorage. | ||
func (c *Client) DeleteBackupStorage(ctx context.Context, namespace, name string) error { | ||
return c.customClientSet.BackupStorage(namespace).Delete(ctx, name, metav1.DeleteOptions{}) | ||
} |
Oops, something went wrong.