Skip to content

Commit

Permalink
fix panic in status cmd (#2625)
Browse files Browse the repository at this point in the history
  • Loading branch information
elchead authored Nov 22, 2023
1 parent 0c1e6e9 commit 9af514d
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 13 deletions.
3 changes: 3 additions & 0 deletions cli/internal/cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ func (s *statusCmd) status(
if errors.As(err, &configValidationErr) {
cmd.PrintErrln(configValidationErr.LongMessage())
}
if err != nil {
return fmt.Errorf("loading config file: %w", err)
}

nodeVersion, err := kubeClient.GetConstellationVersion(cmd.Context())
if err != nil {
Expand Down
35 changes: 33 additions & 2 deletions cli/internal/cmd/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ func TestStatus(t *testing.T) {
cmd.SetErr(&errOut)

fileHandler := file.NewHandler(afero.NewMemMapFs())
cfg, err := createConfigWithAttestationVariant(cloudprovider.QEMU, "", variant.QEMUVTPM{})
cfg, err := createConfigWithAttestationVariant(cloudprovider.Azure, "", variant.AzureSEVSNP{})
require.NoError(err)
modifyConfigForAzureToPassValidate(cfg)
require.NoError(fileHandler.WriteYAML(constants.ConfigFilename, cfg))

s := statusCmd{fileHandler: fileHandler}

err = s.status(
Expand All @@ -287,6 +287,37 @@ func TestStatus(t *testing.T) {
}
}

func modifyConfigForAzureToPassValidate(c *config.Config) {
c.RemoveProviderAndAttestationExcept(cloudprovider.Azure)
c.Image = constants.BinaryVersion().String()
c.Provider.Azure.SubscriptionID = "11111111-1111-1111-1111-111111111111"
c.Provider.Azure.TenantID = "11111111-1111-1111-1111-111111111111"
c.Provider.Azure.Location = "westus"
c.Provider.Azure.ResourceGroup = "test"
c.Provider.Azure.UserAssignedIdentity = "/subscriptions/11111111-1111-1111-1111-111111111111/resourcegroups/constellation-identity/providers/Microsoft.ManagedIdentity/userAssignedIdentities/constellation-identity"
c.Attestation.AzureSEVSNP.Measurements = measurements.M{
0: measurements.WithAllBytes(0x00, measurements.Enforce, measurements.PCRMeasurementLength),
}
c.NodeGroups = map[string]config.NodeGroup{
constants.ControlPlaneDefault: {
Role: "control-plane",
Zone: "",
InstanceType: "Standard_DC4as_v5",
StateDiskSizeGB: 30,
StateDiskType: "StandardSSD_LRS",
InitialCount: 3,
},
constants.WorkerDefault: {
Role: "worker",
Zone: "",
InstanceType: "Standard_DC4as_v5",
StateDiskSizeGB: 30,
StateDiskType: "StandardSSD_LRS",
InitialCount: 3,
},
}
}

type stubKubeClient struct {
status map[string]kubecmd.NodeStatus
statusErr error
Expand Down
11 changes: 0 additions & 11 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,6 @@ func TestValidate(t *testing.T) {
cnf := Default()
cnf.RemoveProviderAndAttestationExcept(cloudprovider.Azure)
cnf.Image = constants.BinaryVersion().String()
az := cnf.Provider.Azure
az.SubscriptionID = "01234567-0123-0123-0123-0123456789ab"
az.TenantID = "01234567-0123-0123-0123-0123456789ab"
az.Location = "test-location"
az.UserAssignedIdentity = "test-identity"
az.ResourceGroup = "test-resource-group"
cnf.Provider = ProviderConfig{}
cnf.Provider.Azure = az
cnf.Attestation.AzureSEVSNP.Measurements = measurements.M{
0: measurements.WithAllBytes(0x00, measurements.Enforce, measurements.PCRMeasurementLength),
}
modifyConfigForAzureToPassValidate(cnf)
return cnf
}(),
Expand Down

0 comments on commit 9af514d

Please sign in to comment.