Skip to content

Commit

Permalink
Merge pull request #11 from enxebre/implement-update
Browse files Browse the repository at this point in the history
Implement update
  • Loading branch information
openshift-merge-robot committed May 10, 2019
2 parents 19f1046 + 4ae01d0 commit 6aa44e6
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
24 changes: 19 additions & 5 deletions pkg/cloud/gcp/actuators/machine/actuator.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package machine

// This is a thin layer to implement the machine actuator interface with cloud provider details.
// The lifetime of scope and reconciler is a machine actuator operation.
// when scope is closed, it will persist to etcd the given machine spec and machine status (if modified)
import (
"context"
"fmt"
Expand Down Expand Up @@ -42,8 +45,6 @@ func (a *Actuator) Create(ctx context.Context, cluster *clusterv1.Cluster, machi
if err != nil {
return fmt.Errorf("failed to create scope for machine %q: %v", machine.Name, err)
}
// scope and reconciler lifetime is a machine actuator operation
// when scope is closed, it will persist to etcd the given machine spec and machine status (if modified)
defer scope.Close()
return newReconciler(scope).create()
}
Expand All @@ -58,13 +59,26 @@ func (a *Actuator) Exists(ctx context.Context, cluster *clusterv1.Cluster, machi
if err != nil {
return false, fmt.Errorf("failed to create scope for machine %q: %v", machine.Name, err)
}
defer scope.Close()
// The core machine controller calls exists() + create()/update() in the same reconciling operation.
// If exists() would store machineSpec/status object then create()/update() would still receive the local version.
// When create()/update() try to store machineSpec/status this might result in
// "Operation cannot be fulfilled; the object has been modified; please apply your changes to the latest version and try again."
// Therefore we don't close the scope here and we only store spec/status atomically either in create()/update()"
return newReconciler(scope).exists()
}

func (a *Actuator) Update(ctx context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error {
// TODO(alberto): implement this
return nil
klog.Infof("Updating machine %q", machine.Name)
scope, err := newMachineScope(machineScopeParams{
machineClient: a.machineClient,
coreClient: a.coreClient,
machine: machine,
})
if err != nil {
return fmt.Errorf("failed to create scope for machine %q: %v", machine.Name, err)
}
defer scope.Close()
return newReconciler(scope).update()
}

func (a *Actuator) Delete(ctx context.Context, cluster *clusterv1.Cluster, machine *machinev1.Machine) error {
Expand Down
2 changes: 2 additions & 0 deletions pkg/cloud/gcp/actuators/machine/machine_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func (s *machineScope) storeMachineSpec(machine *machinev1.Machine) (*machinev1.
return nil, err
}

klog.V(4).Infof("Storing machine spec for %q, resourceVersion: %v, generation: %v", s.machine.Name, s.machine.ResourceVersion, s.machine.Generation)
machine.Spec.ProviderSpec.Value = ext
return s.machineClient.Update(machine)
}
Expand All @@ -125,6 +126,7 @@ func (s *machineScope) storeMachineStatus(machine *machinev1.Machine) (*machinev
return nil, err
}

klog.V(4).Infof("Storing machine status for %q, resourceVersion: %v, generation: %v", s.machine.Name, s.machine.ResourceVersion, s.machine.Generation)
s.machine.Status.DeepCopyInto(&machine.Status)
machine.Status.ProviderStatus = ext
return s.machineClient.UpdateStatus(machine)
Expand Down
4 changes: 4 additions & 0 deletions pkg/cloud/gcp/actuators/machine/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ func (r *Reconciler) create() error {
return nil
}

func (r *Reconciler) update() error {
return r.reconcileMachineWithCloudState()
}

func (r *Reconciler) reconcileMachineWithCloudState() error {
klog.Infof("Reconciling machine object %q with cloud state", r.machine.Name)
freshInstance, err := r.computeService.InstancesGet(r.projectID, r.providerSpec.Zone, r.machine.Name)
Expand Down

0 comments on commit 6aa44e6

Please sign in to comment.