feat: only retry to update ref-count on conflict

This commit is contained in:
wencaiwulue
2023-01-26 21:57:15 +08:00
parent 95f81df658
commit f128f5d58e
3 changed files with 36 additions and 2 deletions

View File

@@ -2,7 +2,7 @@
[中文](README_ZH.md) | [English](README.md) | [Wiki](https://github.com/wencaiwulue/kubevpn/wiki/Architecture) [中文](README_ZH.md) | [English](README.md) | [Wiki](https://github.com/wencaiwulue/kubevpn/wiki/Architecture)
A tools which can connect to kubernetes cluster network, you can access remote kubernetes cluster network, remote A tunnel tools which can connect to kubernetes cluster network, you can access remote kubernetes cluster network, remote
kubernetes cluster service can also access your local service kubernetes cluster service can also access your local service
## QuickStart ## QuickStart

View File

@@ -70,7 +70,15 @@ func updateRefCount(configMapInterface v12.ConfigMapInterface, name string, incr
err = retry.OnError( err = retry.OnError(
retry.DefaultRetry, retry.DefaultRetry,
func(err error) bool { func(err error) bool {
return !k8serrors.IsNotFound(err) notFound := k8serrors.IsNotFound(err)
if notFound {
return false
}
conflict := k8serrors.IsConflict(err)
if conflict {
return true
}
return false
}, },
func() (err error) { func() (err error) {
var cm *corev1.ConfigMap var cm *corev1.ConfigMap

View File

@@ -4,7 +4,9 @@
package util package util
import ( import (
"fmt"
"os" "os"
"os/exec"
"strings" "strings"
"syscall" "syscall"
@@ -32,6 +34,30 @@ func RunWithElevated() {
} }
} }
// still can't use env KUBECONFIG
func RunWithElevatedInnerExec() error {
var si windows.StartupInfo
var pi windows.ProcessInformation
path, err := exec.LookPath("Powershell")
if err != nil {
return err
}
executable, _ := os.Executable()
join := strings.Join(append([]string{executable}, os.Args[1:]...), " ")
// Powershell Start C:\Users\naison\Desktop\kubevpn-windows-amd64.exe -Verb Runas -Wait -WindowStyle Hidden
c, _ := syscall.UTF16PtrFromString(fmt.Sprintf(`%s Start "%s" -Verb Runas`, path, join))
err = windows.CreateProcess(nil, c, nil, nil, true, windows.INHERIT_PARENT_AFFINITY, nil, nil, &si, &pi)
if err != nil {
return err
}
p, err := os.FindProcess(int(pi.ProcessId))
if err != nil {
return err
}
_, err = p.Wait()
return err
}
func IsAdmin() bool { func IsAdmin() bool {
_, err := os.Open("\\\\.\\PHYSICALDRIVE0") _, err := os.Open("\\\\.\\PHYSICALDRIVE0")
if err != nil { if err != nil {