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

modify the local-up-karmada.sh to optimize the creation of clusters #1552

Closed

Conversation

Charlie17Li
Copy link
Contributor

What type of PR is this?

/kind bug

What this PR does / why we need it:

Fixed a bug in a extreme case that the cluster kubeconfig created earlier will be overwritten by the cluster created later

Which issue(s) this PR fixes:
Fixes #1545

Special notes for your reviewer:

Does this PR introduce a user-facing change?:
NONE


@karmada-bot karmada-bot added the kind/bug Categorizes issue or PR as related to a bug. label Mar 26, 2022
@karmada-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
To complete the pull request process, please assign mrlihanbo after the PR has been reviewed.
You can assign the PR to them by writing /assign @mrlihanbo in a comment when ready.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@karmada-bot karmada-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Mar 26, 2022
@RainbowMango
Copy link
Member

# hack/local-up-karmada.sh
.,.
Waiting for the host clusters to be ready...
Waiting for kubeconfig file /root/.kube/karmada.config and clusters karmada-host to be ready...
error: cannot rename the context "kind-karmada-host", the context "karmada-host" already exists in /root/.kube/karmada.config

When I run hack/local-up-karmada.sh again, I met this error. Can we fix that?

By the way, the hack/local-up-karmada.sh used heavily in our daily development. I don't want to cleanup the kubeconfig file manually.

@Charlie17Li
Copy link
Contributor Author

Charlie17Li commented Mar 26, 2022

I also met this (I just remove the following line:393), I find when wait the cluster ready, it will rename the context name

karmada/hack/util.sh

Lines 385 to 393 in e85d376

function util::check_clusters_ready() {
local kubeconfig_path=${1}
local context_name=${2}
echo "Waiting for kubeconfig file ${kubeconfig_path} and clusters ${context_name} to be ready..."
util::wait_file_exist "${kubeconfig_path}" 300
util::wait_for_condition 'running' "docker inspect --format='{{.State.Status}}' ${context_name}-control-plane &> /dev/null" 300
kubectl config rename-context "kind-${context_name}" "${context_name}" --kubeconfig="${kubeconfig_path}"

so it can't do it again if the cluster context has been renamed

@Charlie17Li
Copy link
Contributor Author

I think it will be more logical that renaming the cluster context in create cluster func rather than in wait cluster ready func

@RainbowMango
Copy link
Member

I think it will be more logical that renaming the cluster context in create cluster func rather than in wait cluster ready func

Yes. agree. But how?

@Charlie17Li
Copy link
Contributor Author

Charlie17Li commented Mar 28, 2022

How about this ?

diff --git a/hack/util.sh b/hack/util.sh
index 46349bea..cbbdd163 100755
--- a/hack/util.sh
+++ b/hack/util.sh
@@ -355,7 +355,7 @@ function util::create_cluster() {

   mkdir -p ${log_path}
   rm -rf "${log_path}/${cluster_name}.log"
-  nohup kind delete cluster --name="${cluster_name}" --kubeconfig="${kubeconfig}" >> "${log_path}"/"${cluster_name}".log 2>&1 && kind create cluster --name "${cluster_name}" --kubeconfig="${kubeconfig}" --image="${kind_image}" --config="${cluster_config}" >> "${log_path}"/"${cluster_name}".log 2>&1 &
+  nohup kind delete cluster --name="${cluster_name}" --kubeconfig="${kubeconfig}" >> "${log_path}"/"${cluster_name}".log 2>&1 && kind create cluster --name "${cluster_name}" --kubeconfig="${kubeconfig}" --image="${kind_image}" --config="${cluster_config}" >> "${log_path}"/"${cluster_name}".log 2>&1 && kubectl config rename-context "kind-${context_name}" "${context_name}" --kubeconfig="${kubeconfig}"  &
   echo "Creating cluster ${cluster_name}"
 }

@RainbowMango
Copy link
Member

Does this work? Have you tested it?

I guess it might not work, as after cluster is created, the control plan of that cluster might not ready. Maybe you need specify a --wait for waiting control plane node ready. Such as kind create cluster --name horen1 --wait=xxs

@RainbowMango
Copy link
Member

/close
As lack of activity.

@karmada-bot
Copy link
Collaborator

@RainbowMango: Closed this PR.

In response to this:

/close
As lack of activity.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Categorizes issue or PR as related to a bug. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The kubeconfig maybe overwritten aboout the create_cluster function in hack/scripts
3 participants