mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-01-12 16:09:39 -05:00
GCP: Only create debugd loadbalancer when debugCluster is set
This commit is contained in:
parent
d74c7a3769
commit
72d4456b3f
@ -20,7 +20,7 @@ type gcpclient interface {
|
|||||||
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
|
||||||
CreateLoadBalancers(ctx context.Context) error
|
CreateLoadBalancers(ctx context.Context, isDebugCluster bool) error
|
||||||
TerminateFirewall(ctx context.Context) error
|
TerminateFirewall(ctx context.Context) error
|
||||||
TerminateVPCs(context.Context) error
|
TerminateVPCs(context.Context) error
|
||||||
TerminateLoadBalancers(context.Context) error
|
TerminateLoadBalancers(context.Context) error
|
||||||
|
@ -284,7 +284,7 @@ func (c *fakeGcpClient) CreateInstances(ctx context.Context, input gcpcl.CreateI
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *fakeGcpClient) CreateLoadBalancers(ctx context.Context) error {
|
func (c *fakeGcpClient) CreateLoadBalancers(ctx context.Context, isDebugCluster bool) error {
|
||||||
c.loadbalancers = []string{"kube-lb", "boot-lb", "verify-lb"}
|
c.loadbalancers = []string{"kube-lb", "boot-lb", "verify-lb"}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -361,7 +361,7 @@ func (c *stubGcpClient) CreateInstances(ctx context.Context, input gcpcl.CreateI
|
|||||||
return c.createInstancesErr
|
return c.createInstancesErr
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *stubGcpClient) CreateLoadBalancers(ctx context.Context) error {
|
func (c *stubGcpClient) CreateLoadBalancers(ctx context.Context, isDebugClient bool) error {
|
||||||
return c.createLoadBalancerErr
|
return c.createLoadBalancerErr
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ func (c *Creator) createGCP(ctx context.Context, cl gcpclient, config *config.Co
|
|||||||
return state.ConstellationState{}, err
|
return state.ConstellationState{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := cl.CreateLoadBalancers(ctx); err != nil {
|
if err := cl.CreateLoadBalancers(ctx, config.IsDebugCluster()); err != nil {
|
||||||
return state.ConstellationState{}, err
|
return state.ConstellationState{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ type loadBalancer struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateLoadBalancers creates all necessary load balancers.
|
// CreateLoadBalancers creates all necessary load balancers.
|
||||||
func (c *Client) CreateLoadBalancers(ctx context.Context) error {
|
func (c *Client) CreateLoadBalancers(ctx context.Context, isDebugCluster bool) error {
|
||||||
if err := c.createIPAddr(ctx); err != nil {
|
if err := c.createIPAddr(ctx); err != nil {
|
||||||
return fmt.Errorf("creating load balancer IP address: %w", err)
|
return fmt.Errorf("creating load balancer IP address: %w", err)
|
||||||
}
|
}
|
||||||
@ -69,6 +69,8 @@ func (c *Client) CreateLoadBalancers(ctx context.Context) error {
|
|||||||
healthCheck: computepb.HealthCheck_TCP,
|
healthCheck: computepb.HealthCheck_TCP,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Only create when the debug cluster flag is set in the Constellation config
|
||||||
|
if isDebugCluster {
|
||||||
c.loadbalancers = append(c.loadbalancers, &loadBalancer{
|
c.loadbalancers = append(c.loadbalancers, &loadBalancer{
|
||||||
name: c.buildResourceName("debugd"),
|
name: c.buildResourceName("debugd"),
|
||||||
ip: c.loadbalancerIPname,
|
ip: c.loadbalancerIPname,
|
||||||
@ -76,6 +78,7 @@ func (c *Client) CreateLoadBalancers(ctx context.Context) error {
|
|||||||
backendPortName: "debugd",
|
backendPortName: "debugd",
|
||||||
healthCheck: computepb.HealthCheck_TCP,
|
healthCheck: computepb.HealthCheck_TCP,
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Load balancer creation.
|
// Load balancer creation.
|
||||||
|
|
||||||
|
@ -9,6 +9,7 @@ package client
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -28,6 +29,7 @@ func TestCreateLoadBalancers(t *testing.T) {
|
|||||||
backendAPI backendServicesAPI
|
backendAPI backendServicesAPI
|
||||||
forwardAPI forwardingRulesAPI
|
forwardAPI forwardingRulesAPI
|
||||||
opRegAPI operationRegionAPI
|
opRegAPI operationRegionAPI
|
||||||
|
isDebugCluster bool
|
||||||
wantErr bool
|
wantErr bool
|
||||||
}{
|
}{
|
||||||
"successful create": {
|
"successful create": {
|
||||||
@ -37,6 +39,14 @@ func TestCreateLoadBalancers(t *testing.T) {
|
|||||||
forwardAPI: &stubForwardingRulesAPI{forwardingRule: forwardingRule},
|
forwardAPI: &stubForwardingRulesAPI{forwardingRule: forwardingRule},
|
||||||
opRegAPI: stubOperationRegionAPI{},
|
opRegAPI: stubOperationRegionAPI{},
|
||||||
},
|
},
|
||||||
|
"successful create (debug cluster)": {
|
||||||
|
addrAPI: &stubAddressesAPI{getAddr: proto.String("192.0.2.1")},
|
||||||
|
healthAPI: &stubHealthChecksAPI{},
|
||||||
|
backendAPI: &stubBackendServicesAPI{},
|
||||||
|
forwardAPI: &stubForwardingRulesAPI{forwardingRule: forwardingRule},
|
||||||
|
opRegAPI: stubOperationRegionAPI{},
|
||||||
|
isDebugCluster: true,
|
||||||
|
},
|
||||||
"createIPAddr fails": {
|
"createIPAddr fails": {
|
||||||
addrAPI: &stubAddressesAPI{insertErr: someErr},
|
addrAPI: &stubAddressesAPI{insertErr: someErr},
|
||||||
healthAPI: &stubHealthChecksAPI{},
|
healthAPI: &stubHealthChecksAPI{},
|
||||||
@ -72,14 +82,33 @@ func TestCreateLoadBalancers(t *testing.T) {
|
|||||||
operationRegionAPI: tc.opRegAPI,
|
operationRegionAPI: tc.opRegAPI,
|
||||||
}
|
}
|
||||||
|
|
||||||
err := client.CreateLoadBalancers(ctx)
|
err := client.CreateLoadBalancers(ctx, tc.isDebugCluster)
|
||||||
|
|
||||||
|
// In case we expect an error, check for the error and continue otherwise.
|
||||||
if tc.wantErr {
|
if tc.wantErr {
|
||||||
assert.Error(err)
|
assert.Error(err)
|
||||||
} else {
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we don't expect an error, check if the resources have been successfully created.
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotEmpty(client.loadbalancerIPname)
|
assert.NotEmpty(client.loadbalancerIPname)
|
||||||
|
|
||||||
|
var foundDebugdLB bool
|
||||||
|
for _, lb := range client.loadbalancers {
|
||||||
|
// Expect load balancer name to have the format of "name-serviceName-uid" which is what buildResourceName does currently.
|
||||||
|
if lb.name == fmt.Sprintf("%s-debugd-%s", client.name, client.uid) {
|
||||||
|
foundDebugdLB = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if tc.isDebugCluster {
|
||||||
assert.Equal(4, len(client.loadbalancers))
|
assert.Equal(4, len(client.loadbalancers))
|
||||||
|
assert.True(foundDebugdLB, "debugd loadbalancer not found in debug-mode")
|
||||||
|
} else {
|
||||||
|
assert.Equal(3, len(client.loadbalancers))
|
||||||
|
assert.False(foundDebugdLB, "debugd loadbalancer found in non-debug mode")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user