Skip to content

Commit

Permalink
webhook: should also consider the old Spec.Filesystem.Provisioned
Browse files Browse the repository at this point in the history
   - sync the `Spec.Provision` and `Spec.Filesystem.Provisioned`

Signed-off-by: Vicente Cheng <[email protected]>
  • Loading branch information
Vicente-Cheng committed Oct 17, 2024
1 parent a835deb commit e2ebe73
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 2 deletions.
1 change: 0 additions & 1 deletion pkg/controller/blockdevice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ func (c *Controller) generateProvisioner(device *diskv1.BlockDevice) (provisione
// upgrade case, we need to update some fields
if device.Spec.Provisioner == nil && device.Status.ProvisionPhase == diskv1.ProvisionPhaseProvisioned {
device.Spec.Provision = true
device.Spec.FileSystem.Provisioned = false
provisionerLHV1 := &diskv1.LonghornProvisionerInfo{
EngineVersion: provisioner.TypeLonghornV1,
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/provisioner/longhornv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ func (p *LonghornV1Provisioner) Provision() (bool, error) {
}

if (synced && !diskv1.DiskAddedToNode.IsTrue(p.device)) || provisioned {
// mark `filesystem.provisioned` to true, that the mutator could work
p.device.Spec.FileSystem.Provisioned = true
logrus.Debugf("Set blockdevice CRD (%v) to provisioned", p.device)
msg := fmt.Sprintf("Added disk %s to longhorn node `%s` as an additional disk", p.device.Name, p.nodeObj.Name)
setCondDiskAddedToNodeTrue(p.device, msg, diskv1.ProvisionPhaseProvisioned)
Expand All @@ -111,6 +113,7 @@ func (p *LonghornV1Provisioner) UnProvision() (bool, error) {

// inner functions
updateProvisionPhaseUnprovisioned := func() {
p.device.Spec.FileSystem.Provisioned = false
msg := fmt.Sprintf("Disk not in longhorn node `%s`", p.nodeObj.Name)
setCondDiskAddedToNodeFalse(p.device, msg, diskv1.ProvisionPhaseUnprovisioned)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/webhook/blockdevice/mutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (m *Mutator) Update(req *admission.Request, oldObj, newObj runtime.Object)
return patchOps, nil
}
// means we need to disable, align the .spec.filesystem.provisioned with .spec.provision -> false
if prevProvision && !newBd.Spec.FileSystem.Provisioned {
if prevProvision && !newBd.Spec.FileSystem.Provisioned && oldBd.Spec.FileSystem.Provisioned {
if newBd.Spec.Provision {
patchProvision := admission.PatchOp{
Op: admission.PatchOpReplace,
Expand Down

0 comments on commit e2ebe73

Please sign in to comment.