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

implement K8S_TEST_NAMESPACE #20

Merged
merged 2 commits into from
Mar 13, 2024
Merged

Conversation

apesternikov
Copy link
Contributor

@apesternikov apesternikov commented Mar 13, 2024

implement K8S_TEST_NAMESPACE to allow to run integration test in specified namespace.
This is a backwards-compatible reimplementation of adobe/rules_gitops@3159eb6

Comment on lines 48 to 58
set +e
if [ -n "${K8S_MYNAMESPACE:-}" ]
if [ -n "${K8S_TEST_NAMESPACE:-}" ]
then
# use provided namespace
NAMESPACE=${K8S_TEST_NAMESPACE}
# do not delete namespace after the test is complete
DELETE_NAMESPACE_FLAG=""
elif [ -n "${K8S_MYNAMESPACE:-}" ]
then
# do not create random namesspace
NAMESPACE=`whoami`

Choose a reason for hiding this comment

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

The script uses set +e which disables the automatic exit when a command fails. This can lead to the script continuing execution even after critical commands fail, potentially leading to unexpected behavior or security issues. It's recommended to handle errors explicitly and use set -e to ensure the script exits on failure.

The use of backticks for command substitution in line 58 is deprecated in favor of $(...) syntax. The latter is more readable, especially in complex commands or when nested. It's recommended to replace backticks with $(whoami) for better readability and maintainability.

Comment on lines 48 to 61
set +e
if [ -n "${K8S_MYNAMESPACE:-}" ]
if [ -n "${K8S_TEST_NAMESPACE:-}" ]
then
# use provided namespace
NAMESPACE=${K8S_TEST_NAMESPACE}
# do not delete namespace after the test is complete
DELETE_NAMESPACE_FLAG=""
elif [ -n "${K8S_MYNAMESPACE:-}" ]
then
# do not create random namesspace
NAMESPACE=`whoami`
NAMESPACE=$(whoami)
# do not delete namespace after the test is complete
DELETE_NAMESPACE_FLAG=""
else

Choose a reason for hiding this comment

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

The script's logic for determining the namespace and whether to delete it after tests could lead to unintended consequences due to its reliance on environment variables without clear validation or fallback. Specifically, the script assumes that if K8S_TEST_NAMESPACE or K8S_MYNAMESPACE is set, these should be used without further checks. This could potentially lead to using incorrect namespaces or not deleting namespaces when expected, especially in complex CI environments where environment variables might be set unintentionally.

To improve this, introduce explicit validation for the namespace values being used, ensuring they conform to expected patterns or naming conventions. Additionally, consider adding a clear, documented default behavior for namespace creation and deletion when neither environment variable is set, to avoid ambiguity and ensure clean-up is handled correctly in all scenarios. This approach will enhance the script's robustness and predictability, making it safer to use in diverse environments.

Copy link
Collaborator

@michaelschiff michaelschiff left a comment

Choose a reason for hiding this comment

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

nice!

@apesternikov apesternikov merged commit 055f2e7 into main Mar 13, 2024
2 checks passed
@apesternikov apesternikov deleted the ap/flag-for-test-namespace branch March 13, 2024 01:37
shraykay pushed a commit to shraykay/rules_gitops that referenced this pull request Jan 22, 2025
# This is the 1st commit message:

app name first

# This is the commit message nazzzzz#2:

clean up file

# This is the commit message nazzzzz#3:

fix reference to proto package

# This is the commit message fasterci#4:

better parse

# This is the commit message fasterci#5:

fix again

# This is the commit message fasterci#6:

fix again

# This is the commit message fasterci#7:

fix again

# This is the commit message fasterci#8:

fix again

# This is the commit message fasterci#9:

fix again

# This is the commit message fasterci#10:

fix again

# This is the commit message fasterci#11:

add debug statements for seeing if branch is dirty

# This is the commit message fasterci#12:

fix again

# This is the commit message fasterci#13:

fix again

# This is the commit message fasterci#14:

fix again

# This is the commit message fasterci#15:

fix again

# This is the commit message fasterci#16:

fix again

# This is the commit message fasterci#17:

fix again

# This is the commit message fasterci#18:

fix again

# This is the commit message fasterci#19:

fix again

# This is the commit message fasterci#20:

fix again

# This is the commit message fasterci#21:

fix again

# This is the commit message fasterci#22:

fix again

# This is the commit message fasterci#23:

fix again
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.

2 participants