constellation/debugd/cdbg/state/state.go

79 lines
3.3 KiB
Go
Raw Normal View History

package state
import (
"errors"
"github.com/edgelesssys/constellation/internal/cloud/cloudtypes"
2022-06-07 10:50:12 -04:00
"github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/state"
)
// Code in this file is mostly copied from constellation-controlPlane
// TODO: import as package from controlPlane once it is properly refactored
func GetScalingGroupsFromConfig(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
switch {
case len(stat.GCPControlPlanes) != 0:
return getGCPInstances(stat, config)
case len(stat.AzureControlPlane) != 0:
return getAzureInstances(stat, config)
case len(stat.QEMUControlPlane) != 0:
return getQEMUInstances(stat, config)
default:
2022-06-07 11:15:23 -04:00
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no instances to init")
}
}
func getGCPInstances(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
if len(stat.GCPControlPlanes) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane workers available, can't create Constellation without any instance")
}
// GroupID of controlPlanes is empty, since they currently do not scale.
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.GCPControlPlanes}
if len(stat.GCPWorkers) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no worker workers available, can't create Constellation with one instance")
}
// TODO: make min / max configurable and abstract autoscaling for different cloud providers
workers = cloudtypes.ScalingGroup{Instances: stat.GCPWorkers}
return
}
func getAzureInstances(stat state.ConstellationState, _ *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
if len(stat.AzureControlPlane) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane workers available, can't create Constellation cluster without any instance")
}
2022-06-07 11:15:23 -04:00
// GroupID of controlPlanes is empty, since they currently do not scale.
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.AzureControlPlane}
if len(stat.AzureWorkers) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no worker workers available, can't create Constellation cluster with one instance")
}
// TODO: make min / max configurable and abstract autoscaling for different cloud providers
workers = cloudtypes.ScalingGroup{Instances: stat.AzureWorkers}
return
}
func getQEMUInstances(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
controlPlaneMap := stat.QEMUControlPlane
if len(controlPlaneMap) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no controlPlanes available, can't create Constellation without any instance")
}
2022-06-07 11:15:23 -04:00
// QEMU does not support autoscaling
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.QEMUControlPlane}
2022-06-07 11:15:23 -04:00
if len(stat.QEMUWorkers) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no workers available, can't create Constellation with one instance")
}
2022-06-07 11:15:23 -04:00
// QEMU does not support autoscaling
workers = cloudtypes.ScalingGroup{Instances: stat.QEMUWorkers}
return
}