mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
Remove checks for GetState/SetState
This commit is contained in:
parent
f28e00659c
commit
9f599c3993
@ -2,7 +2,6 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"time"
|
"time"
|
||||||
@ -168,128 +167,42 @@ func (c *Client) init(location, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetState returns the state of the client as ConstellationState.
|
// GetState returns the state of the client as ConstellationState.
|
||||||
func (c *Client) GetState() (state.ConstellationState, error) {
|
func (c *Client) GetState() state.ConstellationState {
|
||||||
var stat state.ConstellationState
|
return state.ConstellationState{
|
||||||
stat.CloudProvider = cloudprovider.Azure.String()
|
Name: c.name,
|
||||||
if len(c.resourceGroup) == 0 {
|
UID: c.uid,
|
||||||
return state.ConstellationState{}, errors.New("client has no resource group")
|
CloudProvider: cloudprovider.Azure.String(),
|
||||||
|
BootstrapperHost: c.loadBalancerPubIP,
|
||||||
|
AzureLocation: c.location,
|
||||||
|
AzureSubscription: c.subscriptionID,
|
||||||
|
AzureTenant: c.tenantID,
|
||||||
|
AzureResourceGroup: c.resourceGroup,
|
||||||
|
AzureNetworkSecurityGroup: c.networkSecurityGroup,
|
||||||
|
AzureSubnet: c.subnetID,
|
||||||
|
AzureWorkerScaleSet: c.workerScaleSet,
|
||||||
|
AzureControlPlaneScaleSet: c.controlPlaneScaleSet,
|
||||||
|
AzureWorkerInstances: c.workers,
|
||||||
|
AzureControlPlaneInstances: c.controlPlanes,
|
||||||
|
AzureADAppObjectID: c.adAppObjectID,
|
||||||
}
|
}
|
||||||
stat.AzureResourceGroup = c.resourceGroup
|
|
||||||
if c.name == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no name")
|
|
||||||
}
|
|
||||||
stat.Name = c.name
|
|
||||||
if len(c.uid) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no uid")
|
|
||||||
}
|
|
||||||
stat.UID = c.uid
|
|
||||||
if len(c.loadBalancerPubIP) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no load balancer public IP")
|
|
||||||
}
|
|
||||||
stat.BootstrapperHost = c.loadBalancerPubIP
|
|
||||||
if len(c.location) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no location")
|
|
||||||
}
|
|
||||||
stat.AzureLocation = c.location
|
|
||||||
if len(c.subscriptionID) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no subscription")
|
|
||||||
}
|
|
||||||
stat.AzureSubscription = c.subscriptionID
|
|
||||||
if len(c.tenantID) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no tenant")
|
|
||||||
}
|
|
||||||
stat.AzureTenant = c.tenantID
|
|
||||||
if len(c.subnetID) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no subnet")
|
|
||||||
}
|
|
||||||
stat.AzureSubnet = c.subnetID
|
|
||||||
if len(c.networkSecurityGroup) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no network security group")
|
|
||||||
}
|
|
||||||
stat.AzureNetworkSecurityGroup = c.networkSecurityGroup
|
|
||||||
if len(c.workerScaleSet) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no worker scale set")
|
|
||||||
}
|
|
||||||
stat.AzureWorkerScaleSet = c.workerScaleSet
|
|
||||||
if len(c.controlPlaneScaleSet) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no control plane scale set")
|
|
||||||
}
|
|
||||||
stat.AzureControlPlaneScaleSet = c.controlPlaneScaleSet
|
|
||||||
if len(c.workers) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no workers")
|
|
||||||
}
|
|
||||||
stat.AzureWorkerInstances = c.workers
|
|
||||||
if len(c.controlPlanes) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no control planes")
|
|
||||||
}
|
|
||||||
stat.AzureControlPlaneInstances = c.controlPlanes
|
|
||||||
// AD App Object ID does not have to be set at all times
|
|
||||||
stat.AzureADAppObjectID = c.adAppObjectID
|
|
||||||
|
|
||||||
return stat, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetState sets the state of the client to the handed ConstellationState.
|
// SetState sets the state of the client to the handed ConstellationState.
|
||||||
func (c *Client) SetState(stat state.ConstellationState) error {
|
func (c *Client) SetState(stat state.ConstellationState) {
|
||||||
if stat.CloudProvider != cloudprovider.Azure.String() {
|
|
||||||
return errors.New("state is not azure state")
|
|
||||||
}
|
|
||||||
if len(stat.AzureResourceGroup) == 0 {
|
|
||||||
return errors.New("state has no resource group")
|
|
||||||
}
|
|
||||||
c.resourceGroup = stat.AzureResourceGroup
|
c.resourceGroup = stat.AzureResourceGroup
|
||||||
if stat.Name == "" {
|
|
||||||
return errors.New("state has no name")
|
|
||||||
}
|
|
||||||
c.name = stat.Name
|
c.name = stat.Name
|
||||||
if len(stat.UID) == 0 {
|
|
||||||
return errors.New("state has no uuid")
|
|
||||||
}
|
|
||||||
c.uid = stat.UID
|
c.uid = stat.UID
|
||||||
if len(stat.BootstrapperHost) == 0 {
|
|
||||||
return errors.New("state has no bootstrapper host")
|
|
||||||
}
|
|
||||||
c.loadBalancerPubIP = stat.BootstrapperHost
|
c.loadBalancerPubIP = stat.BootstrapperHost
|
||||||
if len(stat.AzureLocation) == 0 {
|
|
||||||
return errors.New("state has no location")
|
|
||||||
}
|
|
||||||
c.location = stat.AzureLocation
|
c.location = stat.AzureLocation
|
||||||
if len(stat.AzureSubscription) == 0 {
|
|
||||||
return errors.New("state has no subscription")
|
|
||||||
}
|
|
||||||
c.subscriptionID = stat.AzureSubscription
|
c.subscriptionID = stat.AzureSubscription
|
||||||
if len(stat.AzureTenant) == 0 {
|
|
||||||
return errors.New("state has no tenant")
|
|
||||||
}
|
|
||||||
c.tenantID = stat.AzureTenant
|
c.tenantID = stat.AzureTenant
|
||||||
if len(stat.AzureSubnet) == 0 {
|
|
||||||
return errors.New("state has no subnet")
|
|
||||||
}
|
|
||||||
c.subnetID = stat.AzureSubnet
|
c.subnetID = stat.AzureSubnet
|
||||||
if len(stat.AzureNetworkSecurityGroup) == 0 {
|
|
||||||
return errors.New("state has no subnet")
|
|
||||||
}
|
|
||||||
c.networkSecurityGroup = stat.AzureNetworkSecurityGroup
|
c.networkSecurityGroup = stat.AzureNetworkSecurityGroup
|
||||||
if len(stat.AzureWorkerScaleSet) == 0 {
|
|
||||||
return errors.New("state has no worker scale set")
|
|
||||||
}
|
|
||||||
c.workerScaleSet = stat.AzureWorkerScaleSet
|
c.workerScaleSet = stat.AzureWorkerScaleSet
|
||||||
if len(stat.AzureControlPlaneScaleSet) == 0 {
|
|
||||||
return errors.New("state has no worker scale set")
|
|
||||||
}
|
|
||||||
c.controlPlaneScaleSet = stat.AzureControlPlaneScaleSet
|
c.controlPlaneScaleSet = stat.AzureControlPlaneScaleSet
|
||||||
if len(stat.AzureWorkerInstances) == 0 {
|
|
||||||
return errors.New("state has no workers")
|
|
||||||
}
|
|
||||||
c.workers = stat.AzureWorkerInstances
|
c.workers = stat.AzureWorkerInstances
|
||||||
if len(stat.AzureControlPlaneInstances) == 0 {
|
|
||||||
return errors.New("state has no control planes")
|
|
||||||
}
|
|
||||||
c.controlPlanes = stat.AzureControlPlaneInstances
|
c.controlPlanes = stat.AzureControlPlaneInstances
|
||||||
// AD App Object ID does not have to be set at all times
|
|
||||||
c.adAppObjectID = stat.AzureADAppObjectID
|
c.adAppObjectID = stat.AzureADAppObjectID
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) generateUID() (string, error) {
|
func (c *Client) generateUID() (string, error) {
|
||||||
|
@ -16,509 +16,69 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetGetState(t *testing.T) {
|
func TestSetGetState(t *testing.T) {
|
||||||
testCases := map[string]struct {
|
state := state.ConstellationState{
|
||||||
state state.ConstellationState
|
CloudProvider: cloudprovider.Azure.String(),
|
||||||
wantErr bool
|
AzureWorkerInstances: cloudtypes.Instances{
|
||||||
}{
|
"0": {PublicIP: "ip1", PrivateIP: "ip2"},
|
||||||
"valid state": {
|
|
||||||
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",
|
|
||||||
AzureControlPlaneScaleSet: "controlplane-scale-set",
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
"missing workers": {
|
AzureControlPlaneInstances: cloudtypes.Instances{
|
||||||
state: state.ConstellationState{
|
"0": {PublicIP: "ip3", PrivateIP: "ip4"},
|
||||||
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,
|
|
||||||
},
|
},
|
||||||
|
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",
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("SetState", func(t *testing.T) {
|
t.Run("SetState", func(t *testing.T) {
|
||||||
for name, tc := range testCases {
|
assert := assert.New(t)
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
client := Client{}
|
client := Client{}
|
||||||
if tc.wantErr {
|
client.SetState(state)
|
||||||
assert.Error(client.SetState(tc.state))
|
assert.Equal(state.AzureWorkerInstances, client.workers)
|
||||||
} else {
|
assert.Equal(state.AzureControlPlaneInstances, client.controlPlanes)
|
||||||
assert.NoError(client.SetState(tc.state))
|
assert.Equal(state.Name, client.name)
|
||||||
assert.Equal(tc.state.AzureWorkerInstances, client.workers)
|
assert.Equal(state.UID, client.uid)
|
||||||
assert.Equal(tc.state.AzureControlPlaneInstances, client.controlPlanes)
|
assert.Equal(state.AzureResourceGroup, client.resourceGroup)
|
||||||
assert.Equal(tc.state.Name, client.name)
|
assert.Equal(state.AzureLocation, client.location)
|
||||||
assert.Equal(tc.state.UID, client.uid)
|
assert.Equal(state.AzureSubscription, client.subscriptionID)
|
||||||
assert.Equal(tc.state.AzureResourceGroup, client.resourceGroup)
|
assert.Equal(state.AzureTenant, client.tenantID)
|
||||||
assert.Equal(tc.state.AzureLocation, client.location)
|
assert.Equal(state.AzureSubnet, client.subnetID)
|
||||||
assert.Equal(tc.state.AzureSubscription, client.subscriptionID)
|
assert.Equal(state.AzureNetworkSecurityGroup, client.networkSecurityGroup)
|
||||||
assert.Equal(tc.state.AzureTenant, client.tenantID)
|
assert.Equal(state.AzureWorkerScaleSet, client.workerScaleSet)
|
||||||
assert.Equal(tc.state.AzureSubnet, client.subnetID)
|
assert.Equal(state.AzureControlPlaneScaleSet, client.controlPlaneScaleSet)
|
||||||
assert.Equal(tc.state.AzureNetworkSecurityGroup, client.networkSecurityGroup)
|
|
||||||
assert.Equal(tc.state.AzureWorkerScaleSet, client.workerScaleSet)
|
|
||||||
assert.Equal(tc.state.AzureControlPlaneScaleSet, client.controlPlaneScaleSet)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("GetState", func(t *testing.T) {
|
t.Run("GetState", func(t *testing.T) {
|
||||||
for name, tc := range testCases {
|
assert := assert.New(t)
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
client := Client{
|
client := Client{
|
||||||
workers: tc.state.AzureWorkerInstances,
|
workers: state.AzureWorkerInstances,
|
||||||
controlPlanes: tc.state.AzureControlPlaneInstances,
|
controlPlanes: state.AzureControlPlaneInstances,
|
||||||
name: tc.state.Name,
|
name: state.Name,
|
||||||
uid: tc.state.UID,
|
uid: state.UID,
|
||||||
loadBalancerPubIP: tc.state.BootstrapperHost,
|
loadBalancerPubIP: state.BootstrapperHost,
|
||||||
resourceGroup: tc.state.AzureResourceGroup,
|
resourceGroup: state.AzureResourceGroup,
|
||||||
location: tc.state.AzureLocation,
|
location: state.AzureLocation,
|
||||||
subscriptionID: tc.state.AzureSubscription,
|
subscriptionID: state.AzureSubscription,
|
||||||
tenantID: tc.state.AzureTenant,
|
tenantID: state.AzureTenant,
|
||||||
subnetID: tc.state.AzureSubnet,
|
subnetID: state.AzureSubnet,
|
||||||
networkSecurityGroup: tc.state.AzureNetworkSecurityGroup,
|
networkSecurityGroup: state.AzureNetworkSecurityGroup,
|
||||||
workerScaleSet: tc.state.AzureWorkerScaleSet,
|
workerScaleSet: state.AzureWorkerScaleSet,
|
||||||
controlPlaneScaleSet: tc.state.AzureControlPlaneScaleSet,
|
controlPlaneScaleSet: state.AzureControlPlaneScaleSet,
|
||||||
}
|
|
||||||
if tc.wantErr {
|
|
||||||
_, err := client.GetState()
|
|
||||||
assert.Error(err)
|
|
||||||
} else {
|
|
||||||
state, err := client.GetState()
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(tc.state, state)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
stat := client.GetState()
|
||||||
|
assert.Equal(state, stat)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetStateCloudProvider(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
client := Client{}
|
|
||||||
stateMissingCloudProvider := state.ConstellationState{
|
|
||||||
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",
|
|
||||||
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",
|
|
||||||
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",
|
|
||||||
AzureSubnet: "azure-subnet",
|
|
||||||
AzureNetworkSecurityGroup: "network-security-group",
|
|
||||||
AzureWorkerScaleSet: "worker-scale-set",
|
|
||||||
AzureControlPlaneScaleSet: "controlplane-scale-set",
|
|
||||||
}
|
|
||||||
assert.Error(client.SetState(stateIncorrectCloudProvider))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type gcpclient interface {
|
type gcpclient interface {
|
||||||
GetState() (state.ConstellationState, error)
|
GetState() state.ConstellationState
|
||||||
SetState(state.ConstellationState) error
|
SetState(state.ConstellationState)
|
||||||
CreateVPCs(ctx context.Context) error
|
CreateVPCs(ctx context.Context) error
|
||||||
CreateFirewall(ctx context.Context, input gcpcl.FirewallInput) error
|
CreateFirewall(ctx context.Context, input gcpcl.FirewallInput) error
|
||||||
CreateInstances(ctx context.Context, input gcpcl.CreateInstancesInput) error
|
CreateInstances(ctx context.Context, input gcpcl.CreateInstancesInput) error
|
||||||
@ -25,8 +25,8 @@ type gcpclient interface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type azureclient interface {
|
type azureclient interface {
|
||||||
GetState() (state.ConstellationState, error)
|
GetState() state.ConstellationState
|
||||||
SetState(state.ConstellationState) error
|
SetState(state.ConstellationState)
|
||||||
CreateApplicationInsight(ctx context.Context) error
|
CreateApplicationInsight(ctx context.Context) error
|
||||||
CreateResourceGroup(ctx context.Context) error
|
CreateResourceGroup(ctx context.Context) error
|
||||||
CreateExternalLoadBalancer(ctx context.Context) error
|
CreateExternalLoadBalancer(ctx context.Context) error
|
||||||
|
@ -41,8 +41,8 @@ type fakeAzureClient struct {
|
|||||||
adAppObjectID string
|
adAppObjectID string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeAzureClient) GetState() (state.ConstellationState, error) {
|
func (c *fakeAzureClient) GetState() state.ConstellationState {
|
||||||
stat := state.ConstellationState{
|
return state.ConstellationState{
|
||||||
CloudProvider: cloudprovider.Azure.String(),
|
CloudProvider: cloudprovider.Azure.String(),
|
||||||
AzureWorkerInstances: c.workers,
|
AzureWorkerInstances: c.workers,
|
||||||
AzureControlPlaneInstances: c.controlPlanes,
|
AzureControlPlaneInstances: c.controlPlanes,
|
||||||
@ -58,10 +58,9 @@ func (c *fakeAzureClient) GetState() (state.ConstellationState, error) {
|
|||||||
AzureControlPlaneScaleSet: c.controlPlaneScaleSet,
|
AzureControlPlaneScaleSet: c.controlPlaneScaleSet,
|
||||||
AzureADAppObjectID: c.adAppObjectID,
|
AzureADAppObjectID: c.adAppObjectID,
|
||||||
}
|
}
|
||||||
return stat, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeAzureClient) SetState(stat state.ConstellationState) error {
|
func (c *fakeAzureClient) SetState(stat state.ConstellationState) {
|
||||||
c.workers = stat.AzureWorkerInstances
|
c.workers = stat.AzureWorkerInstances
|
||||||
c.controlPlanes = stat.AzureControlPlaneInstances
|
c.controlPlanes = stat.AzureControlPlaneInstances
|
||||||
c.name = stat.Name
|
c.name = stat.Name
|
||||||
@ -75,7 +74,6 @@ func (c *fakeAzureClient) SetState(stat state.ConstellationState) error {
|
|||||||
c.workerScaleSet = stat.AzureWorkerScaleSet
|
c.workerScaleSet = stat.AzureWorkerScaleSet
|
||||||
c.controlPlaneScaleSet = stat.AzureControlPlaneScaleSet
|
c.controlPlaneScaleSet = stat.AzureControlPlaneScaleSet
|
||||||
c.adAppObjectID = stat.AzureADAppObjectID
|
c.adAppObjectID = stat.AzureADAppObjectID
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeAzureClient) CreateApplicationInsight(ctx context.Context) error {
|
func (c *fakeAzureClient) CreateApplicationInsight(ctx context.Context) error {
|
||||||
@ -167,8 +165,6 @@ type stubAzureClient struct {
|
|||||||
terminateResourceGroupCalled bool
|
terminateResourceGroupCalled bool
|
||||||
terminateServicePrincipalCalled bool
|
terminateServicePrincipalCalled bool
|
||||||
|
|
||||||
getStateErr error
|
|
||||||
setStateErr error
|
|
||||||
createApplicationInsightErr error
|
createApplicationInsightErr error
|
||||||
createResourceGroupErr error
|
createResourceGroupErr error
|
||||||
createVirtualNetworkErr error
|
createVirtualNetworkErr error
|
||||||
@ -180,12 +176,11 @@ type stubAzureClient struct {
|
|||||||
terminateServicePrincipalErr error
|
terminateServicePrincipalErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubAzureClient) GetState() (state.ConstellationState, error) {
|
func (c *stubAzureClient) GetState() state.ConstellationState {
|
||||||
return state.ConstellationState{}, c.getStateErr
|
return state.ConstellationState{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubAzureClient) SetState(state.ConstellationState) error {
|
func (c *stubAzureClient) SetState(state.ConstellationState) {
|
||||||
return c.setStateErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubAzureClient) CreateExternalLoadBalancer(ctx context.Context) error {
|
func (c *stubAzureClient) CreateExternalLoadBalancer(ctx context.Context) error {
|
||||||
@ -257,8 +252,8 @@ type fakeGcpClient struct {
|
|||||||
forwardingRule string
|
forwardingRule string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeGcpClient) GetState() (state.ConstellationState, error) {
|
func (c *fakeGcpClient) GetState() state.ConstellationState {
|
||||||
stat := state.ConstellationState{
|
return state.ConstellationState{
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
CloudProvider: cloudprovider.GCP.String(),
|
||||||
GCPWorkerInstances: c.workers,
|
GCPWorkerInstances: c.workers,
|
||||||
GCPControlPlaneInstances: c.controlPlanes,
|
GCPControlPlaneInstances: c.controlPlanes,
|
||||||
@ -278,10 +273,9 @@ func (c *fakeGcpClient) GetState() (state.ConstellationState, error) {
|
|||||||
GCPZone: c.zone,
|
GCPZone: c.zone,
|
||||||
GCPServiceAccount: c.serviceAccount,
|
GCPServiceAccount: c.serviceAccount,
|
||||||
}
|
}
|
||||||
return stat, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeGcpClient) SetState(stat state.ConstellationState) error {
|
func (c *fakeGcpClient) SetState(stat state.ConstellationState) {
|
||||||
c.workers = stat.GCPWorkerInstances
|
c.workers = stat.GCPWorkerInstances
|
||||||
c.controlPlanes = stat.GCPControlPlaneInstances
|
c.controlPlanes = stat.GCPControlPlaneInstances
|
||||||
c.workerInstanceGroup = stat.GCPWorkerInstanceGroup
|
c.workerInstanceGroup = stat.GCPWorkerInstanceGroup
|
||||||
@ -299,7 +293,6 @@ func (c *fakeGcpClient) SetState(stat state.ConstellationState) error {
|
|||||||
c.healthCheck = stat.GCPHealthCheck
|
c.healthCheck = stat.GCPHealthCheck
|
||||||
c.backendService = stat.GCPBackendService
|
c.backendService = stat.GCPBackendService
|
||||||
c.forwardingRule = stat.GCPForwardingRule
|
c.forwardingRule = stat.GCPForwardingRule
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeGcpClient) CreateVPCs(ctx context.Context) error {
|
func (c *fakeGcpClient) CreateVPCs(ctx context.Context) error {
|
||||||
@ -409,8 +402,6 @@ type stubGcpClient struct {
|
|||||||
terminateServiceAccountCalled bool
|
terminateServiceAccountCalled bool
|
||||||
closeCalled bool
|
closeCalled bool
|
||||||
|
|
||||||
getStateErr error
|
|
||||||
setStateErr error
|
|
||||||
createVPCsErr error
|
createVPCsErr error
|
||||||
createFirewallErr error
|
createFirewallErr error
|
||||||
createInstancesErr error
|
createInstancesErr error
|
||||||
@ -424,12 +415,11 @@ type stubGcpClient struct {
|
|||||||
closeErr error
|
closeErr error
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubGcpClient) GetState() (state.ConstellationState, error) {
|
func (c *stubGcpClient) GetState() state.ConstellationState {
|
||||||
return state.ConstellationState{}, c.getStateErr
|
return state.ConstellationState{}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubGcpClient) SetState(state.ConstellationState) error {
|
func (c *stubGcpClient) SetState(state.ConstellationState) {
|
||||||
return c.setStateErr
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubGcpClient) CreateVPCs(ctx context.Context) error {
|
func (c *stubGcpClient) CreateVPCs(ctx context.Context) error {
|
||||||
|
@ -137,7 +137,7 @@ func (c *Creator) createGCP(ctx context.Context, cl gcpclient, config *config.Co
|
|||||||
return state.ConstellationState{}, err
|
return state.ConstellationState{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cl.GetState()
|
return cl.GetState(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Creator) createAzure(ctx context.Context, cl azureclient, config *config.Config, insType string, controlPlaneCount, workerCount int,
|
func (c *Creator) createAzure(ctx context.Context, cl azureclient, config *config.Config, insType string, controlPlaneCount, workerCount int,
|
||||||
@ -176,5 +176,5 @@ func (c *Creator) createAzure(ctx context.Context, cl azureclient, config *confi
|
|||||||
return state.ConstellationState{}, err
|
return state.ConstellationState{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return cl.GetState()
|
return cl.GetState(), nil
|
||||||
}
|
}
|
||||||
|
@ -68,9 +68,7 @@ func (c *ServiceAccountCreator) Create(ctx context.Context, stat state.Constella
|
|||||||
func (c *ServiceAccountCreator) createServiceAccountGCP(ctx context.Context, cl gcpclient,
|
func (c *ServiceAccountCreator) createServiceAccountGCP(ctx context.Context, cl gcpclient,
|
||||||
stat state.ConstellationState, config *config.Config,
|
stat state.ConstellationState, config *config.Config,
|
||||||
) (string, state.ConstellationState, error) {
|
) (string, state.ConstellationState, error) {
|
||||||
if err := cl.SetState(stat); err != nil {
|
cl.SetState(stat)
|
||||||
return "", state.ConstellationState{}, fmt.Errorf("setting state while creating service account: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
input := gcpcl.ServiceAccountInput{
|
input := gcpcl.ServiceAccountInput{
|
||||||
Roles: config.Provider.GCP.ServiceAccountRoles,
|
Roles: config.Provider.GCP.ServiceAccountRoles,
|
||||||
@ -80,27 +78,18 @@ func (c *ServiceAccountCreator) createServiceAccountGCP(ctx context.Context, cl
|
|||||||
return "", state.ConstellationState{}, fmt.Errorf("creating service account: %w", err)
|
return "", state.ConstellationState{}, fmt.Errorf("creating service account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, err = cl.GetState()
|
return serviceAccount, cl.GetState(), nil
|
||||||
if err != nil {
|
|
||||||
return "", state.ConstellationState{}, fmt.Errorf("getting state after creating service account: %w", err)
|
|
||||||
}
|
|
||||||
return serviceAccount, stat, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *ServiceAccountCreator) createServiceAccountAzure(ctx context.Context, cl azureclient,
|
func (c *ServiceAccountCreator) createServiceAccountAzure(ctx context.Context, cl azureclient,
|
||||||
stat state.ConstellationState, _ *config.Config,
|
stat state.ConstellationState, _ *config.Config,
|
||||||
) (string, state.ConstellationState, error) {
|
) (string, state.ConstellationState, error) {
|
||||||
if err := cl.SetState(stat); err != nil {
|
cl.SetState(stat)
|
||||||
return "", state.ConstellationState{}, fmt.Errorf("setting state while creating service account: %w", err)
|
|
||||||
}
|
|
||||||
serviceAccount, err := cl.CreateServicePrincipal(ctx)
|
serviceAccount, err := cl.CreateServicePrincipal(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", state.ConstellationState{}, fmt.Errorf("creating service account: %w", err)
|
return "", state.ConstellationState{}, fmt.Errorf("creating service account: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
stat, err = cl.GetState()
|
return serviceAccount, cl.GetState(), nil
|
||||||
if err != nil {
|
|
||||||
return "", state.ConstellationState{}, fmt.Errorf("getting state after creating service account: %w", err)
|
|
||||||
}
|
|
||||||
return serviceAccount, stat, nil
|
|
||||||
}
|
}
|
||||||
|
@ -60,14 +60,6 @@ func TestServiceAccountCreator(t *testing.T) {
|
|||||||
config: config.Default(),
|
config: config.Default(),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"gcp client setState error": {
|
|
||||||
newGCPClient: func(ctx context.Context) (gcpclient, error) {
|
|
||||||
return &stubGcpClient{setStateErr: someErr}, nil
|
|
||||||
},
|
|
||||||
state: someGCPState(),
|
|
||||||
config: config.Default(),
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"gcp client createServiceAccount error": {
|
"gcp client createServiceAccount error": {
|
||||||
newGCPClient: func(ctx context.Context) (gcpclient, error) {
|
newGCPClient: func(ctx context.Context) (gcpclient, error) {
|
||||||
return &stubGcpClient{createServiceAccountErr: someErr}, nil
|
return &stubGcpClient{createServiceAccountErr: someErr}, nil
|
||||||
@ -76,14 +68,6 @@ func TestServiceAccountCreator(t *testing.T) {
|
|||||||
config: config.Default(),
|
config: config.Default(),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"gcp client getState error": {
|
|
||||||
newGCPClient: func(ctx context.Context) (gcpclient, error) {
|
|
||||||
return &stubGcpClient{getStateErr: someErr}, nil
|
|
||||||
},
|
|
||||||
state: someGCPState(),
|
|
||||||
config: config.Default(),
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"azure": {
|
"azure": {
|
||||||
newAzureClient: func(subscriptionID, tenantID string) (azureclient, error) {
|
newAzureClient: func(subscriptionID, tenantID string) (azureclient, error) {
|
||||||
return &fakeAzureClient{}, nil
|
return &fakeAzureClient{}, nil
|
||||||
@ -102,14 +86,6 @@ func TestServiceAccountCreator(t *testing.T) {
|
|||||||
config: config.Default(),
|
config: config.Default(),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"azure client setState error": {
|
|
||||||
newAzureClient: func(subscriptionID, tenantID string) (azureclient, error) {
|
|
||||||
return &stubAzureClient{setStateErr: someErr}, nil
|
|
||||||
},
|
|
||||||
state: someAzureState(),
|
|
||||||
config: config.Default(),
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"azure client createServiceAccount error": {
|
"azure client createServiceAccount error": {
|
||||||
newAzureClient: func(subscriptionID, tenantID string) (azureclient, error) {
|
newAzureClient: func(subscriptionID, tenantID string) (azureclient, error) {
|
||||||
return &stubAzureClient{createServicePrincipalErr: someErr}, nil
|
return &stubAzureClient{createServicePrincipalErr: someErr}, nil
|
||||||
@ -118,14 +94,6 @@ func TestServiceAccountCreator(t *testing.T) {
|
|||||||
config: config.Default(),
|
config: config.Default(),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"azure client getState error": {
|
|
||||||
newAzureClient: func(subscriptionID, tenantID string) (azureclient, error) {
|
|
||||||
return &stubAzureClient{getStateErr: someErr}, nil
|
|
||||||
},
|
|
||||||
state: someAzureState(),
|
|
||||||
config: config.Default(),
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"qemu": {
|
"qemu": {
|
||||||
state: state.ConstellationState{CloudProvider: "qemu"},
|
state: state.ConstellationState{CloudProvider: "qemu"},
|
||||||
wantStateMutator: func(cs *state.ConstellationState) {},
|
wantStateMutator: func(cs *state.ConstellationState) {},
|
||||||
|
@ -51,9 +51,7 @@ func (t *Terminator) Terminate(ctx context.Context, state state.ConstellationSta
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminator) terminateGCP(ctx context.Context, cl gcpclient, state state.ConstellationState) error {
|
func (t *Terminator) terminateGCP(ctx context.Context, cl gcpclient, state state.ConstellationState) error {
|
||||||
if err := cl.SetState(state); err != nil {
|
cl.SetState(state)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cl.TerminateLoadBalancer(ctx); err != nil {
|
if err := cl.TerminateLoadBalancer(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
@ -71,9 +69,7 @@ func (t *Terminator) terminateGCP(ctx context.Context, cl gcpclient, state state
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (t *Terminator) terminateAzure(ctx context.Context, cl azureclient, state state.ConstellationState) error {
|
func (t *Terminator) terminateAzure(ctx context.Context, cl azureclient, state state.ConstellationState) error {
|
||||||
if err := cl.SetState(state); err != nil {
|
cl.SetState(state)
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := cl.TerminateServicePrincipal(ctx); err != nil {
|
if err := cl.TerminateServicePrincipal(ctx); err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -65,11 +65,6 @@ func TestTerminator(t *testing.T) {
|
|||||||
state: someGCPState(),
|
state: someGCPState(),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"gcp setState error": {
|
|
||||||
gcpclient: &stubGcpClient{setStateErr: someErr},
|
|
||||||
state: someGCPState(),
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"gcp terminateInstances error": {
|
"gcp terminateInstances error": {
|
||||||
gcpclient: &stubGcpClient{terminateInstancesErr: someErr},
|
gcpclient: &stubGcpClient{terminateInstancesErr: someErr},
|
||||||
state: someGCPState(),
|
state: someGCPState(),
|
||||||
@ -99,11 +94,6 @@ func TestTerminator(t *testing.T) {
|
|||||||
state: someAzureState(),
|
state: someAzureState(),
|
||||||
wantErr: true,
|
wantErr: true,
|
||||||
},
|
},
|
||||||
"azure setState error": {
|
|
||||||
azureclient: &stubAzureClient{setStateErr: someErr},
|
|
||||||
state: someAzureState(),
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"azure terminateServicePrincipal error": {
|
"azure terminateServicePrincipal error": {
|
||||||
azureclient: &stubAzureClient{terminateServicePrincipalErr: someErr},
|
azureclient: &stubAzureClient{terminateServicePrincipalErr: someErr},
|
||||||
state: someAzureState(),
|
state: someAzureState(),
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
|
|
||||||
@ -239,199 +238,51 @@ func (c *Client) init(project, zone, region, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetState returns the state of the client as ConstellationState.
|
// GetState returns the state of the client as ConstellationState.
|
||||||
func (c *Client) GetState() (state.ConstellationState, error) {
|
func (c *Client) GetState() state.ConstellationState {
|
||||||
var stat state.ConstellationState
|
return state.ConstellationState{
|
||||||
stat.CloudProvider = cloudprovider.GCP.String()
|
Name: c.name,
|
||||||
if len(c.workers) == 0 {
|
UID: c.uid,
|
||||||
return state.ConstellationState{}, errors.New("client has no workers")
|
CloudProvider: cloudprovider.GCP.String(),
|
||||||
|
BootstrapperHost: c.controlPlanes.PublicIPs()[0],
|
||||||
|
GCPProject: c.project,
|
||||||
|
GCPZone: c.zone,
|
||||||
|
GCPRegion: c.region,
|
||||||
|
GCPWorkerInstances: c.workers,
|
||||||
|
GCPWorkerInstanceGroup: c.workerInstanceGroup,
|
||||||
|
GCPWorkerInstanceTemplate: c.workerTemplate,
|
||||||
|
GCPControlPlaneInstances: c.controlPlanes,
|
||||||
|
GCPControlPlaneInstanceGroup: c.controlPlaneInstanceGroup,
|
||||||
|
GCPControlPlaneInstanceTemplate: c.controlPlaneTemplate,
|
||||||
|
GCPFirewalls: c.firewalls,
|
||||||
|
GCPNetwork: c.network,
|
||||||
|
GCPSubnetwork: c.subnetwork,
|
||||||
|
GCPHealthCheck: c.healthCheck,
|
||||||
|
GCPBackendService: c.backendService,
|
||||||
|
GCPForwardingRule: c.forwardingRule,
|
||||||
|
GCPServiceAccount: c.serviceAccount,
|
||||||
}
|
}
|
||||||
stat.GCPWorkerInstances = c.workers
|
|
||||||
|
|
||||||
if len(c.controlPlanes) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no controlPlanes")
|
|
||||||
}
|
|
||||||
stat.GCPControlPlaneInstances = c.controlPlanes
|
|
||||||
publicIPs := c.controlPlanes.PublicIPs()
|
|
||||||
if len(publicIPs) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no bootstrapper endpoint")
|
|
||||||
}
|
|
||||||
stat.BootstrapperHost = publicIPs[0]
|
|
||||||
|
|
||||||
if c.workerInstanceGroup == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no workerInstanceGroup")
|
|
||||||
}
|
|
||||||
stat.GCPWorkerInstanceGroup = c.workerInstanceGroup
|
|
||||||
|
|
||||||
if c.controlPlaneInstanceGroup == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no controlPlaneInstanceGroup")
|
|
||||||
}
|
|
||||||
stat.GCPControlPlaneInstanceGroup = c.controlPlaneInstanceGroup
|
|
||||||
|
|
||||||
if c.project == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no project")
|
|
||||||
}
|
|
||||||
stat.GCPProject = c.project
|
|
||||||
|
|
||||||
if c.zone == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no zone")
|
|
||||||
}
|
|
||||||
stat.GCPZone = c.zone
|
|
||||||
|
|
||||||
if c.region == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no region")
|
|
||||||
}
|
|
||||||
stat.GCPRegion = c.region
|
|
||||||
|
|
||||||
if c.name == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no name")
|
|
||||||
}
|
|
||||||
stat.Name = c.name
|
|
||||||
|
|
||||||
if c.uid == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no uid")
|
|
||||||
}
|
|
||||||
stat.UID = c.uid
|
|
||||||
|
|
||||||
if len(c.firewalls) == 0 {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no firewalls")
|
|
||||||
}
|
|
||||||
stat.GCPFirewalls = c.firewalls
|
|
||||||
|
|
||||||
if c.network == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no network")
|
|
||||||
}
|
|
||||||
stat.GCPNetwork = c.network
|
|
||||||
|
|
||||||
if c.subnetwork == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no subnetwork")
|
|
||||||
}
|
|
||||||
stat.GCPSubnetwork = c.subnetwork
|
|
||||||
|
|
||||||
if c.workerTemplate == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no worker instance template")
|
|
||||||
}
|
|
||||||
stat.GCPWorkerInstanceTemplate = c.workerTemplate
|
|
||||||
|
|
||||||
if c.controlPlaneTemplate == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no controlPlane instance template")
|
|
||||||
}
|
|
||||||
stat.GCPControlPlaneInstanceTemplate = c.controlPlaneTemplate
|
|
||||||
|
|
||||||
if c.healthCheck == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no health check")
|
|
||||||
}
|
|
||||||
stat.GCPHealthCheck = c.healthCheck
|
|
||||||
|
|
||||||
if c.backendService == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no backend service")
|
|
||||||
}
|
|
||||||
stat.GCPBackendService = c.backendService
|
|
||||||
|
|
||||||
if c.forwardingRule == "" {
|
|
||||||
return state.ConstellationState{}, errors.New("client has no forwarding rule")
|
|
||||||
}
|
|
||||||
stat.GCPForwardingRule = c.forwardingRule
|
|
||||||
|
|
||||||
// service account does not have to be set at all times
|
|
||||||
stat.GCPServiceAccount = c.serviceAccount
|
|
||||||
|
|
||||||
return stat, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetState sets the state of the client to the handed ConstellationState.
|
// SetState sets the state of the client to the handed ConstellationState.
|
||||||
func (c *Client) SetState(stat state.ConstellationState) error {
|
func (c *Client) SetState(stat state.ConstellationState) {
|
||||||
if stat.CloudProvider != cloudprovider.GCP.String() {
|
|
||||||
return errors.New("state is not gcp state")
|
|
||||||
}
|
|
||||||
if len(stat.GCPWorkerInstances) == 0 {
|
|
||||||
return errors.New("state has no workers")
|
|
||||||
}
|
|
||||||
c.workers = stat.GCPWorkerInstances
|
c.workers = stat.GCPWorkerInstances
|
||||||
|
|
||||||
if len(stat.GCPControlPlaneInstances) == 0 {
|
|
||||||
return errors.New("state has no controlPlane")
|
|
||||||
}
|
|
||||||
c.controlPlanes = stat.GCPControlPlaneInstances
|
c.controlPlanes = stat.GCPControlPlaneInstances
|
||||||
|
|
||||||
if stat.GCPWorkerInstanceGroup == "" {
|
|
||||||
return errors.New("state has no workerInstanceGroup")
|
|
||||||
}
|
|
||||||
c.workerInstanceGroup = stat.GCPWorkerInstanceGroup
|
c.workerInstanceGroup = stat.GCPWorkerInstanceGroup
|
||||||
|
|
||||||
if stat.GCPControlPlaneInstanceGroup == "" {
|
|
||||||
return errors.New("state has no controlPlaneInstanceGroup")
|
|
||||||
}
|
|
||||||
c.controlPlaneInstanceGroup = stat.GCPControlPlaneInstanceGroup
|
c.controlPlaneInstanceGroup = stat.GCPControlPlaneInstanceGroup
|
||||||
|
|
||||||
if stat.GCPProject == "" {
|
|
||||||
return errors.New("state has no project")
|
|
||||||
}
|
|
||||||
c.project = stat.GCPProject
|
c.project = stat.GCPProject
|
||||||
|
|
||||||
if stat.GCPZone == "" {
|
|
||||||
return errors.New("state has no zone")
|
|
||||||
}
|
|
||||||
c.zone = stat.GCPZone
|
c.zone = stat.GCPZone
|
||||||
|
|
||||||
if stat.GCPRegion == "" {
|
|
||||||
return errors.New("state has no region")
|
|
||||||
}
|
|
||||||
c.region = stat.GCPRegion
|
c.region = stat.GCPRegion
|
||||||
|
|
||||||
if stat.Name == "" {
|
|
||||||
return errors.New("state has no name")
|
|
||||||
}
|
|
||||||
c.name = stat.Name
|
c.name = stat.Name
|
||||||
|
|
||||||
if stat.UID == "" {
|
|
||||||
return errors.New("state has no uid")
|
|
||||||
}
|
|
||||||
c.uid = stat.UID
|
c.uid = stat.UID
|
||||||
|
|
||||||
if len(stat.GCPFirewalls) == 0 {
|
|
||||||
return errors.New("state has no firewalls")
|
|
||||||
}
|
|
||||||
c.firewalls = stat.GCPFirewalls
|
c.firewalls = stat.GCPFirewalls
|
||||||
|
|
||||||
if stat.GCPNetwork == "" {
|
|
||||||
return errors.New("state has no network")
|
|
||||||
}
|
|
||||||
c.network = stat.GCPNetwork
|
c.network = stat.GCPNetwork
|
||||||
|
|
||||||
if stat.GCPSubnetwork == "" {
|
|
||||||
return errors.New("state has no subnetwork")
|
|
||||||
}
|
|
||||||
c.subnetwork = stat.GCPSubnetwork
|
c.subnetwork = stat.GCPSubnetwork
|
||||||
|
|
||||||
if stat.GCPWorkerInstanceTemplate == "" {
|
|
||||||
return errors.New("state has no worker instance template")
|
|
||||||
}
|
|
||||||
c.workerTemplate = stat.GCPWorkerInstanceTemplate
|
c.workerTemplate = stat.GCPWorkerInstanceTemplate
|
||||||
|
|
||||||
if stat.GCPControlPlaneInstanceTemplate == "" {
|
|
||||||
return errors.New("state has no controlPlane instance template")
|
|
||||||
}
|
|
||||||
c.controlPlaneTemplate = stat.GCPControlPlaneInstanceTemplate
|
c.controlPlaneTemplate = stat.GCPControlPlaneInstanceTemplate
|
||||||
|
|
||||||
if stat.GCPHealthCheck == "" {
|
|
||||||
return errors.New("state has no health check")
|
|
||||||
}
|
|
||||||
c.healthCheck = stat.GCPHealthCheck
|
c.healthCheck = stat.GCPHealthCheck
|
||||||
|
|
||||||
if stat.GCPBackendService == "" {
|
|
||||||
return errors.New("state has no backend service")
|
|
||||||
}
|
|
||||||
c.backendService = stat.GCPBackendService
|
c.backendService = stat.GCPBackendService
|
||||||
|
|
||||||
if stat.GCPForwardingRule == "" {
|
|
||||||
return errors.New("state has no forwarding rule")
|
|
||||||
}
|
|
||||||
c.forwardingRule = stat.GCPForwardingRule
|
c.forwardingRule = stat.GCPForwardingRule
|
||||||
|
|
||||||
// service account does not have to be set at all times
|
|
||||||
c.serviceAccount = stat.GCPServiceAccount
|
c.serviceAccount = stat.GCPServiceAccount
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) generateUID() (string, error) {
|
func (c *Client) generateUID() (string, error) {
|
||||||
|
@ -20,796 +20,89 @@ func TestMain(m *testing.M) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSetGetState(t *testing.T) {
|
func TestSetGetState(t *testing.T) {
|
||||||
testCases := map[string]struct {
|
state := state.ConstellationState{
|
||||||
state state.ConstellationState
|
CloudProvider: cloudprovider.GCP.String(),
|
||||||
wantErr bool
|
GCPWorkerInstances: cloudtypes.Instances{
|
||||||
}{
|
"id-1": {
|
||||||
"valid state": {
|
PublicIP: "ip1",
|
||||||
state: state.ConstellationState{
|
PrivateIP: "ip2",
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPServiceAccount: "service-account",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
"missing workers": {
|
GCPControlPlaneInstances: cloudtypes.Instances{
|
||||||
state: state.ConstellationState{
|
"id-1": {
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
PublicIP: "ip3",
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
PrivateIP: "ip4",
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
},
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing control plane": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing worker group": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing control plane group": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing project id": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing zone": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing region": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing name": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing uid": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
Name: "name",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing firewalls": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing network": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing external network": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing subnetwork": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing external subnetwork": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing worker template": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing control plane template": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing backend service": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing health check": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
"missing forwarding rule": {
|
|
||||||
state: state.ConstellationState{
|
|
||||||
CloudProvider: cloudprovider.GCP.String(),
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
},
|
||||||
|
GCPWorkerInstanceGroup: "group-id",
|
||||||
|
GCPControlPlaneInstanceGroup: "group-id",
|
||||||
|
GCPProject: "proj-id",
|
||||||
|
GCPZone: "zone-id",
|
||||||
|
GCPRegion: "region-id",
|
||||||
|
Name: "name",
|
||||||
|
UID: "uid",
|
||||||
|
BootstrapperHost: "ip3",
|
||||||
|
GCPNetwork: "net-id",
|
||||||
|
GCPSubnetwork: "subnet-id",
|
||||||
|
GCPFirewalls: []string{"fw-1", "fw-2"},
|
||||||
|
GCPWorkerInstanceTemplate: "temp-id",
|
||||||
|
GCPControlPlaneInstanceTemplate: "temp-id",
|
||||||
|
GCPServiceAccount: "service-account",
|
||||||
|
GCPBackendService: "backend-service-id",
|
||||||
|
GCPHealthCheck: "health-check-id",
|
||||||
|
GCPForwardingRule: "forwarding-rule-id",
|
||||||
}
|
}
|
||||||
|
|
||||||
t.Run("SetState", func(t *testing.T) {
|
t.Run("SetState", func(t *testing.T) {
|
||||||
for name, tc := range testCases {
|
assert := assert.New(t)
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
client := Client{}
|
client := Client{}
|
||||||
if tc.wantErr {
|
client.SetState(state)
|
||||||
assert.Error(client.SetState(tc.state))
|
assert.Equal(state.GCPWorkerInstances, client.workers)
|
||||||
} else {
|
assert.Equal(state.GCPControlPlaneInstances, client.controlPlanes)
|
||||||
assert.NoError(client.SetState(tc.state))
|
assert.Equal(state.GCPWorkerInstanceGroup, client.workerInstanceGroup)
|
||||||
assert.Equal(tc.state.GCPWorkerInstances, client.workers)
|
assert.Equal(state.GCPControlPlaneInstanceGroup, client.controlPlaneInstanceGroup)
|
||||||
assert.Equal(tc.state.GCPControlPlaneInstances, client.controlPlanes)
|
assert.Equal(state.GCPProject, client.project)
|
||||||
assert.Equal(tc.state.GCPWorkerInstanceGroup, client.workerInstanceGroup)
|
assert.Equal(state.GCPZone, client.zone)
|
||||||
assert.Equal(tc.state.GCPControlPlaneInstanceGroup, client.controlPlaneInstanceGroup)
|
assert.Equal(state.Name, client.name)
|
||||||
assert.Equal(tc.state.GCPProject, client.project)
|
assert.Equal(state.UID, client.uid)
|
||||||
assert.Equal(tc.state.GCPZone, client.zone)
|
assert.Equal(state.GCPNetwork, client.network)
|
||||||
assert.Equal(tc.state.Name, client.name)
|
assert.Equal(state.GCPFirewalls, client.firewalls)
|
||||||
assert.Equal(tc.state.UID, client.uid)
|
assert.Equal(state.GCPControlPlaneInstanceTemplate, client.controlPlaneTemplate)
|
||||||
assert.Equal(tc.state.GCPNetwork, client.network)
|
assert.Equal(state.GCPWorkerInstanceTemplate, client.workerTemplate)
|
||||||
assert.Equal(tc.state.GCPFirewalls, client.firewalls)
|
assert.Equal(state.GCPServiceAccount, client.serviceAccount)
|
||||||
assert.Equal(tc.state.GCPControlPlaneInstanceTemplate, client.controlPlaneTemplate)
|
|
||||||
assert.Equal(tc.state.GCPWorkerInstanceTemplate, client.workerTemplate)
|
|
||||||
assert.Equal(tc.state.GCPServiceAccount, client.serviceAccount)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("GetState", func(t *testing.T) {
|
t.Run("GetState", func(t *testing.T) {
|
||||||
for name, tc := range testCases {
|
assert := assert.New(t)
|
||||||
t.Run(name, func(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
client := Client{
|
client := Client{
|
||||||
workers: tc.state.GCPWorkerInstances,
|
workers: state.GCPWorkerInstances,
|
||||||
controlPlanes: tc.state.GCPControlPlaneInstances,
|
controlPlanes: state.GCPControlPlaneInstances,
|
||||||
workerInstanceGroup: tc.state.GCPWorkerInstanceGroup,
|
workerInstanceGroup: state.GCPWorkerInstanceGroup,
|
||||||
controlPlaneInstanceGroup: tc.state.GCPControlPlaneInstanceGroup,
|
controlPlaneInstanceGroup: state.GCPControlPlaneInstanceGroup,
|
||||||
project: tc.state.GCPProject,
|
project: state.GCPProject,
|
||||||
zone: tc.state.GCPZone,
|
zone: state.GCPZone,
|
||||||
region: tc.state.GCPRegion,
|
region: state.GCPRegion,
|
||||||
name: tc.state.Name,
|
name: state.Name,
|
||||||
uid: tc.state.UID,
|
uid: state.UID,
|
||||||
network: tc.state.GCPNetwork,
|
network: state.GCPNetwork,
|
||||||
subnetwork: tc.state.GCPSubnetwork,
|
subnetwork: state.GCPSubnetwork,
|
||||||
firewalls: tc.state.GCPFirewalls,
|
firewalls: state.GCPFirewalls,
|
||||||
workerTemplate: tc.state.GCPWorkerInstanceTemplate,
|
workerTemplate: state.GCPWorkerInstanceTemplate,
|
||||||
controlPlaneTemplate: tc.state.GCPControlPlaneInstanceTemplate,
|
controlPlaneTemplate: state.GCPControlPlaneInstanceTemplate,
|
||||||
serviceAccount: tc.state.GCPServiceAccount,
|
serviceAccount: state.GCPServiceAccount,
|
||||||
healthCheck: tc.state.GCPHealthCheck,
|
healthCheck: state.GCPHealthCheck,
|
||||||
backendService: tc.state.GCPBackendService,
|
backendService: state.GCPBackendService,
|
||||||
forwardingRule: tc.state.GCPForwardingRule,
|
forwardingRule: state.GCPForwardingRule,
|
||||||
}
|
|
||||||
if tc.wantErr {
|
|
||||||
_, err := client.GetState()
|
|
||||||
assert.Error(err)
|
|
||||||
} else {
|
|
||||||
stat, err := client.GetState()
|
|
||||||
assert.NoError(err)
|
|
||||||
assert.Equal(tc.state, stat)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stat := client.GetState()
|
||||||
|
|
||||||
|
assert.Equal(state, stat)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestSetStateCloudProvider(t *testing.T) {
|
|
||||||
assert := assert.New(t)
|
|
||||||
|
|
||||||
client := Client{}
|
|
||||||
stateMissingCloudProvider := state.ConstellationState{
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
}
|
|
||||||
assert.Error(client.SetState(stateMissingCloudProvider))
|
|
||||||
stateIncorrectCloudProvider := state.ConstellationState{
|
|
||||||
CloudProvider: "incorrect",
|
|
||||||
GCPWorkerInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip1",
|
|
||||||
PrivateIP: "ip2",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPControlPlaneInstances: cloudtypes.Instances{
|
|
||||||
"id-1": {
|
|
||||||
PublicIP: "ip3",
|
|
||||||
PrivateIP: "ip4",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
GCPWorkerInstanceGroup: "group-id",
|
|
||||||
GCPControlPlaneInstanceGroup: "group-id",
|
|
||||||
GCPProject: "proj-id",
|
|
||||||
GCPZone: "zone-id",
|
|
||||||
GCPRegion: "region-id",
|
|
||||||
Name: "name",
|
|
||||||
UID: "uid",
|
|
||||||
BootstrapperHost: "ip3",
|
|
||||||
GCPNetwork: "net-id",
|
|
||||||
GCPSubnetwork: "subnet-id",
|
|
||||||
GCPFirewalls: []string{"fw-1", "fw-2"},
|
|
||||||
GCPWorkerInstanceTemplate: "temp-id",
|
|
||||||
GCPControlPlaneInstanceTemplate: "temp-id",
|
|
||||||
GCPBackendService: "backend-service-id",
|
|
||||||
GCPHealthCheck: "health-check-id",
|
|
||||||
GCPForwardingRule: "forwarding-rule-id",
|
|
||||||
}
|
|
||||||
assert.Error(client.SetState(stateIncorrectCloudProvider))
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestInit(t *testing.T) {
|
func TestInit(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
require := require.New(t)
|
require := require.New(t)
|
||||||
|
Loading…
Reference in New Issue
Block a user