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

AKS/EKS using Longhorn repo Manifests: Deploy MinIO/NFS for Backup Store Creation #2188

Merged
merged 3 commits into from
Dec 15, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion test_framework/scripts/longhorn-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,18 @@ install_backupstores(){
setup_azuitize_backup_store
}

install_backupstores_from_lh_repo(){
MINIO_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml"
NFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml"
CIFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml"
AZURITE_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/azurite-backupstore.yaml"
kubectl create -f ${MINIO_BACKUPSTORE_URL} \
-f ${NFS_BACKUPSTORE_URL} \
-f ${CIFS_BACKUPSTORE_URL} \
-f ${AZURITE_BACKUPSTORE_URL}
setup_azuitize_backup_store
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Consider refactoring to eliminate code duplication.

The new function is almost identical to install_backupstores. Consider refactoring both functions to use a common implementation with configurable base URLs.

-install_backupstores_from_lh_repo(){
-  MINIO_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml"
-  NFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml"
-  CIFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml"
-  AZURITE_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/azurite-backupstore.yaml"
-  kubectl create -f ${MINIO_BACKUPSTORE_URL} \
-                 -f ${NFS_BACKUPSTORE_URL} \
-                 -f ${CIFS_BACKUPSTORE_URL} \
-                 -f ${AZURITE_BACKUPSTORE_URL}
-  setup_azuitize_backup_store
-}

+install_backupstores() {
+  local base_url="${1:-https://raw.githubusercontent.com/longhorn/longhorn-tests/master/manager/integration/deploy/backupstores}"
+  
+  # Use arrays for better maintainability
+  local manifests=(
+    "minio-backupstore.yaml"
+    "nfs-backupstore.yaml" 
+    "cifs-backupstore.yaml"
+    "azurite-backupstore.yaml"
+  )
+  
+  local kubectl_args=""
+  for manifest in "${manifests[@]}"; do
+    kubectl_args="${kubectl_args} -f ${base_url}/${manifest}"
+  done
+
+  if ! kubectl create ${kubectl_args}; then
+    echo "Error: Failed to create backup stores"
+    return 1
+  fi
+
+  setup_azuitize_backup_store
+}
+
+# Wrapper for backward compatibility
+install_backupstores_from_lh_repo() {
+  install_backupstores "https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores"
+}
📝 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
install_backupstores_from_lh_repo(){
MINIO_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/minio-backupstore.yaml"
NFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/nfs-backupstore.yaml"
CIFS_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/cifs-backupstore.yaml"
AZURITE_BACKUPSTORE_URL="https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores/azurite-backupstore.yaml"
kubectl create -f ${MINIO_BACKUPSTORE_URL} \
-f ${NFS_BACKUPSTORE_URL} \
-f ${CIFS_BACKUPSTORE_URL} \
-f ${AZURITE_BACKUPSTORE_URL}
setup_azuitize_backup_store
}
install_backupstores() {
local base_url="${1:-https://raw.githubusercontent.com/longhorn/longhorn-tests/master/manager/integration/deploy/backupstores}"
# Use arrays for better maintainability
local manifests=(
"minio-backupstore.yaml"
"nfs-backupstore.yaml"
"cifs-backupstore.yaml"
"azurite-backupstore.yaml"
)
local kubectl_args=""
for manifest in "${manifests[@]}"; do
kubectl_args="${kubectl_args} -f ${base_url}/${manifest}"
done
if ! kubectl create ${kubectl_args}; then
echo "Error: Failed to create backup stores"
return 1
fi
setup_azuitize_backup_store
}
# Wrapper for backward compatibility
install_backupstores_from_lh_repo() {
install_backupstores "https://raw.githubusercontent.com/longhorn/longhorn/master/deploy/backupstores"
}


setup_azuitize_backup_store(){
roger-ryao marked this conversation as resolved.
Show resolved Hide resolved
RETRY=0
MAX_RETRY=60
Expand Down Expand Up @@ -557,7 +569,11 @@ main(){
install_cluster_autoscaler
fi
if [[ ${PYTEST_CUSTOM_OPTIONS} != *"--include-cluster-autoscaler-test"* ]]; then
install_backupstores
if [[ "${TF_VAR_k8s_distro_name}" == "eks" || "${TF_VAR_k8s_distro_name}" == "aks" ]]; then
install_backupstores_from_lh_repo
else
install_backupstores
fi
fi
install_csi_snapshotter_crds
if [[ "${TF_VAR_enable_mtls}" == true ]]; then
Expand Down
Loading