Skip to content

Conversation

@amirbenun
Copy link
Contributor

Refactors the error handling in the GCP Elastic Agent Infrastructure Manager deployment script to use a more idiomatic shell pattern. The change replaces the explicit exit code capture and conditional check with a direct if-not pattern for the gcloud command, making the script more readable and following shell scripting best practices.

@amirbenun amirbenun requested a review from a team as a code owner January 19, 2026 12:27
Copilot AI review requested due to automatic review settings January 19, 2026 12:27
@mergify
Copy link

mergify bot commented Jan 19, 2026

This pull request does not have a backport label. Could you fix it @amirbenun? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-v./d./d./d is the label to automatically backport to the 8./d branch. /d is the digit
  • backport-active-all is the label that automatically backports to all active branches.
  • backport-active-8 is the label that automatically backports to all active minor branches for the 8 major.
  • backport-active-9 is the label that automatically backports to all active minor branches for the 9 major.

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 refactors the error handling in the GCP Elastic Agent Infrastructure Manager deployment script to use a more idiomatic shell scripting pattern. The change simplifies the code by replacing explicit exit code capture with a direct if ! conditional pattern.

Changes:

  • Replaced explicit exit code capture (EXIT_CODE=$?) with inline if ! pattern for the gcloud deployment command
  • Simplified error message by removing specific exit code output
  • Normalized exit behavior to always return code 1 on deployment failure

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

--input-values="${INPUT_VALUES}"; then
echo ""
echo "Deployment failed with exit code $EXIT_CODE"
echo "Deployment failed"
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The error message no longer includes the specific exit code from the gcloud command. While the refactored pattern is more idiomatic, the exit code can provide valuable debugging information. Consider preserving this information by capturing the exit code in a variable within the if block or including it in the error message using $? immediately after the command fails.

Copilot uses AI. Check for mistakes.
echo " gcloud compute instances get-serial-port-output elastic-agent-vm-${RESOURCE_SUFFIX} --zone=${EFFECTIVE_ZONE} --project=${PROJECT_ID}"
echo ""
exit $EXIT_CODE
exit 1
Copy link

Copilot AI Jan 19, 2026

Choose a reason for hiding this comment

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

The exit code is now hardcoded to 1, which loses the original exit code from the gcloud command. This could impact automated systems or scripts that depend on specific exit codes to determine the type of failure. Consider using 'exit $?' immediately after the if condition to preserve the original exit code, or document why normalizing to exit code 1 is preferred.

Copilot uses AI. Check for mistakes.
@amirbenun amirbenun merged commit 59c61ae into elastic:main Jan 21, 2026
9 checks passed
@amirbenun amirbenun deleted the infra-manager-agent-if branch January 21, 2026 15:25
@amirbenun amirbenun linked an issue Jan 22, 2026 that may be closed by this pull request
2 tasks
amirbenun added a commit to amirbenun/cloudbeat that referenced this pull request Jan 22, 2026
…y script (elastic#3865)

Refactors the error handling in the GCP Elastic Agent Infrastructure
Manager deployment script to use a more idiomatic shell pattern. The
change replaces the explicit exit code capture and conditional check
with a direct if-not pattern for the gcloud command, making the script
more readable and following shell scripting best practices.

(cherry picked from commit 59c61ae)
amirbenun added a commit to amirbenun/cloudbeat that referenced this pull request Jan 22, 2026
…y script (elastic#3865)

Refactors the error handling in the GCP Elastic Agent Infrastructure
Manager deployment script to use a more idiomatic shell pattern. The
change replaces the explicit exit code capture and conditional check
with a direct if-not pattern for the gcloud command, making the script
more readable and following shell scripting best practices.

(cherry picked from commit 59c61ae)
amirbenun added a commit to amirbenun/cloudbeat that referenced this pull request Jan 22, 2026
…y script (elastic#3865)

Refactors the error handling in the GCP Elastic Agent Infrastructure
Manager deployment script to use a more idiomatic shell pattern. The
change replaces the explicit exit code capture and conditional check
with a direct if-not pattern for the gcloud command, making the script
more readable and following shell scripting best practices.

(cherry picked from commit 59c61ae)
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.

Replace GCP deployment-manager scripts with infrastructure-manager

2 participants