From f2f332a9c03c7c48023a1a216cc611bc70a6834e Mon Sep 17 00:00:00 2001 From: Angel Marin Date: Tue, 31 Mar 2026 21:44:27 +0200 Subject: [PATCH] HYPERFLEET-869 - feat: update e2e repository to new sentinel config schema --- deploy-scripts/lib/adapter.sh | 23 ++- deploy-scripts/lib/sentinel.sh | 278 ++++++++++++++++----------------- 2 files changed, 150 insertions(+), 151 deletions(-) diff --git a/deploy-scripts/lib/adapter.sh b/deploy-scripts/lib/adapter.sh index e2ffbfd..e7b49b4 100755 --- a/deploy-scripts/lib/adapter.sh +++ b/deploy-scripts/lib/adapter.sh @@ -32,7 +32,7 @@ discover_adapters() { # Add cluster adapters if [[ -n "${cluster_adapters}" ]]; then - IFS=',' read -ra cluster_adapter_array <<< "${cluster_adapters}" + IFS=',' read -ra cluster_adapter_array <<<"${cluster_adapters}" for adapter_name in "${cluster_adapter_array[@]}"; do # Trim whitespace adapter_name=$(echo "${adapter_name}" | xargs) @@ -52,7 +52,7 @@ discover_adapters() { # Add nodepool adapters if [[ -n "${nodepool_adapters}" ]]; then - IFS=',' read -ra nodepool_adapter_array <<< "${nodepool_adapters}" + IFS=',' read -ra nodepool_adapter_array <<<"${nodepool_adapters}" for adapter_name in "${nodepool_adapter_array[@]}"; do # Trim whitespace adapter_name=$(echo "${adapter_name}" | xargs) @@ -183,7 +183,6 @@ install_adapter_instance() { return 0 fi - # Build helm command with labels to track adapter metadata local helm_cmd=( helm upgrade --install @@ -198,12 +197,12 @@ install_adapter_instance() { --set "image.registry=${IMAGE_REGISTRY}" --set "image.repository=${ADAPTER_IMAGE_REPO}" --set "image.tag=${ADAPTER_IMAGE_TAG}" - --set "broker.googlepubsub.projectId=${GCP_PROJECT_ID}" - --set "broker.googlepubsub.createTopicIfMissing=${ADAPTER_GOOGLEPUBSUB_CREATE_TOPIC_IF_MISSING}" - --set "broker.googlepubsub.createSubscriptionIfMissing=${ADAPTER_GOOGLEPUBSUB_CREATE_SUBSCRIPTION_IF_MISSING}" - --set "broker.googlepubsub.subscriptionId=${subscription_id}" - --set "broker.googlepubsub.topic=${topic}" - --set "broker.googlepubsub.deadLetterTopic=${dead_letter_topic}" + --set "config.clients.broker.googlepubsub.projectId=${GCP_PROJECT_ID}" + --set "config.clients.broker.googlepubsub.createTopicIfMissing=${ADAPTER_GOOGLEPUBSUB_CREATE_TOPIC_IF_MISSING}" + --set "config.clients.broker.googlepubsub.createSubscriptionIfMissing=${ADAPTER_GOOGLEPUBSUB_CREATE_SUBSCRIPTION_IF_MISSING}" + --set "config.clients.broker.googlepubsub.subscriptionId=${subscription_id}" + --set "config.clients.broker.googlepubsub.topic=${topic}" + --set "config.clients.broker.googlepubsub.deadLetterTopic=${dead_letter_topic}" --labels "adapter-resource-type=${resource_type},adapter-name=${adapter_name}" ) @@ -271,7 +270,7 @@ install_adapters() { log_warning "Failed to install adapter: ${adapter_dir}" ((failed++)) fi - done <<< "${adapters}" + done <<<"${adapters}" if [[ ${failed} -gt 0 ]]; then log_error "${failed} adapter(s) failed to install" @@ -338,7 +337,7 @@ uninstall_adapter_instance() { ((uninstall_errors++)) fi fi - done <<< "${matching_releases}" + done <<<"${matching_releases}" if [[ ${uninstall_errors} -gt 0 ]]; then return 1 @@ -363,7 +362,7 @@ uninstall_adapters() { log_warning "Failed to uninstall adapter: ${adapter_dir}" ((failed++)) fi - done <<< "${adapters}" + done <<<"${adapters}" if [[ ${failed} -gt 0 ]]; then log_error "${failed} adapter(s) failed to uninstall" diff --git a/deploy-scripts/lib/sentinel.sh b/deploy-scripts/lib/sentinel.sh index b04da41..5f08168 100755 --- a/deploy-scripts/lib/sentinel.sh +++ b/deploy-scripts/lib/sentinel.sh @@ -10,158 +10,158 @@ # ============================================================================ install_sentinel_instance() { - local resource_type="$1" # "clusters" or "nodepools" - - local component_name="Sentinel (${resource_type})" - local release_name="sentinel-${resource_type}" - local full_chart_path="${WORK_DIR}/sentinel/${SENTINEL_CHART_PATH}" - - log_section "Installing ${component_name}" - - # Determine API base URL - local api_url="${API_BASE_URL}" - - if [[ "${DRY_RUN}" == "true" ]]; then - log_info "[DRY-RUN] Would install ${component_name} with:" - log_info " Release name: ${release_name}" - log_info " Namespace: ${NAMESPACE}" - log_info " Chart path: ${full_chart_path}" - log_info " Image: ${IMAGE_REGISTRY}/${SENTINEL_IMAGE_REPO}:${SENTINEL_IMAGE_TAG}" - log_info " API base URL: ${api_url} (config.hyperfleetApi.baseUrl)" - log_info " Broker type: ${SENTINEL_BROKER_TYPE}" - log_info " Resource type: ${resource_type}" - log_info " Google Pub/Sub Project ID: ${GCP_PROJECT_ID}" - log_info " Google Pub/Sub Create Topic If Missing: ${SENTINEL_GOOGLEPUBSUB_CREATE_TOPIC_IF_MISSING}" - return 0 - fi - - log_info "Installing ${component_name}..." - log_verbose "Release name: ${release_name}" - log_verbose "Image: ${IMAGE_REGISTRY}/${SENTINEL_IMAGE_REPO}:${SENTINEL_IMAGE_TAG}" - log_verbose "API base URL: ${api_url}" - log_verbose "Resource type: ${resource_type}" - - # Build helm command - local helm_cmd=( - helm upgrade --install - "${release_name}" - "${full_chart_path}" - --namespace "${NAMESPACE}" - --create-namespace - --wait - --timeout 3m - --set "image.registry=${IMAGE_REGISTRY}" - --set "image.repository=${SENTINEL_IMAGE_REPO}" - --set "image.tag=${SENTINEL_IMAGE_TAG}" - --set "config.hyperfleetApi.baseUrl=${api_url}" - --set "config.resourceType=${resource_type}" - --set "broker.type=${SENTINEL_BROKER_TYPE}" - --set "broker.googlepubsub.projectId=${GCP_PROJECT_ID}" - --set "broker.googlepubsub.createTopicIfMissing=${SENTINEL_GOOGLEPUBSUB_CREATE_TOPIC_IF_MISSING}" + local resource_type="$1" # "clusters" or "nodepools" + + local component_name="Sentinel (${resource_type})" + local release_name="sentinel-${resource_type}" + local full_chart_path="${WORK_DIR}/sentinel/${SENTINEL_CHART_PATH}" + + log_section "Installing ${component_name}" + + # Determine API base URL + local api_url="${API_BASE_URL}" + + if [[ "${DRY_RUN}" == "true" ]]; then + log_info "[DRY-RUN] Would install ${component_name} with:" + log_info " Release name: ${release_name}" + log_info " Namespace: ${NAMESPACE}" + log_info " Chart path: ${full_chart_path}" + log_info " Image: ${IMAGE_REGISTRY}/${SENTINEL_IMAGE_REPO}:${SENTINEL_IMAGE_TAG}" + log_info " API base URL: ${api_url} (config.clients.hyperfleetApi.baseUrl)" + log_info " Broker type: ${SENTINEL_BROKER_TYPE}" + log_info " Resource type: ${resource_type}" + log_info " Google Pub/Sub Project ID: ${GCP_PROJECT_ID}" + log_info " Google Pub/Sub Create Topic If Missing: ${SENTINEL_GOOGLEPUBSUB_CREATE_TOPIC_IF_MISSING}" + return 0 + fi + + log_info "Installing ${component_name}..." + log_verbose "Release name: ${release_name}" + log_verbose "Image: ${IMAGE_REGISTRY}/${SENTINEL_IMAGE_REPO}:${SENTINEL_IMAGE_TAG}" + log_verbose "API base URL: ${api_url}" + log_verbose "Resource type: ${resource_type}" + + # Build helm command + local helm_cmd=( + helm upgrade --install + "${release_name}" + "${full_chart_path}" + --namespace "${NAMESPACE}" + --create-namespace + --wait + --timeout 3m + --set "image.registry=${IMAGE_REGISTRY}" + --set "image.repository=${SENTINEL_IMAGE_REPO}" + --set "image.tag=${SENTINEL_IMAGE_TAG}" + --set "config.clients.hyperfleetApi.baseUrl=${api_url}" + --set "config.resourceType=${resource_type}" + --set "config.clients.broker.type=${SENTINEL_BROKER_TYPE}" + --set "config.clients.broker.googlepubsub.projectId=${GCP_PROJECT_ID}" + --set "config.clients.broker.googlepubsub.createTopicIfMissing=${SENTINEL_GOOGLEPUBSUB_CREATE_TOPIC_IF_MISSING}" + ) + + # Add message_data.owner_references configuration for nodepools resource type + # This enables the sentinel to include ownerReferences from the Kubernetes resource + # in the message data sent to adapters, which is required for nodepools management + if [[ "${resource_type}" == "nodepools" ]]; then + helm_cmd+=( + --set "config.messageData.owner_references.id=resource.owner_references.id" + --set "config.messageData.owner_references.href=resource.owner_references.href" + --set "config.messageData.owner_references.kind=resource.owner_references.kind" ) + fi - # Add message_data.owner_references configuration for nodepools resource type - # This enables the sentinel to include ownerReferences from the Kubernetes resource - # in the message data sent to adapters, which is required for nodepools management - if [[ "${resource_type}" == "nodepools" ]]; then - helm_cmd+=( - --set "config.messageData.owner_references.id=resource.owner_references.id" - --set "config.messageData.owner_references.href=resource.owner_references.href" - --set "config.messageData.owner_references.kind=resource.owner_references.kind" - ) - fi + log_info "Executing: ${helm_cmd[*]}" - log_info "Executing: ${helm_cmd[*]}" - - if "${helm_cmd[@]}"; then - log_success "${component_name} Helm release created successfully" - - # Verify pod health - log_info "Verifying pod health..." - if verify_pod_health "${NAMESPACE}" "app.kubernetes.io/instance=${release_name}" "${component_name}" 120 5; then - log_success "${component_name} is running and healthy" - else - log_error "${component_name} deployment failed health check" - - # Capture debug logs before cleanup - local debug_log_dir="${DEBUG_LOG_DIR:-${WORK_DIR}/debug-logs}" - capture_debug_logs "${NAMESPACE}" "app.kubernetes.io/instance=${release_name}" "${release_name}" "${debug_log_dir}" - - # Cleanup failed deployment - log_warning "Cleaning up failed ${component_name} deployment: ${release_name}" - if helm uninstall "${release_name}" -n "${NAMESPACE}" --wait --timeout 5m; then - log_info "Failed ${component_name} deployment cleaned up successfully" - else - log_warning "Failed to cleanup ${component_name} deployment, it may need manual cleanup" - fi - return 1 - fi + if "${helm_cmd[@]}"; then + log_success "${component_name} Helm release created successfully" + + # Verify pod health + log_info "Verifying pod health..." + if verify_pod_health "${NAMESPACE}" "app.kubernetes.io/instance=${release_name}" "${component_name}" 120 5; then + log_success "${component_name} is running and healthy" else - log_error "Failed to install ${component_name}" - - # Check if release was created (partial deployment) and cleanup - if helm list -n "${NAMESPACE}" 2>/dev/null | grep -q "^${release_name}"; then - # Capture debug logs before cleanup - local debug_log_dir="${DEBUG_LOG_DIR:-${WORK_DIR}/debug-logs}" - capture_debug_logs "${NAMESPACE}" "app.kubernetes.io/instance=${release_name}" "${release_name}" "${debug_log_dir}" - - log_warning "Cleaning up failed ${component_name} deployment: ${release_name}" - if helm uninstall "${release_name}" -n "${NAMESPACE}" --wait --timeout 5m; then - log_info "Failed ${component_name} deployment cleaned up successfully" - else - log_warning "Failed to cleanup ${component_name} deployment, it may need manual cleanup" - fi - fi - return 1 + log_error "${component_name} deployment failed health check" + + # Capture debug logs before cleanup + local debug_log_dir="${DEBUG_LOG_DIR:-${WORK_DIR}/debug-logs}" + capture_debug_logs "${NAMESPACE}" "app.kubernetes.io/instance=${release_name}" "${release_name}" "${debug_log_dir}" + + # Cleanup failed deployment + log_warning "Cleaning up failed ${component_name} deployment: ${release_name}" + if helm uninstall "${release_name}" -n "${NAMESPACE}" --wait --timeout 5m; then + log_info "Failed ${component_name} deployment cleaned up successfully" + else + log_warning "Failed to cleanup ${component_name} deployment, it may need manual cleanup" + fi + return 1 + fi + else + log_error "Failed to install ${component_name}" + + # Check if release was created (partial deployment) and cleanup + if helm list -n "${NAMESPACE}" 2>/dev/null | grep -q "^${release_name}"; then + # Capture debug logs before cleanup + local debug_log_dir="${DEBUG_LOG_DIR:-${WORK_DIR}/debug-logs}" + capture_debug_logs "${NAMESPACE}" "app.kubernetes.io/instance=${release_name}" "${release_name}" "${debug_log_dir}" + + log_warning "Cleaning up failed ${component_name} deployment: ${release_name}" + if helm uninstall "${release_name}" -n "${NAMESPACE}" --wait --timeout 5m; then + log_info "Failed ${component_name} deployment cleaned up successfully" + else + log_warning "Failed to cleanup ${component_name} deployment, it may need manual cleanup" + fi fi + return 1 + fi } install_sentinel() { - install_sentinel_instance "clusters" || return 1 - install_sentinel_instance "nodepools" || return 1 + install_sentinel_instance "clusters" || return 1 + install_sentinel_instance "nodepools" || return 1 } uninstall_sentinel_instance() { - local resource_type="$1" # "clusters" or "nodepools" - - # Capitalize first letter for display - local resource_type_display - if [[ "${resource_type}" == "clusters" ]]; then - resource_type_display="Clusters" - else - resource_type_display="Nodepools" - fi - - local component_name="Sentinel (${resource_type_display})" - local release_name="sentinel-${resource_type}" - - log_section "Uninstalling ${component_name}" - - # Check if release exists - if ! helm list -n "${NAMESPACE}" | grep -q "^${release_name}"; then - log_warning "Release '${release_name}' not found in namespace '${NAMESPACE}'" - return 0 - fi - - if [[ "${DRY_RUN}" == "true" ]]; then - log_info "[DRY-RUN] Would uninstall ${component_name} (release: ${release_name})" - return 0 - fi - - log_info "Uninstalling ${component_name}..." - log_info "Executing: helm uninstall ${release_name} -n ${NAMESPACE} --wait --timeout 5m" - - if helm uninstall "${release_name}" -n "${NAMESPACE}" --wait --timeout 5m; then - log_success "${component_name} uninstalled successfully" - else - log_error "Failed to uninstall ${component_name}" - return 1 - fi + local resource_type="$1" # "clusters" or "nodepools" + + # Capitalize first letter for display + local resource_type_display + if [[ "${resource_type}" == "clusters" ]]; then + resource_type_display="Clusters" + else + resource_type_display="Nodepools" + fi + + local component_name="Sentinel (${resource_type_display})" + local release_name="sentinel-${resource_type}" + + log_section "Uninstalling ${component_name}" + + # Check if release exists + if ! helm list -n "${NAMESPACE}" | grep -q "^${release_name}"; then + log_warning "Release '${release_name}' not found in namespace '${NAMESPACE}'" + return 0 + fi + + if [[ "${DRY_RUN}" == "true" ]]; then + log_info "[DRY-RUN] Would uninstall ${component_name} (release: ${release_name})" + return 0 + fi + + log_info "Uninstalling ${component_name}..." + log_info "Executing: helm uninstall ${release_name} -n ${NAMESPACE} --wait --timeout 5m" + + if helm uninstall "${release_name}" -n "${NAMESPACE}" --wait --timeout 5m; then + log_success "${component_name} uninstalled successfully" + else + log_error "Failed to uninstall ${component_name}" + return 1 + fi } uninstall_sentinel() { - # Uninstall in reverse order - uninstall_sentinel_instance "nodepools" || log_warning "Failed to uninstall Sentinel (Nodepools)" - uninstall_sentinel_instance "clusters" || log_warning "Failed to uninstall Sentinel (Clusters)" + # Uninstall in reverse order + uninstall_sentinel_instance "nodepools" || log_warning "Failed to uninstall Sentinel (Nodepools)" + uninstall_sentinel_instance "clusters" || log_warning "Failed to uninstall Sentinel (Clusters)" }