re-enable azure node groups in statefile and send azure scaleset as autoscaling group

This commit is contained in:
Malte Poll 2022-03-29 13:30:50 +02:00 committed by Malte Poll
parent 71b5a0c6c0
commit f04765dab5
5 changed files with 98 additions and 79 deletions

View file

@ -0,0 +1,8 @@
package azure
import "fmt"
// AutoscalingNodeGroup converts an azure scale set into a node group used by the k8s cluster-autoscaler.
func AutoscalingNodeGroup(scaleSet string, min int, max int) string {
return fmt.Sprintf("%d:%d:%s", min, max, scaleSet)
}

View file

@ -0,0 +1,14 @@
package azure
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestAutoscalingNodeGroup(t *testing.T) {
assert := assert.New(t)
nodeGroups := AutoscalingNodeGroup("scale-set", 0, 100)
expectedNodeGroups := "0:100:scale-set"
assert.Equal(expectedNodeGroups, nodeGroups)
}

View file

@ -165,15 +165,14 @@ func (c *Client) GetState() (state.ConstellationState, error) {
return state.ConstellationState{}, errors.New("client has no network security group") return state.ConstellationState{}, errors.New("client has no network security group")
} }
stat.AzureNetworkSecurityGroup = c.networkSecurityGroup stat.AzureNetworkSecurityGroup = c.networkSecurityGroup
// TODO: un-deprecate as soon as scale sets are available if len(c.nodesScaleSet) == 0 {
// if len(c.nodesScaleSet) == 0 { return state.ConstellationState{}, errors.New("client has no nodes scale set")
// return state.ConstellationState{}, errors.New("client has no nodes scale set") }
// } stat.AzureNodesScaleSet = c.nodesScaleSet
// stat.AzureNodesScaleSet = c.nodesScaleSet if len(c.coordinatorsScaleSet) == 0 {
// if len(c.coordinatorsScaleSet) == 0 { return state.ConstellationState{}, errors.New("client has no coordinators scale set")
// return state.ConstellationState{}, errors.New("client has no coordinators scale set") }
// } stat.AzureCoordinatorsScaleSet = c.coordinatorsScaleSet
// stat.AzureCoordinatorsScaleSet = c.coordinatorsScaleSet
if len(c.nodes) == 0 { if len(c.nodes) == 0 {
return state.ConstellationState{}, errors.New("client has no nodes") return state.ConstellationState{}, errors.New("client has no nodes")
} }
@ -225,15 +224,14 @@ func (c *Client) SetState(stat state.ConstellationState) error {
return errors.New("state has no subnet") return errors.New("state has no subnet")
} }
c.networkSecurityGroup = stat.AzureNetworkSecurityGroup c.networkSecurityGroup = stat.AzureNetworkSecurityGroup
// TODO: un-deprecate as soon as scale sets are available if len(stat.AzureNodesScaleSet) == 0 {
//if len(stat.AzureNodesScaleSet) == 0 { return errors.New("state has no nodes scale set")
// return errors.New("state has no nodes scale set") }
//} c.nodesScaleSet = stat.AzureNodesScaleSet
//c.nodesScaleSet = stat.AzureNodesScaleSet if len(stat.AzureCoordinatorsScaleSet) == 0 {
//if len(stat.AzureCoordinatorsScaleSet) == 0 { return errors.New("state has no nodes scale set")
// return errors.New("state has no nodes scale set") }
//} c.coordinatorsScaleSet = stat.AzureCoordinatorsScaleSet
//c.coordinatorsScaleSet = stat.AzureCoordinatorsScaleSet
if len(stat.AzureNodes) == 0 { if len(stat.AzureNodes) == 0 {
return errors.New("state has no coordinator scale set") return errors.New("state has no coordinator scale set")
} }

View file

