mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-25 17:12:50 +00:00
bugfix : fix issue 6796 (#2752)
bugfix : fix bug 6796 bugfix : fix bug 6796 bugfix : fix bug 6796 bugfix : fix issue 6796 Signed-off-by: xuesongzuo@yunify.com <xuesongzuo@yunify.com>
This commit is contained in:
parent
602afffcfa
commit
3d1461f8ce
|
|
@ -164,6 +164,17 @@ type SchemaTable struct {
|
|||
Playbook map[string]SchemaTablePlaybook `json:"playbook"` // Map of playbook labels to playbook details
|
||||
}
|
||||
|
||||
// InventoryConnect only use for list ip connect check
|
||||
type InventoryConnect struct {
|
||||
Connector InventoryConnectHostPort `json:"connector"`
|
||||
}
|
||||
|
||||
// InventoryConnectHostPort only use for list ip connect check ,show connector host and port
|
||||
type InventoryConnectHostPort struct {
|
||||
Host string `json:"host"`
|
||||
Port string `json:"port"`
|
||||
}
|
||||
|
||||
// IPTable represents an IP address entry and its SSH status information.
|
||||
// It indicates whether the IP is a localhost, if SSH is reachable, and if SSH authorization is present.
|
||||
type IPTable struct {
|
||||
|
|
@ -172,6 +183,7 @@ type IPTable struct {
|
|||
Localhost bool `json:"localhost"` // Whether the IP is a localhost IP
|
||||
SSHReachable bool `json:"sshReachable"` // Whether SSH port is reachable on this IP
|
||||
SSHAuthorized bool `json:"sshAuthorized"` // Whether SSH is authorized for this IP
|
||||
Added bool `json:"added"` // Indicates whether this IP has already been added to the inventory
|
||||
}
|
||||
|
||||
// SchemaFile2Table converts a SchemaFile and its filename into a SchemaTable structure.
|
||||
|
|
|
|||
|
|
@ -190,6 +190,30 @@ func (h ResourceHandler) ListIP(request *restful.Request, response *restful.Resp
|
|||
cidr := request.QueryParameter("cidr")
|
||||
sshPort := query.DefaultString(request.QueryParameter("sshPort"), "22")
|
||||
|
||||
var existsInventoryList kkcorev1.InventoryList
|
||||
err := h.client.List(request.Request.Context(), &existsInventoryList)
|
||||
|
||||
if err != nil && ctrlclient.IgnoreNotFound(err) != nil {
|
||||
klog.Errorf("failed to list inventory objects: %v", err)
|
||||
_ = response.WriteError(http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
var addedPorts = make(map[string]struct{})
|
||||
for _, item := range existsInventoryList.Items {
|
||||
for _, iData := range item.Spec.Hosts {
|
||||
var iHost api.InventoryConnect
|
||||
err = json.Unmarshal(iData.Raw, &iHost)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
if iHost.Connector.Port == "" {
|
||||
iHost.Connector.Port = "22"
|
||||
}
|
||||
addedPorts[iHost.Connector.Host+":"+iHost.Connector.Port] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
ips := utils.ParseIP(cidr)
|
||||
ipTable := make([]api.IPTable, 0, len(ips))
|
||||
maxConcurrency := 20
|
||||
|
|
@ -202,12 +226,17 @@ func (h ResourceHandler) ListIP(request *restful.Request, response *restful.Resp
|
|||
for ip := range jobChannel {
|
||||
if utils.IsLocalhostIP(ip) {
|
||||
mu.Lock()
|
||||
var added = false
|
||||
if _, ok := addedPorts[ip+":"+sshPort]; ok {
|
||||
added = true
|
||||
}
|
||||
ipTable = append(ipTable, api.IPTable{
|
||||
IP: ip,
|
||||
SSHPort: sshPort,
|
||||
Localhost: true,
|
||||
SSHReachable: true,
|
||||
SSHAuthorized: true,
|
||||
Added: added,
|
||||
})
|
||||
mu.Unlock()
|
||||
continue
|
||||
|
|
|
|||
Loading…
Reference in New Issue