diff --git a/go.mod b/go.mod index 80fef9c71..b82a375f5 100644 --- a/go.mod +++ b/go.mod @@ -17,7 +17,7 @@ require ( github.com/nmstate/kubernetes-nmstate/api v0.0.0-20240605150941-df565dd7bf35 github.com/onsi/ginkgo/v2 v2.20.2 github.com/onsi/gomega v1.34.2 - github.com/openshift-kni/eco-goinfra v0.0.0-20241210131438-0f9dd43fb291 // latest + github.com/openshift-kni/eco-goinfra v0.0.0-20241217200120-05d41a9e26ce // latest github.com/openshift-kni/k8sreporter v1.0.6 github.com/openshift/api v3.9.1-0.20191111211345-a27ff30ebf09+incompatible github.com/openshift/cluster-nfd-operator v0.0.0-20240902145504-f70d1389d329 // release-4.17 diff --git a/go.sum b/go.sum index ee80a2993..85a5946b3 100644 --- a/go.sum +++ b/go.sum @@ -1257,8 +1257,8 @@ github.com/opencontainers/runtime-spec v1.2.0 h1:z97+pHb3uELt/yiAWD691HNHQIF07bE github.com/opencontainers/runtime-spec v1.2.0/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20240918194836-a0a3f896c283 h1:KGQuA0R53YMHkUVWVK5NcFKixjTXB/vaQswcwt3Pdy0= github.com/openshift-kni/cluster-group-upgrades-operator v0.0.0-20240918194836-a0a3f896c283/go.mod h1:TYB+3zGmMhqOmyZ6FCbtNZSndvRDcfh16U7wgYGpe/8= -github.com/openshift-kni/eco-goinfra v0.0.0-20241210131438-0f9dd43fb291 h1:LI6bBiOQTSxD6ulGxEJgO6IKTvwz7n+wxy5id2j+kbs= -github.com/openshift-kni/eco-goinfra v0.0.0-20241210131438-0f9dd43fb291/go.mod h1:T51OM/Mq7OogaCm7rBxdaaCrK8iXVh4E3FlEv8v90B4= +github.com/openshift-kni/eco-goinfra v0.0.0-20241217200120-05d41a9e26ce h1:yuN/Yw5Fq0HlITWfkmcNd2wHyPDjgJlaG5gWDbLO1Es= +github.com/openshift-kni/eco-goinfra v0.0.0-20241217200120-05d41a9e26ce/go.mod h1:T51OM/Mq7OogaCm7rBxdaaCrK8iXVh4E3FlEv8v90B4= github.com/openshift-kni/k8sreporter v1.0.6 h1:aaxDzZx3s9bo1I3nopR63RGVZxcJgR94j5X87aDihYo= github.com/openshift-kni/k8sreporter v1.0.6/go.mod h1:tX6LOg0m0oXje7WNLFo8LKHC9Ix8VV0a7vUc6eyeFBQ= github.com/openshift-kni/lifecycle-agent v0.0.0-20241002223755-1e32b456449f h1:2k35EoDXvfOx/pgQKaBp2DkbBvMUBi+LuGATTH0El+U= diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmc/bmc.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmc/bmc.go index 074df2851..813160d8b 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmc/bmc.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/bmc/bmc.go @@ -64,7 +64,7 @@ type BMC struct { systemIndex int powerControlIndex int - sshSessionForSerialConsole *ssh.Session + sshClientForSerialConsole *ssh.Client errorMsg string } @@ -747,52 +747,6 @@ func (bmc *BMC) SetSystemBootOrderReferences(bootOrderReferences []string) error return system.SetBoot(newBoot) } -// CreateCLISSHSession creates a ssh Session to the host. -func (bmc *BMC) CreateCLISSHSession() (*ssh.Session, error) { - if valid, err := bmc.validateSSH(); !valid { - return nil, err - } - - glog.V(100).Infof("Creating SSH session to run commands in the BMC's CLI.") - - config := &ssh.ClientConfig{ - User: bmc.sshUser.Name, - Auth: []ssh.AuthMethod{ - ssh.Password(bmc.sshUser.Password), - ssh.KeyboardInteractive(func(user, instruction string, questions []string, - echos []bool) (answers []string, err error) { - answers = make([]string, len(questions)) - // The second parameter is unused - for n := range questions { - answers[n] = bmc.sshUser.Password - } - - return answers, nil - }), - }, - Timeout: bmc.timeOuts.SSH, - HostKeyCallback: ssh.InsecureIgnoreHostKey(), - } - - // Establish SSH connection - client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", bmc.host, bmc.sshPort), config) - if err != nil { - glog.V(100).Infof("Failed to connect to BMC's SSH server: %v", err) - - return nil, fmt.Errorf("failed to connect to BMC's SSH server: %w", err) - } - - // Create a session - session, err := client.NewSession() - if err != nil { - glog.V(100).Infof("Failed to create a new SSH session: %v", err) - - return nil, fmt.Errorf("failed to create a new ssh session: %w", err) - } - - return session, nil -} - // RunCLICommand runs a CLI command in the BMC's console over SSH. This method will block until the command has // finished, and its output is copied to stdout and/or stderr if applicable. If combineOutput is true, stderr content is // merged in stdout. The timeout param is used to avoid the caller to be stuck forever in case something goes wrong or @@ -805,14 +759,21 @@ func (bmc *BMC) RunCLICommand( glog.V(100).Infof("Running CLI command in BMC's CLI: %s", cmd) - sshSession, err := bmc.CreateCLISSHSession() + client, err := bmc.createCLISSHClient() if err != nil { glog.V(100).Infof("Failed to connect to CLI: %v", err) return "", "", fmt.Errorf("failed to connect to CLI: %w", err) } + // Create a session + sshSession, err := client.NewSession() + if err != nil { + glog.V(100).Infof("Failed to create a new SSH session: %v", err) + + return "", "", fmt.Errorf("failed to create a new ssh session: %w", err) + } - defer sshSession.Close() + defer client.Close() var stdoutBuffer, stderrBuffer bytes.Buffer if !combineOutput { @@ -859,6 +820,8 @@ func (bmc *BMC) RunCLICommand( // opened in the BMC's ssh server. If openConsoleCliCmd is provided, it will be sent to the BMC's cli. Otherwise, a best // effort will be made to run the appropriate cli command based on the system manufacturer. This method requires both a // Redfish and SSH user configured. +// +//nolint:funlen func (bmc *BMC) OpenSerialConsole(openConsoleCliCmd string) (io.Reader, io.WriteCloser, error) { // We use both Redfish and SSH so make sure both are valid before continuing. if valid, err := bmc.validateRedfish(); !valid { @@ -871,7 +834,7 @@ func (bmc *BMC) OpenSerialConsole(openConsoleCliCmd string) (io.Reader, io.Write glog.V(100).Infof("Opening serial console on %v.", bmc.host) - if bmc.sshSessionForSerialConsole != nil { + if bmc.sshClientForSerialConsole != nil { glog.V(100).Infof("There is already a serial console opened for %v's BMC. Use OpenSerialConsole() first.", bmc.host) @@ -898,19 +861,27 @@ func (bmc *BMC) OpenSerialConsole(openConsoleCliCmd string) (io.Reader, io.Write } } - sshSession, err := bmc.CreateCLISSHSession() + client, err := bmc.createCLISSHClient() if err != nil { glog.V(100).Infof("Failed to create underlying ssh session for %v: %v", bmc.host, err) return nil, nil, fmt.Errorf("failed to create underlying ssh session for %v: %w", bmc.host, err) } + // Create a session + sshSession, err := client.NewSession() + if err != nil { + glog.V(100).Infof("Failed to create a new SSH session: %v", err) + + return nil, nil, fmt.Errorf("failed to create a new ssh session: %w", err) + } + // Pipes need to be retrieved before session.Start() reader, err := sshSession.StdoutPipe() if err != nil { glog.V(100).Infof("Failed to get stdout pipe from %v's ssh session: %v", bmc.host, err) - _ = sshSession.Close() + _ = client.Close() return nil, nil, fmt.Errorf("failed to get stdout pipe from %v's ssh session: %w", bmc.host, err) } @@ -919,7 +890,7 @@ func (bmc *BMC) OpenSerialConsole(openConsoleCliCmd string) (io.Reader, io.Write if err != nil { glog.V(100).Infof("Failed to get stdin pipe from from %v's ssh session: %w", bmc.host, err) - _ = sshSession.Close() + _ = client.Close() return nil, nil, fmt.Errorf("failed to get stdin pipe from %v's ssh session: %w", bmc.host, err) } @@ -928,15 +899,13 @@ func (bmc *BMC) OpenSerialConsole(openConsoleCliCmd string) (io.Reader, io.Write if err != nil { glog.V(100).Infof("Failed to start CLI command %q on %v: %v", openConsoleCliCmd, bmc.host, err) - _ = sshSession.Close() + _ = client.Close() return nil, nil, fmt.Errorf( "failed to start serial console with cli command %q on %v: %w", openConsoleCliCmd, bmc.host, err) } - go func() { _ = sshSession.Wait() }() - - bmc.sshSessionForSerialConsole = sshSession + bmc.sshClientForSerialConsole = client return reader, writer, nil } @@ -949,20 +918,20 @@ func (bmc *BMC) CloseSerialConsole() error { glog.V(100).Infof("Closing serial console for %v.", bmc.host) - if bmc.sshSessionForSerialConsole == nil { + if bmc.sshClientForSerialConsole == nil { glog.V(100).Infof("No underlying ssh session found for %v. Please use OpenSerialConsole() first.", bmc.host) return fmt.Errorf("no underlying ssh session found for %v", bmc.host) } - err := bmc.sshSessionForSerialConsole.Close() + err := bmc.sshClientForSerialConsole.Close() if err != nil { glog.V(100).Infof("Failed to close underlying ssh session for %v: %v", bmc.host, err) return fmt.Errorf("failed to close underlying ssh session for %v: %w", bmc.host, err) } - bmc.sshSessionForSerialConsole = nil + bmc.sshClientForSerialConsole = nil return nil } @@ -1131,3 +1100,41 @@ func (bmc *BMC) getSupportedResetTypes() ([]redfish.ResetType, error) { return system.SupportedResetTypes, nil } + +// createCLISSHClient creates a ssh Session to the host. +func (bmc *BMC) createCLISSHClient() (*ssh.Client, error) { + if valid, err := bmc.validateSSH(); !valid { + return nil, err + } + + glog.V(100).Infof("Creating SSH session to run commands in the BMC's CLI.") + + config := &ssh.ClientConfig{ + User: bmc.sshUser.Name, + Auth: []ssh.AuthMethod{ + ssh.Password(bmc.sshUser.Password), + ssh.KeyboardInteractive(func(user, instruction string, questions []string, + echos []bool) (answers []string, err error) { + answers = make([]string, len(questions)) + // The second parameter is unused + for n := range questions { + answers[n] = bmc.sshUser.Password + } + + return answers, nil + }), + }, + Timeout: bmc.timeOuts.SSH, + HostKeyCallback: ssh.InsecureIgnoreHostKey(), + } + + // Establish SSH connection + client, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", bmc.host, bmc.sshPort), config) + if err != nil { + glog.V(100).Infof("Failed to connect to BMC's SSH server: %v", err) + + return nil, fmt.Errorf("failed to connect to BMC's SSH server: %w", err) + } + + return client, nil +} diff --git a/vendor/github.com/openshift-kni/eco-goinfra/pkg/namespace/namespace.go b/vendor/github.com/openshift-kni/eco-goinfra/pkg/namespace/namespace.go index 411b33ca8..e5d9a7cab 100644 --- a/vendor/github.com/openshift-kni/eco-goinfra/pkg/namespace/namespace.go +++ b/vendor/github.com/openshift-kni/eco-goinfra/pkg/namespace/namespace.go @@ -179,6 +179,10 @@ func (builder *Builder) Delete() error { glog.V(100).Infof("Deleting namespace %s", builder.Definition.Name) if !builder.Exists() { + glog.V(100).Infof("Namespace %s does not exist", builder.Definition.Name) + + builder.Object = nil + return nil } @@ -212,6 +216,10 @@ func (builder *Builder) DeleteAndWait(timeout time.Duration) error { return true, nil } + if err != nil { + glog.V(100).Infof("Failed to get namespace %s: %v", builder.Definition.Name, err) + } + return false, nil }) } diff --git a/vendor/modules.txt b/vendor/modules.txt index 8a90855db..0d2177294 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -564,7 +564,7 @@ github.com/opencontainers/runtime-spec/specs-go ## explicit; go 1.22.0 github.com/openshift-kni/cluster-group-upgrades-operator/pkg/api/clustergroupupgrades github.com/openshift-kni/cluster-group-upgrades-operator/pkg/api/clustergroupupgrades/v1alpha1 -# github.com/openshift-kni/eco-goinfra v0.0.0-20241210131438-0f9dd43fb291 +# github.com/openshift-kni/eco-goinfra v0.0.0-20241217200120-05d41a9e26ce ## explicit; go 1.23 github.com/openshift-kni/eco-goinfra/pkg/apiservers github.com/openshift-kni/eco-goinfra/pkg/argocd