Skip to content

Commit

Permalink
refactor(platform): set less info when check proxy (#2073)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo Ryu committed Aug 31, 2022
1 parent 0662a39 commit 8caa439
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
21 changes: 10 additions & 11 deletions pkg/platform/provider/baremetal/validation/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package validation

import (
"context"
"encoding/base64"
"fmt"
"net"
"strings"
Expand Down Expand Up @@ -172,7 +173,7 @@ func ValidateClusterMachines(cls *platform.Cluster, fldPath *field.Path) field.E
sshproxy.Retry = 0
proxy = sshproxy
}
proxyErrs = append(proxyErrs, ValidateProxy(fldPath.Index(i), one.IP, int(one.Port), one.Username, one.Password, one.PrivateKey, one.PassPhrase, proxy)...)
proxyErrs = append(proxyErrs, ValidateProxy(fldPath.Index(i), proxy)...)
proxyResult.Checked = true
// if proxy has err, no need to check ssh
if len(proxyErrs) == 0 {
Expand All @@ -193,15 +194,15 @@ func ValidateClusterMachines(cls *platform.Cluster, fldPath *field.Path) field.E
timeResult.Checked = true
}
if _, ok := cls.Annotations[platform.AnywhereValidateAnno]; ok {
proxyResult.Name = "TunnelConnectivity"
proxyResult.Name = AnywhereValidateItemTunnelConnectivity
proxyResult.Description = "Verify Proxy Tunnel Connectivity"
proxyResult.ErrorList = proxyErrs

sshResult.Name = "SSH"
sshResult.Name = AnywhereValidateItemSSH
sshResult.Description = "Verify SSH is Available"
sshResult.ErrorList = sshErrs

timeResult.Name = "TimeDiff"
timeResult.Name = AnywhereValidateItemTimeDiff
timeResult.Description = fmt.Sprintf("Verify Clock Gap between Master nodes is not More than %d Second(s)", MaxTimeOffset)
timeResult.ErrorList = timeErrs

Expand All @@ -215,15 +216,13 @@ func ValidateClusterMachines(cls *platform.Cluster, fldPath *field.Path) field.E
return allErrs
}

func ValidateProxy(fldPath *field.Path, ip string, port int, user string, password []byte, privateKey []byte, passPhrase []byte, proxy ssh.Proxy) field.ErrorList {
func ValidateProxy(fldPath *field.Path, proxy ssh.Proxy) field.ErrorList {
allErrs := field.ErrorList{}
sshConfig := &ssh.Config{
User: user,
Host: ip,
Port: port,
Password: string(password),
PrivateKey: privateKey,
PassPhrase: passPhrase,
User: "validate",
Host: "127.0.0.1",
Port: 22,
Password: base64.StdEncoding.EncodeToString([]byte("validate")),
DialTimeOut: time.Second,
Retry: 0,
Proxy: proxy,
Expand Down
25 changes: 25 additions & 0 deletions pkg/platform/provider/baremetal/validation/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Tencent is pleased to support the open source community by making TKEStack
* available.
*
* Copyright (C) 2012-2022 Tencent. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the “License”); you may not use
* this file except in compliance with the License. You may obtain a copy of the
* License at
*
* https://opensource.org/licenses/Apache-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
* WARRANTIES OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*/

package validation

const (
AnywhereValidateItemTunnelConnectivity = "TunnelConnectivity"
AnywhereValidateItemSSH = "SSH"
AnywhereValidateItemTimeDiff = "TimeDiff"
)
2 changes: 1 addition & 1 deletion pkg/util/ssh/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (sj JumpServer) ProxyConn(targetAddr string) (net.Conn, func(), error) {
closer()
log.Errorf("proxy %s dial %s failed: %v", sj.Host, targetAddr)
} else {
log.Infof("proxy %s dial %s sucess", sj.Host, targetAddr)
log.Debugf("proxy %s dial %s sucess", sj.Host, targetAddr)
}
r := result{conn: conn, err: err}
ch <- r
Expand Down

0 comments on commit 8caa439

Please sign in to comment.