mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
Move ScalingGroup to cloudtypes
This commit is contained in:
parent
87b9203110
commit
d71e97a940
@ -56,3 +56,9 @@ func (i Instances) GetOthers(id string) Instances {
|
|||||||
}
|
}
|
||||||
return others
|
return others
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ScalingGroup is a group of instances, with an identifying group ID.
|
||||||
|
type ScalingGroup struct {
|
||||||
|
Instances
|
||||||
|
GroupID string
|
||||||
|
}
|
||||||
|
131
cli/cmd/init.go
131
cli/cmd/init.go
@ -12,6 +12,7 @@ import (
|
|||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"github.com/edgelesssys/constellation/cli/cloud/cloudcmd"
|
"github.com/edgelesssys/constellation/cli/cloud/cloudcmd"
|
||||||
|
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
||||||
"github.com/edgelesssys/constellation/cli/internal/azure"
|
"github.com/edgelesssys/constellation/cli/internal/azure"
|
||||||
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
"github.com/edgelesssys/constellation/cli/internal/gcp"
|
||||||
"github.com/edgelesssys/constellation/cli/internal/proto"
|
"github.com/edgelesssys/constellation/cli/internal/proto"
|
||||||
@ -395,7 +396,7 @@ func readOrGeneratedMasterSecret(w io.Writer, fileHandler file.Handler, filename
|
|||||||
return masterSecret, nil
|
return masterSecret, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getScalingGroupsFromConfig(stat state.ConstellationState, config *config.Config) (coordinators, nodes ScalingGroup, err error) {
|
func getScalingGroupsFromConfig(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
switch {
|
switch {
|
||||||
case len(stat.GCPCoordinators) != 0:
|
case len(stat.GCPCoordinators) != 0:
|
||||||
return getGCPInstances(stat, config)
|
return getGCPInstances(stat, config)
|
||||||
@ -404,103 +405,76 @@ func getScalingGroupsFromConfig(stat state.ConstellationState, config *config.Co
|
|||||||
case len(stat.QEMUCoordinators) != 0:
|
case len(stat.QEMUCoordinators) != 0:
|
||||||
return getQEMUInstances(stat, config)
|
return getQEMUInstances(stat, config)
|
||||||
default:
|
default:
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no instances to initialize")
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no instances to initialize")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGCPInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes ScalingGroup, err error) {
|
func getGCPInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
coordinatorMap := stat.GCPCoordinators
|
if len(stat.GCPCoordinators) == 0 {
|
||||||
if len(coordinatorMap) == 0 {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane nodes available, can't create Constellation without any instance")
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no control-plane nodes available, can't create Constellation without any instance")
|
|
||||||
}
|
|
||||||
var coordinatorInstances Instances
|
|
||||||
for _, node := range coordinatorMap {
|
|
||||||
coordinatorInstances = append(coordinatorInstances, Instance(node))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupID of coordinators is empty, since they currently do not scale.
|
// GroupID of coordinators is empty, since they currently do not scale.
|
||||||
coordinators = ScalingGroup{
|
coordinators = cloudtypes.ScalingGroup{
|
||||||
Instances: coordinatorInstances,
|
Instances: stat.GCPCoordinators,
|
||||||
GroupID: "",
|
GroupID: "",
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeMap := stat.GCPNodes
|
if len(stat.GCPNodes) == 0 {
|
||||||
if len(nodeMap) == 0 {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no worker nodes available, can't create Constellation with one instance")
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no worker nodes available, can't create Constellation with one instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
var nodeInstances Instances
|
|
||||||
for _, node := range nodeMap {
|
|
||||||
nodeInstances = append(nodeInstances, Instance(node))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 = cloudtypes.ScalingGroup{
|
||||||
Instances: nodeInstances,
|
Instances: stat.GCPNodes,
|
||||||
GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPNodeInstanceGroup, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
|
GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPNodeInstanceGroup, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAzureInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes ScalingGroup, err error) {
|
func getAzureInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
coordinatorMap := stat.AzureCoordinators
|
if len(stat.AzureCoordinators) == 0 {
|
||||||
if len(coordinatorMap) == 0 {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane nodes available, can't create Constellation cluster without any instance")
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no control-plane nodes available, can't create Constellation cluster without any instance")
|
|
||||||
}
|
|
||||||
var coordinatorInstances Instances
|
|
||||||
for _, node := range coordinatorMap {
|
|
||||||
coordinatorInstances = append(coordinatorInstances, Instance(node))
|
|
||||||
}
|
|
||||||
// GroupID of coordinators is empty, since they currently do not scale.
|
|
||||||
coordinators = ScalingGroup{
|
|
||||||
Instances: coordinatorInstances,
|
|
||||||
GroupID: "",
|
|
||||||
}
|
|
||||||
nodeMap := stat.AzureNodes
|
|
||||||
if len(nodeMap) == 0 {
|
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no worker nodes available, can't create Constellation cluster with one instance")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodeInstances Instances
|
// GroupID of coordinators is empty, since they currently do not scale.
|
||||||
for _, node := range nodeMap {
|
coordinators = cloudtypes.ScalingGroup{
|
||||||
nodeInstances = append(nodeInstances, Instance(node))
|
Instances: stat.AzureCoordinators,
|
||||||
|
GroupID: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(stat.AzureNodes) == 0 {
|
||||||
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no worker nodes available, can't create Constellation cluster with one instance")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 = cloudtypes.ScalingGroup{
|
||||||
Instances: nodeInstances,
|
Instances: stat.AzureNodes,
|
||||||
GroupID: azure.AutoscalingNodeGroup(stat.AzureNodesScaleSet, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
|
GroupID: azure.AutoscalingNodeGroup(stat.AzureNodesScaleSet, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQEMUInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes ScalingGroup, err error) {
|
func getQEMUInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
coordinatorMap := stat.QEMUCoordinators
|
coordinatorMap := stat.QEMUCoordinators
|
||||||
if len(coordinatorMap) == 0 {
|
if len(coordinatorMap) == 0 {
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
|
||||||
}
|
|
||||||
var coordinatorInstances Instances
|
|
||||||
for _, node := range coordinatorMap {
|
|
||||||
coordinatorInstances = append(coordinatorInstances, Instance(node))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QEMU does not support autoscaling
|
// QEMU does not support autoscaling
|
||||||
coordinators = ScalingGroup{
|
coordinators = cloudtypes.ScalingGroup{
|
||||||
Instances: coordinatorInstances,
|
Instances: stat.QEMUCoordinators,
|
||||||
GroupID: "",
|
GroupID: "",
|
||||||
}
|
}
|
||||||
nodeMap := stat.QEMUNodes
|
|
||||||
if len(nodeMap) == 0 {
|
|
||||||
return ScalingGroup{}, ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
var nodeInstances Instances
|
if len(stat.QEMUNodes) == 0 {
|
||||||
for _, node := range nodeMap {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
|
||||||
nodeInstances = append(nodeInstances, Instance(node))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// QEMU does not support autoscaling
|
// QEMU does not support autoscaling
|
||||||
nodes = ScalingGroup{
|
nodes = cloudtypes.ScalingGroup{
|
||||||
Instances: nodeInstances,
|
Instances: stat.QEMUNodes,
|
||||||
GroupID: "",
|
GroupID: "",
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -514,38 +488,3 @@ func initCompletion(cmd *cobra.Command, args []string, toComplete string) ([]str
|
|||||||
}
|
}
|
||||||
return []string{}, cobra.ShellCompDirectiveDefault
|
return []string{}, cobra.ShellCompDirectiveDefault
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
// TODO: Code below is target of multicloud refactoring.
|
|
||||||
//
|
|
||||||
|
|
||||||
// Instance is a cloud instance.
|
|
||||||
type Instance struct {
|
|
||||||
PublicIP string
|
|
||||||
PrivateIP string
|
|
||||||
}
|
|
||||||
|
|
||||||
type Instances []Instance
|
|
||||||
|
|
||||||
type ScalingGroup struct {
|
|
||||||
Instances
|
|
||||||
GroupID string
|
|
||||||
}
|
|
||||||
|
|
||||||
// PublicIPs returns the public IPs of all the instances.
|
|
||||||
func (i Instances) PublicIPs() []string {
|
|
||||||
var ips []string
|
|
||||||
for _, instance := range i {
|
|
||||||
ips = append(ips, instance.PublicIP)
|
|
||||||
}
|
|
||||||
return ips
|
|
||||||
}
|
|
||||||
|
|
||||||
// PrivateIPs returns the private IPs of all the instances of the Constellation.
|
|
||||||
func (i Instances) PrivateIPs() []string {
|
|
||||||
var ips []string
|
|
||||||
for _, instance := range i {
|
|
||||||
ips = append(ips, instance.PrivateIP)
|
|
||||||
}
|
|
||||||
return ips
|
|
||||||
}
|
|
||||||
|
@ -3,7 +3,7 @@ package state
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
cmdc "github.com/edgelesssys/constellation/cli/cmd"
|
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
|
||||||
"github.com/edgelesssys/constellation/internal/config"
|
"github.com/edgelesssys/constellation/internal/config"
|
||||||
"github.com/edgelesssys/constellation/internal/state"
|
"github.com/edgelesssys/constellation/internal/state"
|
||||||
)
|
)
|
||||||
@ -11,7 +11,7 @@ import (
|
|||||||
// Code in this file is mostly copied from constellation-coordinator
|
// Code in this file is mostly copied from constellation-coordinator
|
||||||
// TODO: import as package from coordinator once it is properly refactored
|
// TODO: import as package from coordinator once it is properly refactored
|
||||||
|
|
||||||
func GetScalingGroupsFromConfig(stat state.ConstellationState, config *config.Config) (coordinators, nodes cmdc.ScalingGroup, err error) {
|
func GetScalingGroupsFromConfig(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
switch {
|
switch {
|
||||||
case len(stat.GCPCoordinators) != 0:
|
case len(stat.GCPCoordinators) != 0:
|
||||||
return getGCPInstances(stat, config)
|
return getGCPInstances(stat, config)
|
||||||
@ -20,92 +20,59 @@ func GetScalingGroupsFromConfig(stat state.ConstellationState, config *config.Co
|
|||||||
case len(stat.QEMUCoordinators) != 0:
|
case len(stat.QEMUCoordinators) != 0:
|
||||||
return getQEMUInstances(stat, config)
|
return getQEMUInstances(stat, config)
|
||||||
default:
|
default:
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no instances to init")
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no instances to init")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getGCPInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes cmdc.ScalingGroup, err error) {
|
func getGCPInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
coordinatorMap := stat.GCPCoordinators
|
if len(stat.GCPCoordinators) == 0 {
|
||||||
if len(coordinatorMap) == 0 {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane nodes available, can't create Constellation without any instance")
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
|
|
||||||
}
|
|
||||||
var coordinatorInstances cmdc.Instances
|
|
||||||
for _, node := range coordinatorMap {
|
|
||||||
coordinatorInstances = append(coordinatorInstances, cmdc.Instance(node))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GroupID of coordinators is empty, since they currently do not scale.
|
// GroupID of coordinators is empty, since they currently do not scale.
|
||||||
coordinators = cmdc.ScalingGroup{
|
coordinators = cloudtypes.ScalingGroup{Instances: stat.GCPCoordinators}
|
||||||
Instances: coordinatorInstances,
|
|
||||||
GroupID: "",
|
|
||||||
}
|
|
||||||
|
|
||||||
nodeMap := stat.GCPNodes
|
if len(stat.GCPNodes) == 0 {
|
||||||
if len(nodeMap) == 0 {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no worker nodes available, can't create Constellation with one instance")
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
|
|
||||||
}
|
|
||||||
|
|
||||||
var nodeInstances cmdc.Instances
|
|
||||||
for _, node := range nodeMap {
|
|
||||||
nodeInstances = append(nodeInstances, cmdc.Instance(node))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 = cmdc.ScalingGroup{Instances: nodeInstances}
|
nodes = cloudtypes.ScalingGroup{Instances: stat.GCPNodes}
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAzureInstances(stat state.ConstellationState, _ *config.Config) (coordinators, nodes cmdc.ScalingGroup, err error) {
|
func getAzureInstances(stat state.ConstellationState, _ *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
coordinatorMap := stat.AzureCoordinators
|
if len(stat.AzureCoordinators) == 0 {
|
||||||
if len(coordinatorMap) == 0 {
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane nodes available, can't create Constellation cluster without any instance")
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
|
|
||||||
}
|
|
||||||
var coordinatorInstances cmdc.Instances
|
|
||||||
for _, node := range coordinatorMap {
|
|
||||||
coordinatorInstances = append(coordinatorInstances, cmdc.Instance(node))
|
|
||||||
}
|
|
||||||
// GroupID of coordinators is empty, since they currently do not scale.
|
|
||||||
coordinators = cmdc.ScalingGroup{
|
|
||||||
Instances: coordinatorInstances,
|
|
||||||
GroupID: "",
|
|
||||||
}
|
|
||||||
nodeMap := stat.AzureNodes
|
|
||||||
if len(nodeMap) == 0 {
|
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var nodeInstances cmdc.Instances
|
// GroupID of coordinators is empty, since they currently do not scale.
|
||||||
for _, node := range nodeMap {
|
coordinators = cloudtypes.ScalingGroup{Instances: stat.AzureCoordinators}
|
||||||
nodeInstances = append(nodeInstances, cmdc.Instance(node))
|
|
||||||
|
if len(stat.AzureNodes) == 0 {
|
||||||
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no worker nodes available, can't create Constellation cluster with one instance")
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 = cmdc.ScalingGroup{Instances: nodeInstances}
|
nodes = cloudtypes.ScalingGroup{Instances: stat.AzureNodes}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func getQEMUInstances(stat state.ConstellationState, _ *config.Config) (coordinators, nodes cmdc.ScalingGroup, err error) {
|
func getQEMUInstances(stat state.ConstellationState, config *config.Config) (coordinators, nodes cloudtypes.ScalingGroup, err error) {
|
||||||
coordinatorMap := stat.QEMUCoordinators
|
coordinatorMap := stat.QEMUCoordinators
|
||||||
if len(coordinatorMap) == 0 {
|
if len(coordinatorMap) == 0 {
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no coordinators available, can't create Constellation without any instance")
|
||||||
}
|
}
|
||||||
var coordinatorInstances cmdc.Instances
|
|
||||||
for _, node := range coordinatorMap {
|
// QEMU does not support autoscaling
|
||||||
coordinatorInstances = append(coordinatorInstances, cmdc.Instance(node))
|
coordinators = cloudtypes.ScalingGroup{Instances: stat.QEMUCoordinators}
|
||||||
|
|
||||||
|
if len(stat.QEMUNodes) == 0 {
|
||||||
|
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
|
||||||
}
|
}
|
||||||
// GroupID of coordinators is empty, since they currently do not scale.
|
|
||||||
coordinators = cmdc.ScalingGroup{
|
// QEMU does not support autoscaling
|
||||||
Instances: coordinatorInstances,
|
nodes = cloudtypes.ScalingGroup{Instances: stat.QEMUNodes}
|
||||||
GroupID: "",
|
|
||||||
}
|
|
||||||
nodeMap := stat.QEMUNodes
|
|
||||||
if len(nodeMap) == 0 {
|
|
||||||
return cmdc.ScalingGroup{}, cmdc.ScalingGroup{}, errors.New("no nodes available, can't create Constellation with one instance")
|
|
||||||
}
|
|
||||||
var nodeInstances cmdc.Instances
|
|
||||||
for _, node := range nodeMap {
|
|
||||||
nodeInstances = append(nodeInstances, cmdc.Instance(node))
|
|
||||||
}
|
|
||||||
nodes = cmdc.ScalingGroup{Instances: nodeInstances}
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user