Skip to content

Commit

Permalink
cli: expose internalLoadBalancer in config
Browse files Browse the repository at this point in the history
  • Loading branch information
3u13r committed Oct 5, 2023
1 parent 645aa42 commit 84e6568
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 24 deletions.
20 changes: 12 additions & 8 deletions cli/internal/cloudcmd/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func awsTerraformVars(conf *config.Config, imageRef string) *terraform.AWSCluste
Debug: conf.IsDebugCluster(),
EnableSNP: conf.GetAttestationConfig().GetVariant().Equal(variant.AWSSEVSNP{}),
CustomEndpoint: conf.CustomEndpoint,
InternalLoadBalancer: conf.InternalLoadBalancer,
}
}

Expand Down Expand Up @@ -143,6 +144,7 @@ func azureTerraformVars(conf *config.Config, imageRef string) *terraform.AzureCl
UserAssignedIdentity: conf.Provider.Azure.UserAssignedIdentity,
ResourceGroup: conf.Provider.Azure.ResourceGroup,
CustomEndpoint: conf.CustomEndpoint,
InternalLoadBalancer: conf.InternalLoadBalancer,
}

vars = normalizeAzureURIs(vars)
Expand Down Expand Up @@ -172,14 +174,15 @@ func gcpTerraformVars(conf *config.Config, imageRef string) *terraform.GCPCluste
}
}
return &terraform.GCPClusterVariables{
Name: conf.Name,
NodeGroups: nodeGroups,
Project: conf.Provider.GCP.Project,
Region: conf.Provider.GCP.Region,
Zone: conf.Provider.GCP.Zone,
ImageID: imageRef,
Debug: conf.IsDebugCluster(),
CustomEndpoint: conf.CustomEndpoint,
Name: conf.Name,
NodeGroups: nodeGroups,
Project: conf.Provider.GCP.Project,
Region: conf.Provider.GCP.Region,
Zone: conf.Provider.GCP.Zone,
ImageID: imageRef,
Debug: conf.IsDebugCluster(),
CustomEndpoint: conf.CustomEndpoint,
InternalLoadBalancer: conf.InternalLoadBalancer,
}
}

Expand Down Expand Up @@ -218,6 +221,7 @@ func openStackTerraformVars(conf *config.Config, imageRef string) *terraform.Ope
Debug: conf.IsDebugCluster(),
NodeGroups: nodeGroups,
CustomEndpoint: conf.CustomEndpoint,
InternalLoadBalancer: conf.InternalLoadBalancer,
}
}

Expand Down
10 changes: 10 additions & 0 deletions cli/internal/terraform/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ type AWSClusterVariables struct {
NodeGroups map[string]AWSNodeGroup `hcl:"node_groups" cty:"node_groups"`
// CustomEndpoint is the (optional) custom dns hostname for the kubernetes api server.
CustomEndpoint string `hcl:"custom_endpoint" cty:"custom_endpoint"`
// InternalLoadBalancer is true if an internal load balancer should be created.
InternalLoadBalancer bool `hcl:"internal_load_balancer" cty:"internal_load_balancer"`
}

// GetCreateMAA gets the CreateMAA variable.
Expand Down Expand Up @@ -131,6 +133,8 @@ type GCPClusterVariables struct {
NodeGroups map[string]GCPNodeGroup `hcl:"node_groups" cty:"node_groups"`
// CustomEndpoint is the (optional) custom dns hostname for the kubernetes api server.
CustomEndpoint string `hcl:"custom_endpoint" cty:"custom_endpoint"`
// InternalLoadBalancer is true if an internal load balancer should be created.
InternalLoadBalancer bool `hcl:"internal_load_balancer" cty:"internal_load_balancer"`
}

// GetCreateMAA gets the CreateMAA variable.
Expand Down Expand Up @@ -203,6 +207,8 @@ type AzureClusterVariables struct {
NodeGroups map[string]AzureNodeGroup `hcl:"node_groups" cty:"node_groups"`
// CustomEndpoint is the (optional) custom dns hostname for the kubernetes api server.
CustomEndpoint string `hcl:"custom_endpoint" cty:"custom_endpoint"`
// InternalLoadBalancer is true if an internal load balancer should be created.
InternalLoadBalancer bool `hcl:"internal_load_balancer" cty:"internal_load_balancer"`
}

// GetCreateMAA gets the CreateMAA variable.
Expand Down Expand Up @@ -275,6 +281,8 @@ type OpenStackClusterVariables struct {
Debug bool `hcl:"debug" cty:"debug"`
// CustomEndpoint is the (optional) custom dns hostname for the kubernetes api server.
CustomEndpoint string `hcl:"custom_endpoint" cty:"custom_endpoint"`
// InternalLoadBalancer is true if an internal load balancer should be created.
InternalLoadBalancer bool `hcl:"internal_load_balancer" cty:"internal_load_balancer"`
}

// GetCreateMAA gets the CreateMAA variable.
Expand Down Expand Up @@ -346,6 +354,8 @@ type QEMUVariables struct {
KernelCmdline *string `hcl:"constellation_cmdline" cty:"constellation_cmdline"`
// CustomEndpoint is the (optional) custom dns hostname for the kubernetes api server.
CustomEndpoint string `hcl:"custom_endpoint" cty:"custom_endpoint"`
// InternalLoadBalancer is true if an internal load balancer should be created.
InternalLoadBalancer bool `hcl:"internal_load_balancer" cty:"internal_load_balancer"`
}

// GetCreateMAA gets the CreateMAA variable.
Expand Down
11 changes: 8 additions & 3 deletions cli/internal/terraform/variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ node_groups = {
zone = "eu-central-1c"
}
}
custom_endpoint = "example.com"
custom_endpoint = "example.com"
internal_load_balancer = false
`
got := vars.String()
assert.Equal(t, want, got)
Expand Down Expand Up @@ -147,7 +148,8 @@ node_groups = {
zone = "eu-central-1b"
}
}
custom_endpoint = "example.com"
custom_endpoint = "example.com"
internal_load_balancer = false
`
got := vars.String()
assert.Equal(t, want, got)
Expand Down Expand Up @@ -212,7 +214,8 @@ node_groups = {
zones = null
}
}
custom_endpoint = "example.com"
custom_endpoint = "example.com"
internal_load_balancer = false
`
got := vars.String()
assert.Equal(t, want, got)
Expand Down Expand Up @@ -279,6 +282,7 @@ openstack_username = "my-username"
openstack_password = "my-password"
debug = true
custom_endpoint = "example.com"
internal_load_balancer = false
`
got := vars.String()
assert.Equal(t, want, got)
Expand Down Expand Up @@ -333,6 +337,7 @@ nvram = "/usr/share/OVMF/OVMF_VARS.fd"
constellation_initrd = "/var/lib/libvirt/images/cluster-name-initrd"
constellation_cmdline = "console=ttyS0,115200n8"
custom_endpoint = "example.com"
internal_load_balancer = false
`
got := vars.String()
assert.Equal(t, want, got)
Expand Down
9 changes: 9 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ type Config struct {
// A fallback to DNS name is always available.
CustomEndpoint string `yaml:"customEndpoint" validate:"omitempty,hostname_rfc1123"`
// description: |
// Flag to enable/disable the internal load balancer. If enabled, the Constellation is only accessible from within the VPC.
InternalLoadBalancer bool `yaml:"internalLoadBalancer" validate:"omitempty"`
// description: |
// Supported cloud providers and their specific configurations.
Provider ProviderConfig `yaml:"provider" validate:"dive"`
// description: |
Expand Down Expand Up @@ -830,6 +833,12 @@ func (c *Config) Validate(force bool) error {
}
}

if c.InternalLoadBalancer {
if c.GetProvider() != cloudprovider.AWS && c.GetProvider() != cloudprovider.GCP {
return &ValidationError{validationErrMsgs: []string{"internalLoadBalancer is only supported for AWS and GCP"}}
}
}

err := validate.Struct(c)
if err == nil {
return nil
Expand Down
31 changes: 18 additions & 13 deletions internal/config/config_doc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 84e6568

Please sign in to comment.