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

feat: initialize admission webhook #234

Merged
merged 6 commits into from
Dec 17, 2024

Conversation

daviderli614
Copy link
Member

@daviderli614 daviderli614 commented Dec 16, 2024

related issue: #153
related docs: https://kubebuilder.io/cronjob-tutorial/webhook-implementation

Summary by CodeRabbit

  • New Features

    • Introduced webhook configurations for GreptimeDBCluster and GreptimeDBStandalone resources, enabling validation.
    • Added webhooks for handling create, update, and delete operations for both resources.
  • Bug Fixes

    • Updated resource path for GreptimeDBStandalone for consistency.
  • Documentation

    • Enhanced deepcopy methods for various data structures to improve robustness.

Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request introduces webhook configurations for GreptimeDBCluster and GreptimeDBStandalone resources in the GreptimeDB Operator. The project configuration file has been updated to enable validation webhooks with version v1, and the resource path has been modified from github.com/greptime/greptimedb-operator to github.com/GreptimeTeam/greptimedb-operator. Two new webhook files have been added to implement basic validation methods for create, update, and delete operations, currently serving as scaffolding for future validation logic.

Changes

File Change Summary
project configuration - Updated resource path from greptime to GreptimeTeam
- Added webhook configurations for GreptimeDBCluster and GreptimeDBStandalone
apis/v1alpha1/greptimedbcluster_webhook.go - Added webhook setup method
- Implemented placeholder validation methods for create, update, and delete operations
apis/v1alpha1/greptimedbstandalone_webhook.go - Added webhook setup method
- Implemented placeholder validation methods for create, update, and delete operations
apis/v1alpha1/zz_generated.deepcopy.go - Updated runtime import
- Generated deepcopy methods for multiple structs

Sequence Diagram

sequenceDiagram
    participant Webhook as Admission Webhook
    participant Cluster as GreptimeDBCluster/Standalone
    participant Manager as Controller Manager

    Cluster ->> Webhook: Create/Update/Delete Request
    Webhook ->> Webhook: Validate Request
    alt Validation Passes
        Webhook -->> Manager: Allow Operation
    else Validation Fails
        Webhook -->> Manager: Deny Operation
    end
Loading

Possibly related PRs

Suggested reviewers

  • zyy17

Poem

🐰 Webhooks hopping, validation leaping,
Through clusters and standalones creeping,
Config paths shifted with grace,
A rabbit's dance in Kubernetes space,
Deepcopy methods softly weeping! 🌈


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7282fc4 and 66c1719.

