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

ci: expose os and k8s version info in gke pipeline #2289

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

yangchiu
Copy link
Member

@yangchiu yangchiu commented Jan 23, 2025

Which issue(s) this PR fixes:

Issue longhorn/longhorn#10285

What this PR does / why we need it:

expose os and k8s version info in gke pipeline

Special notes for your reviewer:

Additional documentation or context

Summary by CodeRabbit

  • Tests

    • Updated Longhorn component readiness check in test suite to improve reliability and error reporting.
    • Enhanced test script to print cluster information and OS release details.
  • Chores

    • Updated GKE cluster minimum master version from 1.31.1 to 1.31.4.

@yangchiu yangchiu self-assigned this Jan 23, 2025
@yangchiu yangchiu requested a review from a team as a code owner January 23, 2025 06:46
Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

This pull request introduces modifications across three files: manager/integration/tests/common.py, pipelines/gke/scripts/longhorn-setup.sh, and pipelines/gke/terraform/main.tf. The changes include enhancing the Longhorn component readiness check in the test common utility, adding a function to print cluster and OS information in the GKE setup script, and updating the GKE cluster's minimum master version in the Terraform configuration.

Changes

File Change Summary
manager/integration/tests/common.py Modified check_longhorn function to use a retry loop for checking Longhorn pod statuses with improved error reporting
pipelines/gke/scripts/longhorn-setup.sh Added print_out_cluster_info function to retrieve and display Kubernetes node version and OS release information
pipelines/gke/terraform/main.tf Updated min_master_version from "1.31.1-gke.2105000" to "1.31.4-gke.1183000"

Assessment against linked issues

