Replace hardcoded nsg values with constants

This commit is contained in:
Sam Kingston 2020-04-17 15:49:50 +10:00 коммит произвёл Jim Minter
Родитель b315c1d329
Коммит c86e8d3d11
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 0730CBDA10D1A2D3
4 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -214,7 +214,7 @@ func (i *Installer) deployStorageTemplate(ctx context.Context, installConfig *in
},
},
},
Name: to.StringPtr(infraID + "-controlplane-nsg"),
Name: to.StringPtr(infraID + subnet.NSGControlPlaneSuffix),
Type: to.StringPtr("Microsoft.Network/networkSecurityGroups"),
Location: &installConfig.Config.Azure.Region,
},
@ -222,7 +222,7 @@ func (i *Installer) deployStorageTemplate(ctx context.Context, installConfig *in
},
{
Resource: &mgmtnetwork.SecurityGroup{
Name: to.StringPtr(infraID + "-node-nsg"),
Name: to.StringPtr(infraID + subnet.NSGNodeSuffix),
Type: to.StringPtr("Microsoft.Network/networkSecurityGroups"),
Location: &installConfig.Config.Azure.Region,
},

10
pkg/util/subnet/const.go Normal file
Просмотреть файл

@ -0,0 +1,10 @@
package subnet
// Copyright (c) Microsoft Corporation.
// Licensed under the Apache License 2.0.
// Network security group constants
const (
NSGControlPlaneSuffix = "-controlplane-nsg"
NSGNodeSuffix = "-node-nsg"
)

Просмотреть файл

@ -86,9 +86,9 @@ func NetworkSecurityGroupID(oc *api.OpenShiftCluster, subnetID string) (string,
switch {
case strings.EqualFold(subnetID, oc.Properties.MasterProfile.SubnetID):
return oc.Properties.ClusterProfile.ResourceGroupID + "/providers/Microsoft.Network/networkSecurityGroups/" + infraID + "-controlplane-nsg", nil
return oc.Properties.ClusterProfile.ResourceGroupID + "/providers/Microsoft.Network/networkSecurityGroups/" + infraID + NSGControlPlaneSuffix, nil
case strings.EqualFold(subnetID, oc.Properties.WorkerProfiles[0].SubnetID):
return oc.Properties.ClusterProfile.ResourceGroupID + "/providers/Microsoft.Network/networkSecurityGroups/" + infraID + "-node-nsg", nil
return oc.Properties.ClusterProfile.ResourceGroupID + "/providers/Microsoft.Network/networkSecurityGroups/" + infraID + NSGNodeSuffix, nil
default:
return "", fmt.Errorf("unknown subnetID %q", subnetID)
}

Просмотреть файл

@ -178,13 +178,13 @@ func TestNetworkSecurityGroupID(t *testing.T) {
{
name: "master",
subnetID: "/subscriptions/subscriptionId/resourceGroups/vnetResourceGroup/providers/Microsoft.Network/virtualNetworks/vnet/subnets/master",
wantNSGID: "/subscriptions/subscriptionId/resourceGroups/clusterResourceGroup/providers/Microsoft.Network/networkSecurityGroups/aro-controlplane-nsg",
wantNSGID: "/subscriptions/subscriptionId/resourceGroups/clusterResourceGroup/providers/Microsoft.Network/networkSecurityGroups/aro" + NSGControlPlaneSuffix,
},
{
name: "worker",
infraID: "test-1234",
subnetID: "/subscriptions/subscriptionId/resourceGroups/vnetResourceGroup/providers/Microsoft.Network/virtualNetworks/vnet/subnets/worker",
wantNSGID: "/subscriptions/subscriptionId/resourceGroups/clusterResourceGroup/providers/Microsoft.Network/networkSecurityGroups/test-1234-node-nsg",
wantNSGID: "/subscriptions/subscriptionId/resourceGroups/clusterResourceGroup/providers/Microsoft.Network/networkSecurityGroups/test-1234" + NSGNodeSuffix,
},
{
name: "invalid",