⛔ Files ignored due to path filters (8)
  • config/certmanager/certificate.yaml is excluded by !config/**
  • config/certmanager/kustomization.yaml is excluded by !config/**
  • config/certmanager/kustomizeconfig.yaml is excluded by !config/**
  • config/default/manager_webhook_patch.yaml is excluded by !config/**
  • config/default/webhookcainjection_patch.yaml is excluded by !config/**
  • config/webhook/kustomization.yaml is excluded by !config/**
  • config/webhook/kustomizeconfig.yaml is excluded by !config/**
  • config/webhook/service.yaml is excluded by !config/**
📒 Files selected for processing (1)
  • PROJECT (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • PROJECT

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (5)
tests/e2e/webhook_suite_test.go (3)

125-132: Specify an explicit timeout for Eventually to ensure consistent test duration

Currently, the Eventually block relies on the default timeout and polling interval. Specifying explicit values can help prevent flaky tests and ensure consistent behavior across different environments.

Apply this diff to set explicit timeout and interval:

     }).Should(Succeed())
+    }, "10s", "100ms").Should(Succeed())

Adjust the timeout ("10s") and polling interval ("100ms") as appropriate for your test environment.


64-67: Consider setting ErrorIfCRDPathMissing to true to catch missing CRDs

Setting ErrorIfCRDPathMissing to true helps detect missing or misconfigured CRD paths early in the test setup, preventing silent failures.

Apply this diff:

     testEnv = &envtest.Environment{
         CRDDirectoryPaths:     []string{filepath.Join("..", "..", "config", "crd", "resources")},
-        ErrorIfCRDPathMissing: false,
+        ErrorIfCRDPathMissing: true,
         WebhookInstallOptions: envtest.WebhookInstallOptions{

79-85: Remove unnecessary addition of admissionv1beta1 scheme

The admission v1beta1 API has been deprecated in favor of v1. Since you are using admissionReviewVersions=v1, adding admissionv1beta1 to the scheme may be unnecessary.

Apply this diff to remove the deprecated API:

     scheme := runtime.NewScheme()
     err = v1alpha1.AddToScheme(scheme)
     Expect(err).NotTo(HaveOccurred())

-    err = admissionv1beta1.AddToScheme(scheme)
-    Expect(err).NotTo(HaveOccurred())

     //+kubebuilder:scaffold:scheme
apis/v1alpha1/greptimedbcluster_webhook.go (1)

58-63: Consider enabling delete validation or removing the ValidateDelete method

The ValidateDelete method includes a TODO but the webhook is not registered for delete operations (verbs). If deletion validation is required, update the webhook configuration to include the delete verb. Otherwise, consider removing the unused method to keep the codebase clean.

Apply this diff to update the webhook configuration:

 //+kubebuilder:webhook:path=/validate-greptime-io-v1alpha1-greptimedbcluster,mutating=false,failurePolicy=fail,sideEffects=None,groups=greptime.io,resources=greptimedbclusters,verbs=create;update,versions=v1alpha1,name=vgreptimedbcluster.kb.io,admissionReviewVersions=v1
+// TODO: change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
apis/v1alpha1/greptimedbstandalone_webhook.go (1)

58-63: Decide on delete validation for the webhook

The ValidateDelete method includes a TODO comment, but the webhook does not handle delete operations due to the missing delete verb in the configuration. If delete validation is needed, update the webhook verbs accordingly. If not, consider removing the method.

Apply this diff to include delete validation:

 //+kubebuilder:webhook:path=/validate-greptime-io-v1alpha1-greptimedbstandalone,mutating=false,failurePolicy=fail,sideEffects=None,groups=greptime.io,resources=greptimedbstandalones,verbs=create;update,versions=v1alpha1,name=vgreptimedbstandalone.kb.io,admissionReviewVersions=v1
+// TODO: change verbs to "verbs=create;update;delete" if you want to enable deletion validation.
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e8a1e07 and 7282fc4.

⛔ Files ignored due to path filters (9)
  • config/certmanager/certificate.yaml is excluded by !config/**
  • config/certmanager/kustomization.yaml is excluded by !config/**
  • config/certmanager/kustomizeconfig.yaml is excluded by !config/**
  • config/default/manager_webhook_patch.yaml is excluded by !config/**
  • config/default/webhookcainjection_patch.yaml is excluded by !config/**
  • config/webhook/kustomization.yaml is excluded by !config/**
  • config/webhook/kustomizeconfig.yaml is excluded by !config/**
  • config/webhook/manifests.yaml is excluded by !config/**
  • config/webhook/service.yaml is excluded by !config/**
📒 Files selected for processing (5)
  • PROJECT (2 hunks)
  • apis/v1alpha1/greptimedbcluster_webhook.go (1 hunks)
  • apis/v1alpha1/greptimedbstandalone_webhook.go (1 hunks)
  • apis/v1alpha1/zz_generated.deepcopy.go (1 hunks)
  • tests/e2e/webhook_suite_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (2)
  • PROJECT
  • apis/v1alpha1/zz_generated.deepcopy.go
🔇 Additional comments (1)
tests/e2e/webhook_suite_test.go (1)

136-141: LGTM

The AfterSuite function correctly handles cleanup by canceling the context and stopping the test environment.

tests/e2e/webhook_suite_test.go Outdated Show resolved Hide resolved
apis/v1alpha1/greptimedbcluster_webhook.go Show resolved Hide resolved
apis/v1alpha1/greptimedbcluster_webhook.go Show resolved Hide resolved
apis/v1alpha1/greptimedbstandalone_webhook.go Show resolved Hide resolved
apis/v1alpha1/greptimedbstandalone_webhook.go Show resolved Hide resolved
@daviderli614 daviderli614 requested a review from zyy17 December 16, 2024 16:41
@daviderli614 daviderli614 marked this pull request as ready for review December 16, 2024 16:43
Copy link
Collaborator

@zyy17 zyy17 left a comment

Choose a reason for hiding this comment

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

mostly lgtm

PROJECT Outdated Show resolved Hide resolved
PROJECT Outdated Show resolved Hide resolved
@zyy17 zyy17 merged commit b735d9a into GreptimeTeam:main Dec 17, 2024
5 checks passed
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.

2 participants