Skip to content

Commit ffdc341

Browse files
committed
hide change behind a cns flag
1 parent db64cfa commit ffdc341

File tree

10 files changed

+53
-47
lines changed

10 files changed

+53
-47
lines changed

cns/configuration/cns_config.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@
3333
"MellanoxMonitorIntervalSecs": 30,
3434
"AZRSettings": {
3535
"PopulateHomeAzCacheRetryIntervalSecs": 60
36-
}
36+
},
37+
"OverrideApipaGatewayAddress": false
3738
}

cns/configuration/configuration.go

+2
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ type CNSConfig struct {
5252
WatchPods bool `json:"-"`
5353
WireserverIP string
5454
GRPCSettings GRPCSettings
55+
// Flag to override Apipa default Gateway address (169.254.128.1) to 169.254.128.2
56+
OverrideApipaGatewayAddress bool
5557
}
5658

5759
type TelemetrySettings struct {

cns/configuration/configuration_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,10 @@ func TestReadConfigFromFile(t *testing.T) {
8686
AZRSettings: AZRSettings{
8787
PopulateHomeAzCacheRetryIntervalSecs: 60,
8888
},
89-
UseHTTPS: true,
90-
UseMTLS: true,
91-
WireserverIP: "168.63.129.16",
89+
UseHTTPS: true,
90+
UseMTLS: true,
91+
WireserverIP: "168.63.129.16",
92+
OverrideApipaGatewayAddress: true,
9293
},
9394
wantErr: false,
9495
},
@@ -220,6 +221,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
220221
IPAddress: "localhost",
221222
Port: 8080,
222223
},
224+
OverrideApipaGatewayAddress: false,
223225
},
224226
},
225227
{
@@ -250,6 +252,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
250252
IPAddress: "192.168.1.1",
251253
Port: 9090,
252254
},
255+
OverrideApipaGatewayAddress: true,
253256
},
254257
want: CNSConfig{
255258
ChannelMode: "Other",
@@ -279,6 +282,7 @@ func TestSetCNSConfigDefaults(t *testing.T) {
279282
IPAddress: "192.168.1.1",
280283
Port: 9090,
281284
},
285+
OverrideApipaGatewayAddress: true,
282286
},
283287
},
284288
}

cns/configuration/testdata/good.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@
3434
"WireserverIP": "168.63.129.16",
3535
"AZRSettings": {
3636
"PopulateHomeAzCacheRetryIntervalSecs": 60
37-
}
37+
},
38+
"OverrideApipaGatewayAddress": true
3839
}

cns/hnsclient/hnsclient_linux.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ func CreateHostNCApipaEndpoint(
3939
localIPConfiguration cns.IPConfiguration,
4040
allowNCToHostCommunication bool,
4141
allowHostToNCCommunication bool,
42-
ncPolicies []cns.NetworkContainerRequestPolicies) (string, error) {
42+
ncPolicies []cns.NetworkContainerRequestPolicies,
43+
overrideApipaGatewayAddress bool) (string, error) {
4344
return "", nil
4445
}
4546

cns/hnsclient/hnsclient_linux_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func TestLinuxHnsNetwork(t *testing.T) {
1717
require.Error(t, CreateHnsNetwork(cns.CreateHnsNetworkRequest{}))
1818
require.Error(t, DeleteHnsNetwork(""))
1919
// these no-op but return no error
20-
_, err := CreateHostNCApipaEndpoint("", cns.IPConfiguration{}, false, false, []cns.NetworkContainerRequestPolicies{})
20+
_, err := CreateHostNCApipaEndpoint("", cns.IPConfiguration{}, false, false, []cns.NetworkContainerRequestPolicies{}, false)
2121
require.NoError(t, err)
2222
require.NoError(t, DeleteHostNCApipaEndpoint(""))
2323
}

cns/hnsclient/hnsclient_windows.go

+6-7
Original file line numberDiff line numberDiff line change
@@ -542,12 +542,9 @@ func configureHostNCApipaEndpoint(
542542
}
543543