@ -38,9 +38,8 @@ func TestSetGetState(t *testing.T) {
AzureTenant: "tenant", AzureTenant: "tenant",
AzureSubnet: "azure-subnet", AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group", AzureNetworkSecurityGroup: "network-security-group",
// TODO: un-deprecate as soon as scale sets are available AzureNodesScaleSet: "node-scale-set",
// AzureNodesScaleSet: "node-scale-set", AzureCoordinatorsScaleSet: "coordinator-scale-set",
// AzureCoordinatorsScaleSet: "coordinator-scale-set",
}, },
}, },
"missing nodes": { "missing nodes": {
@ -303,61 +302,60 @@ func TestSetGetState(t *testing.T) {
}, },
errExpected: true, errExpected: true,
}, },
// TODO: un-deprecate as soon as scale sets are available "missing node scale set": {
// "missing node scale set": { state: state.ConstellationState{
// state: state.ConstellationState{ CloudProvider: cloudprovider.Azure.String(),
// CloudProvider: cloudprovider.Azure.String(), AzureNodes: azure.Instances{
// AzureNodes: azure.Instances{ "0": {
// "0": { PublicIP: "ip1",
// PublicIP: "ip1", PrivateIP: "ip2",
// PrivateIP: "ip2", },
// }, },
// }, AzureCoordinators: azure.Instances{
// AzureCoordinators: azure.Instances{ "0": {
// "0": { PublicIP: "ip3",
// PublicIP: "ip3", PrivateIP: "ip4",
// PrivateIP: "ip4", },
// }, },
// }, Name: "name",
// Name: "name", UID: "uid",
// UID: "uid", AzureResourceGroup: "resource-group",
// AzureResourceGroup: "resource-group", AzureLocation: "location",
// AzureLocation: "location", AzureSubscription: "subscription",
// AzureSubscription: "subscription", AzureTenant: "tenant",
// AzureTenant: "tenant", AzureSubnet: "azure-subnet",
// AzureSubnet: "azure-subnet", AzureNetworkSecurityGroup: "network-security-group",
// AzureNetworkSecurityGroup: "network-security-group", AzureCoordinatorsScaleSet: "coordinator-scale-set",
// AzureCoordinatorsScaleSet: "coordinator-scale-set", },
// }, errExpected: true,
// errExpected: true, },
// }, "missing coordinator scale set": {
// "missing coordinator scale set": { state: state.ConstellationState{
// state: state.ConstellationState{ CloudProvider: cloudprovider.Azure.String(),
// CloudProvider: cloudprovider.Azure.String(), AzureNodes: azure.Instances{
// AzureNodes: azure.Instances{ "0": {
// "0": { PublicIP: "ip1",
// PublicIP: "ip1", PrivateIP: "ip2",
// PrivateIP: "ip2", },
// }, },
// }, AzureCoordinators: azure.Instances{
// AzureCoordinators: azure.Instances{ "0": {
// "0": { PublicIP: "ip3",
// PublicIP: "ip3", PrivateIP: "ip4",
// PrivateIP: "ip4", },
// }, },
// }, Name: "name",
// Name: "name", UID: "uid",
// UID: "uid", AzureResourceGroup: "resource-group",
// AzureResourceGroup: "resource-group", AzureLocation: "location",
// AzureLocation: "location", AzureSubscription: "subscription",
// AzureSubscription: "subscription", AzureTenant: "tenant",
// AzureTenant: "tenant", AzureSubnet: "azure-subnet",
// AzureSubnet: "azure-subnet", AzureNetworkSecurityGroup: "network-security-group",
// AzureNetworkSecurityGroup: "network-security-group", AzureNodesScaleSet: "node-scale-set",
// AzureNodesScaleSet: "node-scale-set", },
// }, errExpected: true,
// errExpected: true, },
// },
} }
t.Run("SetState", func(t *testing.T) { t.Run("SetState", func(t *testing.T) {

View file

@ -13,6 +13,7 @@ import (
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
"github.com/edgelesssys/constellation/cli/azure"
"github.com/edgelesssys/constellation/cli/file" "github.com/edgelesssys/constellation/cli/file"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/gcp"
"github.com/edgelesssys/constellation/cli/proto" "github.com/edgelesssys/constellation/cli/proto"
@ -355,7 +356,7 @@ func getScalingGroupsFromConfig(stat state.ConstellationState, config *config.Co
case len(stat.GCPCoordinators) != 0: case len(stat.GCPCoordinators) != 0:
return getGCPInstances(stat, config) return getGCPInstances(stat, config)
case len(stat.AzureCoordinators) != 0: case len(stat.AzureCoordinators) != 0:
return getAzureInstances(stat) return getAzureInstances(stat, config)
default: default:
return ScalingGroup{}, ScalingGroup{}, errors.New("no instances to init") return ScalingGroup{}, ScalingGroup{}, errors.New("no instances to init")
} }
@ -413,7 +414,7 @@ func getGCPInstances(stat state.ConstellationState, config *config.Config) (coor
return return
} }
func getAzureInstances(stat state.ConstellationState) (coordinators, nodes ScalingGroup, err error) { func getAzureInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes ScalingGroup, err error) {
_, coordinator, err := stat.AzureCoordinators.GetOne() _, coordinator, err := stat.AzureCoordinators.GetOne()
if err != nil { if err != nil {
return return
@ -434,7 +435,7 @@ func getAzureInstances(stat state.ConstellationState) (coordinators, nodes Scali
// TODO: make min / max configurable and abstract autoscaling for different cloud providers // TODO: make min / max configurable and abstract autoscaling for different cloud providers
nodes = ScalingGroup{ nodes = ScalingGroup{
Instances: nodeInstances, Instances: nodeInstances,
GroupID: "", GroupID: azure.AutoscalingNodeGroup(stat.AzureNodesScaleSet, *config.AutoscalingNodeGroupsMin, *config.AutoscalingNodeGroupsMax),
} }
return return
} }