mirror of
https://github.com/kubesphere/kubekey.git
synced 2025-12-26 01:22:51 +00:00
fix: symbolic bug in GatherFacts function (#2411)
* fix: replace `bytes.TrimSuffix` with `bytes.TrimSpace` in HostInfo function, to avoid unexpected `\r` symbolic with different os system. * fix: replace trim function with trimSpace * fix bug
This commit is contained in:
parent
e4957a648b
commit
4261580a60
|
|
@ -120,17 +120,17 @@ func (c *localConnector) HostInfo(ctx context.Context) (map[string]any, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("get kernel version error: %w", err)
|
||||
}
|
||||
osVars[_const.VariableOSKernelVersion] = string(bytes.TrimSuffix(kernel, []byte("\n")))
|
||||
osVars[_const.VariableOSKernelVersion] = string(bytes.TrimSpace(kernel))
|
||||
hn, err := c.ExecuteCommand(ctx, "hostname")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get hostname error: %w", err)
|
||||
}
|
||||
osVars[_const.VariableOSHostName] = string(bytes.TrimSuffix(hn, []byte("\n")))
|
||||
osVars[_const.VariableOSHostName] = string(bytes.TrimSpace(hn))
|
||||
arch, err := c.ExecuteCommand(ctx, "arch")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get arch error: %w", err)
|
||||
}
|
||||
osVars[_const.VariableOSArchitecture] = string(bytes.TrimSuffix(arch, []byte("\n")))
|
||||
osVars[_const.VariableOSArchitecture] = string(bytes.TrimSpace(arch))
|
||||
|
||||
// process information
|
||||
procVars := make(map[string]any)
|
||||
|
|
|
|||
|
|
@ -158,8 +158,8 @@ func (c *sshConnector) Init(context.Context) error {
|
|||
return fmt.Errorf("env command error: %w", err)
|
||||
}
|
||||
|
||||
if strings.TrimSuffix(string(output), "\n") != "" {
|
||||
c.shell = strings.TrimSuffix(string(output), "\n")
|
||||
if strings.TrimSpace(string(output)) != "" {
|
||||
c.shell = strings.TrimSpace(string(output))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
@ -293,17 +293,17 @@ func (c *sshConnector) HostInfo(ctx context.Context) (map[string]any, error) {
|
|||
if err != nil {
|
||||
return nil, fmt.Errorf("get kernel version error: %w", err)
|
||||
}
|
||||
osVars[_const.VariableOSKernelVersion] = string(bytes.TrimSuffix(kernel, []byte("\n")))
|
||||
osVars[_const.VariableOSKernelVersion] = string(bytes.TrimSpace(kernel))
|
||||
hn, err := c.ExecuteCommand(ctx, "hostname")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get hostname error: %w", err)
|
||||
}
|
||||
osVars[_const.VariableOSHostName] = string(bytes.TrimSuffix(hn, []byte("\n")))
|
||||
osVars[_const.VariableOSHostName] = string(bytes.TrimSpace(hn))
|
||||
arch, err := c.ExecuteCommand(ctx, "arch")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("get arch error: %w", err)
|
||||
}
|
||||
osVars[_const.VariableOSArchitecture] = string(bytes.TrimSuffix(arch, []byte("\n")))
|
||||
osVars[_const.VariableOSArchitecture] = string(bytes.TrimSpace(arch))
|
||||
|
||||
// process information
|
||||
procVars := make(map[string]any)
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ func toYAML(v any) string {
|
|||
return ""
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(string(data), "\n")
|
||||
return strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
// ipInCIDR get the IP of a specific location within the cidr range
|
||||
|
|
|
|||
|
|
@ -68,7 +68,7 @@ func ParseString(ctx map[string]any, input string) (string, error) {
|
|||
}
|
||||
klog.V(6).InfoS(" parse template succeed", "result", result.String())
|
||||
|
||||
return strings.TrimPrefix(strings.TrimSuffix(result.String(), "\n"), "\n"), nil
|
||||
return strings.Trim(result.String(), "\r\n"), nil
|
||||
}
|
||||
|
||||
// IsTmplSyntax Check if the string conforms to the template syntax.
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func ModuleCommand(ctx context.Context, options ExecOptions) (string, string) {
|
|||
stderr = err.Error()
|
||||
}
|
||||
if data != nil {
|
||||
stdout = strings.TrimSuffix(string(data), "\n")
|
||||
stdout = strings.TrimSpace(string(data))
|
||||
}
|
||||
|
||||
return stdout, stderr
|
||||
|
|
|
|||
Loading…
Reference in New Issue