Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
185 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# This script ensures the contents of the CNI config file is correct, and returns the HNS endpoint IP | ||
|
||
Import-Module -DisableNameChecking HNS_MODULE_PATH | ||
|
||
$cni_template=@' | ||
{ | ||
"CniVersion":"0.2.0", | ||
"Name":"HNS_NETWORK", | ||
"Type":"win-overlay", | ||
"apiVersion": 2, | ||
"Capabilities":{ | ||
"portMappings": true, | ||
"Dns":true | ||
}, | ||
"Ipam":{ | ||
"Type":"host-local", | ||
"Subnet":"ovn_host_subnet" | ||
}, | ||
"Policies":[ | ||
{ | ||
"Name": "EndpointPolicy", | ||
"Value": { | ||
"Type": "OutBoundNAT", | ||
"Settings": { | ||
"ExceptionList": [ | ||
"SERVICE_NETWORK_CIDR" | ||
], | ||
"DestinationPrefix": "", | ||
"NeedEncap": false | ||
} | ||
} | ||
}, | ||
{ | ||
"Name": "EndpointPolicy", | ||
"Value": { | ||
"Type": "SDNROUTE", | ||
"Settings": { | ||
"ExceptionList": [], | ||
"DestinationPrefix": "SERVICE_NETWORK_CIDR", | ||
"NeedEncap": true | ||
} | ||
} | ||
}, | ||
{ | ||
"Name": "EndpointPolicy", | ||
"Value": { | ||
"Type": "ProviderAddress", | ||
"Settings": { | ||
"ProviderAddress": "provider_address" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
'@ | ||
|
||
# Generate CNI Config | ||
$hns_network=Get-HnsNetwork | where { $_.Name -eq 'HNS_NETWORK'} | ||
$subnet=$hns_network.Subnets.AddressPrefix | ||
$cni_template -replace "ovn_host_subnet",$subnet | Out-Null | ||
$provider_address=$hns_network.ManagementIP | ||
$cni_template -replace "provider_address",$provider_address | Out-Null | ||
|
||
# Compare CNI config with existing file, and replace if necessary | ||
$existing_config="" | ||
if(Test-Path -Path CNI_CONFIG_PATH) { | ||
$existing_config= Get-Content -Path "CNI_CONFIG_PATH" | ||
} | ||
if($existing_config -ne $cni_template){ | ||
Set-Content -Path "CNI_CONFIG_PATH" -Value $cni_template -NoNewline | ||
} | ||
|
||
# Create HNS endpoint if it doesn't exist | ||
$endpoint = Invoke-HNSRequest GET endpoints | where { $_.Name -eq 'VIPEndpoint'} | ||
if( $endpoint -eq $null) { | ||
$endpoint = New-HnsEndpoint -NetworkId $hns_network.ID -Name "VIPEndpoint" | ||
Attach-HNSHostEndpoint -EndpointID $endpoint.ID -CompartmentID 1 | ||
} | ||
|
||
# Return HNS endpoint IP | ||
(Get-NetIPConfiguration -AllCompartments -All -Detailed | where { $_.NetAdapter.LinkLayerAddress -eq $endpoint.MacAddress }).IPV4Address.IPAddress.Trim() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.