Skip to content

Commit

Permalink
Merge pull request #8198 from jandubois/guestagent-utils
Browse files Browse the repository at this point in the history
Clean up guestagent/utils package
  • Loading branch information
Nino-K authored Feb 7, 2025
2 parents 2436820 + f5b78ad commit 8f19eaa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/actions/spelling/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ clustertemplates
cmds
CNCF
cni
cnutils
codeql
commandline
commitish
Expand Down
18 changes: 9 additions & 9 deletions src/go/guestagent/pkg/containerd/events_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ import (
"github.com/Masterminds/log-go"
"github.com/containerd/containerd"
"github.com/containerd/containerd/api/events"
containerdNamespace "github.com/containerd/containerd/namespaces"
"github.com/containernetworking/plugins/pkg/utils"
"github.com/containerd/containerd/namespaces"
cnutils "github.com/containernetworking/plugins/pkg/utils"
"github.com/docker/go-connections/nat"
"github.com/rancher-sandbox/rancher-desktop/src/go/guestagent/pkg/tracker"
rdUtils "github.com/rancher-sandbox/rancher-desktop/src/go/guestagent/pkg/utils"
"github.com/rancher-sandbox/rancher-desktop/src/go/guestagent/pkg/utils"
"google.golang.org/protobuf/proto"
)

Expand All @@ -57,7 +57,7 @@ func NewEventMonitor(
containerdSock string,
portTracker tracker.Tracker,
) (*EventMonitor, error) {
client, err := containerd.New(containerdSock, containerd.WithDefaultNamespace(containerdNamespace.Default))
client, err := containerd.New(containerdSock, containerd.WithDefaultNamespace(namespaces.Default))
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -311,7 +311,7 @@ func execIptablesRules(ctx context.Context, portMappings nat.PortMap, containerI
}

if len(errs) != 0 {
return fmt.Errorf("%w: %+v", rdUtils.ErrExecIptablesRule, errs)
return fmt.Errorf("%w: %+v", utils.ErrExecIptablesRule, errs)
}

return nil
Expand Down Expand Up @@ -345,7 +345,7 @@ func createLoopbackIPtablesRules(ctx context.Context, networks []string, contain

// Run the rule per network
for _, network := range networks {
chainName := utils.MustFormatChainNameWithPrefix(network, cID, "DN-")
chainName := cnutils.MustFormatChainNameWithPrefix(network, cID, "DN-")

// Instead of modifying the existing rule, a new rule is added that overrides the previous one.
// The original rule only allows traffic from anywhere to localhost, but the new rule permits traffic
Expand Down Expand Up @@ -402,7 +402,7 @@ func createPortMappingFromString(portMapping string) (nat.PortMap, error) {
}

portBinding := nat.PortBinding{
HostIP: rdUtils.NormalizeHostIP(port.HostIP),
HostIP: utils.NormalizeHostIP(port.HostIP),
HostPort: strconv.Itoa(port.HostPort),
}
if pb, ok := portMap[portMapKey]; ok {
Expand All @@ -423,12 +423,12 @@ func extractIPAddress(pid string) (string, error) {
return "", err
}
// Regular expression pattern to match the IP address
rx := regexp.MustCompile(`\binet\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\/\d{1,2}`)
rx := regexp.MustCompile(`\binet\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})/\d{1,2}`)

matches := rx.FindStringSubmatch(string(output))
segments := 2
if len(matches) < segments {
return "", rdUtils.ErrIPAddressNotFound
return "", utils.ErrIPAddressNotFound
}

return matches[1], nil
Expand Down
File renamed without changes.

0 comments on commit 8f19eaa

Please sign in to comment.