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

Commit

Permalink
EVEREST-458 Restart everest operator once a new version of operator i…
Browse files Browse the repository at this point in the history
…s installed (#172)
  • Loading branch information
gen1us2k authored Oct 12, 2023
1 parent 4f2fa6e commit cd623f3
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 3 deletions.
13 changes: 12 additions & 1 deletion pkg/install/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,10 @@ func (o *Operators) provisionOLM(ctx context.Context) error {
}

func (o *Operators) provisionOperators(ctx context.Context) error {
deploymentsBefore, err := o.kubeClient.ListEngineDeploymentNames(ctx, o.config.Namespace)
if err != nil {
return err
}
g, gCtx := errgroup.WithContext(ctx)
// We set the limit to 1 since operator installation
// requires an update to the same installation plan which
Expand Down Expand Up @@ -738,7 +742,14 @@ func (o *Operators) provisionOperators(ctx context.Context) error {
if err := o.installOperator(ctx, o.config.Channel.Everest, everestOperatorName)(); err != nil {
return err
}
return o.restartEverestOperatorPod(ctx)
deploymentsAfter, err := o.kubeClient.ListEngineDeploymentNames(ctx, o.config.Namespace)
if err != nil {
return err
}
if len(deploymentsBefore) != len(deploymentsAfter) {
return o.restartEverestOperatorPod(ctx)
}
return nil
}

func (o *Operators) installOperator(ctx context.Context, channel, operatorName string) func() error {
Expand Down
8 changes: 8 additions & 0 deletions pkg/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,14 @@ func (c *Client) GetDeployment(ctx context.Context, name string, namespace strin
return c.clientset.AppsV1().Deployments(namespace).Get(ctx, name, metav1.GetOptions{})
}

// ListDeployments returns deployment by name.
func (c *Client) ListDeployments(ctx context.Context, namespace string) (*appsv1.DeploymentList, error) {
if namespace == "" {
namespace = c.namespace
}
return c.clientset.AppsV1().Deployments(namespace).List(ctx, metav1.ListOptions{})
}

// GetSecret returns secret by name.
func (c *Client) GetSecret(ctx context.Context, name, namespace string) (*corev1.Secret, error) {
return c.clientset.CoreV1().Secrets(namespace).Get(ctx, name, metav1.GetOptions{})
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.

28 changes: 26 additions & 2 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const (

pxcDeploymentName = "percona-xtradb-cluster-operator"
psmdbDeploymentName = "percona-server-mongodb-operator"
postgresDeploymentName = "percona-postgresql-operator"
everestDeploymentName = "everest-operator-controller-manager"
psmdbOperatorContainerName = "percona-server-mongodb-operator"
pxcOperatorContainerName = "percona-xtradb-cluster-operator"
Expand Down Expand Up @@ -509,7 +510,7 @@ func (k *Kubernetes) applyResources(ctx context.Context) ([]unstructured.Unstruc
k.l.Debugf("Applying %q file", f)
if err := k.client.ApplyFile(data); err != nil {
k.l.Debug(errors.Join(err, fmt.Errorf("cannot apply %q file", f)))
k.l.Warn(fmt.Errorf("cannot apply %q file. Reapplying it...", f))
k.l.Warn(fmt.Errorf("cannot apply %q file. Reapplying it", f))
return false, nil
}
return true, nil
Expand Down Expand Up @@ -616,8 +617,15 @@ func (k *Kubernetes) InstallOperator(ctx context.Context, req InstallOperatorReq

return k.approveInstallPlan(ctx, req.Namespace, subs.Status.InstallPlanRef.Name)
})
if err != nil {
return err
}
deploymentName := req.Name
if req.Name == "everest-operator" {
deploymentName = everestDeploymentName
}

return err
return k.client.DoRolloutWait(ctx, types.NamespacedName{Namespace: req.Namespace, Name: deploymentName})
}

func (k *Kubernetes) approveInstallPlan(ctx context.Context, namespace, installPlanName string) (bool, error) {
Expand Down Expand Up @@ -892,3 +900,19 @@ func (k *Kubernetes) getEverestOperatorPod(ctx context.Context, namespace string
}
return podList.Items[0], nil
}

// ListEngineDeploymentNames returns a string array containing found engine deployments for the Everest.
func (k *Kubernetes) ListEngineDeploymentNames(ctx context.Context, namespace string) ([]string, error) {
names := []string{}
deploymentList, err := k.client.ListDeployments(ctx, namespace)
if err != nil {
return names, err
}
for _, deployment := range deploymentList.Items {
switch deployment.Name {
case pxcDeploymentName, psmdbDeploymentName, everestDeploymentName, postgresDeploymentName:
names = append(names, deployment.Name)
}
}
return names, nil
}

0 comments on commit cd623f3

Please sign in to comment.