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

fix(upgrade): Handle Mutated Images #3506

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Khalid-Nowaf
Copy link

Which issue(s) this PR fixes:

Issue longhorn/longhorn#9638

What this PR does / why we need it:

The upgrade has a bug that prevents it from supporting K8s webhook mutation (which is widely adaptable for security reasons), which could alter the image's name.

The new mutated image can not be known before deployment, so there is no way to configure the helm char to adapt it.

Longhorn is not deployable now using the helm in such cases. So we need this fix to make it compatible.

Special notes for your reviewer:

Additional documentation or context

https://github.com/zarf-dev/zarf/blob/main/adr/0005-mutating-webhook.md

Copy link

coderabbitai bot commented Jan 22, 2025

Walkthrough

The changes introduce a new variable runningPodVersion in the upgrade/upgrade.go file, which retrieves the version label from the pod's labels within the isOldManagerPod function. The logic for determining whether a pod is an old manager has been updated to check if the pod has a version label that does not match the image version. Additionally, a new test file upgrade_test.go has been created to validate the functionality of isOldManagerPod through various test cases.

Changes

File Change Summary
upgrade/upgrade.go - Introduced runningPodVersion variable to retrieve pod version label
- Modified isOldManagerPod logic for version comparison based on pod labels
- Imported strings package for string comparison
upgrade/upgrade_test.go - Added newDummyPod function to create test pods
- Implemented TestIsOldManagerPod with multiple test scenarios for validating old manager pod detection

Assessment against linked issues

Objective Addressed Explanation
Handle mutating webhook image modifications
Support version comparison with modified image tags
Prevent unnecessary upgrade checks Unclear if the implementation of the '--upgrade-version-check' flag is addressed.

Possibly related PRs

Suggested reviewers

  • c3y1huang
  • derekbit
  • mantissahz

📜 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 731735f and c5a808c.

📒 Files selected for processing (2)
  • upgrade/upgrade.go (2 hunks)
  • upgrade/upgrage_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • upgrade/upgrade.go
  • upgrade/upgrage_test.go
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary

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

@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: 3

🧹 Nitpick comments (2)
upgrade/upgrage_test.go (2)

11-22: Consider enhancing the helper function for better reusability.

While the current implementation works for these tests, consider making it more robust for potential reuse:

  • Add validation for input parameters
  • Consider adding options for setting other Pod fields
  • Add documentation explaining the purpose and limitations

Example enhancement:

+// newDummyPod creates a minimal Pod object for testing purposes.
+// It only sets the container name and image, other Pod fields are left as defaults.
 func newDummyPod(name string, image string) *corev1.Pod {
+	if name == "" || image == "" {
+		return nil
+	}
 	return &corev1.Pod{
+		ObjectMeta: metav1.ObjectMeta{
+			Name: name,
+		},
 		Spec: corev1.PodSpec{
 			Containers: []corev1.Container{
 				{

25-66: Add test cases for invalid inputs.

Consider adding test cases for:

  • Empty image strings
  • Malformed image references
  • Missing version tags

Example additional test cases:

{
    runningManagerImage: "",
    deployManagerImage:  "longhornio/longhorn-manager:v1.8.0",
    isOld:              false,
    expectError:        true,
},
{
    runningManagerImage: "longhornio/longhorn-manager",  // missing tag
    deployManagerImage:  "longhornio/longhorn-manager:v1.8.0",
    isOld:              false,
    expectError:        true,
},
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ca32967 and 6a283de.

📒 Files selected for processing (2)
  • upgrade/upgrade.go (2 hunks)
  • upgrade/upgrage_test.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (2)
upgrade/upgrage_test.go (2)

1-9: LGTM! Clean and minimal imports.

The package declaration and imports are appropriate for the test requirements.


24-67: Test cases effectively cover the mutation scenarios.

The test cases comprehensively cover various image mutation patterns, including:

  • Registry prefixed images
  • Version matches and upgrades
  • Non-semver scenarios

This aligns well with the PR objective of handling mutated images.

upgrade/upgrade.go Outdated Show resolved Hide resolved
upgrade/upgrade.go Outdated Show resolved Hide resolved
upgrade/upgrage_test.go Outdated Show resolved Hide resolved
@Khalid-Nowaf Khalid-Nowaf force-pushed the 9638-mutating_webhook_image_compatibility branch 4 times, most recently from d75d9ce to 731735f Compare January 23, 2025 00:04
@Khalid-Nowaf
Copy link
Author

@coderabbitai full review

Copy link

coderabbitai bot commented Jan 23, 2025

✅ Actions performed

Full review triggered.

@Khalid-Nowaf Khalid-Nowaf force-pushed the 9638-mutating_webhook_image_compatibility branch from 731735f to c5a808c Compare January 23, 2025 22:51
@Khalid-Nowaf
Copy link
Author

To test it, I have built a container Khalid/longhorn-manager:v1.8.0-patch1. Currently, it works with no issues.

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