fix: loop on conflict
It is expected that the loop will resolve quickly. The most
likely reason for it is that the service is bound/unbound
concurrently. In that case the loop breaks at the recheck for
service un/bound.
@@ -13,6 +13,7 @@ import (
"github.com/suse/carrier/kubernetes"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
+ apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
@@ -66,6 +67,7 @@ func (a *Application) Services() (interfaces.ServiceList, error) {
// Unbind dissolves the binding of the service to the application.
func (a *Application) Unbind(service interfaces.Service) error {
+ for {
deployment, err := a.deployment()
if err != nil {
return err
@@ -108,10 +110,16 @@ func (a *Application) Unbind(service interfaces.Service) error {
deployment,
metav1.UpdateOptions{},
)
- if err != nil {
+ if err == nil {
+ break
+ }
+ if !apierrors.IsConflict(err) {
return err
}
+ // Found a conflict. Try again from the beginning.
+ }
+
// delete binding - DeleteBinding(a.Name)
return service.DeleteBinding(a.Name)
}
@@ -131,6 +139,7 @@ func (a *Application) Bind(service interfaces.Service) error {
return err
}
+ for {
deployment, err := a.deployment()
if err != nil {
return err
@@ -168,9 +177,17 @@ func (a *Application) Bind(service interfaces.Service) error {
deployment,
metav1.UpdateOptions{},
)
+
+ if err == nil || !apierrors.IsConflict(err) {
return err
}
+ // Found a conflict. Try again from the beginning.
+ }
+
+ // Not reachable
+}
+
// Lookup locates an Application by org and name
func Lookup(
kubeClient *kubernetes.Cluster,
