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:
zuoxuesong-worker 2025-09-08 11:07:36 +08:00 committed by GitHub
parent 602afffcfa
commit 3d1461f8ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 41 additions and 0 deletions

View File

@ -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.

View File

@ -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