Remove gcp instances

This commit is contained in:
katexochen 2022-06-07 11:35:08 +02:00 committed by Paul Meyer
parent 4b30dd21c8
commit 3562345da4
13 changed files with 88 additions and 224 deletions

View File

@ -7,7 +7,7 @@ import (
"github.com/edgelesssys/constellation/cli/azure" "github.com/edgelesssys/constellation/cli/azure"
azurecl "github.com/edgelesssys/constellation/cli/azure/client" azurecl "github.com/edgelesssys/constellation/cli/azure/client"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
gcpcl "github.com/edgelesssys/constellation/cli/gcp/client" gcpcl "github.com/edgelesssys/constellation/cli/gcp/client"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
@ -216,8 +216,8 @@ func (c *stubAzureClient) TerminateServicePrincipal(ctx context.Context) error {
} }
type fakeGcpClient struct { type fakeGcpClient struct {
nodes gcp.Instances nodes cloudtypes.Instances
coordinators gcp.Instances coordinators cloudtypes.Instances
nodesInstanceGroup string nodesInstanceGroup string
coordinatorInstanceGroup string coordinatorInstanceGroup string
@ -293,15 +293,15 @@ func (c *fakeGcpClient) CreateInstances(ctx context.Context, input gcpcl.CreateI
c.nodesInstanceGroup = "nodes-group" c.nodesInstanceGroup = "nodes-group"
c.nodeTemplate = "node-template" c.nodeTemplate = "node-template"
c.coordinatorTemplate = "coordinator-template" c.coordinatorTemplate = "coordinator-template"
c.nodes = make(gcp.Instances) c.nodes = make(cloudtypes.Instances)
for i := 0; i < input.CountNodes; i++ { for i := 0; i < input.CountNodes; i++ {
id := "id-" + strconv.Itoa(i) id := "id-" + strconv.Itoa(i)
c.nodes[id] = gcp.Instance{PublicIP: "192.0.2.1", PrivateIP: "192.0.2.1"} c.nodes[id] = cloudtypes.Instance{PublicIP: "192.0.2.1", PrivateIP: "192.0.2.1"}
} }
c.coordinators = make(gcp.Instances) c.coordinators = make(cloudtypes.Instances)
for i := 0; i < input.CountCoordinators; i++ { for i := 0; i < input.CountCoordinators; i++ {
id := "id-" + strconv.Itoa(i) id := "id-" + strconv.Itoa(i)
c.coordinators[id] = gcp.Instance{PublicIP: "192.0.2.1", PrivateIP: "192.0.2.1"} c.coordinators[id] = cloudtypes.Instance{PublicIP: "192.0.2.1", PrivateIP: "192.0.2.1"}
} }
return nil return nil
} }

View File

@ -7,7 +7,7 @@ import (
"testing" "testing"
"github.com/edgelesssys/constellation/cli/azure" "github.com/edgelesssys/constellation/cli/azure"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
@ -18,11 +18,11 @@ func TestCreator(t *testing.T) {
wantGCPState := state.ConstellationState{ wantGCPState := state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPProject: "project", GCPProject: "project",
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "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-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "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-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
"id-2": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "id-2": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},

View File

@ -5,7 +5,7 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/config" "github.com/edgelesssys/constellation/internal/config"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
@ -17,8 +17,8 @@ func TestServiceAccountCreator(t *testing.T) {
return state.ConstellationState{ return state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPProject: "project", GCPProject: "project",
GCPNodes: gcp.Instances{}, GCPNodes: cloudtypes.Instances{},
GCPCoordinators: gcp.Instances{}, GCPCoordinators: cloudtypes.Instances{},
GCPNodeInstanceGroup: "nodes-group", GCPNodeInstanceGroup: "nodes-group",
GCPCoordinatorInstanceGroup: "coord-group", GCPCoordinatorInstanceGroup: "coord-group",
GCPNodeInstanceTemplate: "template", GCPNodeInstanceTemplate: "template",

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/edgelesssys/constellation/cli/azure" "github.com/edgelesssys/constellation/cli/azure"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -17,11 +17,11 @@ func TestTerminator(t *testing.T) {
return state.ConstellationState{ return state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPProject: "project", GCPProject: "project",
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "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-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
GCPNodeInstanceGroup: "nodes-group", GCPNodeInstanceGroup: "nodes-group",

View File

@ -13,7 +13,6 @@ import (
"github.com/edgelesssys/constellation/cli/azure" "github.com/edgelesssys/constellation/cli/azure"
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/cli/ec2" "github.com/edgelesssys/constellation/cli/ec2"
"github.com/edgelesssys/constellation/cli/gcp"
"github.com/edgelesssys/constellation/internal/constants" "github.com/edgelesssys/constellation/internal/constants"
"github.com/edgelesssys/constellation/internal/file" "github.com/edgelesssys/constellation/internal/file"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
@ -37,11 +36,11 @@ func TestInitialize(t *testing.T) {
testKey := base64.StdEncoding.EncodeToString([]byte("32bytesWireGuardKeyForTheTesting")) testKey := base64.StdEncoding.EncodeToString([]byte("32bytesWireGuardKeyForTheTesting"))
testGcpState := state.ConstellationState{ testGcpState := state.ConstellationState{
CloudProvider: "GCP", CloudProvider: "GCP",
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "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-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
} }
@ -515,11 +514,11 @@ func TestAutoscaleFlag(t *testing.T) {
testKey := base64.StdEncoding.EncodeToString([]byte("32bytesWireGuardKeyForTheTesting")) testKey := base64.StdEncoding.EncodeToString([]byte("32bytesWireGuardKeyForTheTesting"))
testGcpState := state.ConstellationState{ testGcpState := state.ConstellationState{
CloudProvider: "gcp", CloudProvider: "gcp",
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-0": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "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-1": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"}, "id-c": {PrivateIP: "192.0.2.1", PublicIP: "192.0.2.1"},
}, },
} }

View File

@ -11,7 +11,7 @@ import (
compute "cloud.google.com/go/compute/apiv1" compute "cloud.google.com/go/compute/apiv1"
admin "cloud.google.com/go/iam/admin/apiv1" admin "cloud.google.com/go/iam/admin/apiv1"
resourcemanager "cloud.google.com/go/resourcemanager/apiv3" resourcemanager "cloud.google.com/go/resourcemanager/apiv3"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
) )
@ -30,8 +30,8 @@ type Client struct {
iamAPI iamAPI
projectsAPI projectsAPI
nodes gcp.Instances nodes cloudtypes.Instances
coordinators gcp.Instances coordinators cloudtypes.Instances
nodesInstanceGroup string nodesInstanceGroup string
coordinatorInstanceGroup string coordinatorInstanceGroup string
@ -128,8 +128,8 @@ func NewFromDefault(ctx context.Context) (*Client, error) {
instanceGroupManagersAPI: &instanceGroupManagersClient{groupAPI}, instanceGroupManagersAPI: &instanceGroupManagersClient{groupAPI},
iamAPI: &iamClient{iamAPI}, iamAPI: &iamClient{iamAPI},
projectsAPI: &projectsClient{projectsAPI}, projectsAPI: &projectsClient{projectsAPI},
nodes: make(gcp.Instances), nodes: make(cloudtypes.Instances),
coordinators: make(gcp.Instances), coordinators: make(cloudtypes.Instances),
}, nil }, nil
} }

View File

@ -4,7 +4,7 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/internal/cloud/cloudprovider" "github.com/edgelesssys/constellation/internal/cloud/cloudprovider"
"github.com/edgelesssys/constellation/internal/state" "github.com/edgelesssys/constellation/internal/state"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -19,13 +19,13 @@ func TestSetGetState(t *testing.T) {
"valid state": { "valid state": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -49,7 +49,7 @@ func TestSetGetState(t *testing.T) {
"missing nodes": { "missing nodes": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -73,7 +73,7 @@ func TestSetGetState(t *testing.T) {
"missing coordinator": { "missing coordinator": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
@ -97,13 +97,13 @@ func TestSetGetState(t *testing.T) {
"missing node group": { "missing node group": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -126,13 +126,13 @@ func TestSetGetState(t *testing.T) {
"missing coordinator group": { "missing coordinator group": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -155,13 +155,13 @@ func TestSetGetState(t *testing.T) {
"missing project id": { "missing project id": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -184,13 +184,13 @@ func TestSetGetState(t *testing.T) {
"missing zone": { "missing zone": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -213,13 +213,13 @@ func TestSetGetState(t *testing.T) {
"missing region": { "missing region": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -242,13 +242,13 @@ func TestSetGetState(t *testing.T) {
"missing name": { "missing name": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -270,13 +270,13 @@ func TestSetGetState(t *testing.T) {
"missing uid": { "missing uid": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -299,13 +299,13 @@ func TestSetGetState(t *testing.T) {
"missing firewalls": { "missing firewalls": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -328,13 +328,13 @@ func TestSetGetState(t *testing.T) {
"missing network": { "missing network": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -356,13 +356,13 @@ func TestSetGetState(t *testing.T) {
"missing external network": { "missing external network": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -385,13 +385,13 @@ func TestSetGetState(t *testing.T) {
"missing subnetwork": { "missing subnetwork": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -414,13 +414,13 @@ func TestSetGetState(t *testing.T) {
"missing external subnetwork": { "missing external subnetwork": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -443,13 +443,13 @@ func TestSetGetState(t *testing.T) {
"missing node template": { "missing node template": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -472,13 +472,13 @@ func TestSetGetState(t *testing.T) {
"missing coordinator template": { "missing coordinator template": {
state: state.ConstellationState{ state: state.ConstellationState{
CloudProvider: cloudprovider.GCP.String(), CloudProvider: cloudprovider.GCP.String(),
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -568,13 +568,13 @@ func TestSetStateCloudProvider(t *testing.T) {
client := Client{} client := Client{}
stateMissingCloudProvider := state.ConstellationState{ stateMissingCloudProvider := state.ConstellationState{
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",
@ -596,13 +596,13 @@ func TestSetStateCloudProvider(t *testing.T) {
assert.Error(client.SetState(stateMissingCloudProvider)) assert.Error(client.SetState(stateMissingCloudProvider))
stateIncorrectCloudProvider := state.ConstellationState{ stateIncorrectCloudProvider := state.ConstellationState{
CloudProvider: "incorrect", CloudProvider: "incorrect",
GCPNodes: gcp.Instances{ GCPNodes: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip1", PublicIP: "ip1",
PrivateIP: "ip2", PrivateIP: "ip2",
}, },
}, },
GCPCoordinators: gcp.Instances{ GCPCoordinators: cloudtypes.Instances{
"id-1": { "id-1": {
PublicIP: "ip3", PublicIP: "ip3",
PrivateIP: "ip4", PrivateIP: "ip4",

View File

@ -7,7 +7,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/coordinator/role" "github.com/edgelesssys/constellation/coordinator/role"
"google.golang.org/api/iterator" "google.golang.org/api/iterator"
computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"
@ -134,7 +134,7 @@ func (c *Client) TerminateInstances(ctx context.Context) error {
} }
ops = append(ops, op) ops = append(ops, op)
c.nodesInstanceGroup = "" c.nodesInstanceGroup = ""
c.nodes = make(gcp.Instances) c.nodes = make(cloudtypes.Instances)
} }
if c.coordinatorInstanceGroup != "" { if c.coordinatorInstanceGroup != "" {
@ -144,7 +144,7 @@ func (c *Client) TerminateInstances(ctx context.Context) error {
} }
ops = append(ops, op) ops = append(ops, op)
c.coordinatorInstanceGroup = "" c.coordinatorInstanceGroup = ""
c.coordinators = make(gcp.Instances) c.coordinators = make(cloudtypes.Instances)
} }
if err := c.waitForOperations(ctx, ops); err != nil { if err := c.waitForOperations(ctx, ops); err != nil {
return err return err
@ -228,7 +228,7 @@ func (c *Client) waitForInstanceGroupScaling(ctx context.Context, groupId string
} }
// getInstanceIPs requests the IPs of the client's instances. // getInstanceIPs requests the IPs of the client's instances.
func (c *Client) getInstanceIPs(ctx context.Context, groupId string, list gcp.Instances) error { func (c *Client) getInstanceIPs(ctx context.Context, groupId string, list cloudtypes.Instances) error {
req := &computepb.ListInstancesRequest{ req := &computepb.ListInstancesRequest{
Filter: proto.String("name=" + groupId + "*"), Filter: proto.String("name=" + groupId + "*"),
Project: c.project, Project: c.project,
@ -258,7 +258,7 @@ func (c *Client) getInstanceIPs(ctx context.Context, groupId string, list gcp.In
if resp.NetworkInterfaces[0].AccessConfigs[0].NatIP == nil { if resp.NetworkInterfaces[0].AccessConfigs[0].NatIP == nil {
return errors.New("natIP is nil") return errors.New("natIP is nil")
} }
instance := gcp.Instance{ instance := cloudtypes.Instance{
PrivateIP: *resp.NetworkInterfaces[0].NetworkIP, PrivateIP: *resp.NetworkInterfaces[0].NetworkIP,
PublicIP: *resp.NetworkInterfaces[0].AccessConfigs[0].NatIP, PublicIP: *resp.NetworkInterfaces[0].AccessConfigs[0].NatIP,
} }

View File

@ -5,7 +5,7 @@ import (
"errors" "errors"
"testing" "testing"
"github.com/edgelesssys/constellation/cli/gcp" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
computepb "google.golang.org/genproto/googleapis/cloud/compute/v1" computepb "google.golang.org/genproto/googleapis/cloud/compute/v1"
"google.golang.org/protobuf/proto" "google.golang.org/protobuf/proto"
@ -157,8 +157,8 @@ func TestCreateInstances(t *testing.T) {
operationGlobalAPI: tc.operationGlobalAPI, operationGlobalAPI: tc.operationGlobalAPI,
instanceTemplateAPI: tc.instanceTemplateAPI, instanceTemplateAPI: tc.instanceTemplateAPI,
instanceGroupManagersAPI: tc.instanceGroupManagersAPI, instanceGroupManagersAPI: tc.instanceGroupManagersAPI,
nodes: make(gcp.Instances), nodes: make(cloudtypes.Instances),
coordinators: make(gcp.Instances), coordinators: make(cloudtypes.Instances),
} }
if tc.wantErr { if tc.wantErr {
@ -231,8 +231,8 @@ func TestTerminateInstances(t *testing.T) {
operationGlobalAPI: tc.operationGlobalAPI, operationGlobalAPI: tc.operationGlobalAPI,
instanceTemplateAPI: tc.instanceTemplateAPI, instanceTemplateAPI: tc.instanceTemplateAPI,
instanceGroupManagersAPI: tc.instanceGroupManagersAPI, instanceGroupManagersAPI: tc.instanceGroupManagersAPI,
nodes: gcp.Instances{"node-id-1": gcp.Instance{}, "node-id-2": gcp.Instance{}}, nodes: cloudtypes.Instances{"node-id-1": cloudtypes.Instance{}, "node-id-2": cloudtypes.Instance{}},
coordinators: gcp.Instances{"coordinator-id-1": gcp.Instance{}}, coordinators: cloudtypes.Instances{"coordinator-id-1": cloudtypes.Instance{}},
firewalls: []string{"firewall-1", "firewall-2"}, firewalls: []string{"firewall-1", "firewall-2"},
network: "network-id-1", network: "network-id-1",
nodesInstanceGroup: "nodeInstanceGroup-id-1", nodesInstanceGroup: "nodeInstanceGroup-id-1",
@ -242,7 +242,7 @@ func TestTerminateInstances(t *testing.T) {
} }
if tc.missingNodeInstanceGroup { if tc.missingNodeInstanceGroup {
client.nodesInstanceGroup = "" client.nodesInstanceGroup = ""
client.nodes = gcp.Instances{} client.nodes = cloudtypes.Instances{}
} }
if tc.wantErr { if tc.wantErr {

View File

@ -6,7 +6,6 @@ import (
"testing" "testing"
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/cli/gcp"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
@ -70,8 +69,8 @@ func TestCreateVPCs(t *testing.T) {
operationRegionAPI: tc.operationRegionAPI, operationRegionAPI: tc.operationRegionAPI,
networksAPI: tc.networksAPI, networksAPI: tc.networksAPI,
subnetworksAPI: tc.subnetworksAPI, subnetworksAPI: tc.subnetworksAPI,
nodes: make(gcp.Instances), nodes: make(cloudtypes.Instances),
coordinators: make(gcp.Instances), coordinators: make(cloudtypes.Instances),
} }
if tc.wantErr { if tc.wantErr {

View File

@ -1,62 +0,0 @@
package gcp
// copy of ec2/instances.go
// TODO(katexochen): refactor into mulitcloud package.
import "errors"
// Instance is a gcp instance.
type Instance struct {
PublicIP string
PrivateIP string
}
// Instances is a map of gcp Instances. The ID of an instance is used as key.
type Instances map[string]Instance
// IDs returns the IDs of all instances of the Constellation.
func (i Instances) IDs() []string {
var ids []string
for id := range i {
ids = append(ids, id)
}
return ids
}
// PublicIPs returns the public IPs of all the instances of the Constellation.
func (i Instances) PublicIPs() []string {
var ips []string
for _, instance := range i {
ips = append(ips, instance.PublicIP)
}
return ips
}
// PrivateIPs returns the private IPs of all the instances of the Constellation.
func (i Instances) PrivateIPs() []string {
var ips []string
for _, instance := range i {
ips = append(ips, instance.PrivateIP)
}
return ips
}
// GetOne return anyone instance out of the instances and its ID.
func (i Instances) GetOne() (string, Instance, error) {
for id, instance := range i {
return id, instance, nil
}
return "", Instance{}, errors.New("map is empty")
}
// GetOthers returns all instances but the one with the handed ID.
func (i Instances) GetOthers(id string) Instances {
others := make(Instances)
for key, instance := range i {
if key != id {
others[key] = instance
}
}
return others
}

View File

@ -1,71 +0,0 @@
package gcp
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIDs(t *testing.T) {
assert := assert.New(t)
testState := testInstances()
wantIDs := []string{"id-9", "id-10", "id-11", "id-12"}
assert.ElementsMatch(wantIDs, testState.IDs())
}
func TestPublicIPs(t *testing.T) {
assert := assert.New(t)
testState := testInstances()
wantIPs := []string{"192.0.2.1", "192.0.2.3", "192.0.2.5", "192.0.2.7"}
assert.ElementsMatch(wantIPs, testState.PublicIPs())
}
func TestPrivateIPs(t *testing.T) {
assert := assert.New(t)
testState := testInstances()
wantIPs := []string{"192.0.2.2", "192.0.2.4", "192.0.2.6", "192.0.2.8"}
assert.ElementsMatch(wantIPs, testState.PrivateIPs())
}
func TestGetOne(t *testing.T) {
assert := assert.New(t)
testState := testInstances()
id, instance, err := testState.GetOne()
assert.NoError(err)
assert.Contains(testState, id)
assert.Equal(testState[id], instance)
}
func TestGetOthers(t *testing.T) {
assert := assert.New(t)
testCases := testInstances().IDs()
for _, id := range testCases {
others := testInstances().GetOthers(id)
assert.NotContains(others, id)
wantInstances := testInstances()
delete(wantInstances, id)
assert.ElementsMatch(others.IDs(), wantInstances.IDs())
}
}
func testInstances() Instances {
return Instances{
"id-9": {
PublicIP: "192.0.2.1",
PrivateIP: "192.0.2.2",
},
"id-10": {
PublicIP: "192.0.2.3",
PrivateIP: "192.0.2.4",
},
"id-11": {
PublicIP: "192.0.2.5",
PrivateIP: "192.0.2.6",
},
"id-12": {
PublicIP: "192.0.2.7",
PrivateIP: "192.0.2.8",
},
}
}

View File

@ -4,7 +4,6 @@ import (
"github.com/edgelesssys/constellation/cli/azure" "github.com/edgelesssys/constellation/cli/azure"
"github.com/edgelesssys/constellation/cli/cloud/cloudtypes" "github.com/edgelesssys/constellation/cli/cloud/cloudtypes"
"github.com/edgelesssys/constellation/cli/ec2" "github.com/edgelesssys/constellation/cli/ec2"
"github.com/edgelesssys/constellation/cli/gcp"
) )
// ConstellationState is the state of a Constellation. // ConstellationState is the state of a Constellation.
@ -16,19 +15,19 @@ type ConstellationState struct {
EC2Instances ec2.Instances `json:"ec2instances,omitempty"` EC2Instances ec2.Instances `json:"ec2instances,omitempty"`
EC2SecurityGroup string `json:"ec2securitygroup,omitempty"` EC2SecurityGroup string `json:"ec2securitygroup,omitempty"`
GCPNodes gcp.Instances `json:"gcpnodes,omitempty"` GCPNodes cloudtypes.Instances `json:"gcpnodes,omitempty"`
GCPCoordinators gcp.Instances `json:"gcpcoordinators,omitempty"` GCPCoordinators cloudtypes.Instances `json:"gcpcoordinators,omitempty"`
GCPNodeInstanceGroup string `json:"gcpnodeinstancegroup,omitempty"` GCPNodeInstanceGroup string `json:"gcpnodeinstancegroup,omitempty"`
GCPCoordinatorInstanceGroup string `json:"gcpcoordinatorinstancegroup,omitempty"` GCPCoordinatorInstanceGroup string `json:"gcpcoordinatorinstancegroup,omitempty"`
GCPNodeInstanceTemplate string `json:"gcpnodeinstancetemplate,omitempty"` GCPNodeInstanceTemplate string `json:"gcpnodeinstancetemplate,omitempty"`
GCPCoordinatorInstanceTemplate string `json:"gcpcoordinatorinstancetemplate,omitempty"` GCPCoordinatorInstanceTemplate string `json:"gcpcoordinatorinstancetemplate,omitempty"`
GCPNetwork string `json:"gcpnetwork,omitempty"` GCPNetwork string `json:"gcpnetwork,omitempty"`
GCPSubnetwork string `json:"gcpsubnetwork,omitempty"` GCPSubnetwork string `json:"gcpsubnetwork,omitempty"`
GCPFirewalls []string `json:"gcpfirewalls,omitempty"` GCPFirewalls []string `json:"gcpfirewalls,omitempty"`
GCPProject string `json:"gcpproject,omitempty"` GCPProject string `json:"gcpproject,omitempty"`
GCPZone string `json:"gcpzone,omitempty"` GCPZone string `json:"gcpzone,omitempty"`
GCPRegion string `json:"gcpregion,omitempty"` GCPRegion string `json:"gcpregion,omitempty"`
GCPServiceAccount string `json:"gcpserviceaccount,omitempty"` GCPServiceAccount string `json:"gcpserviceaccount,omitempty"`
AzureNodes azure.Instances `json:"azurenodes,omitempty"` AzureNodes azure.Instances `json:"azurenodes,omitempty"`
AzureCoordinators azure.Instances `json:"azurecoordinators,omitempty"` AzureCoordinators azure.Instances `json:"azurecoordinators,omitempty"`