Skip to content

Commit

Permalink
Merge pull request #81 from steadybit/fix/dont-exclude-unused-health-…
Browse files Browse the repository at this point in the history
…port

Fix/dont exclude unused health port
  • Loading branch information
joshiste authored Jul 16, 2024
2 parents 349d710 + 6f241d0 commit ec1d43f
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
36 changes: 33 additions & 3 deletions exthost/action_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/steadybit/extension-kit"
"github.com/steadybit/extension-kit/extutil"
"net"
"strings"
)

type networkOptsProvider func(ctx context.Context, sidecar network.SidecarOpts, request action_kit_api.PrepareActionRequestBody) (network.Opts, error)
Expand Down Expand Up @@ -205,6 +206,9 @@ func mapToNetworkFilter(ctx context.Context, r runc.Runc, sidecar network.Sideca
}

includes := network.NewNetWithPortRanges(includeCidrs, portRanges...)
for _, i := range includes {
i.Comment = "parameters"
}
var excludes []network.NetWithPortRange

for _, restrictedEndpoint := range restrictedEndpoints {
Expand All @@ -213,7 +217,22 @@ func mapToNetworkFilter(ctx context.Context, r runc.Runc, sidecar network.Sideca
if err != nil {
return network.Filter{}, fmt.Errorf("invalid cidr %s: %w", restrictedEndpoint.Cidr, err)
}
excludes = append(excludes, network.NewNetWithPortRanges([]net.IPNet{*cidr}, network.PortRange{From: uint16(restrictedEndpoint.PortMin), To: uint16(restrictedEndpoint.PortMax)})...)
nwps := network.NewNetWithPortRanges([]net.IPNet{*cidr}, network.PortRange{From: uint16(restrictedEndpoint.PortMin), To: uint16(restrictedEndpoint.PortMax)})
for _, n := range nwps {
var sb strings.Builder
sb.WriteString("restricted-endpoint ")
if restrictedEndpoint.Name != "" {
sb.WriteString(restrictedEndpoint.Name)
sb.WriteString(" ")
}
if restrictedEndpoint.Url != "" {
sb.WriteString(restrictedEndpoint.Url)
sb.WriteString(" ")
}
n.Comment = sb.String()
}

excludes = append(excludes, nwps...)
}

ownIps := network.GetOwnIPs()
Expand All @@ -222,8 +241,19 @@ func mapToNetworkFilter(ctx context.Context, r runc.Runc, sidecar network.Sideca
nets := network.IpsToNets(ownIps)

log.Debug().Msgf("Adding own ip %s to exclude list (Ports %d and %d)", ownIps, ownPort, ownHealthPort)
excludes = append(excludes, network.NewNetWithPortRanges(nets, network.PortRange{From: ownPort, To: ownPort})...)
excludes = append(excludes, network.NewNetWithPortRanges(nets, network.PortRange{From: ownHealthPort, To: ownHealthPort})...)
excludePort := network.NewNetWithPortRanges(nets, network.PortRange{From: ownPort, To: ownPort})
for _, n := range excludePort {
n.Comment = "extension own-port"
}
excludes = append(excludes, excludePort...)

if ownHealthPort > 0 && ownHealthPort != ownPort {
excludeHeathPort := network.NewNetWithPortRanges(nets, network.PortRange{From: ownHealthPort, To: ownHealthPort})
for _, n := range excludePort {
n.Comment = "extension health-port"
}
excludes = append(excludes, excludeHeathPort...)
}

return network.Filter{
Include: includes,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.33.0
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.0
github.com/steadybit/action-kit/go/action_kit_commons v1.2.2
github.com/steadybit/action-kit/go/action_kit_commons v1.2.3
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.9
github.com/steadybit/action-kit/go/action_kit_test v1.2.15
github.com/steadybit/discovery-kit/go/discovery_kit_api v1.5.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An
github.com/spkg/bom v0.0.0-20160624110644-59b7046e48ad/go.mod h1:qLr4V1qq6nMqFKkMo8ZTx3f+BZEkzsRUY10Xsm2mwU0=
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.0 h1:8whTfgk0UpNVj/d0hrXmW+mgAN0HUAvaafMW+yPHbqA=
github.com/steadybit/action-kit/go/action_kit_api/v2 v2.9.0/go.mod h1:VvrWrWS4lFAmtlYW06wY1G8+L9gbw/Tq0HDceSN21M8=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.2 h1:mKUgQRtqSZghaWLpN3UiqxY9hiu/AmU8FZIafCMJexg=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.2/go.mod h1:oayHOMwS2sC2UbL9xJDT8oHWuji9wrJ51JDjDaf9lVI=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.3 h1:oauHpRWekLW7uHHYzad/2wzhkMjUPJvBUSsUXYszMgU=
github.com/steadybit/action-kit/go/action_kit_commons v1.2.3/go.mod h1:oayHOMwS2sC2UbL9xJDT8oHWuji9wrJ51JDjDaf9lVI=
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.9 h1:EZCQA7FWxyWpA6du9Kt/5PMAZ2JXn9s1twWHuh8DMQo=
github.com/steadybit/action-kit/go/action_kit_sdk v1.1.9/go.mod h1:doeEvG/3OQSd3Xvb4UvWpnwmY3VT+Pf9f6NfxV5i2rU=
github.com/steadybit/action-kit/go/action_kit_test v1.2.15 h1:A9FrK5jthzjhPzBRDeAZbCfgoFkEO3q654kFvyjD07o=
Expand Down

0 comments on commit ec1d43f

Please sign in to comment.