Skip to content

Commit

Permalink
Retry dns-operator updates on conflicts
Browse files Browse the repository at this point in the history
This uses the standard K8s retry pattern. It’s not the only place in
subctl where we need to do this, I’ll follow up with another PR to fix
the rest.

Fixes: #236
Signed-off-by: Stephen Kitt <skitt@redhat.com>
(cherry picked from commit 2afe090)
  • Loading branch information
skitt authored and mangelajo committed Mar 6, 2020
1 parent e4658d3 commit d5dd0f7
Showing 1 changed file with 21 additions and 22 deletions.
43 changes: 21 additions & 22 deletions pkg/subctl/lighthouse/dns/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
clientset "k8s.io/client-go/kubernetes"
clientsetifc "k8s.io/client-go/kubernetes/typed/apps/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/util/retry"

"github.com/submariner-io/submariner-operator/pkg/internal/cli"
)
Expand Down Expand Up @@ -223,32 +224,30 @@ func setupOpenShift(status *cli.Status, clientSet *clientset.Clientset, repo str

// Update operator deployment
deployments := clientSet.AppsV1().Deployments("openshift-dns-operator")
if deployments == nil {
// Assume we're not on OpenShift
return nil
}
deployment, err := deployments.Get("dns-operator", metav1.GetOptions{})
if err != nil {
return err
}
if deployment == nil {
// Assume we're not on OpenShift
return nil
}
for i, container := range deployment.Spec.Template.Spec.Containers {
if container.Name == "dns-operator" {
deployment.Spec.Template.Spec.Containers[i].Image = repo + operatorImage + ":" + version
for j, env := range container.Env {
if env.Name == "IMAGE" {
deployment.Spec.Template.Spec.Containers[i].Env[j].Value = repo + openShiftCoreDNSImage + ":" + version
retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
deployment, err := deployments.Get("dns-operator", metav1.GetOptions{})
if errors.IsNotFound(err) {
// Assume we're not on OpenShift
return nil
} else if err != nil {
return err
}
for i, container := range deployment.Spec.Template.Spec.Containers {
if container.Name == "dns-operator" {
deployment.Spec.Template.Spec.Containers[i].Image = repo + operatorImage + ":" + version
for j, env := range container.Env {
if env.Name == "IMAGE" {
deployment.Spec.Template.Spec.Containers[i].Env[j].Value = repo + openShiftCoreDNSImage + ":" + version
}
}
status.QueueSuccessMessage("Updated DNS operator deployment")
}
status.QueueSuccessMessage("Updated DNS operator deployment")
}
}
_, err = deployments.Update(deployment)
if err != nil {
_, err = deployments.Update(deployment)
return err
})
if retryErr != nil {
return fmt.Errorf("Error updating dns-operator deployment: %v", retryErr)
}

// Scale DNS operator down and back up
Expand Down

0 comments on commit d5dd0f7

Please sign in to comment.