Objective Addressed Explanation
Expose OS version info in GKE pipeline [#10285]

Possibly related PRs

Suggested reviewers

  • roger-ryao
  • khushboo-rancher

Poem

🐰 In pipelines of code, a rabbit's delight,
Versions and clusters now shine so bright!
Longhorn checks dance, GKE takes flight,
With version and OS info, our systems ignite! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 77a0860 and 33d0088.

📒 Files selected for processing (3)
  • manager/integration/tests/common.py (1 hunks)
  • pipelines/gke/scripts/longhorn-setup.sh (2 hunks)
  • pipelines/gke/terraform/main.tf (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • pipelines/gke/terraform/main.tf
  • manager/integration/tests/common.py
🧰 Additional context used
🪛 Shellcheck (0.10.0)
pipelines/gke/scripts/longhorn-setup.sh

[warning] 30-30: Quote this to prevent word splitting.

(SC2046)


[warning] 30-30: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: Build images
  • GitHub Check: Summary
🔇 Additional comments (1)
pipelines/gke/scripts/longhorn-setup.sh (1)

289-289: LGTM!

The placement of print_out_cluster_info is appropriate in the execution flow.


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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: 4

🧹 Nitpick comments (3)
pipelines/gke/scripts/longhorn-setup.sh (1)

39-40: Use specific Alpine version for better reproducibility.

The Alpine image tag should be specified for better reproducibility and security.

-    image: alpine
-    args: ["/bin/sh", "-c", "while true;do date;sleep 5; done"]
+    image: alpine:3.19
+    command: ["/bin/sh"]
+    args: ["-c", "while true; do date; sleep 5; done"]
manager/integration/tests/common.py (2)

4051-4091: Add docstring and type hints for better code maintainability.

The function would benefit from a docstring explaining its purpose and parameters, and type hints for better code maintainability.

-def check_longhorn(core_api):
+def check_longhorn(core_api: k8sclient.CoreV1Api) -> None:
+    """
+    Wait for all Longhorn components to be ready.
+    
+    Args:
+        core_api: The Kubernetes CoreV1Api client
+        
+    Raises:
+        AssertionError: If components are not ready within the retry period
+    """
🧰 Tools
🪛 Ruff (0.8.2)

4091-4091: f-string without any placeholders

Remove extraneous f prefix

(F541)

🪛 GitHub Actions: build

[warning] 4060-4060: Line length exceeds 79 characters (E501)


[error] 4091-4091: f-string is missing placeholders (F541)


4060-4060: Fix line length to comply with PEP 8.

The line exceeds the 79-character limit. Split it for better readability.

-                elif labels.get('longhorn.io/component', '') == 'engine-image' \
+                elif (labels.get('longhorn.io/component', '') == 'engine-image'
+                      and item.status.phase == "Running"):
-                        and item.status.phase == "Running":
🧰 Tools
🪛 GitHub Actions: build

[warning] 4060-4060: Line length exceeds 79 characters (E501)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 958d54b and 77a0860.

📒 Files selected for processing (3)
  • manager/integration/tests/common.py (1 hunks)
  • pipelines/gke/scripts/longhorn-setup.sh (2 hunks)
  • pipelines/gke/terraform/main.tf (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
manager/integration/tests/common.py

4091-4091: f-string without any placeholders

Remove extraneous f prefix

(F541)

🪛 GitHub Actions: build
manager/integration/tests/common.py

[warning] 4060-4060: Line length exceeds 79 characters (E501)


[error] 4091-4091: f-string is missing placeholders (F541)

🪛 Shellcheck (0.10.0)
pipelines/gke/scripts/longhorn-setup.sh

[warning] 30-30: Quote this to prevent word splitting.

(SC2046)


[warning] 30-30: Quote this to prevent word splitting.

(SC2046)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (2)
pipelines/gke/terraform/main.tf (1)

45-45: Verify GKE version compatibility and availability.

The GKE version update from 1.31.1 to 1.31.4 looks good, but let's verify its availability and release notes.

pipelines/gke/scripts/longhorn-setup.sh (1)

289-289: LGTM: Function call placement is correct.

The placement of print_out_cluster_info call in the main function is appropriate, executing before any cluster operations.

@@ -26,6 +26,32 @@ set_kubeconfig_envvar(){
gcloud container clusters get-credentials `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --project ${TF_VAR_gcp_project}
}

print_out_cluster_info(){
gcloud container clusters describe `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --format="value(currentNodeVersion)"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Fix word splitting in gcloud command.

The gcloud command needs proper quoting to prevent word splitting issues.

-  gcloud container clusters describe `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --format="value(currentNodeVersion)"
+  gcloud container clusters describe "$(terraform -chdir="${TF_VAR_tf_workspace}/terraform" output -raw cluster_name)" --zone "$(terraform -chdir="${TF_VAR_tf_workspace}/terraform" output -raw cluster_zone)" --format="value(currentNodeVersion)"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
gcloud container clusters describe `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --format="value(currentNodeVersion)"
gcloud container clusters describe "$(terraform -chdir="${TF_VAR_tf_workspace}/terraform" output -raw cluster_name)" --zone "$(terraform -chdir="${TF_VAR_tf_workspace}/terraform" output -raw cluster_zone)" --format="value(currentNodeVersion)"
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 30-30: Quote this to prevent word splitting.

(SC2046)


[warning] 30-30: Quote this to prevent word splitting.

(SC2046)

Comment on lines +50 to +52
kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s
kubectl exec -it print-os-release -- cat /mnt/host/etc/os-release
kubectl delete pod/print-os-release
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for pod operations.

The pod operations lack proper error handling and could leave resources behind if commands fail.

-  kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s
-  kubectl exec -it print-os-release -- cat /mnt/host/etc/os-release
-  kubectl delete pod/print-os-release
+  if ! kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s; then
+    echo "Error: Pod failed to become ready"
+    kubectl delete pod/print-os-release
+    return 1
+  fi
+
+  if ! kubectl exec print-os-release -- cat /mnt/host/etc/os-release; then
+    echo "Error: Failed to read OS release info"
+    kubectl delete pod/print-os-release
+    return 1
+  fi
+
+  if ! kubectl delete pod/print-os-release; then
+    echo "Error: Failed to delete pod"
+    return 1
+  fi
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s
kubectl exec -it print-os-release -- cat /mnt/host/etc/os-release
kubectl delete pod/print-os-release
if ! kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s; then
echo "Error: Pod failed to become ready"
kubectl delete pod/print-os-release
return 1
fi
if ! kubectl exec print-os-release -- cat /mnt/host/etc/os-release; then
echo "Error: Failed to read OS release info"
kubectl delete pod/print-os-release
return 1
fi
if ! kubectl delete pod/print-os-release; then
echo "Error: Failed to delete pod"
return 1
fi

Comment on lines +29 to +53
print_out_cluster_info(){
gcloud container clusters describe `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --format="value(currentNodeVersion)"
kubectl create -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: print-os-release
spec:
containers:
- name: print-os-release
image: alpine
args: ["/bin/sh", "-c", "while true;do date;sleep 5; done"]
volumeMounts:
- name: host
mountPath: /mnt/host
volumes:
- name: host
hostPath:
path: /
type: Directory
EOF
kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s
kubectl exec -it print-os-release -- cat /mnt/host/etc/os-release
kubectl delete pod/print-os-release
}
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security: Restrict host mount access and remove interactive terminal usage.

The current implementation has several security concerns:

  1. Mounting the entire host root directory is excessive when only /etc/os-release is needed
  2. Using -it flags for kubectl exec is unnecessary and may cause issues in non-interactive environments

Apply these changes to improve security:

-    volumeMounts:
-    - name: host
-      mountPath: /mnt/host
-  volumes:
-  - name: host
-    hostPath:
-      path: /
-      type: Directory
+    volumeMounts:
+    - name: os-release
+      mountPath: /mnt/host/etc/os-release
+      readOnly: true
+  volumes:
+  - name: os-release
+    hostPath:
+      path: /etc/os-release
+      type: File

-  kubectl exec -it print-os-release -- cat /mnt/host/etc/os-release
+  kubectl exec print-os-release -- cat /mnt/host/etc/os-release
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
print_out_cluster_info(){
gcloud container clusters describe `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --format="value(currentNodeVersion)"
kubectl create -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: print-os-release
spec:
containers:
- name: print-os-release
image: alpine
args: ["/bin/sh", "-c", "while true;do date;sleep 5; done"]
volumeMounts:
- name: host
mountPath: /mnt/host
volumes:
- name: host
hostPath:
path: /
type: Directory
EOF
kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s
kubectl exec -it print-os-release -- cat /mnt/host/etc/os-release
kubectl delete pod/print-os-release
}
print_out_cluster_info(){
gcloud container clusters describe `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_name` --zone `terraform -chdir=${TF_VAR_tf_workspace}/terraform output -raw cluster_zone` --format="value(currentNodeVersion)"
kubectl create -f - <<EOF
apiVersion: v1
kind: Pod
metadata:
name: print-os-release
spec:
containers:
- name: print-os-release
image: alpine
args: ["/bin/sh", "-c", "while true;do date;sleep 5; done"]
volumeMounts:
- name: os-release
mountPath: /mnt/host/etc/os-release
readOnly: true
volumes:
- name: os-release
hostPath:
path: /etc/os-release
type: File
EOF
kubectl wait --for=condition=Ready pod/print-os-release --timeout=60s
kubectl exec print-os-release -- cat /mnt/host/etc/os-release
kubectl delete pod/print-os-release
}
🧰 Tools
🪛 Shellcheck (0.10.0)

[warning] 30-30: Quote this to prevent word splitting.

(SC2046)


[warning] 30-30: Quote this to prevent word splitting.

(SC2046)


assert ready
assert ready, f"Failed to wait for Longhorn components ready"
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Remove unnecessary f-string prefix.

The string doesn't contain any placeholders, so the f-string prefix is unnecessary.

-    assert ready, f"Failed to wait for Longhorn components ready"
+    assert ready, "Failed to wait for Longhorn components ready"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
assert ready, f"Failed to wait for Longhorn components ready"
assert ready, "Failed to wait for Longhorn components ready"
🧰 Tools
🪛 Ruff (0.8.2)

4091-4091: f-string without any placeholders

Remove extraneous f prefix

(F541)

🪛 GitHub Actions: build

[error] 4091-4091: f-string is missing placeholders (F541)

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