Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable protogetter linter and fix up issues #2229

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ linters:
# - nlreturn
- noctx
- nolintlint
- protogetter
# - rowserrcheck
# - scopelint
# - sqlclosecheck
Expand Down
2 changes: 1 addition & 1 deletion pkg/guestagent/api/ipport.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ import (
)

func (x *IPPort) HostString() string {
return net.JoinHostPort(x.Ip, strconv.Itoa(int(x.Port)))
return net.JoinHostPort(x.GetIp(), strconv.Itoa(int(x.GetPort())))
}
2 changes: 1 addition & 1 deletion pkg/hostagent/hostagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ func (a *HostAgent) processGuestAgentEvents(ctx context.Context, client *guestag

onEvent := func(ev *guestagentapi.Event) {
logrus.Debugf("guest agent event: %+v", ev)
for _, f := range ev.Errors {
for _, f := range ev.GetErrors() {
logrus.Warnf("received error from the guest: %q", f)
}
a.portForwarder.OnEvent(ctx, ev)
Expand Down
18 changes: 10 additions & 8 deletions pkg/hostagent/port.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,24 @@ func hostAddress(rule limayaml.PortForward, guest *api.IPPort) string {
return rule.HostSocket
}
host := &api.IPPort{Ip: rule.HostIP.String()}
if guest.Port == 0 {
port := guest.GetPort()
if port == 0 {
// guest is a socket
host.Port = int32(rule.HostPort)
} else {
host.Port = guest.Port + int32(rule.HostPortRange[0]-rule.GuestPortRange[0])
host.Port = port + int32(rule.HostPortRange[0]-rule.GuestPortRange[0])
}
return host.HostString()
}

func (pf *portForwarder) forwardingAddresses(guest *api.IPPort) (hostAddr, guestAddr string) {
guestIP := net.ParseIP(guest.Ip)
guestIP := net.ParseIP(guest.GetIp())
for _, rule := range pf.rules {
if rule.GuestSocket != "" {
continue
}
if guest.Port < int32(rule.GuestPortRange[0]) || guest.Port > int32(rule.GuestPortRange[1]) {
port := int(guest.GetPort())
if port < rule.GuestPortRange[0] || port > rule.GuestPortRange[1] {
continue
}
switch {
Expand All @@ -75,25 +77,25 @@ func (pf *portForwarder) forwardingAddresses(guest *api.IPPort) (hostAddr, guest
}

func (pf *portForwarder) OnEvent(ctx context.Context, ev *api.Event) {
for _, f := range ev.LocalPortsRemoved {
for _, f := range ev.GetLocalPortsRemoved() {
local, remote := pf.forwardingAddresses(f)
if local == "" {
continue
}
logrus.Infof("Stopping forwarding TCP from %s to %s", remote, local)
if err := forwardTCP(ctx, pf.sshConfig, pf.sshHostPort, local, remote, verbCancel); err != nil {
logrus.WithError(err).Warnf("failed to stop forwarding tcp port %d", f.Port)
logrus.WithError(err).Warnf("failed to stop forwarding tcp port %d", f.GetPort())
}
}
for _, f := range ev.LocalPortsAdded {
for _, f := range ev.GetLocalPortsAdded() {
local, remote := pf.forwardingAddresses(f)
if local == "" {
logrus.Infof("Not forwarding TCP %s", remote)
continue
}
logrus.Infof("Forwarding TCP from %s to %s", remote, local)
if err := forwardTCP(ctx, pf.sshConfig, pf.sshHostPort, local, remote, verbForward); err != nil {
logrus.WithError(err).Warnf("failed to set up forwarding tcp port %d (negligible if already forwarded)", f.Port)
logrus.WithError(err).Warnf("failed to set up forwarding tcp port %d (negligible if already forwarded)", f.GetPort())
}
}
}
Loading