Skip to content

Commit

Permalink
Add Version field to ETCDSnapshotRestoreSpec
Browse files Browse the repository at this point in the history
Signed-off-by: Vatsal Parekh <[email protected]>
  • Loading branch information
vatsalparekh committed Dec 18, 2024
1 parent 5662135 commit 7f5c6f5
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ spec:
type: string
machineName:
type: string
version:
type: string
required:
- clusterName
type: object
Expand Down
1 change: 1 addition & 0 deletions exp/etcdrestore/api/v1alpha1/etcdmachinesnapshot_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type ETCDMachineSnapshotSpec struct {
ClusterName string `json:"clusterName"`
MachineName string `json:"machineName,omitempty"`
Location string `json:"location,omitempty"`
Version string `json:"version,omitempty"`
}

// EtcdSnapshotRestoreStatus defines observed state of EtcdSnapshotRestore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
type: string
machineName:
type: string
version:
type: string
required:
- clusterName
type: object
Expand Down
20 changes: 16 additions & 4 deletions exp/etcdrestore/controllers/etcdmachinesnapshot_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type snapshotScope struct {

// snapshot is the snapshot object which is used for reconcile
snapshot *snapshotrestorev1.ETCDMachineSnapshot

// controlPlaneVersion is lowest found kubernetes version among the Control plane machines
controlPlaneVersion *string
}

// SetupWithManager sets up the controller with the Manager.
Expand Down Expand Up @@ -144,6 +147,10 @@ func (r *ETCDMachineSnapshotReconciler) newScope(ctx context.Context, etcdMachin
}

controlPlaneMachines := machines.Filter(collections.ControlPlaneMachines(cluster.Name))
if len(controlPlaneMachines) == 0 {
return nil, fmt.Errorf("no control plane machines found for cluster: %s", cluster.Name)
}

targetMachineCandidates := controlPlaneMachines.Filter(func(machine *clusterv1.Machine) bool {
return machine.Name == etcdMachineSnapshot.Spec.MachineName
}).UnsortedList()
Expand All @@ -156,10 +163,11 @@ func (r *ETCDMachineSnapshotReconciler) newScope(ctx context.Context, etcdMachin
}

return &snapshotScope{
cluster: cluster,
machines: controlPlaneMachines,
machine: targetMachineCandidates[0],
snapshot: etcdMachineSnapshot,
cluster: cluster,
machines: controlPlaneMachines,
machine: targetMachineCandidates[0],
snapshot: etcdMachineSnapshot,
controlPlaneVersion: controlPlaneMachines.LowestVersion(),
}, nil
}

Expand Down Expand Up @@ -190,6 +198,10 @@ func (r *ETCDMachineSnapshotReconciler) reconcileNormal(
// Initial phase, set to Pending
etcdMachineSnapshot.Status.Phase = snapshotrestorev1.ETCDSnapshotPhasePending

// Set the Version field as k8s version of the cluster
fmt.Printf("\nsetting control-plane version as: %v\n", *scope.controlPlaneVersion)
etcdMachineSnapshot.Spec.Version = *scope.controlPlaneVersion

return ctrl.Result{}, nil
case snapshotrestorev1.ETCDSnapshotPhasePending, snapshotrestorev1.ETCDSnapshotPhasePlanning:
// Transition to Running
Expand Down

0 comments on commit 7f5c6f5

Please sign in to comment.