Merge pull request #98043 from JornShen/migrate_string_overlay_as_const

migrate winkernel network type string "overlay" as const
This commit is contained in:
Kubernetes Prow Robot 2021-01-14 20:43:51 -08:00 committed by GitHub
commit 857c06eb49
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 30 deletions

View File

@ -27,17 +27,19 @@ import (
"testing"
)
const sourceVip = "192.168.1.2"
const serviceVip = "11.0.0.1"
const addressPrefix = "192.168.1.0/24"
const gatewayAddress = "192.168.1.1"
const epMacAddress = "00-11-22-33-44-55"
const epIpAddress = "192.168.1.3"
const epIpAddressRemote = "192.168.2.3"
const epPaAddress = "10.0.0.3"
const protocol = 6
const internalPort = 80
const externalPort = 32440
const (
sourceVip = "192.168.1.2"
serviceVip = "11.0.0.1"
addressPrefix = "192.168.1.0/24"
gatewayAddress = "192.168.1.1"
epMacAddress = "00-11-22-33-44-55"
epIpAddress = "192.168.1.3"
epIpAddressRemote = "192.168.2.3"
epPaAddress = "10.0.0.3"
protocol = 6
internalPort = 80
externalPort = 32440
)
func TestGetNetworkByName(t *testing.T) {
hnsV1 := hnsV1{}
@ -484,7 +486,7 @@ func mustTestNetwork(t *testing.T) *hcn.HostComputeNetwork {
}
func createTestNetwork() (*hcn.HostComputeNetwork, error) {
network := &hcn.HostComputeNetwork{
Type: "Overlay",
Type: NETWORK_TYPE_OVERLAY,
Name: "TestOverlay",
MacPool: hcn.MacPool{
Ranges: []hcn.MacRange{

View File

@ -24,6 +24,7 @@ import (
"net"
"os"
"strconv"
"strings"
"sync"
"sync/atomic"
"time"
@ -135,6 +136,8 @@ type remoteSubnetInfo struct {
drMacAddress string
}
const NETWORK_TYPE_OVERLAY = "overlay"
func Log(v interface{}, message string, level klog.Level) {
klog.V(level).Infof("%s, %s", message, spewSdump(v))
}
@ -563,7 +566,7 @@ func NewProxier(
// Network could have been detected before Remote Subnet Routes are applied or ManagementIP is updated
// Sleep and update the network to include new information
if hnsNetworkInfo.networkType == "Overlay" {
if strings.EqualFold(hnsNetworkInfo.networkType, NETWORK_TYPE_OVERLAY) {
time.Sleep(10 * time.Second)
hnsNetworkInfo, err = hns.getNetworkByName(hnsNetworkName)
if err != nil {
@ -583,7 +586,7 @@ func NewProxier(
var sourceVip string
var hostMac string
if hnsNetworkInfo.networkType == "Overlay" {
if strings.EqualFold(hnsNetworkInfo.networkType, NETWORK_TYPE_OVERLAY) {
if !utilfeature.DefaultFeatureGate.Enabled(kubefeatures.WinOverlay) {
return nil, fmt.Errorf("WinOverlay feature gate not enabled")
}
@ -981,7 +984,7 @@ func (proxier *Proxier) syncProxyRules() {
}
}
if proxier.network.networkType == "Overlay" {
if strings.EqualFold(proxier.network.networkType, NETWORK_TYPE_OVERLAY) {
existingSourceVip, err := hns.getEndpointByIpAddress(proxier.sourceVip, hnsNetworkName)
if existingSourceVip == nil {
_, err = newSourceVIP(hns, hnsNetworkName, proxier.sourceVip, proxier.hostMac, proxier.nodeIP.String())
@ -1007,7 +1010,7 @@ func (proxier *Proxier) syncProxyRules() {
continue
}
if proxier.network.networkType == "Overlay" {
if strings.EqualFold(proxier.network.networkType, NETWORK_TYPE_OVERLAY) {
serviceVipEndpoint, _ := hns.getEndpointByIpAddress(svcInfo.ClusterIP().String(), hnsNetworkName)
if serviceVipEndpoint == nil {
klog.V(4).Infof("No existing remote endpoint for service VIP %v", svcInfo.ClusterIP().String())
@ -1075,7 +1078,7 @@ func (proxier *Proxier) syncProxyRules() {
continue
}
if proxier.network.networkType == "Overlay" {
if strings.EqualFold(proxier.network.networkType, NETWORK_TYPE_OVERLAY) {
klog.Infof("Updating network %v to check for new remote subnet policies", proxier.network.name)
networkName := proxier.network.name
updatedNetwork, err := hns.getNetworkByName(networkName)
@ -1130,7 +1133,7 @@ func (proxier *Proxier) syncProxyRules() {
// a) Endpoints are any IP's outside the cluster ==> Choose NodeIP as the SourceVIP
// b) Endpoints are IP addresses of a remote node => Choose NodeIP as the SourceVIP
// c) Everything else (Local POD's, Remote POD's, Node IP of current node) ==> Choose the configured SourceVIP
if proxier.network.networkType == "Overlay" && !ep.GetIsLocal() {
if strings.EqualFold(proxier.network.networkType, NETWORK_TYPE_OVERLAY) && !ep.GetIsLocal() {
providerAddress := proxier.network.findRemoteSubnetProviderAddress(ep.IP())
isNodeIP := (ep.IP() == providerAddress)

View File

@ -35,12 +35,14 @@ import (
"time"
)
const testHostName = "test-hostname"
const macAddress = "00-11-22-33-44-55"
const clusterCIDR = "192.168.1.0/24"
const destinationPrefix = "192.168.2.0/24"
const providerAddress = "10.0.0.3"
const guid = "123ABC"
const (
testHostName = "test-hostname"
macAddress = "00-11-22-33-44-55"
clusterCIDR = "192.168.1.0/24"
destinationPrefix = "192.168.2.0/24"
providerAddress = "10.0.0.3"
guid = "123ABC"
)
type fakeHNS struct{}
@ -60,7 +62,7 @@ func (hns fakeHNS) getNetworkByName(name string) (*hnsNetworkInfo, error) {
return &hnsNetworkInfo{
id: strings.ToUpper(guid),
name: name,
networkType: "Overlay",
networkType: NETWORK_TYPE_OVERLAY,
remoteSubnets: remoteSubnets,
}, nil
}
@ -142,7 +144,7 @@ func NewFakeProxier(syncPeriod time.Duration, minSyncPeriod time.Duration, clust
func TestCreateServiceVip(t *testing.T) {
syncPeriod := 30 * time.Second
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), "Overlay", false)
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), NETWORK_TYPE_OVERLAY, false)
if proxier == nil {
t.Error()
}
@ -198,7 +200,7 @@ func TestCreateServiceVip(t *testing.T) {
func TestCreateRemoteEndpointOverlay(t *testing.T) {
syncPeriod := 30 * time.Second
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), "Overlay", false)
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), NETWORK_TYPE_OVERLAY, false)
if proxier == nil {
t.Error()
}
@ -649,7 +651,7 @@ func TestSharedRemoteEndpointUpdate(t *testing.T) {
}
func TestCreateLoadBalancer(t *testing.T) {
syncPeriod := 30 * time.Second
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), "Overlay", false)
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), NETWORK_TYPE_OVERLAY, false)
if proxier == nil {
t.Error()
}
@ -708,7 +710,7 @@ func TestCreateLoadBalancer(t *testing.T) {
func TestCreateDsrLoadBalancer(t *testing.T) {
syncPeriod := 30 * time.Second
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), "Overlay", false)
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), NETWORK_TYPE_OVERLAY, false)
if proxier == nil {
t.Error()
}
@ -770,7 +772,7 @@ func TestCreateDsrLoadBalancer(t *testing.T) {
func TestEndpointSlice(t *testing.T) {
syncPeriod := 30 * time.Second
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), "Overlay", true)
proxier := NewFakeProxier(syncPeriod, syncPeriod, clusterCIDR, "testhost", net.ParseIP("10.0.0.1"), NETWORK_TYPE_OVERLAY, true)
if proxier == nil {
t.Error()
}