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

Issue open-horizon#4141 - Allow both cluster-scoped agent and namespa… #4143

Merged
merged 1 commit into from
Aug 20, 2024
Merged
Changes from all commits
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
34 changes: 18 additions & 16 deletions agent-install/agent-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3666,23 +3666,25 @@ function check_cluster_agent_scope() {
# continue to check_agent_deployment_exist() to check scope
AGENT_DEPLOYMENT_EXIST_IN_SAME_NAMESPACE="true"
else
# has agent in other namespace(s). Pick one agent deployment and check scope
# current is cluster scoped agent => error
# current is namespace scoped agent:
# namespace scope agent in other namespace => can proceed to install
# cluster scope agent in other namespace => error
# A namespace-scoped agent is allowed to install in a cluster with cluster-scoped agent or namespace-scoped agents
# A cluster-scoped agent is NOT allowed to be installed in a cluster which already had a cluster-scoped agent
if ! $NAMESPACE_SCOPED; then
log_fatal 3 "One or more agents detected in $namespaces_have_agent. A cluster scoped agent cannot be installed to the same cluster that has agent(s) already"
fi

IFS="," read -ra namespace_array <<< "$namespaces_have_agent"
namespace_to_check=${namespace_array[0]}
local namespace_scoped_env_value_in_use=$($KUBECTL get deployment agent -n ${namespace_to_check} -o json | jq '.spec.template.spec.containers[0].env' | jq -r '.[] | select(.name=="HZN_NAMESPACE_SCOPED").value')
log_debug "Current HZN_NAMESPACE_SCOPED in agent deployment under namespace $namespace_to_check is: $namespace_scoped_env_value_in_use"
log_debug "NAMESPACE_SCOPED passed to this script is: $NAMESPACE_SCOPED" # namespace scoped

if [[ "$namespace_scoped_env_value_in_use" == "" ]] || [[ "$namespace_scoped_env_value_in_use" == "false" ]] ; then
log_fatal 3 "A cluster scoped agent detected in $namespace_to_check. A namespace scoped agent cannot be installed to the same cluster that has a cluster scoped agent"
log_debug "NAMESPACE_SCOPED passed to this script is: $NAMESPACE_SCOPED" # namespace scoped

local namespace_to_check
local namespace_scoped_env_value_in_use

IFS="," read -ra namespace_array <<< "$namespaces_have_agent"
arrayLen=${#namespace_array[@]}
for (( i=0 ; i<$arrayLen ; i++ ));
do
namespace_to_check=${namespace_array[i]}
namespace_scoped_env_value_in_use=$($KUBECTL get deployment agent -n ${namespace_to_check} -o json | jq '.spec.template.spec.containers[0].env' | jq -r '.[] | select(.name=="HZN_NAMESPACE_SCOPED").value')
log_debug "Current HZN_NAMESPACE_SCOPED in agent deployment under namespace $namespace_to_check is: $namespace_scoped_env_value_in_use"
if [[ "$namespace_scoped_env_value_in_use" == "" ]] || [[ "$namespace_scoped_env_value_in_use" == "false" ]] ; then
log_fatal 3 "A cluster scoped agent detected in $namespace_to_check. A cluster scoped agent cannot be installed to the same cluster that already has a cluster scoped agent"
fi
done
fi
fi

Expand Down
Loading