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

feat: only use tag judge daemon version #277

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion pkg/daemon/action/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (svr *Server) Upgrade(ctx context.Context, req *rpc.UpgradeRequest) (*rpc.U
if err != nil {
return nil, err
}
if clientVersion.GreaterThan(daemonVersion) || (clientVersion.Equal(daemonVersion) && req.ClientCommitId != config.GitCommit) {
if clientVersion.GreaterThan(daemonVersion) {
log.Info("daemon version is less than client, needs to upgrade")
return &rpc.UpgradeResponse{NeedUpgrade: true}, nil
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/daemon/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,7 @@ func GetClient(isSudo bool) (cli rpc.DaemonClient) {
cli = rpc.NewDaemonClient(conn)
var resp *rpc.UpgradeResponse
resp, err = cli.Upgrade(ctx, &rpc.UpgradeRequest{
ClientVersion: config.Version,
ClientCommitId: config.GitCommit,
ClientVersion: config.Version,
})
if err == nil && resp.NeedUpgrade {
// quit daemon
Expand Down
4 changes: 2 additions & 2 deletions pkg/daemon/handler/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,12 +233,12 @@ func (w *wsHandler) installKubevpnOnRemote(ctx context.Context, sshClient *ssh.C
if config.GitHubOAuthToken != "" {
client = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.GitHubOAuthToken, TokenType: "Bearer"}))
}
latestVersion, latestCommit, url, err := util.GetManifest(client, "linux", "amd64")
latestVersion, url, err := util.GetManifest(client, "linux", "amd64")
if err != nil {
w.Log("Get latest kubevpn version failed: %v", err)
return err
}
w.Log("The latest version is: %s, commit: %s", latestVersion, latestCommit)
w.Log("The latest version is: %s", latestVersion)
var temp *os.File
temp, err = os.CreateTemp("", "")
if err != nil {
Expand Down
256 changes: 123 additions & 133 deletions pkg/daemon/rpc/daemon.pb.go

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion pkg/daemon/rpc/daemon.proto
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,6 @@ message GetResponse {

message UpgradeRequest {
string ClientVersion = 1;
string ClientCommitId = 2;
}

message UpgradeResponse {
Expand Down
10 changes: 5 additions & 5 deletions pkg/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
// 6) check permission of putting new kubevpn back
// 7) chmod +x, move old to /temp, move new to CURRENT_FOLDER
func Main(ctx context.Context) error {
client, url, up, err := needsUpgrade(ctx, config.Version, config.GitCommit)
client, url, up, err := needsUpgrade(ctx, config.Version)
if err != nil {
return err
}
Expand Down Expand Up @@ -125,11 +125,11 @@ func elevate() error {
return nil
}

func needsUpgrade(ctx context.Context, version string, commit string) (client *http.Client, url string, upgrade bool, err error) {
var latestVersion, latestCommit string
func needsUpgrade(ctx context.Context, version string) (client *http.Client, url string, upgrade bool, err error) {
var latestVersion string
if config.GitHubOAuthToken != "" {
client = oauth2.NewClient(ctx, oauth2.StaticTokenSource(&oauth2.Token{AccessToken: config.GitHubOAuthToken, TokenType: "Bearer"}))
latestVersion, latestCommit, url, err = util.GetManifest(client, runtime.GOOS, runtime.GOARCH)
latestVersion, url, err = util.GetManifest(client, runtime.GOOS, runtime.GOARCH)
} else {
client = http.DefaultClient
v := "https://github.com/kubenetworks/kubevpn/raw/master/plugins/stable.txt"
Expand All @@ -151,7 +151,7 @@ func needsUpgrade(ctx context.Context, version string, commit string) (client *h
if err != nil {
return
}
if currV.GreaterThan(latestV) || (currV.Equal(latestV) && commit == latestCommit) {
if currV.GreaterThan(latestV) {
fmt.Fprintf(os.Stdout, "Already up to date, don't needs to upgrade, version: %s\n", latestV)
return
}
Expand Down
3 changes: 1 addition & 2 deletions pkg/util/upgarde.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const (
addr = "https://github.com/wencaiwulue/kubevpn/releases/latest"
)

func GetManifest(httpCli *http.Client, os string, arch string) (version string, commit string, url string, err error) {
func GetManifest(httpCli *http.Client, os string, arch string) (version string, url string, err error) {
var resp *http.Response
var errs []error
for _, addr := range address {
Expand Down Expand Up @@ -54,7 +54,6 @@ func GetManifest(httpCli *http.Client, os string, arch string) (version string,
return
}
version = m.TagName
commit = m.TargetCommitish
for _, asset := range m.Assets {
if strings.Contains(asset.Name, arch) && strings.Contains(asset.Name, os) {
url = asset.BrowserDownloadUrl
Expand Down
Loading