mirror of
https://github.com/openshift/installer.git
synced 2026-02-05 15:47:14 +01:00
Merge pull request #10024 from bfournie/add-node-dup-proxy
OCPBUGS-60873: Prevent duplicate noProxy when adding nodes
This commit is contained in:
@@ -204,10 +204,13 @@ func (ci *ClusterInfo) retrieveProxy() error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// Remove any duplicates in noProxy
|
||||
noProxy := ci.removeDuplicates(proxy.Spec.NoProxy)
|
||||
|
||||
ci.Proxy = &types.Proxy{
|
||||
HTTPProxy: proxy.Spec.HTTPProxy,
|
||||
HTTPSProxy: proxy.Spec.HTTPSProxy,
|
||||
NoProxy: proxy.Spec.NoProxy,
|
||||
NoProxy: noProxy,
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -688,3 +691,31 @@ func (ci *ClusterInfo) reportResult(ctx context.Context) error {
|
||||
|
||||
return workflowreport.GetReport(ctx).StageResult(workflow.StageClusterInspection, string(data))
|
||||
}
|
||||
|
||||
func (ci *ClusterInfo) removeDuplicates(input string) string {
|
||||
entries := strings.Split(strings.TrimSpace(input), ",")
|
||||
|
||||
duplicates := []string{}
|
||||
uniqueMap := make(map[string]bool)
|
||||
var uniqueList []string
|
||||
for _, entry := range entries {
|
||||
trimmedEntry := strings.TrimSpace(entry)
|
||||
|
||||
// Check if the entry is not empty and hasn't been added to the map yet
|
||||
if trimmedEntry == "" {
|
||||
continue
|
||||
}
|
||||
if _, exists := uniqueMap[trimmedEntry]; !exists {
|
||||
// If it doesn't exist, add it to the map and the unique list
|
||||
uniqueMap[trimmedEntry] = true
|
||||
uniqueList = append(uniqueList, trimmedEntry)
|
||||
} else {
|
||||
duplicates = append(duplicates, trimmedEntry)
|
||||
}
|
||||
}
|
||||
|
||||
if len(duplicates) > 0 {
|
||||
logrus.Infof("Duplicates detected in noProxy: %v", duplicates)
|
||||
}
|
||||
return strings.Join(uniqueList, ",")
|
||||
}
|
||||
|
||||
@@ -252,6 +252,31 @@ passwd:
|
||||
return clusterInfo
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "duplicate noProxy entries are removed",
|
||||
workflow: workflow.AgentWorkflowTypeAddNodes,
|
||||
objs: func(t *testing.T) ([]runtime.Object, []runtime.Object, []runtime.Object) {
|
||||
t.Helper()
|
||||
objs, ocObjs, ocMachineConfigObjs := defaultObjects()(t)
|
||||
for i, o := range ocObjs {
|
||||
if proxy, ok := o.(*configv1.Proxy); ok {
|
||||
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"
|
||||
ocObjs[i] = proxy
|
||||
break
|
||||
}
|
||||
}
|
||||
return objs, ocObjs, ocMachineConfigObjs
|
||||
},
|
||||
overrideExpectedClusterInfo: func(clusterInfo ClusterInfo) ClusterInfo {
|
||||
t.Helper()
|
||||
clusterInfo.Proxy = &types.Proxy{
|
||||
HTTPProxy: "http://proxy",
|
||||
HTTPSProxy: "https://proxy",
|
||||
NoProxy: "172.22.0.0/24,192.168.111.0/24,.ostest.test.metalkube.org,172.30.0.0/16",
|
||||
}
|
||||
return clusterInfo
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user