Skip to content

Commit 2a8322a

Browse files
committed
OCPBUGS-60873: Prevent duplicate noProxy when adding nodes
A cluster may have duplicate CIDR entries in the noProxy string. This only causes a problem when adding nodes, a validation in assisted will detect the duplicate and fail the add node. This fix detects duplicate entries and removes them.
1 parent f07db8d commit 2a8322a

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

pkg/asset/agent/joiner/clusterinfo.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,13 @@ func (ci *ClusterInfo) retrieveProxy() error {
204204
if err != nil {
205205
return err
206206
}
207+
// Remove any duplicates in noProxy
208+
noProxy := ci.removeDuplicates(proxy.Spec.NoProxy)
209+
207210
ci.Proxy = &types.Proxy{
208211
HTTPProxy: proxy.Spec.HTTPProxy,
209212
HTTPSProxy: proxy.Spec.HTTPSProxy,
210-
NoProxy: proxy.Spec.NoProxy,
213+
NoProxy: noProxy,
211214
}
212215

213216
return nil
@@ -688,3 +691,31 @@ func (ci *ClusterInfo) reportResult(ctx context.Context) error {
688691

689692
return workflowreport.GetReport(ctx).StageResult(workflow.StageClusterInspection, string(data))
690693
}
694+
695+
func (ci *ClusterInfo) removeDuplicates(input string) string {
696+
entries := strings.Split(strings.TrimSpace(input), ",")
697+
698+
duplicates := []string{}
699+
uniqueMap := make(map[string]bool)
700+
var uniqueList []string
701+
for _, entry := range entries {
702+
trimmedEntry := strings.TrimSpace(entry)
703+
704+
// Check if the entry is not empty and hasn't been added to the map yet
705+
if trimmedEntry == "" {
706+
continue
707+
}
708+
if _, exists := uniqueMap[trimmedEntry]; !exists {
709+
// If it doesn't exist, add it to the map and the unique list
710+
uniqueMap[trimmedEntry] = true
711+
uniqueList = append(uniqueList, trimmedEntry)
712+
} else {
713+
duplicates = append(duplicates, trimmedEntry)
714+
}
715+
}
716+
717+
if len(duplicates) > 0 {
718+
logrus.Infof("Duplicates detected in noProxy: %v", duplicates)
719+
}
720+
return strings.Join(uniqueList, ",")
721+
}

pkg/asset/agent/joiner/clusterinfo_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,31 @@ passwd:
252252
return clusterInfo
253253
},
254254
},
255+
{
256+
name: "duplicate noProxy entries are removed",
257+
workflow: workflow.AgentWorkflowTypeAddNodes,
258+
objs: func(t *testing.T) ([]runtime.Object, []runtime.Object, []runtime.Object) {
259+
t.Helper()
260+
objs, ocObjs, ocMachineConfigObjs := defaultObjects()(t)
261+
for i, o := range ocObjs {
262+
if proxy, ok := o.(*configv1.Proxy); ok {
263+
proxy.Spec.NoProxy = "172.22.0.0/24,192.168.111.0/24,.ostest.test.metalkube.org,172.30.0.0/16,192.168.111.0/24"
264+
ocObjs[i] = proxy
265+
break
266+
}
267+
}
268+
return objs, ocObjs, ocMachineConfigObjs
269+
},
270+
overrideExpectedClusterInfo: func(clusterInfo ClusterInfo) ClusterInfo {
271+
t.Helper()
272+
clusterInfo.Proxy = &types.Proxy{
273+
HTTPProxy: "http://proxy",
274+
HTTPSProxy: "https://proxy",
275+
NoProxy: "172.22.0.0/24,192.168.111.0/24,.ostest.test.metalkube.org,172.30.0.0/16",
276+
}
277+
return clusterInfo
278+
},
279+
},
255280
}
256281
for _, tc := range cases {
257282
t.Run(tc.name, func(t *testing.T) {

0 commit comments

Comments
 (0)