Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions pacts/replicated-cli-vendor-api.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
"app": {
"channels": [
{
},
},
{
},
},
{
}
}
],
"created": "2000-02-01T12:30:00Z",
"description": "",
Expand Down Expand Up @@ -83,7 +83,7 @@
{
"channels": [
{
}
}
],
"id": "replicated-cli-list-apps-app",
"name": "Replicated CLI List Apps App",
Expand Down Expand Up @@ -223,7 +223,8 @@
"id": "replicated-cli-get-channel-unstable",
"name": "Unstable",
"releases": [
]

]
}
},
"matchingRules": {
Expand Down Expand Up @@ -773,7 +774,7 @@
{
"eventType": "release.promoted",
"filters": {
}
}
}
],
"id": "notif-sub-1",
Expand Down Expand Up @@ -817,7 +818,7 @@
{
"eventType": "release.promoted",
"filters": {
}
}
}
],
"isEnabled": true,
Expand All @@ -834,7 +835,7 @@
{
"eventType": "release.promoted",
"filters": {
}
}
}
],
"id": "notif-sub-1",
Expand Down Expand Up @@ -877,7 +878,7 @@
{
"eventType": "release.promoted",
"filters": {
}
}
}
],
"id": "notif-sub-1",
Expand Down Expand Up @@ -923,7 +924,7 @@
{
"eventType": "release.promoted",
"filters": {
}
}
}
],
"id": "notif-sub-1",
Expand Down Expand Up @@ -983,7 +984,8 @@
"events": [
{
"attempts": [
],

],
"eventData": {
"releaseId": "rel-1"
},
Expand Down Expand Up @@ -1720,7 +1722,8 @@
},
"body": {
"releases": [
]

]
}
}
},
Expand Down
5 changes: 4 additions & 1 deletion pkg/kotsclient/cluster_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,12 @@ func (c *VendorV3Client) doCreateClusterDryRunRequest(req CreateClusterRequest)
return nil, nil, err
}

if resp.Error.Message != "" {
if resp.Error.Message != "" || resp.Error.ValidationError != nil || resp.Error.MaxDiskGiB != 0 || resp.Error.MaxEKS != 0 || resp.Error.MaxGKE != 0 || resp.Error.MaxAKS != 0 {
return nil, &resp.Error, nil
}
if resp.TotalCost == nil || resp.TTL == nil {
return nil, nil, fmt.Errorf("create cluster dry-run response missing total_cost or ttl")
}
cl := &types.Cluster{
EstimatedCost: *resp.TotalCost,
TTL: *resp.TTL,
Expand Down
46 changes: 46 additions & 0 deletions pkg/kotsclient/create_request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,49 @@ func TestCreateClusterIncludesNetworkPolicy(t *testing.T) {
require.Equal(t, "test-cluster", requestBody["name"])
require.Equal(t, "airgap", requestBody["network_policy"])
}

func TestCreateClusterDryRunReturnsValidationErrorWithoutMessage(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method)
require.Equal(t, "/v3/cluster", r.URL.Path)
require.Equal(t, "dry-run=true", r.URL.RawQuery)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"error":{"validationError":{"errors":["bad version"]}}}`))
}))
defer server.Close()

httpClient := platformclient.NewHTTPClient(server.URL, "fake-api-key")
client := &VendorV3Client{HTTPClient: *httpClient}

cluster, ve, err := client.CreateCluster(CreateClusterOpts{DryRun: true})
require.NoError(t, err)
require.Nil(t, cluster)
require.NotNil(t, ve)
require.NotNil(t, ve.ValidationError)
require.Equal(t, []string{"bad version"}, ve.ValidationError.Errors)
}

func TestCreateVMDryRunReturnsValidationErrorWithoutMessage(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
require.Equal(t, http.MethodPost, r.Method)
require.Equal(t, "/v3/vm", r.URL.Path)
require.Equal(t, "dry-run=true", r.URL.RawQuery)

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
_, _ = w.Write([]byte(`{"error":{"validationError":{"errors":["bad version"]}}}`))
}))
defer server.Close()

httpClient := platformclient.NewHTTPClient(server.URL, "fake-api-key")
client := &VendorV3Client{HTTPClient: *httpClient}

vms, ve, err := client.CreateVM(CreateVMOpts{DryRun: true})
require.NoError(t, err)
require.Nil(t, vms)
require.NotNil(t, ve)
require.NotNil(t, ve.ValidationError)
require.Equal(t, []string{"bad version"}, ve.ValidationError.Errors)
}
5 changes: 4 additions & 1 deletion pkg/kotsclient/vm_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ func (c *VendorV3Client) doCreateVMDryRunRequest(req CreateVMRequest) ([]*types.
return nil, nil, err
}

if resp.Error.Message != "" {
if resp.Error.Message != "" || resp.Error.ValidationError != nil || resp.Error.MaxDiskGiB != 0 {
return nil, &resp.Error, nil
}
if resp.TotalCost == nil || resp.TTL == nil {
return nil, nil, fmt.Errorf("create vm dry-run response missing total_cost or ttl")
}
vms := []*types.VM{
{
EstimatedCost: *resp.TotalCost,
Expand Down
Loading