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

EVEREST-203 #137

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion commands/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"github.com/percona/percona-everest-cli/commands/provision"
)

func newProvisionCmd(l *zap.SugaredLogger) *cobra.Command {
func newProvisionCmd(l *zap.SugaredLogger) *cobra.Command { //nolint:deadcode,unused
cmd := &cobra.Command{
Use: "provision",
}
Expand Down
26 changes: 26 additions & 0 deletions pkg/install/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ func (o *Operators) checkEverestConnection(ctx context.Context) error {
}

func (o *Operators) performProvisioning(ctx context.Context) error {
if err := o.checkPreviousInstallations(ctx); err != nil {
return err
}

if err := o.provisionNamespace(); err != nil {
return err
}
Expand Down Expand Up @@ -661,6 +665,7 @@ func (o *Operators) runOperatorsWizard() error {
// provisionNamespace provisions a namespace for Everest.
func (o *Operators) provisionNamespace() error {
o.l.Infof("Creating namespace %s", o.config.Namespace)

err := o.kubeClient.CreateNamespace(o.config.Namespace)
if err != nil {
return errors.Join(err, errors.New("could not provision namespace"))
Expand All @@ -670,6 +675,24 @@ func (o *Operators) provisionNamespace() error {
return nil
}

func (o *Operators) checkPreviousInstallations(ctx context.Context) error {
// check if the current cluster already registered in Everest (by its uid)
// if it's NOT registred, run the below check:

o.l.Info("Checking existing Everest components")
namespaces, err := o.kubeClient.ListNamespaces(ctx)
if err != nil {
return errors.Join(err, errors.New("could not list namespaces"))
}
for _, ns := range namespaces {
if ns == o.config.Namespace {
return errors.New("please clean up the old installation of Everest first")
}
}

return nil
}

// provisionAllOperators provisions all configured operators to a k8s cluster.
func (o *Operators) provisionAllOperators(ctx context.Context) error {
o.l.Info("Started provisioning the cluster")
Expand Down Expand Up @@ -792,6 +815,9 @@ func (o *Operators) connectToEverest(ctx context.Context) (*client.KubernetesClu

o.l.Info("Connecting your Kubernetes cluster to Everest")

// list clusters
// check the current uid is there, if so, skip the registration

k, err := o.everestClient.RegisterKubernetesCluster(ctx, client.CreateKubernetesClusterParams{
Kubeconfig: base64.StdEncoding.EncodeToString([]byte(kubeconfig)),
Name: o.config.Name,
Expand Down
15 changes: 15 additions & 0 deletions pkg/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,21 @@ func (c *Client) CreateNamespace(name string) error {
return c.ApplyObject(n)
}

// ListNamespaces lists the existing namespaces.
func (c *Client) ListNamespaces(ctx context.Context) ([]string, error) {
list, err := c.clientset.CoreV1().Namespaces().List(ctx, metav1.ListOptions{})
if err != nil {
return nil, err
}

namespaces := make([]string, 0, len(list.Items))
for _, ns := range list.Items {
namespaces = append(namespaces, ns.Name)
}

return namespaces, nil
}

// GetOperatorGroup retrieves an operator group details by namespace and name.
func (c *Client) GetOperatorGroup(ctx context.Context, namespace, name string) (*v1.OperatorGroup, error) {
operatorClient, err := versioned.NewForConfig(c.restConfig)
Expand Down
2 changes: 2 additions & 0 deletions pkg/kubernetes/client/kubeclient_interface.go

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

26 changes: 26 additions & 0 deletions 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.

5 changes: 5 additions & 0 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,11 @@ func (k *Kubernetes) CreateNamespace(name string) error {
return k.client.CreateNamespace(name)
}

// ListNamespaces creates a new namespace.
func (k *Kubernetes) ListNamespaces(ctx context.Context) ([]string, error) {
return k.client.ListNamespaces(ctx)
}

// InstallOperatorRequest holds the fields to make an operator install request.
type InstallOperatorRequest struct {
Namespace string
Expand Down
Loading