Skip to content

Commit

Permalink
Added new Instance.Spec.PlanExecution.UID field
Browse files Browse the repository at this point in the history
so that when the same plan is re-triggered a new UID is generated and the controller can restart the plan.

Signed-off-by: Aleksey Dukhovniy <alex.dukhovniy@googlemail.com>
  • Loading branch information
zen-dog committed Feb 21, 2020
1 parent 7af05a3 commit a441ee6
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 53 deletions.
9 changes: 8 additions & 1 deletion config/crds/kudo.dev_instances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,17 @@ spec:
for canceling and overriding currently running plans in the future.
Note: PlanExecution field defines plan name and corresponding parameters
that IS CURRENTLY executed. Once the instance controller (IC) is done
with the execution, this field will be cleared.'
with the execution, this field will be cleared. Each plan execution
has a unique UID so even if'
properties:
planName:
type: string
uid:
description: UID is a type that holds unique ID values, including
UUIDs. Because we don't ONLY use UUIDs, this is an alias to string. Being
a type captures intent and helps make sure that UIDs and names
do not get conflated.
type: string
type: object
type: object
status:
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/kudo/v1beta1/instance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ type InstanceSpec struct {
// currently running plans in the future.
// Note: PlanExecution field defines plan name and corresponding parameters that IS CURRENTLY executed.
// Once the instance controller (IC) is done with the execution, this field will be cleared.
// Each plan execution has a unique UID so even if
type PlanExecution struct {
PlanName string `json:"planName,omitempty"`
PlanName string `json:"planName,omitempty"`
UID apimachinerytypes.UID `json:"uid,omitempty"`

// Future PE options like Force: bool. Not needed for now
}
Expand Down
31 changes: 3 additions & 28 deletions pkg/controller/instance/instance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"reflect"
"time"

"k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/client-go/discovery"
"k8s.io/client-go/rest"

Expand Down Expand Up @@ -445,33 +444,9 @@ func startPlanExecution(i *v1beta1.Instance, planName string, ov *v1beta1.Operat
ensurePlanStatusInitialized(i, ov)
}

// update status of the instance to reflect the newly starting plan
notFound := true
for planIndex, v := range i.Status.PlanStatus {
if v.Name == planName {
// update plan status
notFound = false
planStatus := i.Status.PlanStatus[planIndex]
planStatus.Set(v1beta1.ExecutionPending)
planStatus.UID = uuid.NewUUID()
for j, p := range v.Phases {
planStatus.Phases[j].Set(v1beta1.ExecutionPending)
for k := range p.Steps {
i.Status.PlanStatus[planIndex].Phases[j].Steps[k].Set(v1beta1.ExecutionPending)
}
}

i.Status.PlanStatus[planIndex] = planStatus // we cannot modify item in map, we need to reassign here

// update activePlan and instance status
i.Status.AggregatedStatus.Status = v1beta1.ExecutionPending
i.Status.AggregatedStatus.ActivePlanName = planName

break
}
}
if notFound {
return &v1beta1.InstanceError{Err: fmt.Errorf("asked to execute a plan %s but no such plan found in instance %s/%s", planName, i.Namespace, i.Name), EventName: kudo.String("PlanNotFound")}
// reset newly starting plan status
if err := i.ResetPlanStatus(planName); err != nil {
return &v1beta1.InstanceError{Err: fmt.Errorf("failed to reset plan status for instance %s/%s: %v", i.Namespace, i.Name, err), EventName: kudo.String("PlanNotFound")}
}

err := saveSnapshot(i)
Expand Down
Loading

0 comments on commit a441ee6

Please sign in to comment.