544544
// CreateHostNCApipaEndpoint creates the endpoint in the apipa network for host container connectivity
545-
func CreateHostNCApipaEndpoint(
546-
networkContainerID string,
547-
localIPConfiguration cns.IPConfiguration,
548-
allowNCToHostCommunication bool,
549-
allowHostToNCCommunication bool,
550-
ncPolicies []cns.NetworkContainerRequestPolicies) (string, error) {
545+
func CreateHostNCApipaEndpoint(networkContainerID string, localIPConfiguration cns.IPConfiguration,
546+
allowNCToHostCommunication bool, allowHostToNCCommunication bool, ncPolicies []cns.NetworkContainerRequestPolicies,
547+
overrideApipaGatewayAddress bool) (string, error) {
551548
var (
552549
network *hcn.HostComputeNetwork
553550
endpoint *hcn.HostComputeEndpoint
@@ -572,7 +569,9 @@ func CreateHostNCApipaEndpoint(
572569
return endpoint.Id, nil
573570
}
574571

575-
adhocAdjustIPConfig(&localIPConfiguration)
572+
if overrideApipaGatewayAddress {
573+
adhocAdjustIPConfig(&localIPConfiguration)
574+
}
576575
if network, err = createHostNCApipaNetwork(localIPConfiguration); err != nil {
577576
logger.Errorf("[Azure CNS] Failed to create HostNCApipaNetwork. Error: %v", err)
578577
return "", err

cns/restserver/api.go

+1-6
Original file line numberDiff line numberDiff line change
@@ -1409,12 +1409,7 @@ func (service *HTTPRestService) CreateHostNCApipaEndpoint(w http.ResponseWriter,
14091409
"AllowNCToHostCommunication or AllowHostToNCCommunication is set to true")
14101410
returnCode = types.InvalidRequest
14111411
} else {
1412-
if endpointID, err = hnsclient.CreateHostNCApipaEndpoint(
1413-
req.NetworkContainerID,
1414-
networkContainerDetails.CreateNetworkContainerRequest.LocalIPConfiguration,
1415-
networkContainerDetails.CreateNetworkContainerRequest.AllowNCToHostCommunication,
1416-
networkContainerDetails.CreateNetworkContainerRequest.AllowHostToNCCommunication,
1417-
networkContainerDetails.CreateNetworkContainerRequest.EndpointPolicies); err != nil {
1412+
if endpointID, err = hnsclient.CreateHostNCApipaEndpoint(req.NetworkContainerID, networkContainerDetails.CreateNetworkContainerRequest.LocalIPConfiguration, networkContainerDetails.CreateNetworkContainerRequest.AllowNCToHostCommunication, networkContainerDetails.CreateNetworkContainerRequest.AllowHostToNCCommunication, networkContainerDetails.CreateNetworkContainerRequest.EndpointPolicies, service.overrideApipaGatewayAddress); err != nil {
14181413
returnMessage = fmt.Sprintf("CreateHostNCApipaEndpoint failed with error: %v", err)
14191414
returnCode = types.UnexpectedError
14201415
}

cns/restserver/restserver.go

+29-26
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,15 @@ type HTTPRestService struct {
7070
state *httpRestServiceState
7171
podsPendingIPAssignment *bounded.TimedSet
7272
sync.RWMutex
73-
dncPartitionKey string
74-
EndpointState map[string]*EndpointInfo // key : container id
75-
EndpointStateStore store.KeyValueStore
76-
cniConflistGenerator CNIConflistGenerator
77-
generateCNIConflistOnce sync.Once
78-
IPConfigsHandlerMiddleware cns.IPConfigsHandlerMiddleware
79-
PnpIDByMacAddress map[string]string
80-
imdsClient imdsClient
73+
dncPartitionKey string
74+
EndpointState map[string]*EndpointInfo // key : container id
75+
EndpointStateStore store.KeyValueStore
76+
cniConflistGenerator CNIConflistGenerator
77+
generateCNIConflistOnce sync.Once
78+
IPConfigsHandlerMiddleware cns.IPConfigsHandlerMiddleware
79+
PnpIDByMacAddress map[string]string
80+
imdsClient imdsClient
81+
overrideApipaGatewayAddress bool
8182
}
8283

8384
type CNIConflistGenerator interface {
@@ -169,6 +170,7 @@ type networkInfo struct {
169170
func NewHTTPRestService(config *common.ServiceConfig, wscli interfaceGetter, wsproxy wireserverProxy, nmagentClient nmagentClient,
170171
endpointStateStore store.KeyValueStore, gen CNIConflistGenerator, homeAzMonitor *HomeAzMonitor,
171172
imdsClient imdsClient,
173+
overrideApipaGatewayAddress bool,
172174
) (*HTTPRestService, error) {
173175
service, err := cns.NewService(config.Name, config.Version, config.ChannelMode, config.Store)
174176
if err != nil {
@@ -214,24 +216,25 @@ func NewHTTPRestService(config *common.ServiceConfig, wscli interfaceGetter, wsp
214216
}
215217

216218
return &HTTPRestService{
217-
Service: service,
218-
store: service.Service.Store,
219-
dockerClient: dc,
220-
wscli: wscli,
221-
ipamClient: ic,
222-
nma: nmagentClient,
223-
wsproxy: wsproxy,
224-
networkContainer: nc,
225-
PodIPIDByPodInterfaceKey: podIPIDByPodInterfaceKey,
226-
PodIPConfigState: podIPConfigState,
227-
routingTable: routingTable,
228-
state: serviceState,
229-
podsPendingIPAssignment: bounded.NewTimedSet(250), // nolint:gomnd // maxpods
230-
EndpointStateStore: endpointStateStore,
231-
EndpointState: make(map[string]*EndpointInfo),
232-
homeAzMonitor: homeAzMonitor,
233-
cniConflistGenerator: gen,
234-
imdsClient: imdsClient,
219+
Service: service,
220+
store: service.Service.Store,
221+
dockerClient: dc,
222+
wscli: wscli,
223+
ipamClient: ic,
224+
nma: nmagentClient,
225+
wsproxy: wsproxy,
226+
networkContainer: nc,
227+
PodIPIDByPodInterfaceKey: podIPIDByPodInterfaceKey,
228+
PodIPConfigState: podIPConfigState,
229+
routingTable: routingTable,
230+
state: serviceState,
231+
podsPendingIPAssignment: bounded.NewTimedSet(250), // nolint:gomnd // maxpods
232+
EndpointStateStore: endpointStateStore,
233+
EndpointState: make(map[string]*EndpointInfo),
234+
homeAzMonitor: homeAzMonitor,
235+
cniConflistGenerator: gen,
236+
imdsClient: imdsClient,
237+
overrideApipaGatewayAddress: overrideApipaGatewayAddress,
235238
}, nil
236239
}
237240

cns/service/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -751,7 +751,7 @@ func main() {
751751
imdsClient := imds.NewClient()
752752

753753
httpRemoteRestService, err := restserver.NewHTTPRestService(&config, wsclient, &wsProxy, nmaClient,
754-
endpointStateStore, conflistGenerator, homeAzMonitor, imdsClient)
754+
endpointStateStore, conflistGenerator, homeAzMonitor, imdsClient, cnsconfig.OverrideApipaGatewayAddress)
755755
if err != nil {
756756
logger.Errorf("Failed to create CNS object, err:%v.\n", err)
757757
return

0 commit comments

Comments
 (0)