Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#273 from wking/exists-describe-eve…
Browse files Browse the repository at this point in the history
…ntual-consistency

Bug 1761882: pkg/actuators/machine: Eventual-consistency guards for Exists/Describe
  • Loading branch information
openshift-merge-robot authored Nov 25, 2019
2 parents ce4e6b6 + 16d9c18 commit 87c20ae
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions pkg/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,21 +490,8 @@ func (a *Actuator) Update(context context.Context, cluster *clusterv1.Cluster, m
// Exists determines if the given machine currently exists.
// A machine which is not terminated is considered as existing.
func (a *Actuator) Exists(context context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) (bool, error) {
glog.Infof("%s: Checking if machine exists", machine.Name)

instances, err := a.getMachineInstances(cluster, machine)
if err != nil {
glog.Errorf("%s: Error getting existing instances: %v", machine.Name, err)
return false, err
}
if len(instances) == 0 {
glog.Infof("%s: Instance does not exist", machine.Name)
return false, nil
}

// If more than one result was returned, it will be handled in Update.
glog.Infof("%s: Instance exists as %q", machine.Name, *instances[0].InstanceId)
return true, nil
instance, err := a.Describe(cluster, machine)
return instance != nil, err
}

// Describe provides information about machine's instance(s)
Expand All @@ -513,10 +500,15 @@ func (a *Actuator) Describe(cluster *clusterv1.Cluster, machine *machinev1.Machi

instances, err := a.getMachineInstances(cluster, machine)
if err != nil {
glog.Errorf("%s: Error getting running instances: %v", machine.Name, err)
glog.Errorf("%s: Error getting existing instances: %v", machine.Name, err)
return nil, err
}
if len(instances) == 0 {
if machine.Spec.ProviderID != nil && (machine.Status.LastUpdated == nil || machine.Status.LastUpdated.Add(requeueAfterSeconds*time.Second).After(time.Now())) {
glog.Infof("%s: Possible eventual-consistency discrepancy; returning an error to requeue", machine.Name)
return nil, &clustererror.RequeueAfterError{RequeueAfter: requeueAfterSeconds * time.Second}
}

glog.Infof("%s: Instance does not exist", machine.Name)
return nil, nil
}
Expand Down

0 comments on commit 87c20ae

Please sign in to comment.