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 during the provisioning
Browse files Browse the repository at this point in the history
  • Loading branch information
gen1us2k committed Oct 4, 2023
1 parent 7a403cf commit aecd819
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 1 deletion.
10 changes: 9 additions & 1 deletion pkg/install/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,10 @@ func (o *Operators) provisionOperators(ctx context.Context) error {
return err
}

return o.installOperator(ctx, o.config.Channel.Everest, everestOperatorName)()
if err := o.installOperator(ctx, o.config.Channel.Everest, everestOperatorName)(); err != nil {
return err
}
return o.restartEverestOperatorPod(ctx)
}

func (o *Operators) installOperator(ctx context.Context, channel, operatorName string) func() error {
Expand Down Expand Up @@ -1002,3 +1005,8 @@ func (o *Operators) getServiceAccountKubeConfig(ctx context.Context) (string, er

return o.kubeClient.GenerateKubeConfigWithToken(everestServiceAccount, secret)
}

func (o *Operators) restartEverestOperatorPod(ctx context.Context) error {
return o.kubeClient.RestartEverestOperator(ctx, o.config.Namespace)

}
5 changes: 5 additions & 0 deletions pkg/kubernetes/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,11 @@ func (c *Client) GetPods(
return c.clientset.CoreV1().Pods(namespace).List(ctx, options)
}

// GetPods returns list of pods.

Check failure on line 493 in pkg/kubernetes/client/client.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

comment on exported method `Client.DeletePod` should be of the form `DeletePod ...` (golint)

Check failure on line 493 in pkg/kubernetes/client/client.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

comment on exported method `Client.DeletePod` should be of the form `DeletePod ...` (golint)
func (c *Client) DeletePod(ctx context.Context, namespace, name string) error {
return c.clientset.CoreV1().Pods(namespace).Delete(ctx, name, metav1.DeleteOptions{})
}

// GetNodes returns list of nodes.
func (c *Client) GetNodes(ctx context.Context) (*corev1.NodeList, error) {
return c.clientset.CoreV1().Nodes().List(ctx, metav1.ListOptions{})
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.

14 changes: 14 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.

38 changes: 38 additions & 0 deletions pkg/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,3 +832,41 @@ func (k *Kubernetes) updateClusterRoleBindingNamespace(o map[string]interface{},

return nil
}

func (k *Kubernetes) RestartEverestOperator(ctx context.Context, namespace string) error {

Check failure on line 836 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

exported method `Kubernetes.RestartEverestOperator` should have comment or be unexported (golint)

Check failure on line 836 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

exported method `Kubernetes.RestartEverestOperator` should have comment or be unexported (golint)
pod, err := k.getEverestOperatorPod(ctx, namespace)
if err != nil {
return err
}
podUid := pod.UID

Check failure on line 841 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

var `podUid` should be `podUID` (golint)

Check failure on line 841 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

var `podUid` should be `podUID` (golint)
err = k.client.DeletePod(ctx, namespace, pod.Name)
if err != nil {
return err
}

return wait.PollImmediate(5*time.Second, time.Minute, func() (done bool, err error) {

Check failure on line 847 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

named return "done" with type "bool" found (nonamedreturns)
pod, err := k.getEverestOperatorPod(ctx, namespace)
if pod.UID != podUid && err != nil {
return false, nil

Check failure on line 850 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

error is not nil (line 848) but it returns nil (nilerr)

Check failure on line 850 in pkg/kubernetes/kubernetes.go

View workflow job for this annotation

GitHub Actions / Check (1.21.x, false)

error is not nil (line 848) but it returns nil (nilerr)
}
return pod.Status.Phase == corev1.PodRunning && pod.Status.ContainerStatuses[0].Ready, nil
})
}

func (k *Kubernetes) getEverestOperatorPod(ctx context.Context, namespace string) (corev1.Pod, error) {
podList, err := k.client.GetPods(ctx, namespace, &metav1.LabelSelector{
MatchLabels: map[string]string{
"app.kubernetes.io/name": "everest-operator",
},
})
if err != nil {
return corev1.Pod{}, err
}
if len(podList.Items) == 0 {
return corev1.Pod{}, errors.New("no instances of everest-opeator are running")
}
if len(podList.Items) > 1 {
return corev1.Pod{}, errors.New("multiple instances of everest-operator found")
}
return podList.Items[0], nil
}

0 comments on commit aecd819

Please sign in to comment.