Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new validator when adding bd (backport #155) #156

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
webhook: should also consider the old Spec.Filesystem.Provisioned
   - sync the `Spec.Provision` and `Spec.Filesystem.Provisioned`

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
(cherry picked from commit e2ebe73)
Vicente-Cheng authored and mergify[bot] committed Oct 17, 2024
commit fd263ad6b83d61974340d293cf0e2ce762fd1783
1 change: 0 additions & 1 deletion pkg/controller/blockdevice/controller.go
Original file line number Diff line number Diff line change
@@ -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,
}
3 changes: 3 additions & 0 deletions pkg/provisioner/longhornv1.go
Original file line number Diff line number Diff line change
@@ -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)
@@ -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)
}
2 changes: 1 addition & 1 deletion pkg/webhook/blockdevice/mutator.go
Original file line number Diff line number Diff line change
@@ -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,