Skip to content

Commit

Permalink
fix: code improve
Browse files Browse the repository at this point in the history
Signed-off-by: imneov <grantliu@yunify.com>
  • Loading branch information
imneov committed Mar 8, 2022
1 parent ba4b3cb commit b37fb1b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions pkg/kubernetes/portforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func NewPortForward(
) (*PortForward, error) {
client, err := k8s.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("can't creat Clientset: %s", deployName)
return nil, fmt.Errorf("can't create Clientset for %q", deployName)
}

podList, err := ListPods(client, namespace, nil)
Expand Down Expand Up @@ -100,7 +100,7 @@ func NewPortForward(
func (pf *PortForward) Init() error {
transport, upgrader, err := spdy.RoundTripperFor(pf.Config)
if err != nil {
return fmt.Errorf("can't connect to a Kubernetes cluster: %v", err)
return fmt.Errorf("can not connect to Kubernetes cluster: %w", err)
}

out := ioutil.Discard
Expand All @@ -115,7 +115,7 @@ func (pf *PortForward) Init() error {

fw, err := portforward.NewOnAddresses(dialer, []string{pf.Host}, ports, pf.StopCh, pf.ReadyCh, out, errOut)
if err != nil {
return fmt.Errorf("can't creat PortForwarder: %w", err)
return fmt.Errorf("can not create PortForwarder: %w", err)
}

failure := make(chan error)
Expand All @@ -126,14 +126,14 @@ func (pf *PortForward) Init() error {
}()

select {
// if `pf.run()` succeeds, block until terminated
// if `fw.ForwardPorts()` succeeds, block until terminated
case <-pf.ReadyCh:
ports, err := fw.GetPorts()
if err != nil {
return fmt.Errorf("can't get the ports that were forwarded: %w", err)
}
if len(ports) == 0 {
return fmt.Errorf("error ports length")
return fmt.Errorf("can not get the ports that were forwarded: error getting ports length")
}

pf.LocalPort = int(ports[0].Local)
Expand Down

0 comments on commit b37fb1b

Please sign in to comment.