-
Notifications
You must be signed in to change notification settings - Fork 1.5k
OCPBUGS-60993: Enrich IBI config image proxy NoProxy with cluster networks #10543
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||||||||||||||||||||||||||||
| package types | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||
| "strings" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| "k8s.io/apimachinery/pkg/util/sets" | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| // BuildNoProxySet creates a set of NoProxy entries from networking configuration. | ||||||||||||||||||||||||||||||||
| // It includes localhost entries (.svc, .cluster.local, 127.0.0.1, localhost), | ||||||||||||||||||||||||||||||||
| // all network CIDRs (cluster, service, machine), and user-provided NoProxy values. | ||||||||||||||||||||||||||||||||
| // The caller can add platform-specific and API-server entries as needed. | ||||||||||||||||||||||||||||||||
| func BuildNoProxySet(networking *Networking, userNoProxy string) sets.String { | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is causing a diagnostic: |
||||||||||||||||||||||||||||||||
| set := sets.NewString( | ||||||||||||||||||||||||||||||||
| "127.0.0.1", | ||||||||||||||||||||||||||||||||
| "localhost", | ||||||||||||||||||||||||||||||||
| ".svc", | ||||||||||||||||||||||||||||||||
| ".cluster.local", | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for _, network := range networking.ServiceNetwork { | ||||||||||||||||||||||||||||||||
| set.Insert(network.String()) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for _, network := range networking.MachineNetwork { | ||||||||||||||||||||||||||||||||
| set.Insert(network.CIDR.String()) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for _, network := range networking.ClusterNetwork { | ||||||||||||||||||||||||||||||||
| set.Insert(network.CIDR.String()) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for _, userValue := range strings.Split(userNoProxy, ",") { | ||||||||||||||||||||||||||||||||
| trimmed := strings.TrimSpace(userValue) | ||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is new. Intentional? If yes please call it out in the commit message and justify
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also must match CNO behavior |
||||||||||||||||||||||||||||||||
| if trimmed != "" { | ||||||||||||||||||||||||||||||||
| set.Insert(trimmed) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
|
Comment on lines
+33
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preserve
Suggested fix func BuildNoProxySet(networking *Networking, userNoProxy string) sets.String {
set := sets.NewString(
"127.0.0.1",
"localhost",
".svc",
".cluster.local",
)
for _, network := range networking.ServiceNetwork {
set.Insert(network.String())
}
for _, network := range networking.MachineNetwork {
set.Insert(network.CIDR.String())
}
for _, network := range networking.ClusterNetwork {
set.Insert(network.CIDR.String())
}
for _, userValue := range strings.Split(userNoProxy, ",") {
trimmed := strings.TrimSpace(userValue)
+ if trimmed == "*" {
+ return sets.NewString("*")
+ }
if trimmed != "" {
set.Insert(trimmed)
}
}
return set
}Please add a regression case for 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| return set | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| package types | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
|
|
||
| "github.com/openshift/installer/pkg/ipnet" | ||
| ) | ||
|
|
||
| func TestBuildNoProxySet(t *testing.T) { | ||
| cases := []struct { | ||
| name string | ||
| networking *Networking | ||
| userNoProxy string | ||
| expected []string | ||
| }{ | ||
| { | ||
| name: "empty networking and no user entries", | ||
| networking: &Networking{}, | ||
| userNoProxy: "", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local"}, | ||
| }, | ||
| { | ||
| name: "service network entries are included", | ||
| networking: &Networking{ | ||
| ServiceNetwork: []ipnet.IPNet{ | ||
| *ipnet.MustParseCIDR("172.30.0.0/16"), | ||
| }, | ||
| }, | ||
| userNoProxy: "", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "172.30.0.0/16"}, | ||
| }, | ||
| { | ||
| name: "machine network entries are included", | ||
| networking: &Networking{ | ||
| MachineNetwork: []MachineNetworkEntry{ | ||
| {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, | ||
| }, | ||
| }, | ||
| userNoProxy: "", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "10.0.0.0/16"}, | ||
| }, | ||
| { | ||
| name: "cluster network entries are included", | ||
| networking: &Networking{ | ||
| ClusterNetwork: []ClusterNetworkEntry{ | ||
| {CIDR: *ipnet.MustParseCIDR("10.128.0.0/14")}, | ||
| }, | ||
| }, | ||
| userNoProxy: "", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "10.128.0.0/14"}, | ||
| }, | ||
| { | ||
| name: "single user no-proxy entry is included", | ||
| networking: &Networking{}, | ||
| userNoProxy: "example.com", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "example.com"}, | ||
| }, | ||
| { | ||
| name: "multiple comma-separated user entries are included", | ||
| networking: &Networking{}, | ||
| userNoProxy: "example.com,internal.corp,192.168.1.0/24", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "example.com", "internal.corp", "192.168.1.0/24"}, | ||
| }, | ||
| { | ||
| name: "user entries with surrounding whitespace are trimmed", | ||
| networking: &Networking{}, | ||
| userNoProxy: " example.com , internal.corp ", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "example.com", "internal.corp"}, | ||
| }, | ||
| { | ||
| name: "empty segments in user no-proxy are ignored", | ||
| networking: &Networking{}, | ||
| userNoProxy: "example.com,,internal.corp,", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "example.com", "internal.corp"}, | ||
| }, | ||
| { | ||
| name: "all network types and user entries combined", | ||
| networking: &Networking{ | ||
| ServiceNetwork: []ipnet.IPNet{ | ||
| *ipnet.MustParseCIDR("172.30.0.0/16"), | ||
| }, | ||
| MachineNetwork: []MachineNetworkEntry{ | ||
| {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, | ||
| }, | ||
| ClusterNetwork: []ClusterNetworkEntry{ | ||
| {CIDR: *ipnet.MustParseCIDR("10.128.0.0/14")}, | ||
| }, | ||
| }, | ||
| userNoProxy: "example.com", | ||
| expected: []string{ | ||
| "127.0.0.1", "localhost", ".svc", ".cluster.local", | ||
| "172.30.0.0/16", "10.0.0.0/16", "10.128.0.0/14", "example.com", | ||
| }, | ||
| }, | ||
| { | ||
| name: "duplicate user entry matching a built-in entry is deduplicated", | ||
| networking: &Networking{ | ||
| ServiceNetwork: []ipnet.IPNet{ | ||
| *ipnet.MustParseCIDR("172.30.0.0/16"), | ||
| }, | ||
| }, | ||
| userNoProxy: "172.30.0.0/16,localhost", | ||
| expected: []string{"127.0.0.1", "localhost", ".svc", ".cluster.local", "172.30.0.0/16"}, | ||
| }, | ||
| { | ||
| name: "multiple entries in each network type", | ||
| networking: &Networking{ | ||
| ServiceNetwork: []ipnet.IPNet{ | ||
| *ipnet.MustParseCIDR("172.30.0.0/16"), | ||
| *ipnet.MustParseCIDR("fd02::/112"), | ||
| }, | ||
| MachineNetwork: []MachineNetworkEntry{ | ||
| {CIDR: *ipnet.MustParseCIDR("10.0.0.0/16")}, | ||
| {CIDR: *ipnet.MustParseCIDR("fd00::/48")}, | ||
| }, | ||
| ClusterNetwork: []ClusterNetworkEntry{ | ||
| {CIDR: *ipnet.MustParseCIDR("10.128.0.0/14")}, | ||
| {CIDR: *ipnet.MustParseCIDR("fd01::/48")}, | ||
| }, | ||
| }, | ||
| userNoProxy: "", | ||
| expected: []string{ | ||
| "127.0.0.1", "localhost", ".svc", ".cluster.local", | ||
| "172.30.0.0/16", "fd02::/112", "10.0.0.0/16", "fd00::/48", "10.128.0.0/14", "fd01::/48", | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range cases { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| result := BuildNoProxySet(tc.networking, tc.userNoProxy) | ||
| assert.ElementsMatch(t, tc.expected, result.List()) | ||
| }) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should call out which specific "Networking configuration" we're expecting here, gives better context on what's happening