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

[BUG] yurtadm join with kube-apisvr addr only override localhost:6443 #2270

Open
rayne-Li opened this issue Jan 14, 2025 · 0 comments · May be fixed by #2271
Open

[BUG] yurtadm join with kube-apisvr addr only override localhost:6443 #2270

rayne-Li opened this issue Jan 14, 2025 · 0 comments · May be fixed by #2271
Labels
kind/bug kind/bug

Comments

@rayne-Li
Copy link

What happened:
by installing yurthub by doc: https://openyurt.io/zh/docs/installation/manually-setup#32-%E5%AE%89%E8%A3%85-yurthub-%E7%9B%B8%E5%85%B3%E9%85%8D%E7%BD%AE

helm upgrade --install yurt-hub -n kube-system --set kubernetesServerAddr=https://1.2.3.4:6443 openyurt/yurthub

kube-apisvr addr in configmap yurt-static-set-yurt-hub will be set to https://1.2.3.4:6443, then if we join edge node with yurtadm join {{https://external_ip:6443}}, will not change kube-apisvr-addr from 1.2.3.4:6443 to external_ip:6443

according to the func useRealServerAddr, only https://127.0.0.1:6443(constants.DefaultServerAddr) will be overwrite by yurtadm join command, if we set it before(by helm install), nothing will changed

// useRealServerAddr check if the server-addr from yurthubTemplate is default value: 127.0.0.1:6443
// if yes, we should use the real server addr
func useRealServerAddr(yurthubTemplate string, kubernetesServerAddrs string) (string, error) {
	scanner := bufio.NewScanner(bytes.NewReader([]byte(yurthubTemplate)))
	var buffer bytes.Buffer
	target := fmt.Sprintf("%v=%v", constants.ServerAddr, constants.DefaultServerAddr)

	for scanner.Scan() {
		line := scanner.Text()
		if strings.Contains(line, target) {
			line = strings.Replace(line, constants.DefaultServerAddr, kubernetesServerAddrs, -1)
		}
		buffer.WriteString(line + "\n")
	}

What you expected to happen:

in my POV, we install yurthub in cloud node first(usually by internal ip like 172.0.0.11), then we join cloud node by yurtadm join {internal_ip}, last we join edge node by yurtadm join {external_ip}, so ip should always be overwritten since it will not be 127.0.0.1 by helm install by 172.0.0.11

here is my solution:

func useRealServerAddr(yurthubTemplate string, kubernetesServerAddrs string) (string, error) {
	scanner := bufio.NewScanner(bytes.NewReader([]byte(yurthubTemplate)))
	var buffer bytes.Buffer
	// compile ipv4 regex
	ipRegex := regexp.MustCompile(`https?://(?:[0-9]{1,3}\.){3}[0-9]{1,3}:\d+`)

	// scan template and replace setAddr
	for scanner.Scan() {
		line := scanner.Text()
		if strings.Contains(line, fmt.Sprintf("- --%s=", constants.ServerAddr)) {
			// replace kubernetesServerAddrs by new addr
			line = ipRegex.ReplaceAllString(line, kubernetesServerAddrs)
		}
		buffer.WriteString(line + "\n")
	}

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

Environment:

  • OpenYurt version: 1.5.0
  • Kubernetes version (use kubectl version): 1.31
  • OS (e.g: cat /etc/os-release): debian12
  • Kernel (e.g. uname -a): 6.1.119-1 (2024-11-22)
  • Install tools:
  • Others:

others

/kind bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug kind/bug
Projects
None yet
1 participant