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

View File

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

View File

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