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

EVEREST-203 Do not run registration for already registered k8s clusters #151

Merged
merged 8 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
20 changes: 19 additions & 1 deletion cli-tests/tests/flow/pg-operator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ test.describe('Everest CLI install operators', async () => {

await out.outNotContains([
'percona-server-mongodb-operator',
'percona-xtradb-cluster-operator',
]);
});
};
Expand All @@ -59,6 +58,25 @@ test.describe('Everest CLI install operators', async () => {

await page.waitForTimeout(10_000);

await verifyClusterResources();
await apiVerifyClusterExists(request, clusterName);

await test.step('re-run everest install operators command', async () => {
const out = await cli.everestExecSkipWizard(
`install operators --operator.mongodb=false --operator.postgresql=true --operator.xtradb-cluster=true --backup.enable=0 --monitoring.enable=0 --name=${clusterName}`,
);

await out.assertSuccess();
await out.outErrContainsNormalizedMany([
'percona-xtradb-cluster-operator operator has been installed',
'everest-operator operator has been installed',
]);
await out.outNotContains([
'Connected Kubernetes cluster to Everest',
]);
});
await page.waitForTimeout(10_000);

await verifyClusterResources();
await apiVerifyClusterExists(request, clusterName);
await cliDeleteCluster(cli, request, clusterName);
Expand Down
3 changes: 3 additions & 0 deletions pkg/install/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import (
//go:generate ../../bin/mockery --name=everestClientConnector --case=snake --inpackage --testonly

type everestClientConnector interface {
ListKubernetesClusters(
ctx context.Context,
) ([]client.KubernetesCluster, error)
RegisterKubernetesCluster(
ctx context.Context,
body client.RegisterKubernetesClusterJSONRequestBody,
Expand Down
28 changes: 27 additions & 1 deletion pkg/install/mock_everest_client_connector_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions pkg/install/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ import (
"net/url"
"time"

k8serrors "k8s.io/apimachinery/pkg/api/errors"
gen1us2k marked this conversation as resolved.
Show resolved Hide resolved

"github.com/AlecAivazis/survey/v2"
"github.com/operator-framework/api/pkg/operators/v1alpha1"
"github.com/percona/percona-everest-backend/client"
"go.uber.org/zap"
"golang.org/x/sync/errgroup"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"

"github.com/percona/percona-everest-cli/commands/common"
Expand Down Expand Up @@ -780,6 +783,24 @@ func (o *Operators) provisionMonitoring() error {

// connectToEverest connects the k8s cluster to Everest.
func (o *Operators) connectToEverest(ctx context.Context) (*client.KubernetesCluster, error) {
clusters, err := o.everestClient.ListKubernetesClusters(ctx)
if err != nil {
return nil, errors.Join(err, errors.New("could not list kubernetes clusters"))
}
for _, cluster := range clusters {
if cluster.Name == o.config.Name {
ns, err := o.kubeClient.GetNamespace(ctx, cluster.Namespace)
if err != nil && !k8serrors.IsNotFound(err) {
return nil, errors.Join(err, errors.New("could not get namespace from Kubernetes"))
}

if ns.UID != types.UID(cluster.Uid) {
return nil, errors.New("namespace UID mismatch. It looks like you're trying to register a new kubernetes cluster using the existing name. Please unregister the existing kubernetes cluster first")
gen1us2k marked this conversation as resolved.
Show resolved Hide resolved
}
// Cluster is already registered. Do nothing
return &cluster, nil
}
}
gen1us2k marked this conversation as resolved.
Show resolved Hide resolved
if err := o.prepareServiceAccount(); err != nil {
return nil, errors.Join(err, errors.New("could not prepare a service account"))
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubernetes/client/mock_kube_client_connector.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading