-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make additional worker node pool fields mandatory
- Loading branch information
1 parent
02c7833
commit 068f2c9
Showing
6 changed files
with
190 additions
and
217 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1491,165 +1491,109 @@ func TestProvision_Provision(t *testing.T) { | |
// then | ||
require.EqualError(t, err, "while validating input parameters: region: region must be one of the following: \"me-central2\"") | ||
}) | ||
} | ||
|
||
t.Run("Should pass with additional worker node pools", func(t *testing.T) { | ||
// given | ||
memoryStorage := storage.NewMemoryStorage() | ||
|
||
queue := &automock.Queue{} | ||
queue.On("Add", mock.AnythingOfType("string")) | ||
|
||
factoryBuilder := &automock.PlanValidator{} | ||
factoryBuilder.On("IsPlanSupport", broker.PreviewPlanID).Return(true) | ||
|
||
planDefaults := func(planID string, platformProvider pkg.CloudProvider, provider *pkg.CloudProvider) (*gqlschema.ClusterConfigInput, error) { | ||
return &gqlschema.ClusterConfigInput{}, nil | ||
} | ||
kcBuilder := &kcMock.KcBuilder{} | ||
kcBuilder.On("GetServerURL", "").Return("", fmt.Errorf("error")) | ||
// #create provisioner endpoint | ||
provisionEndpoint := broker.NewProvision( | ||
broker.Config{ | ||
EnablePlans: []string{"preview"}, | ||
URL: brokerURL, | ||
OnlySingleTrialPerGA: true, | ||
EnableKubeconfigURLLabel: true, | ||
}, | ||
gardener.Config{Project: "test", ShootDomain: "example.com", DNSProviders: fixDNSProviders()}, | ||
memoryStorage.Operations(), | ||
memoryStorage.Instances(), | ||
memoryStorage.InstancesArchived(), | ||
queue, | ||
factoryBuilder, | ||
broker.PlansConfig{}, | ||
planDefaults, | ||
log, | ||
dashboardConfig, | ||
kcBuilder, | ||
whitelist.Set{}, | ||
&broker.OneForAllConvergedCloudRegionsProvider{}, | ||
) | ||
|
||
additionalWorkerNodePools := `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 20}, {"name": "name-2", "machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 20}]` | ||
|
||
// when | ||
_, err := provisionEndpoint.Provision(fixRequestContext(t, "cf-sa30"), instanceID, domain.ProvisionDetails{ | ||
ServiceID: serviceID, | ||
PlanID: broker.PreviewPlanID, | ||
RawParameters: json.RawMessage(fmt.Sprintf(`{"name": "%s", "region": "%s","additionalWorkerNodePools": %s }`, clusterName, "eu-central-1", additionalWorkerNodePools)), | ||
RawContext: json.RawMessage(fmt.Sprintf(`{"globalaccount_id": "%s", "subaccount_id": "%s", "user_id": "%s"}`, "any-global-account-id", subAccountID, "[email protected]")), | ||
}, true) | ||
t.Logf("%+v\n", *provisionEndpoint) | ||
|
||
// then | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("Should pass with empty additional worker node pools", func(t *testing.T) { | ||
// given | ||
memoryStorage := storage.NewMemoryStorage() | ||
|
||
queue := &automock.Queue{} | ||
queue.On("Add", mock.AnythingOfType("string")) | ||
|
||
factoryBuilder := &automock.PlanValidator{} | ||
factoryBuilder.On("IsPlanSupport", broker.PreviewPlanID).Return(true) | ||
|
||
planDefaults := func(planID string, platformProvider pkg.CloudProvider, provider *pkg.CloudProvider) (*gqlschema.ClusterConfigInput, error) { | ||
return &gqlschema.ClusterConfigInput{}, nil | ||
} | ||
kcBuilder := &kcMock.KcBuilder{} | ||
kcBuilder.On("GetServerURL", "").Return("", fmt.Errorf("error")) | ||
// #create provisioner endpoint | ||
provisionEndpoint := broker.NewProvision( | ||
broker.Config{ | ||
EnablePlans: []string{"preview"}, | ||
URL: brokerURL, | ||
OnlySingleTrialPerGA: true, | ||
EnableKubeconfigURLLabel: true, | ||
}, | ||
gardener.Config{Project: "test", ShootDomain: "example.com", DNSProviders: fixDNSProviders()}, | ||
memoryStorage.Operations(), | ||
memoryStorage.Instances(), | ||
memoryStorage.InstancesArchived(), | ||
queue, | ||
factoryBuilder, | ||
broker.PlansConfig{}, | ||
planDefaults, | ||
log, | ||
dashboardConfig, | ||
kcBuilder, | ||
whitelist.Set{}, | ||
&broker.OneForAllConvergedCloudRegionsProvider{}, | ||
) | ||
|
||
additionalWorkerNodePools := "[]" | ||
|
||
// when | ||
_, err := provisionEndpoint.Provision(fixRequestContext(t, "cf-sa30"), instanceID, domain.ProvisionDetails{ | ||
ServiceID: serviceID, | ||
PlanID: broker.PreviewPlanID, | ||
RawParameters: json.RawMessage(fmt.Sprintf(`{"name": "%s", "region": "%s","additionalWorkerNodePools": %s }`, clusterName, "eu-central-1", additionalWorkerNodePools)), | ||
RawContext: json.RawMessage(fmt.Sprintf(`{"globalaccount_id": "%s", "subaccount_id": "%s", "user_id": "%s"}`, "any-global-account-id", subAccountID, "[email protected]")), | ||
}, true) | ||
t.Logf("%+v\n", *provisionEndpoint) | ||
|
||
// then | ||
require.NoError(t, err) | ||
}) | ||
|
||
t.Run("Should fail for autoScalerMin bigger than autoScalerMax", func(t *testing.T) { | ||
// given | ||
memoryStorage := storage.NewMemoryStorage() | ||
func TestAdditionalWorkerNodePools(t *testing.T) { | ||
for tn, tc := range map[string]struct { | ||
additionalWorkerNodePools string | ||
expectedError bool | ||
}{ | ||
"Valid additional worker node pools": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 20}, {"name": "name-2", "machineType": "m6i.large", "autoScalerMin": 0, "autoScalerMax": 0}]`, | ||
expectedError: false, | ||
}, | ||
"Empty additional worker node pools": { | ||
additionalWorkerNodePools: "[]", | ||
expectedError: false, | ||
}, | ||
"Empty name": { | ||
additionalWorkerNodePools: `[{"name": "", "machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 20}]`, | ||
expectedError: true, | ||
}, | ||
"Missing name": { | ||
additionalWorkerNodePools: `[{"machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 20}]`, | ||
expectedError: true, | ||
}, | ||
"Empty machine type": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "machineType": "", "autoScalerMin": 3, "autoScalerMax": 20}]`, | ||
expectedError: true, | ||
}, | ||
"Missing machine type": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "autoScalerMin": 3, "autoScalerMax": 20}]`, | ||
expectedError: true, | ||
}, | ||
"Missing autoScalerMin": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMax": 3}]`, | ||
expectedError: true, | ||
}, | ||
"Missing autoScalerMax": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMin": 20}]`, | ||
expectedError: true, | ||
}, | ||
"AutoScalerMax bigger than 300": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 301}]`, | ||
expectedError: true, | ||
}, | ||
"AutoScalerMin bigger than autoScalerMax": { | ||
additionalWorkerNodePools: `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMin": 20, "autoScalerMax": 3}]`, | ||
expectedError: true, | ||
}, | ||
} { | ||
t.Run(tn, func(t *testing.T) { | ||
// given | ||
log := slog.New(slog.NewTextHandler(os.Stdout, &slog.HandlerOptions{ | ||
Level: slog.LevelInfo, | ||
})) | ||
|
||
queue := &automock.Queue{} | ||
queue.On("Add", mock.AnythingOfType("string")) | ||
memoryStorage := storage.NewMemoryStorage() | ||
|
||
factoryBuilder := &automock.PlanValidator{} | ||
factoryBuilder.On("IsPlanSupport", broker.PreviewPlanID).Return(true) | ||
queue := &automock.Queue{} | ||
queue.On("Add", mock.AnythingOfType("string")) | ||
|
||
planDefaults := func(planID string, platformProvider pkg.CloudProvider, provider *pkg.CloudProvider) (*gqlschema.ClusterConfigInput, error) { | ||
return &gqlschema.ClusterConfigInput{}, nil | ||
} | ||
kcBuilder := &kcMock.KcBuilder{} | ||
kcBuilder.On("GetServerURL", "").Return("", fmt.Errorf("error")) | ||
// #create provisioner endpoint | ||
provisionEndpoint := broker.NewProvision( | ||
broker.Config{ | ||
EnablePlans: []string{"preview"}, | ||
URL: brokerURL, | ||
OnlySingleTrialPerGA: true, | ||
EnableKubeconfigURLLabel: true, | ||
}, | ||
gardener.Config{Project: "test", ShootDomain: "example.com", DNSProviders: fixDNSProviders()}, | ||
memoryStorage.Operations(), | ||
memoryStorage.Instances(), | ||
memoryStorage.InstancesArchived(), | ||
queue, | ||
factoryBuilder, | ||
broker.PlansConfig{}, | ||
planDefaults, | ||
log, | ||
dashboardConfig, | ||
kcBuilder, | ||
whitelist.Set{}, | ||
&broker.OneForAllConvergedCloudRegionsProvider{}, | ||
) | ||
factoryBuilder := &automock.PlanValidator{} | ||
factoryBuilder.On("IsPlanSupport", broker.PreviewPlanID).Return(true) | ||
|
||
additionalWorkerNodePools := `[{"name": "name-1", "machineType": "m6i.large", "autoScalerMin": 20, "autoScalerMax": 3}, {"name": "name-2", "machineType": "m6i.large", "autoScalerMin": 3, "autoScalerMax": 20}]` | ||
planDefaults := func(planID string, platformProvider pkg.CloudProvider, provider *pkg.CloudProvider) (*gqlschema.ClusterConfigInput, error) { | ||
return &gqlschema.ClusterConfigInput{}, nil | ||
} | ||
kcBuilder := &kcMock.KcBuilder{} | ||
kcBuilder.On("GetServerURL", "").Return("", fmt.Errorf("error")) | ||
// #create provisioner endpoint | ||
provisionEndpoint := broker.NewProvision( | ||
broker.Config{ | ||
EnablePlans: []string{"preview"}, | ||
URL: brokerURL, | ||
OnlySingleTrialPerGA: true, | ||
EnableKubeconfigURLLabel: true, | ||
}, | ||
gardener.Config{Project: "test", ShootDomain: "example.com", DNSProviders: fixDNSProviders()}, | ||
memoryStorage.Operations(), | ||
memoryStorage.Instances(), | ||
memoryStorage.InstancesArchived(), | ||
queue, | ||
factoryBuilder, | ||
broker.PlansConfig{}, | ||
planDefaults, | ||
log, | ||
dashboardConfig, | ||
kcBuilder, | ||
whitelist.Set{}, | ||
&broker.OneForAllConvergedCloudRegionsProvider{}, | ||
) | ||
|
||
// when | ||
_, err := provisionEndpoint.Provision(fixRequestContext(t, "cf-sa30"), instanceID, domain.ProvisionDetails{ | ||
ServiceID: serviceID, | ||
PlanID: broker.PreviewPlanID, | ||
RawParameters: json.RawMessage(fmt.Sprintf(`{"name": "%s", "region": "%s","additionalWorkerNodePools": %s }`, clusterName, "eu-central-1", additionalWorkerNodePools)), | ||
RawContext: json.RawMessage(fmt.Sprintf(`{"globalaccount_id": "%s", "subaccount_id": "%s", "user_id": "%s"}`, "any-global-account-id", subAccountID, "[email protected]")), | ||
}, true) | ||
t.Logf("%+v\n", *provisionEndpoint) | ||
// when | ||
_, err := provisionEndpoint.Provision(fixRequestContext(t, "cf-sa30"), instanceID, domain.ProvisionDetails{ | ||
ServiceID: serviceID, | ||
PlanID: broker.PreviewPlanID, | ||
RawParameters: json.RawMessage(fmt.Sprintf(`{"name": "%s", "region": "%s","additionalWorkerNodePools": %s }`, clusterName, "eu-central-1", tc.additionalWorkerNodePools)), | ||
RawContext: json.RawMessage(fmt.Sprintf(`{"globalaccount_id": "%s", "subaccount_id": "%s", "user_id": "%s"}`, "any-global-account-id", subAccountID, "[email protected]")), | ||
}, true) | ||
t.Logf("%+v\n", *provisionEndpoint) | ||
|
||
// then | ||
require.EqualError(t, err, "AutoScalerMax 3 should be larger than AutoScalerMin 20. User provided values min:20, max:3; plan defaults min:0, max:0") | ||
}) | ||
// then | ||
assert.Equal(t, tc.expectedError, err != nil) | ||
}) | ||
} | ||
} | ||
|
||
func TestNetworkingValidation(t *testing.T) { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.