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

Commit

Permalink
EVEREST-838 Fix uninstall command (#295)
Browse files Browse the repository at this point in the history
* 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
recharte authored Feb 14, 2024
1 parent f5d68f1 commit eb26e7b
Show file tree
Hide file tree
Showing 32 changed files with 2,140 additions and 235 deletions.
2 changes: 1 addition & 1 deletion data/crds/olm/everest-catalog.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: everest-catalog
namespace: olm
namespace: everest-olm
spec:
displayName: Everest Catalog
publisher: Percona
Expand Down
38 changes: 10 additions & 28 deletions data/crds/olm/olm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
apiVersion: v1
kind: Namespace
metadata:
name: olm
name: everest-olm
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: latest
Expand All @@ -11,23 +11,11 @@ metadata:
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/warn-version: latest
---
apiVersion: v1
kind: Namespace
metadata:
name: operators
labels:
pod-security.kubernetes.io/enforce: baseline
pod-security.kubernetes.io/enforce-version: latest
pod-security.kubernetes.io/audit: restricted
pod-security.kubernetes.io/audit-version: latest
pod-security.kubernetes.io/warn: restricted
pod-security.kubernetes.io/warn-version: latest
---
kind: ServiceAccount
apiVersion: v1
metadata:
name: olm-operator-serviceaccount
namespace: olm
namespace: everest-olm
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
Expand All @@ -51,7 +39,7 @@ roleRef:
subjects:
- kind: ServiceAccount
name: olm-operator-serviceaccount
namespace: olm
namespace: everest-olm
---
apiVersion: operators.coreos.com/v1
kind: OLMConfig
Expand All @@ -62,7 +50,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: olm-operator
namespace: olm
namespace: everest-olm
labels:
app: olm-operator
spec:
Expand Down Expand Up @@ -129,7 +117,7 @@ apiVersion: apps/v1
kind: Deployment
metadata:
name: catalog-operator
namespace: olm
namespace: everest-olm
labels:
app: catalog-operator
spec:
Expand Down Expand Up @@ -159,7 +147,7 @@ spec:
- /bin/catalog
args:
- '--namespace'
- olm
- everest-olm
- --configmapServerImage=quay.io/operator-framework/configmap-operator-registry:latest
- --util-image
- quay.io/operator-framework/olm@sha256:163bacd69001fea0c666ecf8681e9485351210cde774ee345c06f80d5a651473
Expand Down Expand Up @@ -220,24 +208,18 @@ rules:
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: global-operators
namespace: operators
---
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: olm-operators
namespace: olm
namespace: everest-olm
spec:
targetNamespaces:
- olm
- everest-olm
---
apiVersion: operators.coreos.com/v1alpha1
kind: ClusterServiceVersion
metadata:
name: packageserver
namespace: olm
namespace: everest-olm
labels:
olm.version: v0.25.0
spec:
Expand Down Expand Up @@ -334,7 +316,7 @@ spec:
- --secure-port
- "5443"
- --global-namespace
- olm
- everest-olm
image: quay.io/operator-framework/olm@sha256:163bacd69001fea0c666ecf8681e9485351210cde774ee345c06f80d5a651473
imagePullPolicy: Always
ports:
Expand Down
22 changes: 10 additions & 12 deletions pkg/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ const (
pgOperatorChannel = "stable-v2"
vmOperatorChannel = "stable-v0"

// catalogSourceNamespace is the namespace where the catalog source is installed.
catalogSourceNamespace = "olm"
// catalogSource is the name of the catalog source.
catalogSource = "everest-catalog"

Expand All @@ -79,8 +77,8 @@ const (

// SystemNamespace is the namespace where everest is installed.
SystemNamespace = "everest-system"
// monitoringNamespace is the namespace where the monitoring stack is installed.
monitoringNamespace = "everest-monitoring"
// MonitoringNamespace is the namespace where the monitoring stack is installed.
MonitoringNamespace = "everest-monitoring"
// EverestMonitoringNamespaceEnvVar is the name of the environment variable that holds the monitoring namespace.
EverestMonitoringNamespaceEnvVar = "MONITORING_NAMESPACE"
// disableTelemetryEnvVar is the name of the environment variable that disables telemetry.
Expand Down Expand Up @@ -188,7 +186,7 @@ func (o *Install) populateConfig() error {
}

for _, ns := range o.config.NamespacesList() {
if ns == SystemNamespace || ns == monitoringNamespace {
if ns == SystemNamespace || ns == MonitoringNamespace {
return fmt.Errorf("'%s' namespace is reserved for Everest internals. Please specify another namespace", ns)
}
}
Expand All @@ -198,17 +196,17 @@ func (o *Install) populateConfig() error {

func (o *Install) installVMOperator(ctx context.Context) error {
o.l.Info("Creating operator group for everest")
if err := o.kubeClient.CreateOperatorGroup(ctx, monitoringOperatorGroup, monitoringNamespace, []string{}); err != nil {
if err := o.kubeClient.CreateOperatorGroup(ctx, monitoringOperatorGroup, MonitoringNamespace, []string{}); err != nil {
return err
}
o.l.Infof("Installing %s operator", vmOperatorName)

params := kubernetes.InstallOperatorRequest{
Namespace: monitoringNamespace,
Namespace: MonitoringNamespace,
Name: vmOperatorName,
OperatorGroup: monitoringOperatorGroup,
CatalogSource: catalogSource,
CatalogSourceNamespace: catalogSourceNamespace,
CatalogSourceNamespace: kubernetes.OLMNamespace,
Channel: vmOperatorChannel,
InstallPlanApproval: v1alpha1.ApprovalManual,
}
Expand All @@ -223,15 +221,15 @@ func (o *Install) installVMOperator(ctx context.Context) error {

func (o *Install) provisionMonitoringStack(ctx context.Context) error {
l := o.l.With("action", "monitoring")
if err := o.createNamespace(monitoringNamespace); err != nil {
if err := o.createNamespace(MonitoringNamespace); err != nil {
return err
}

l.Info("Preparing k8s cluster for monitoring")
if err := o.installVMOperator(ctx); err != nil {
return err
}
if err := o.kubeClient.ProvisionMonitoring(monitoringNamespace); err != nil {
if err := o.kubeClient.ProvisionMonitoring(MonitoringNamespace); err != nil {
return errors.Join(err, errors.New("could not provision monitoring configuration"))
}

Expand Down Expand Up @@ -494,7 +492,7 @@ func (o *Install) installOperator(ctx context.Context, channel, operatorName, na
Name: operatorName,
OperatorGroup: systemOperatorGroup,
CatalogSource: catalogSource,
CatalogSourceNamespace: catalogSourceNamespace,
CatalogSourceNamespace: kubernetes.OLMNamespace,
Channel: channel,
InstallPlanApproval: v1alpha1.ApprovalManual,
SubscriptionConfig: &v1alpha1.SubscriptionConfig{
Expand All @@ -511,7 +509,7 @@ func (o *Install) installOperator(ctx context.Context, channel, operatorName, na
params.SubscriptionConfig.Env = append(params.SubscriptionConfig.Env, []corev1.EnvVar{
{
Name: EverestMonitoringNamespaceEnvVar,
Value: monitoringNamespace,
Value: MonitoringNamespace,
},
{
Name: kubernetes.EverestDBNamespacesEnvVar,
Expand Down
102 changes: 102 additions & 0 deletions pkg/kubernetes/backup_storage.go
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
}
51 changes: 51 additions & 0 deletions pkg/kubernetes/client/backup_storage.go
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{})
}
Loading

0 comments on commit eb26e7b

Please sign in to comment.