Fix naming in state file

This commit is contained in:
katexochen 2022-07-29 08:10:51 +02:00 committed by Paul Meyer
parent 779a73a03d
commit c2faa20d6e
13 changed files with 533 additions and 533 deletions

View File

@ -210,19 +210,19 @@ func (c *Client) GetState() (state.ConstellationState, error) {
if len(c.workerScaleSet) == 0 {
return state.ConstellationState{}, errors.New("client has no worker scale set")
}
stat.AzureWorkersScaleSet = c.workerScaleSet
stat.AzureWorkerScaleSet = c.workerScaleSet
if len(c.controlPlaneScaleSet) == 0 {
return state.ConstellationState{}, errors.New("client has no control plane scale set")
}
stat.AzureControlPlanesScaleSet = c.controlPlaneScaleSet
stat.AzureControlPlaneScaleSet = c.controlPlaneScaleSet
if len(c.workers) == 0 {
return state.ConstellationState{}, errors.New("client has no workers")
}
stat.AzureWorkers = c.workers
stat.AzureWorkerInstances = c.workers
if len(c.controlPlanes) == 0 {
return state.ConstellationState{}, errors.New("client has no control planes")
}
stat.AzureControlPlane = c.controlPlanes
stat.AzureControlPlaneInstances = c.controlPlanes
// AD App Object ID does not have to be set at all times
stat.AzureADAppObjectID = c.adAppObjectID
@ -270,22 +270,22 @@ func (c *Client) SetState(stat state.ConstellationState) error {
return errors.New("state has no subnet")
}
c.networkSecurityGroup = stat.AzureNetworkSecurityGroup
if len(stat.AzureWorkersScaleSet) == 0 {
if len(stat.AzureWorkerScaleSet) == 0 {
return errors.New("state has no worker scale set")
}
c.workerScaleSet = stat.AzureWorkersScaleSet
if len(stat.AzureControlPlanesScaleSet) == 0 {
c.workerScaleSet = stat.AzureWorkerScaleSet
if len(stat.AzureControlPlaneScaleSet) == 0 {
return errors.New("state has no worker scale set")
}
c.controlPlaneScaleSet = stat.AzureControlPlanesScaleSet
if len(stat.AzureWorkers) == 0 {
c.controlPlaneScaleSet = stat.AzureControlPlaneScaleSet
if len(stat.AzureWorkerInstances) == 0 {
return errors.New("state has no workers")
}
c.workers = stat.AzureWorkers
if len(stat.AzureControlPlane) == 0 {
c.workers = stat.AzureWorkerInstances
if len(stat.AzureControlPlaneInstances) == 0 {
return errors.New("state has no control planes")
}
c.controlPlanes = stat.AzureControlPlane
c.controlPlanes = stat.AzureControlPlaneInstances
// AD App Object ID does not have to be set at all times
c.adAppObjectID = stat.AzureADAppObjectID

View File

@ -23,367 +23,13 @@ func TestSetGetState(t *testing.T) {
"valid state": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
},
"missing workers": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing controlplane": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing name": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing uid": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing bootstrapper host": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing resource group": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing location": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing subscription": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureTenant: "tenant",
AzureLocation: "location",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing tenant": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureSubscription: "subscription",
AzureLocation: "location",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing subnet": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing network security group": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing worker scale set": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureControlPlanesScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing controlplane scale set": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -398,7 +44,361 @@ func TestSetGetState(t *testing.T) {
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
},
"missing workers": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing controlplane": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing name": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing uid": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing bootstrapper host": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing resource group": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing location": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing subscription": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureTenant: "tenant",
AzureLocation: "location",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing tenant": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureSubscription: "subscription",
AzureLocation: "location",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing subnet": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing network security group": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing worker scale set": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureControlPlaneScaleSet: "controlplane-scale-set",
},
wantErr: true,
},
"missing controlplane scale set": {
state: state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
BootstrapperHost: "bootstrapper-host",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureTenant: "tenant",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
},
wantErr: true,
},
@ -414,8 +414,8 @@ func TestSetGetState(t *testing.T) {
assert.Error(client.SetState(tc.state))
} else {
assert.NoError(client.SetState(tc.state))
assert.Equal(tc.state.AzureWorkers, client.workers)
assert.Equal(tc.state.AzureControlPlane, client.controlPlanes)
assert.Equal(tc.state.AzureWorkerInstances, client.workers)
assert.Equal(tc.state.AzureControlPlaneInstances, client.controlPlanes)
assert.Equal(tc.state.Name, client.name)
assert.Equal(tc.state.UID, client.uid)
assert.Equal(tc.state.AzureResourceGroup, client.resourceGroup)
@ -424,8 +424,8 @@ func TestSetGetState(t *testing.T) {
assert.Equal(tc.state.AzureTenant, client.tenantID)
assert.Equal(tc.state.AzureSubnet, client.subnetID)
assert.Equal(tc.state.AzureNetworkSecurityGroup, client.networkSecurityGroup)
assert.Equal(tc.state.AzureWorkersScaleSet, client.workerScaleSet)
assert.Equal(tc.state.AzureControlPlanesScaleSet, client.controlPlaneScaleSet)
assert.Equal(tc.state.AzureWorkerScaleSet, client.workerScaleSet)
assert.Equal(tc.state.AzureControlPlaneScaleSet, client.controlPlaneScaleSet)
}
})
}
@ -437,8 +437,8 @@ func TestSetGetState(t *testing.T) {
assert := assert.New(t)
client := Client{
workers: tc.state.AzureWorkers,
controlPlanes: tc.state.AzureControlPlane,
workers: tc.state.AzureWorkerInstances,
controlPlanes: tc.state.AzureControlPlaneInstances,
name: tc.state.Name,
uid: tc.state.UID,
loadBalancerPubIP: tc.state.BootstrapperHost,
@ -448,8 +448,8 @@ func TestSetGetState(t *testing.T) {
tenantID: tc.state.AzureTenant,
subnetID: tc.state.AzureSubnet,
networkSecurityGroup: tc.state.AzureNetworkSecurityGroup,
workerScaleSet: tc.state.AzureWorkersScaleSet,
controlPlaneScaleSet: tc.state.AzureControlPlanesScaleSet,
workerScaleSet: tc.state.AzureWorkerScaleSet,
controlPlaneScaleSet: tc.state.AzureControlPlaneScaleSet,
}
if tc.wantErr {
_, err := client.GetState()
@ -469,52 +469,52 @@ func TestSetStateCloudProvider(t *testing.T) {
client := Client{}
stateMissingCloudProvider := state.ConstellationState{
AzureWorkers: cloudtypes.Instances{
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
Name: "name",
UID: "uid",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
}
assert.Error(client.SetState(stateMissingCloudProvider))
stateIncorrectCloudProvider := state.ConstellationState{
CloudProvider: "incorrect",
AzureWorkers: cloudtypes.Instances{
AzureWorkerInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
AzureControlPlane: cloudtypes.Instances{
AzureControlPlaneInstances: cloudtypes.Instances{
"0": {
PublicIP: "ip3",
PrivateIP: "ip4",
},
},
Name: "name",
UID: "uid",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "worker-scale-set",
AzureControlPlanesScaleSet: "controlplane-scale-set",
Name: "name",
UID: "uid",
AzureResourceGroup: "resource-group",
AzureLocation: "location",
AzureSubscription: "subscription",
AzureSubnet: "azure-subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "worker-scale-set",
AzureControlPlaneScaleSet: "controlplane-scale-set",
}
assert.Error(client.SetState(stateIncorrectCloudProvider))
}

View File

@ -44,8 +44,8 @@ type fakeAzureClient struct {
func (c *fakeAzureClient) GetState() (state.ConstellationState, error) {
stat := state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: c.workers,
AzureControlPlane: c.controlPlanes,
AzureWorkerInstances: c.workers,
AzureControlPlaneInstances: c.controlPlanes,
Name: c.name,
UID: c.uid,
AzureResourceGroup: c.resourceGroup,
@ -54,16 +54,16 @@ func (c *fakeAzureClient) GetState() (state.ConstellationState, error) {
AzureTenant: c.tenantID,
AzureSubnet: c.subnetID,
AzureNetworkSecurityGroup: c.networkSecurityGroup,
AzureWorkersScaleSet: c.workerScaleSet,
AzureControlPlanesScaleSet: c.controlPlaneScaleSet,
AzureWorkerScaleSet: c.workerScaleSet,
AzureControlPlaneScaleSet: c.controlPlaneScaleSet,
AzureADAppObjectID: c.adAppObjectID,
}
return stat, nil
}
func (c *fakeAzureClient) SetState(stat state.ConstellationState) error {
c.workers = stat.AzureWorkers
c.controlPlanes = stat.AzureControlPlane
c.workers = stat.AzureWorkerInstances
c.controlPlanes = stat.AzureControlPlaneInstances
c.name = stat.Name
c.uid = stat.UID
c.resourceGroup = stat.AzureResourceGroup
@ -72,8 +72,8 @@ func (c *fakeAzureClient) SetState(stat state.ConstellationState) error {
c.tenantID = stat.AzureTenant
c.subnetID = stat.AzureSubnet
c.networkSecurityGroup = stat.AzureNetworkSecurityGroup
c.workerScaleSet = stat.AzureWorkersScaleSet
c.controlPlaneScaleSet = stat.AzureControlPlanesScaleSet
c.workerScaleSet = stat.AzureWorkerScaleSet
c.controlPlaneScaleSet = stat.AzureControlPlaneScaleSet
c.adAppObjectID = stat.AzureADAppObjectID
return nil
}
@ -260,8 +260,8 @@ type fakeGcpClient struct {
func (c *fakeGcpClient) GetState() (state.ConstellationState, error) {
stat := state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: c.workers,
GCPControlPlanes: c.controlPlanes,
GCPWorkerInstances: c.workers,
GCPControlPlaneInstances: c.controlPlanes,
GCPWorkerInstanceGroup: c.workerInstanceGroup,
GCPControlPlaneInstanceGroup: c.controlPlaneInstanceGroup,
GCPWorkerInstanceTemplate: c.workerTemplate,
@ -282,8 +282,8 @@ func (c *fakeGcpClient) GetState() (state.ConstellationState, error) {
}
func (c *fakeGcpClient) SetState(stat state.ConstellationState) error {
c.workers = stat.GCPWorkers
c.controlPlanes = stat.GCPControlPlanes
c.workers = stat.GCPWorkerInstances
c.controlPlanes = stat.GCPControlPlaneInstances
c.workerInstanceGroup = stat.GCPWorkerInstanceGroup
c.controlPlaneInstanceGroup = stat.GCPControlPlaneInstanceGroup
c.workerTemplate = stat.GCPWorkerInstanceTemplate

View File

@ -17,11 +17,11 @@ func TestCreator(t *testing.T) {
wantGCPState := state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPProject: "project",
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-2": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
@ -44,20 +44,20 @@ func TestCreator(t *testing.T) {
wantAzureState := state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureControlPlane: cloudtypes.Instances{
AzureControlPlaneInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
AzureWorkers: cloudtypes.Instances{
AzureWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-2": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
AzureResourceGroup: "resource-group",
AzureSubnet: "subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkersScaleSet: "workers-scale-set",
AzureControlPlanesScaleSet: "controlplanes-scale-set",
AzureResourceGroup: "resource-group",
AzureSubnet: "subnet",
AzureNetworkSecurityGroup: "network-security-group",
AzureWorkerScaleSet: "workers-scale-set",
AzureControlPlaneScaleSet: "controlplanes-scale-set",
}
someErr := errors.New("failed")

View File

@ -17,8 +17,8 @@ func TestServiceAccountCreator(t *testing.T) {
return state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPProject: "project",
GCPWorkers: cloudtypes.Instances{},
GCPControlPlanes: cloudtypes.Instances{},
GCPWorkerInstances: cloudtypes.Instances{},
GCPControlPlaneInstances: cloudtypes.Instances{},
GCPWorkerInstanceGroup: "workers-group",
GCPControlPlaneInstanceGroup: "controlplane-group",
GCPWorkerInstanceTemplate: "template",

View File

@ -16,11 +16,11 @@ func TestTerminator(t *testing.T) {
return state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPProject: "project",
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
GCPWorkerInstanceGroup: "worker-group",
@ -35,11 +35,11 @@ func TestTerminator(t *testing.T) {
someAzureState := func() state.ConstellationState {
return state.ConstellationState{
CloudProvider: cloudprovider.Azure.String(),
AzureWorkers: cloudtypes.Instances{
AzureWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
AzureControlPlane: cloudtypes.Instances{
AzureControlPlaneInstances: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
AzureResourceGroup: "group",

View File

@ -325,11 +325,11 @@ func readOrGenerateMasterSecret(writer io.Writer, fileHandler file.Handler, file
func getScalingGroupsFromState(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
switch {
case len(stat.GCPControlPlanes) != 0:
case len(stat.GCPControlPlaneInstances) != 0:
return getGCPInstances(stat, config)
case len(stat.AzureControlPlane) != 0:
case len(stat.AzureControlPlaneInstances) != 0:
return getAzureInstances(stat, config)
case len(stat.QEMUControlPlane) != 0:
case len(stat.QEMUControlPlaneInstances) != 0:
return getQEMUInstances(stat, config)
default:
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no instances to initialize")
@ -337,23 +337,23 @@ func getScalingGroupsFromState(stat state.ConstellationState, config *config.Con
}
func getGCPInstances(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
if len(stat.GCPControlPlanes) == 0 {
if len(stat.GCPControlPlaneInstances) == 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,
Instances: stat.GCPControlPlaneInstances,
GroupID: "",
}
if len(stat.GCPWorkers) == 0 {
if len(stat.GCPWorkerInstances) == 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,
Instances: stat.GCPWorkerInstances,
GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPWorkerInstanceGroup, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
}
@ -361,47 +361,47 @@ func getGCPInstances(stat state.ConstellationState, config *config.Config) (cont
}
func getAzureInstances(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
if len(stat.AzureControlPlane) == 0 {
if len(stat.AzureControlPlaneInstances) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane workers available, can't create Constellation cluster without any instance")
}
// GroupID of controlPlanes is empty, since they currently do not scale.
controlPlanes = cloudtypes.ScalingGroup{
Instances: stat.AzureControlPlane,
Instances: stat.AzureControlPlaneInstances,
GroupID: "",
}
if len(stat.AzureWorkers) == 0 {
if len(stat.AzureWorkerInstances) == 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,
GroupID: azure.AutoscalingNodeGroup(stat.AzureWorkersScaleSet, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
Instances: stat.AzureWorkerInstances,
GroupID: azure.AutoscalingNodeGroup(stat.AzureWorkerScaleSet, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax),
}
return
}
func getQEMUInstances(stat state.ConstellationState, _ *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
controlPlanesMap := stat.QEMUControlPlane
controlPlanesMap := stat.QEMUControlPlaneInstances
if len(controlPlanesMap) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no controlPlanes available, can't create Constellation without any instance")
}
// QEMU does not support autoscaling
controlPlanes = cloudtypes.ScalingGroup{
Instances: stat.QEMUControlPlane,
Instances: stat.QEMUControlPlaneInstances,
GroupID: "",
}
if len(stat.QEMUWorkers) == 0 {
if len(stat.QEMUWorkerInstances) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no workers available, can't create Constellation with one instance")
}
// QEMU does not support autoscaling
workers = cloudtypes.ScalingGroup{
Instances: stat.QEMUWorkers,
Instances: stat.QEMUWorkerInstances,
GroupID: "",
}
return

View File

@ -46,22 +46,22 @@ func TestInitialize(t *testing.T) {
testGcpState := state.ConstellationState{
CloudProvider: "GCP",
BootstrapperHost: "192.0.2.1",
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
}
testAzureState := state.ConstellationState{
CloudProvider: "Azure",
BootstrapperHost: "192.0.2.1",
AzureWorkers: cloudtypes.Instances{
AzureWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
AzureControlPlane: cloudtypes.Instances{
AzureControlPlaneInstances: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
AzureResourceGroup: "test",
@ -69,11 +69,11 @@ func TestInitialize(t *testing.T) {
testQemuState := state.ConstellationState{
CloudProvider: "QEMU",
BootstrapperHost: "192.0.2.1",
QEMUWorkers: cloudtypes.Instances{
QEMUWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
QEMUControlPlane: cloudtypes.Instances{
QEMUControlPlaneInstances: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
}
@ -394,11 +394,11 @@ func TestAttestation(t *testing.T) {
existingState := state.ConstellationState{
CloudProvider: "QEMU",
BootstrapperHost: "192.0.2.1",
QEMUWorkers: cloudtypes.Instances{
QEMUWorkerInstances: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
QEMUControlPlane: cloudtypes.Instances{
QEMUControlPlaneInstances: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
},
}

View File

@ -245,12 +245,12 @@ func (c *Client) GetState() (state.ConstellationState, error) {
if len(c.workers) == 0 {
return state.ConstellationState{}, errors.New("client has no workers")
}
stat.GCPWorkers = c.workers
stat.GCPWorkerInstances = c.workers
if len(c.controlPlanes) == 0 {
return state.ConstellationState{}, errors.New("client has no controlPlanes")
}
stat.GCPControlPlanes = c.controlPlanes
stat.GCPControlPlaneInstances = c.controlPlanes
publicIPs := c.controlPlanes.PublicIPs()
if len(publicIPs) == 0 {
return state.ConstellationState{}, errors.New("client has no bootstrapper endpoint")
@ -343,15 +343,15 @@ func (c *Client) SetState(stat state.ConstellationState) error {
if stat.CloudProvider != cloudprovider.GCP.String() {
return errors.New("state is not gcp state")
}
if len(stat.GCPWorkers) == 0 {
if len(stat.GCPWorkerInstances) == 0 {
return errors.New("state has no workers")
}
c.workers = stat.GCPWorkers
c.workers = stat.GCPWorkerInstances
if len(stat.GCPControlPlanes) == 0 {
if len(stat.GCPControlPlaneInstances) == 0 {
return errors.New("state has no controlPlane")
}
c.controlPlanes = stat.GCPControlPlanes
c.controlPlanes = stat.GCPControlPlaneInstances
if stat.GCPWorkerInstanceGroup == "" {
return errors.New("state has no workerInstanceGroup")

View File

@ -27,13 +27,13 @@ func TestSetGetState(t *testing.T) {
"valid state": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -61,7 +61,7 @@ func TestSetGetState(t *testing.T) {
"missing workers": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -89,7 +89,7 @@ func TestSetGetState(t *testing.T) {
"missing control plane": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
@ -117,13 +117,13 @@ func TestSetGetState(t *testing.T) {
"missing worker group": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -150,13 +150,13 @@ func TestSetGetState(t *testing.T) {
"missing control plane group": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -183,13 +183,13 @@ func TestSetGetState(t *testing.T) {
"missing project id": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -216,13 +216,13 @@ func TestSetGetState(t *testing.T) {
"missing zone": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -249,13 +249,13 @@ func TestSetGetState(t *testing.T) {
"missing region": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -282,13 +282,13 @@ func TestSetGetState(t *testing.T) {
"missing name": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -314,13 +314,13 @@ func TestSetGetState(t *testing.T) {
"missing uid": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -347,13 +347,13 @@ func TestSetGetState(t *testing.T) {
"missing firewalls": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -380,13 +380,13 @@ func TestSetGetState(t *testing.T) {
"missing network": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -412,13 +412,13 @@ func TestSetGetState(t *testing.T) {
"missing external network": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -445,13 +445,13 @@ func TestSetGetState(t *testing.T) {
"missing subnetwork": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -478,13 +478,13 @@ func TestSetGetState(t *testing.T) {
"missing external subnetwork": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -511,13 +511,13 @@ func TestSetGetState(t *testing.T) {
"missing worker template": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -544,13 +544,13 @@ func TestSetGetState(t *testing.T) {
"missing control plane template": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -577,13 +577,13 @@ func TestSetGetState(t *testing.T) {
"missing backend service": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -610,13 +610,13 @@ func TestSetGetState(t *testing.T) {
"missing health check": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -643,13 +643,13 @@ func TestSetGetState(t *testing.T) {
"missing forwarding rule": {
state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(),
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -685,8 +685,8 @@ func TestSetGetState(t *testing.T) {
assert.Error(client.SetState(tc.state))
} else {
assert.NoError(client.SetState(tc.state))
assert.Equal(tc.state.GCPWorkers, client.workers)
assert.Equal(tc.state.GCPControlPlanes, client.controlPlanes)
assert.Equal(tc.state.GCPWorkerInstances, client.workers)
assert.Equal(tc.state.GCPControlPlaneInstances, client.controlPlanes)
assert.Equal(tc.state.GCPWorkerInstanceGroup, client.workerInstanceGroup)
assert.Equal(tc.state.GCPControlPlaneInstanceGroup, client.controlPlaneInstanceGroup)
assert.Equal(tc.state.GCPProject, client.project)
@ -709,8 +709,8 @@ func TestSetGetState(t *testing.T) {
assert := assert.New(t)
client := Client{
workers: tc.state.GCPWorkers,
controlPlanes: tc.state.GCPControlPlanes,
workers: tc.state.GCPWorkerInstances,
controlPlanes: tc.state.GCPControlPlaneInstances,
workerInstanceGroup: tc.state.GCPWorkerInstanceGroup,
controlPlaneInstanceGroup: tc.state.GCPControlPlaneInstanceGroup,
project: tc.state.GCPProject,
@ -746,13 +746,13 @@ func TestSetStateCloudProvider(t *testing.T) {
client := Client{}
stateMissingCloudProvider := state.ConstellationState{
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",
@ -778,13 +778,13 @@ func TestSetStateCloudProvider(t *testing.T) {
assert.Error(client.SetState(stateMissingCloudProvider))
stateIncorrectCloudProvider := state.ConstellationState{
CloudProvider: "incorrect",
GCPWorkers: cloudtypes.Instances{
GCPWorkerInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip1",
PrivateIP: "ip2",
},
},
GCPControlPlanes: cloudtypes.Instances{
GCPControlPlaneInstances: cloudtypes.Instances{
"id-1": {
PublicIP: "ip3",
PrivateIP: "ip4",

View File

@ -13,11 +13,11 @@ import (
func GetScalingGroupsFromConfig(stat state.ConstellationState, config *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
switch {
case len(stat.GCPControlPlanes) != 0:
case len(stat.GCPControlPlaneInstances) != 0:
return getGCPInstances(stat, config)
case len(stat.AzureControlPlane) != 0:
case len(stat.AzureControlPlaneInstances) != 0:
return getAzureInstances(stat, config)
case len(stat.QEMUControlPlane) != 0:
case len(stat.QEMUControlPlaneInstances) != 0:
return getQEMUInstances(stat, config)
default:
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no instances to init")
@ -25,54 +25,54 @@ func GetScalingGroupsFromConfig(stat state.ConstellationState, config *config.Co
}
func getGCPInstances(stat state.ConstellationState, _ *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
if len(stat.GCPControlPlanes) == 0 {
if len(stat.GCPControlPlaneInstances) == 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}
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.GCPControlPlaneInstances}
if len(stat.GCPWorkers) == 0 {
if len(stat.GCPWorkerInstances) == 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}
workers = cloudtypes.ScalingGroup{Instances: stat.GCPWorkerInstances}
return
}
func getAzureInstances(stat state.ConstellationState, _ *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
if len(stat.AzureControlPlane) == 0 {
if len(stat.AzureControlPlaneInstances) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no control-plane workers available, can't create Constellation cluster without any instance")
}
// GroupID of controlPlanes is empty, since they currently do not scale.
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.AzureControlPlane}
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.AzureControlPlaneInstances}
if len(stat.AzureWorkers) == 0 {
if len(stat.AzureWorkerInstances) == 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}
workers = cloudtypes.ScalingGroup{Instances: stat.AzureWorkerInstances}
return
}
func getQEMUInstances(stat state.ConstellationState, _ *config.Config) (controlPlanes, workers cloudtypes.ScalingGroup, err error) {
controlPlaneMap := stat.QEMUControlPlane
controlPlaneMap := stat.QEMUControlPlaneInstances
if len(controlPlaneMap) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no controlPlanes available, can't create Constellation without any instance")
}
// QEMU does not support autoscaling
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.QEMUControlPlane}
controlPlanes = cloudtypes.ScalingGroup{Instances: stat.QEMUControlPlaneInstances}
if len(stat.QEMUWorkers) == 0 {
if len(stat.QEMUWorkerInstances) == 0 {
return cloudtypes.ScalingGroup{}, cloudtypes.ScalingGroup{}, errors.New("no workers available, can't create Constellation with one instance")
}
// QEMU does not support autoscaling
workers = cloudtypes.ScalingGroup{Instances: stat.QEMUWorkers}
workers = cloudtypes.ScalingGroup{Instances: stat.QEMUWorkerInstances}
return
}

View File

@ -39,21 +39,21 @@ func terraformOut(workspaceDir string) (terraformOutput, error) {
func transformState(tfOut terraformOutput) state.ConstellationState {
conState := state.ConstellationState{
Name: "qemu",
UID: "debug",
CloudProvider: cloudprovider.QEMU.String(),
BootstrapperHost: tfOut.ControlPlaneIPs.Value[0],
QEMUWorkers: cloudtypes.Instances{},
QEMUControlPlane: cloudtypes.Instances{},
Name: "qemu",
UID: "debug",
CloudProvider: cloudprovider.QEMU.String(),
BootstrapperHost: tfOut.ControlPlaneIPs.Value[0],
QEMUWorkerInstances: cloudtypes.Instances{},
QEMUControlPlaneInstances: cloudtypes.Instances{},
}
for i, ip := range tfOut.ControlPlaneIPs.Value {
conState.QEMUControlPlane[fmt.Sprintf("control-plane-%d", i)] = cloudtypes.Instance{
conState.QEMUControlPlaneInstances[fmt.Sprintf("control-plane-%d", i)] = cloudtypes.Instance{
PublicIP: ip,
PrivateIP: ip,
}
}
for i, ip := range tfOut.WorkerIPs.Value {
conState.QEMUWorkers[fmt.Sprintf("worker-%d", i)] = cloudtypes.Instance{
conState.QEMUWorkerInstances[fmt.Sprintf("worker-%d", i)] = cloudtypes.Instance{
PublicIP: ip,
PrivateIP: ip,
}

View File

@ -11,8 +11,8 @@ type ConstellationState struct {
CloudProvider string `json:"cloudprovider,omitempty"`
BootstrapperHost string `json:"bootstrapperhost,omitempty"`
GCPWorkers cloudtypes.Instances `json:"gcpworkers,omitempty"`
GCPControlPlanes cloudtypes.Instances `json:"gcpcontrolplanes,omitempty"`
GCPWorkerInstances cloudtypes.Instances `json:"gcpworkers,omitempty"`
GCPControlPlaneInstances cloudtypes.Instances `json:"gcpcontrolplanes,omitempty"`
GCPWorkerInstanceGroup string `json:"gcpworkerinstancegroup,omitempty"`
GCPControlPlaneInstanceGroup string `json:"gcpcontrolplaneinstancegroup,omitempty"`
GCPWorkerInstanceTemplate string `json:"gcpworkerinstancetemplate,omitempty"`
@ -28,18 +28,18 @@ type ConstellationState struct {
GCPRegion string `json:"gcpregion,omitempty"`
GCPServiceAccount string `json:"gcpserviceaccount,omitempty"`
AzureWorkers cloudtypes.Instances `json:"azureworkers,omitempty"`
AzureControlPlane cloudtypes.Instances `json:"azurecontrolplanes,omitempty"`
AzureWorkerInstances cloudtypes.Instances `json:"azureworkers,omitempty"`
AzureControlPlaneInstances cloudtypes.Instances `json:"azurecontrolplanes,omitempty"`
AzureResourceGroup string `json:"azureresourcegroup,omitempty"`
AzureLocation string `json:"azurelocation,omitempty"`
AzureSubscription string `json:"azuresubscription,omitempty"`
AzureTenant string `json:"azuretenant,omitempty"`
AzureSubnet string `json:"azuresubnet,omitempty"`
AzureNetworkSecurityGroup string `json:"azurenetworksecuritygroup,omitempty"`
AzureWorkersScaleSet string `json:"azureworkersscaleset,omitempty"`
AzureControlPlanesScaleSet string `json:"azurecontrolplanesscaleset,omitempty"`
AzureWorkerScaleSet string `json:"azureworkersscaleset,omitempty"`
AzureControlPlaneScaleSet string `json:"azurecontrolplanesscaleset,omitempty"`
AzureADAppObjectID string `json:"azureadappobjectid,omitempty"`
QEMUWorkers cloudtypes.Instances `json:"qemuworkers,omitempty"`
QEMUControlPlane cloudtypes.Instances `json:"qemucontrolplanes,omitempty"`
QEMUWorkerInstances cloudtypes.Instances `json:"qemuworkers,omitempty"`
QEMUControlPlaneInstances cloudtypes.Instances `json:"qemucontrolplanes,omitempty"`
}