Skip to content

Conversation

@adity1raut
Copy link
Contributor

What type of PR is this?

/kind testing

What this PR does / why we need it:
This PR adds unit tests for the cert package to validate certificate generation,
Kubernetes Secret handling, and admission webhook CA bundle updates.
The tests use the client-go fake client to ensure correctness without requiring
a live Kubernetes cluster.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

  • This PR adds tests only; no production code is modified.
  • Covers both secret creation and reuse scenarios.
  • Ensures CA bundles are set only when missing in webhook configurations.

Does this PR introduce a user-facing change?:
NONE

Copilot AI review requested due to automatic review settings January 8, 2026 14:50
@volcano-sh-bot
Copy link
Contributor

@adity1raut: The label(s) kind/testing cannot be applied, because the repository doesn't have them.

Details

In response to this:

What type of PR is this?

/kind testing

What this PR does / why we need it:
This PR adds unit tests for the cert package to validate certificate generation,
Kubernetes Secret handling, and admission webhook CA bundle updates.
The tests use the client-go fake client to ensure correctness without requiring
a live Kubernetes cluster.

Which issue(s) this PR fixes:
Fixes #

Special notes for your reviewer:

  • This PR adds tests only; no production code is modified.
  • Covers both secret creation and reuse scenarios.
  • Ensures CA bundles are set only when missing in webhook configurations.

Does this PR introduce a user-facing change?:
NONE

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@volcano-sh-bot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign hzxuzhonghu for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@volcano-sh-bot
Copy link
Contributor

Welcome @adity1raut! It looks like this is your first PR to volcano-sh/kthena 🎉

@gemini-code-assist
Copy link

Summary of Changes

Hello @adity1raut, 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 significantly enhances the test coverage for the cert package by introducing a suite of unit tests. These tests validate the end-to-end process of certificate management, including their generation, secure storage within Kubernetes Secrets, and the crucial updates of CA bundles in both Validating and Mutating Admission Webhook configurations. The primary goal is to ensure the reliability and correctness of these security-sensitive operations.

Highlights

  • New Unit Tests Added: This pull request introduces a new test file, pkg/webhook/cert/secret_test.go, dedicated to unit testing the certificate and webhook CA bundle handling logic.
  • Comprehensive Certificate Handling Tests: The new tests cover various scenarios for EnsureCertificate, including the creation of new Kubernetes Secrets for certificates and the reuse of existing secrets.
  • Admission Webhook CA Bundle Update Tests: Unit tests are added for UpdateValidatingWebhookCABundle and UpdateMutatingWebhookCABundle functions, ensuring that CA bundles are correctly updated in webhook configurations, specifically when they are initially missing.
  • Secret Bundle Loading Test: A test for LoadCertBundleFromSecret is included to verify the correct loading of certificate, key, and CA bundles from a Kubernetes Secret.
  • Fake Client Usage: All tests utilize k8s.io/client-go/kubernetes/fake to simulate Kubernetes API interactions, allowing for robust testing without requiring a live cluster.
  • No Production Code Changes: This PR is purely for testing purposes and does not introduce any modifications to the existing production codebase.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link

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

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 adds unit tests for the cert package, which is a great step towards improving code quality and reliability. The tests cover certificate generation, secret creation/reuse, and webhook CA bundle updates using a fake client.

My review focuses on improving the robustness and completeness of these new tests. I've identified a few areas for improvement:

  • There's a recurring pattern of ignoring errors during the setup phase of the tests. Handling these errors would make the tests more reliable and easier to debug.
  • The tests for updating webhook configurations (ValidatingWebhookConfiguration and MutatingWebhookConfiguration) currently only check if the update function returns an error. They should be extended to verify that the CA bundle is actually written to the webhook objects. I've also suggested adding test cases for scenarios where the CA bundle is already present to ensure the update is correctly skipped.

Overall, this is a valuable contribution. Addressing these points will make the tests even more effective.

@adity1raut
Copy link
Contributor Author

/cc @hzxuzhonghu

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds unit tests for the cert package to validate certificate generation, Kubernetes Secret handling, and admission webhook CA bundle updates. The tests use client-go's fake client to test the functionality without requiring a live Kubernetes cluster.

Key changes:

  • Adds comprehensive unit tests for certificate and webhook operations
  • Tests both happy path scenarios (secret creation, reuse, webhook updates)
  • Uses fake Kubernetes client for isolated testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 103 to 107

err := UpdateValidatingWebhookCABundle(ctx, client, "test-validating", []byte("ca"))
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

The test doesn't verify that the CA bundle was actually set on the webhook configuration after the update. Consider adding an assertion to get the updated webhook configuration and verify that the CABundle field is correctly set to the expected value.

Copilot uses AI. Check for mistakes.
Comment on lines 127 to 129
mwc := &admissionv1.MutatingWebhookConfiguration{
ObjectMeta: metav1.ObjectMeta{
Name: "test-mutating",
Copy link

Copilot AI Jan 8, 2026

Choose a reason for hiding this comment

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

Error from webhook configuration creation is being ignored. While this may succeed in the test, it's better to check the error to ensure the test setup is correct and to catch any unexpected issues during test execution.

Copilot uses AI. Check for mistakes.
@adity1raut
Copy link
Contributor Author

@hzxuzhonghu PTAL Thanks You

Copy link
Member

@hzxuzhonghu hzxuzhonghu left a comment

Choose a reason for hiding this comment

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

YOu can first try to understand the EnsureCertificate, we designed it for multi servers operate concurrently to make sure all instances share same certs. you can test this meaningful case.

Copilot AI review requested due to automatic review settings January 12, 2026 14:01
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@hzxuzhonghu
Copy link
Member

/assign @git-malu

@adity1raut
Copy link
Contributor Author

/assign @hzxuzhonghu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants