From 42fc497477cb6c911a694ab25bed458f7c3a21c4 Mon Sep 17 00:00:00 2001 From: Thomas Tendyck Date: Tue, 24 May 2022 11:57:48 +0200 Subject: [PATCH] cli: fix and tweak config file wording --- cli/cmd/init.go | 4 +-- debugd/cdbg/state/state.go | 2 +- internal/config/config.go | 39 ++++++++++++++------------- internal/config/config_doc.go | 48 +++++++++++++++++----------------- internal/config/config_test.go | 24 ++++++++--------- 5 files changed, 58 insertions(+), 59 deletions(-) diff --git a/cli/cmd/init.go b/cli/cmd/init.go index 4e8b64841..9ef7cd561 100644 --- a/cli/cmd/init.go +++ b/cli/cmd/init.go @@ -468,7 +468,7 @@ func getGCPInstances(stat state.ConstellationState, config *config.Config) (coor // TODO: make min / max configurable and abstract autoscaling for different cloud providers nodes = ScalingGroup{ Instances: nodeInstances, - GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPNodeInstanceGroup, config.AutoscalingNodeGroupsMin, config.AutoscalingNodeGroupsMax), + GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPNodeInstanceGroup, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax), } return @@ -501,7 +501,7 @@ func getAzureInstances(stat state.ConstellationState, config *config.Config) (co // TODO: make min / max configurable and abstract autoscaling for different cloud providers nodes = ScalingGroup{ Instances: nodeInstances, - GroupID: azure.AutoscalingNodeGroup(stat.AzureNodesScaleSet, config.AutoscalingNodeGroupsMin, config.AutoscalingNodeGroupsMax), + GroupID: azure.AutoscalingNodeGroup(stat.AzureNodesScaleSet, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax), } return } diff --git a/debugd/cdbg/state/state.go b/debugd/cdbg/state/state.go index 856c16743..658ef55a4 100644 --- a/debugd/cdbg/state/state.go +++ b/debugd/cdbg/state/state.go @@ -87,7 +87,7 @@ func getGCPInstances(stat state.ConstellationState, config *configc.Config) (coo // TODO: make min / max configurable and abstract autoscaling for different cloud providers nodes = cmdc.ScalingGroup{ Instances: nodeInstances, - GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPNodeInstanceGroup, config.AutoscalingNodeGroupsMin, config.AutoscalingNodeGroupsMax), + GroupID: gcp.AutoscalingNodeGroup(stat.GCPProject, stat.GCPZone, stat.GCPNodeInstanceGroup, config.AutoscalingNodeGroupMin, config.AutoscalingNodeGroupMax), } return diff --git a/internal/config/config.go b/internal/config/config.go index dc4f2efb3..5bdc06d7a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -27,16 +27,14 @@ type Config struct { // Schema version of this configuration file. Version string `yaml:"version" validate:"eq=v1"` // description: | - // Minimum number of nodes in autoscaling group. - // worker nodes. - AutoscalingNodeGroupsMin int `yaml:"autoscalingNodeGroupsMin" validate:"min=0"` + // Minimum number of worker nodes in autoscaling group. + AutoscalingNodeGroupMin int `yaml:"autoscalingNodeGroupMin" validate:"min=0"` // description: | - // Maximum number of nodes in autoscaling group. - // worker nodes. - AutoscalingNodeGroupsMax int `yaml:"autoscalingNodeGroupsMax" validate:"gtefield=AutoscalingNodeGroupsMin"` + // Maximum number of worker nodes in autoscaling group. + AutoscalingNodeGroupMax int `yaml:"autoscalingNodeGroupMax" validate:"gtefield=AutoscalingNodeGroupMin"` // description: | - // Size (in GB) of data disk used for nodes. - StateDiskSizeGB int `yaml:"stateDisksizeGB" validate:"min=0"` + // Size (in GB) of a node's disk to store the non-volatile state. + StateDiskSizeGB int `yaml:"stateDiskSizeGB" validate:"min=0"` // description: | // Ingress firewall rules for node network. IngressFirewall Firewall `yaml:"ingressFirewall,omitempty" validate:"dive"` @@ -55,7 +53,7 @@ type Config struct { // }' EgressFirewall Firewall `yaml:"egressFirewall,omitempty" validate:"dive"` // description: | - // Supported cloud providers & their specific configurations. + // Supported cloud providers and their specific configurations. Provider ProviderConfig `yaml:"provider" validate:"dive"` // description: | // Create SSH users on Constellation nodes. @@ -88,10 +86,10 @@ type FirewallRule struct { // CIDR range for which this rule is applied. IPRange string `yaml:"iprange" validate:"required"` // description: | - // Port of start port of a range. + // Start port of a range. FromPort int `yaml:"fromport" validate:"min=0,max=65535"` // description: | - // End port of a range, or 0 if a single port is given by FromPort. + // End port of a range, or 0 if a single port is given by fromport. ToPort int `yaml:"toport" validate:"omitempty,gtefield=FromPort,max=65535"` } @@ -103,13 +101,13 @@ type Firewall []FirewallRule type ProviderConfig struct { // description: | // Configuration for Azure as provider. - Azure *AzureConfig `yaml:"azureConfig,omitempty" validate:"omitempty,dive"` + Azure *AzureConfig `yaml:"azure,omitempty" validate:"omitempty,dive"` // description: | // Configuration for Google Cloud as provider. - GCP *GCPConfig `yaml:"gcpConfig,omitempty" validate:"omitempty,dive"` + GCP *GCPConfig `yaml:"gcp,omitempty" validate:"omitempty,dive"` // description: | // Configuration for QEMU as provider. - QEMU *QEMUConfig `yaml:"qemuConfig,omitempty" validate:"omitempty,dive"` + QEMU *QEMUConfig `yaml:"qemu,omitempty" validate:"omitempty,dive"` } // AzureConfig are Azure specific configuration values used by the CLI. @@ -131,7 +129,7 @@ type AzureConfig struct { Measurements Measurements `yaml:"measurements"` // description: | // Authorize spawned VMs to access Azure API. See: https://constellation-docs.edgeless.systems/6c320851-bdd2-41d5-bf10-e27427398692/#/getting-started/install?id=azure - UserAssignedIdentity string `yaml:"userassignedIdentity" validate:"required"` + UserAssignedIdentity string `yaml:"userAssignedIdentity" validate:"required"` } // GCPConfig are GCP specific configuration values used by the CLI. @@ -152,7 +150,7 @@ type GCPConfig struct { // Roles added to service account. ServiceAccountRoles []string `yaml:"serviceAccountRoles"` // description: | - // Measurement used to enable measured boot. + // Expected confidential VM measurements. Measurements Measurements `yaml:"measurements"` } @@ -165,10 +163,10 @@ type QEMUConfig struct { // Default returns a struct with the default config. func Default() *Config { return &Config{ - Version: Version1, - AutoscalingNodeGroupsMin: 1, - AutoscalingNodeGroupsMax: 10, - StateDiskSizeGB: 30, + Version: Version1, + AutoscalingNodeGroupMin: 1, + AutoscalingNodeGroupMax: 10, + StateDiskSizeGB: 30, IngressFirewall: Firewall{ { Name: "coordinator", @@ -201,6 +199,7 @@ func Default() *Config { }, }, Provider: ProviderConfig{ + // TODO remove our subscriptions from the default config Azure: &AzureConfig{ SubscriptionID: "0d202bbb-4fa7-4af8-8125-58c269a05435", TenantID: "adb650a8-5da3-4b15-b4b0-3daf65ff7626", diff --git a/internal/config/config_doc.go b/internal/config/config_doc.go index 8297110fc..078294482 100644 --- a/internal/config/config_doc.go +++ b/internal/config/config_doc.go @@ -30,21 +30,21 @@ func init() { ConfigDoc.Fields[0].Note = "" ConfigDoc.Fields[0].Description = "Schema version of this configuration file." ConfigDoc.Fields[0].Comments[encoder.LineComment] = "Schema version of this configuration file." - ConfigDoc.Fields[1].Name = "autoscalingNodeGroupsMin" + ConfigDoc.Fields[1].Name = "autoscalingNodeGroupMin" ConfigDoc.Fields[1].Type = "int" ConfigDoc.Fields[1].Note = "" - ConfigDoc.Fields[1].Description = "Minimum number of nodes in autoscaling group.\nworker nodes." - ConfigDoc.Fields[1].Comments[encoder.LineComment] = "Minimum number of nodes in autoscaling group." - ConfigDoc.Fields[2].Name = "autoscalingNodeGroupsMax" + ConfigDoc.Fields[1].Description = "Minimum number of worker nodes in autoscaling group." + ConfigDoc.Fields[1].Comments[encoder.LineComment] = "Minimum number of worker nodes in autoscaling group." + ConfigDoc.Fields[2].Name = "autoscalingNodeGroupMax" ConfigDoc.Fields[2].Type = "int" ConfigDoc.Fields[2].Note = "" - ConfigDoc.Fields[2].Description = "Maximum number of nodes in autoscaling group.\nworker nodes." - ConfigDoc.Fields[2].Comments[encoder.LineComment] = "Maximum number of nodes in autoscaling group." - ConfigDoc.Fields[3].Name = "stateDisksizeGB" + ConfigDoc.Fields[2].Description = "Maximum number of worker nodes in autoscaling group." + ConfigDoc.Fields[2].Comments[encoder.LineComment] = "Maximum number of worker nodes in autoscaling group." + ConfigDoc.Fields[3].Name = "stateDiskSizeGB" ConfigDoc.Fields[3].Type = "int" ConfigDoc.Fields[3].Note = "" - ConfigDoc.Fields[3].Description = "Size (in GB) of data disk used for nodes." - ConfigDoc.Fields[3].Comments[encoder.LineComment] = "Size (in GB) of data disk used for nodes." + ConfigDoc.Fields[3].Description = "Size (in GB) of a node's disk to store the non-volatile state." + ConfigDoc.Fields[3].Comments[encoder.LineComment] = "Size (in GB) of a node's disk to store the non-volatile state." ConfigDoc.Fields[4].Name = "ingressFirewall" ConfigDoc.Fields[4].Type = "Firewall" ConfigDoc.Fields[4].Note = "" @@ -60,8 +60,8 @@ func init() { ConfigDoc.Fields[6].Name = "provider" ConfigDoc.Fields[6].Type = "ProviderConfig" ConfigDoc.Fields[6].Note = "" - ConfigDoc.Fields[6].Description = "Supported cloud providers & their specific configurations." - ConfigDoc.Fields[6].Comments[encoder.LineComment] = "Supported cloud providers & their specific configurations." + ConfigDoc.Fields[6].Description = "Supported cloud providers and their specific configurations." + ConfigDoc.Fields[6].Comments[encoder.LineComment] = "Supported cloud providers and their specific configurations." ConfigDoc.Fields[7].Name = "sshUsers" ConfigDoc.Fields[7].Type = "[]UserKey" ConfigDoc.Fields[7].Note = "" @@ -120,13 +120,13 @@ func init() { FirewallRuleDoc.Fields[4].Name = "fromport" FirewallRuleDoc.Fields[4].Type = "int" FirewallRuleDoc.Fields[4].Note = "" - FirewallRuleDoc.Fields[4].Description = "Port of start port of a range." - FirewallRuleDoc.Fields[4].Comments[encoder.LineComment] = "Port of start port of a range." + FirewallRuleDoc.Fields[4].Description = "Start port of a range." + FirewallRuleDoc.Fields[4].Comments[encoder.LineComment] = "Start port of a range." FirewallRuleDoc.Fields[5].Name = "toport" FirewallRuleDoc.Fields[5].Type = "int" FirewallRuleDoc.Fields[5].Note = "" - FirewallRuleDoc.Fields[5].Description = "End port of a range, or 0 if a single port is given by FromPort." - FirewallRuleDoc.Fields[5].Comments[encoder.LineComment] = "End port of a range, or 0 if a single port is given by FromPort." + FirewallRuleDoc.Fields[5].Description = "End port of a range, or 0 if a single port is given by fromport." + FirewallRuleDoc.Fields[5].Comments[encoder.LineComment] = "End port of a range, or 0 if a single port is given by fromport." ProviderConfigDoc.Type = "ProviderConfig" ProviderConfigDoc.Comments[encoder.LineComment] = "ProviderConfig are cloud-provider specific configuration values used by the CLI." @@ -138,17 +138,17 @@ func init() { }, } ProviderConfigDoc.Fields = make([]encoder.Doc, 3) - ProviderConfigDoc.Fields[0].Name = "azureConfig" + ProviderConfigDoc.Fields[0].Name = "azure" ProviderConfigDoc.Fields[0].Type = "AzureConfig" ProviderConfigDoc.Fields[0].Note = "" ProviderConfigDoc.Fields[0].Description = "Configuration for Azure as provider." ProviderConfigDoc.Fields[0].Comments[encoder.LineComment] = "Configuration for Azure as provider." - ProviderConfigDoc.Fields[1].Name = "gcpConfig" + ProviderConfigDoc.Fields[1].Name = "gcp" ProviderConfigDoc.Fields[1].Type = "GCPConfig" ProviderConfigDoc.Fields[1].Note = "" ProviderConfigDoc.Fields[1].Description = "Configuration for Google Cloud as provider." ProviderConfigDoc.Fields[1].Comments[encoder.LineComment] = "Configuration for Google Cloud as provider." - ProviderConfigDoc.Fields[2].Name = "qemuConfig" + ProviderConfigDoc.Fields[2].Name = "qemu" ProviderConfigDoc.Fields[2].Type = "QEMUConfig" ProviderConfigDoc.Fields[2].Note = "" ProviderConfigDoc.Fields[2].Description = "Configuration for QEMU as provider." @@ -160,7 +160,7 @@ func init() { AzureConfigDoc.AppearsIn = []encoder.Appearance{ { TypeName: "ProviderConfig", - FieldName: "azureConfig", + FieldName: "azure", }, } AzureConfigDoc.Fields = make([]encoder.Doc, 6) @@ -189,7 +189,7 @@ func init() { AzureConfigDoc.Fields[4].Note = "" AzureConfigDoc.Fields[4].Description = "Expected confidential VM measurements." AzureConfigDoc.Fields[4].Comments[encoder.LineComment] = "Expected confidential VM measurements." - AzureConfigDoc.Fields[5].Name = "userassignedIdentity" + AzureConfigDoc.Fields[5].Name = "userAssignedIdentity" AzureConfigDoc.Fields[5].Type = "string" AzureConfigDoc.Fields[5].Note = "" AzureConfigDoc.Fields[5].Description = "Authorize spawned VMs to access Azure API. See: https://constellation-docs.edgeless.systems/6c320851-bdd2-41d5-bf10-e27427398692/#/getting-started/install?id=azure" @@ -201,7 +201,7 @@ func init() { GCPConfigDoc.AppearsIn = []encoder.Appearance{ { TypeName: "ProviderConfig", - FieldName: "gcpConfig", + FieldName: "gcp", }, } GCPConfigDoc.Fields = make([]encoder.Doc, 6) @@ -233,8 +233,8 @@ func init() { GCPConfigDoc.Fields[5].Name = "measurements" GCPConfigDoc.Fields[5].Type = "Measurements" GCPConfigDoc.Fields[5].Note = "" - GCPConfigDoc.Fields[5].Description = "Measurement used to enable measured boot." - GCPConfigDoc.Fields[5].Comments[encoder.LineComment] = "Measurement used to enable measured boot." + GCPConfigDoc.Fields[5].Description = "Expected confidential VM measurements." + GCPConfigDoc.Fields[5].Comments[encoder.LineComment] = "Expected confidential VM measurements." QEMUConfigDoc.Type = "QEMUConfig" QEMUConfigDoc.Comments[encoder.LineComment] = "" @@ -242,7 +242,7 @@ func init() { QEMUConfigDoc.AppearsIn = []encoder.Appearance{ { TypeName: "ProviderConfig", - FieldName: "qemuConfig", + FieldName: "qemu", }, } QEMUConfigDoc.Fields = make([]encoder.Doc, 1) diff --git a/internal/config/config_test.go b/internal/config/config_test.go index a23cff10f..47a057987 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -46,15 +46,15 @@ func TestFromFile(t *testing.T) { }, "custom config from default file": { config: &Config{ - Version: Version1, - AutoscalingNodeGroupsMin: 42, - AutoscalingNodeGroupsMax: 1337, + Version: Version1, + AutoscalingNodeGroupMin: 42, + AutoscalingNodeGroupMax: 1337, }, configName: constants.ConfigFilename, wantResult: &Config{ - Version: Version1, - AutoscalingNodeGroupsMin: 42, - AutoscalingNodeGroupsMax: 1337, + Version: Version1, + AutoscalingNodeGroupMin: 42, + AutoscalingNodeGroupMax: 1337, }, }, "modify default config": { @@ -103,15 +103,15 @@ func TestFromFileStrictErrors(t *testing.T) { }{ "valid config": { yamlConfig: ` - autoscalingNodeGroupsMin: 5 - autoscalingNodeGroupsMax: 10 + autoscalingNodeGroupMin: 5 + autoscalingNodeGroupMax: 10 stateDisksizeGB: 25 `, }, "typo": { yamlConfig: ` - autoscalingNodeGroupsMini: 5 - autoscalingNodeGroupsMax: 10 + autoscalingNodeGroupMini: 5 + autoscalingNodeGroupMax: 10 stateDisksizeGB: 25 `, wantErr: true, @@ -119,8 +119,8 @@ func TestFromFileStrictErrors(t *testing.T) { "unsupported version": { yamlConfig: ` version: v5 - autoscalingNodeGroupsMin: 1 - autoscalingNodeGroupsMax: 10 + autoscalingNodeGroupMin: 1 + autoscalingNodeGroupMax: 10 stateDisksizeGB: 30 `, wantErr: true,