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 webhook #151

Merged
merged 7 commits into from
Oct 11, 2024
Merged

Add webhook #151

merged 7 commits into from
Oct 11, 2024

Conversation

Vicente-Cheng
Copy link
Collaborator

@Vicente-Cheng Vicente-Cheng commented Oct 6, 2024

Problem:
We need webhook to check and patch the blockdevice CR.

Solution:
Add webhook

Related Issue:

Test plan:

    - Also, we make two jobs can run parallel

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
@Vicente-Cheng Vicente-Cheng force-pushed the add-webhook branch 9 times, most recently from c969da7 to f9b653d Compare October 7, 2024 14:45
Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
@Vicente-Cheng Vicente-Cheng requested review from tserong and bk201 October 7, 2024 23:32
@Vicente-Cheng Vicente-Cheng marked this pull request as ready for review October 7, 2024 23:32
@Vicente-Cheng
Copy link
Collaborator Author

Vicente-Cheng commented Oct 7, 2024

Hi @tserong, @bk201

Please review this PR. I use the new CI implementation (from PR: #150)
to verify both upgrade/fresh installation scenarios. (If we merge this PR, we could close the above PR)

Also, we need this PR harvester/webhook#7 so I can update the vendor again.
(Now, I replace webhook lib with my local repo)

Done

Please review the main logic about webhook and drop spec.filesystem.provisioned.
Thanks!

cmd/node-disk-manager-webhook/main.go Outdated Show resolved Hide resolved
package/Dockerfile.webhook Outdated Show resolved Hide resolved
pkg/webhook/blockdevice/mutator.go Outdated Show resolved Hide resolved
@Vicente-Cheng Vicente-Cheng requested a review from bk201 October 8, 2024 03:16
@Vicente-Cheng Vicente-Cheng force-pushed the add-webhook branch 2 times, most recently from 55b212e to fa4393c Compare October 8, 2024 04:18
Copy link
Contributor

@tserong tserong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a couple of questions :-)

pkg/webhook/blockdevice/mutator.go Outdated Show resolved Hide resolved
Path: "/spec/provision",
Value: false,
}
patchOps = append(patchOps, patchProvision)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should there also be a patch op here to explicitly remove Spec.FileSystem.Provisioned?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it seems the admission mutate cannot update the deprecated part.
The controller now only checks the spec.provision, so we ignore this.

// 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ISTM that by setting Spec.Filesystem.Provisioned = false here, the mutator (which I assume runs later when the BD is subsequently updated?) will hit the prevProvision && (!newBd.Spec.Provision || !newBd.Spec.Filesystem.Provisioned) case, and will then go and patch in Spec.Provision = false, thus unprovisioning the device.

Or am I misunderstanding the order of events?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this might happen. So, the mutator will ignore the changes from the controller.
You can see we have the precheck as below:

        if req.IsFromController() {
		return nil, nil
	}

After that, we could avoid the case you mentioned.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Thank you, I had missed that detail.

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
    - Now we only check the `spec.provision`

Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
Signed-off-by: Vicente Cheng <vicente.cheng@suse.com>
@Vicente-Cheng Vicente-Cheng merged commit cbd3cfa into harvester:master Oct 11, 2024
7 checks passed
@Vicente-Cheng
Copy link
Collaborator Author

@Mergifyio backport v0.7.x

Copy link

mergify bot commented Oct 11, 2024

backport v0.7.x

✅ Backports have been created

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants