Skip to content

feat: add unified admission webhook for Group validation - #261

Open
sunando94 wants to merge 1 commit into
redhat-data-and-ai:mainfrom
sunando94:feat/unified-admission-webhook
Open

feat: add unified admission webhook for Group validation#261
sunando94 wants to merge 1 commit into
redhat-data-and-ai:mainfrom
sunando94:feat/unified-admission-webhook

Conversation

@sunando94

Copy link
Copy Markdown
Collaborator
  • Register validating webhook and TLS in manager
  • Add Group webhook handlers and tests
  • Add cert-manager, webhook service, and kustomize patches
  • Extend RBAC and vendor deps for webhook/testing

Changes

📝 Description

What changed?

  • Register validating webhook and TLS in manager
  • Add Group webhook handlers and tests
  • Add cert-manager, webhook service, and kustomize patches
  • Extend RBAC and vendor deps for webhook/testing

Why is this change needed?

Admission hooks are needed.

Dependencies

  • N/A

🧪 Testing

Test Coverage

Performance Impact

  • N/A

🚀 Deployment

Deploy Steps

  1. N/A

Prerequisites

  • N/A

Post-Deployment Monitoring

  • N/A

Rollback Plan

  • N/A

⚠️ Breaking Changes

  • This PR contains breaking changes
  • Migration guide provided (if applicable)

Details:

  • N/A

⚙️ Configuration Changes

  • N/A

✅ Developer Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have added positive and negative tests that prove my fix is effective or that my feature works
  • Relevant documentation (README, tech specs, etc.) has been added or updated
  • All CI/CD checks are passing

- Register validating webhook and TLS in manager
- Add Group webhook handlers and tests
- Add cert-manager, webhook service, and kustomize patches
- Extend RBAC and vendor deps for webhook/testing

Signed-off-by: Sunando Bhattacharya <subhatta@redhat.com>
@gemini-code-assist

Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a robust admission webhook mechanism for the operator. By implementing a unified validator, the system can now perform cross-resource validation, specifically ensuring that critical dependencies like ServiceAccounts are present when certain backend configurations are requested. The changes include the necessary infrastructure for secure communication via cert-manager and provide a flexible configuration to toggle webhook functionality.

Highlights

  • Unified Admission Webhook: Implemented a unified validating webhook framework to handle resource validation, including logic to decode runtime.Unknown objects and delegate to resource-specific handlers.
  • Group Validation Logic: Added validation for the Group resource to ensure that if a 'rover' backend type is present, the required 'usernaut-prod' ServiceAccount exists in the watched namespace.
  • Infrastructure and Configuration: Configured cert-manager for TLS, added the necessary Kubernetes Service and ValidatingWebhookConfiguration, and updated Kustomize manifests to support webhook deployment.
  • Manager Integration: Updated cmd/main.go to support enabling/disabling the webhook server via flags or environment variables and registered the unified webhook with the manager.
Ignored Files
  • Ignored by pattern: vendor/** (21)
    • vendor/k8s.io/api/imagepolicy/v1alpha1/doc.go
    • vendor/k8s.io/api/imagepolicy/v1alpha1/generated.pb.go
    • vendor/k8s.io/api/imagepolicy/v1alpha1/generated.proto
    • vendor/k8s.io/api/imagepolicy/v1alpha1/register.go
    • vendor/k8s.io/api/imagepolicy/v1alpha1/types.go
    • vendor/k8s.io/api/imagepolicy/v1alpha1/types_swagger_doc_generated.go
    • vendor/k8s.io/api/imagepolicy/v1alpha1/zz_generated.deepcopy.go
    • vendor/k8s.io/apimachinery/pkg/util/rand/rand.go
    • vendor/k8s.io/client-go/applyconfigurations/OWNERS
    • vendor/k8s.io/client-go/applyconfigurations/doc.go
    • vendor/k8s.io/client-go/applyconfigurations/imagepolicy/v1alpha1/imagereview.go
    • vendor/k8s.io/client-go/applyconfigurations/imagepolicy/v1alpha1/imagereviewcontainerspec.go
    • vendor/k8s.io/client-go/applyconfigurations/imagepolicy/v1alpha1/imagereviewspec.go
    • vendor/k8s.io/client-go/applyconfigurations/imagepolicy/v1alpha1/imagereviewstatus.go
    • vendor/k8s.io/client-go/applyconfigurations/utils.go
    • vendor/modules.txt
    • vendor/sigs.k8s.io/controller-runtime/pkg/client/fake/client.go
    • vendor/sigs.k8s.io/controller-runtime/pkg/client/fake/doc.go
    • vendor/sigs.k8s.io/controller-runtime/pkg/client/fake/typeconverter.go
    • vendor/sigs.k8s.io/controller-runtime/pkg/client/interceptor/intercept.go
    • vendor/sigs.k8s.io/controller-runtime/pkg/internal/objectutil/objectutil.go
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


The webhook waits for groups to change, To check the backends in their range. If 'rover' type is found in sight, It checks the SA to keep things right.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a validating admission webhook for the Group resource to ensure that any backend of type rover has a corresponding usernaut-prod ServiceAccount in the watched namespace. It implements a unified webhook architecture that decodes raw API requests and delegates validation to specific resource types. Feedback includes suggestions to improve the decoding safety by providing GVK, centralizing the watched namespace logic to avoid duplication, refining error messages for better troubleshooting, and using named interfaces to enhance code maintainability.

}

gvk := obj.GetObjectKind().GroupVersionKind()
decoded, _, err := v.Decoder.Decode(unknown.Raw, nil, nil)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

When decoding a runtime.Unknown object, it is generally safer to provide the expected GroupVersionKind if it is known from the admission request, rather than passing nil as the second argument to Decode.

Comment on lines +39 to +44
func getWatchedNamespace() string {
if ns := os.Getenv("WATCHED_NAMESPACE"); ns != "" {
return ns
}
return defaultNamespace
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

low

The logic to determine the watched namespace is duplicated here and in cmd/main.go. Consider centralizing this in a utility package or passing the namespace as a configuration parameter to the webhook handler to ensure consistency across the application.


c := ClientFromContext(ctx)
if c == nil {
return fmt.Errorf("internal error: webhook client not available")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

low

The error message 'internal error: webhook client not available' is somewhat generic for an end-user. Consider a more descriptive message such as 'failed to retrieve Kubernetes client from context' to aid in troubleshooting if the context injection fails.

Suggested change
return fmt.Errorf("internal error: webhook client not available")
return fmt.Errorf("failed to retrieve Kubernetes client from context")

Comment on lines +111 to +113
if validator, ok := obj.(interface {
ValidateCreate(ctx context.Context) (admission.Warnings, error)
}); ok {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

low

The anonymous interface for ValidateCreate is repeated for ValidateUpdate and ValidateDelete. Defining a named interface (e.g., ResourceValidator) would improve code readability and maintainability.

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.

1 participant