Skip to content

Commit

Permalink
Merge pull request #32 from hathora/gp/memory-cpu-ratio
Browse files Browse the repository at this point in the history
remove cpu/memory ratio validation
  • Loading branch information
gwprice115 authored Jun 25, 2024
2 parents c93e586 + 859155d commit a54e617
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 135 deletions.
4 changes: 0 additions & 4 deletions internal/commands/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ func (c *DeployConfig) Validate() error {
err = errors.Join(err, requireFloatInRange(c.RequestedCPU, minCPU, maxCPU, requestedCPUFlag.Name))
err = errors.Join(err, requireMaxDecimals(c.RequestedCPU, maxCPUDecimalPlaces, requestedCPUFlag.Name))

if c.RequestedMemoryMB != (c.RequestedCPU * memoryMBPerCPU) {
err = errors.Join(err, invalidMemoryToCPURatio(c.RequestedMemoryMB, c.RequestedCPU))
}

return err
}

Expand Down
5 changes: 0 additions & 5 deletions internal/commands/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ var (
maxCPU = float64(4)
minMemoryMB = float64(1024)
maxMemoryMB = float64(8192)
memoryMBPerCPU = float64(2048)
)

var Deployment = &cli.Command{
Expand Down Expand Up @@ -505,10 +504,6 @@ func (c *CreateDeploymentConfig) Validate() error {
err = errors.Join(err, requireFloatInRange(c.RequestedCPU, minCPU, maxCPU, requestedCPUFlag.Name))
err = errors.Join(err, requireMaxDecimals(c.RequestedCPU, maxCPUDecimalPlaces, requestedCPUFlag.Name))

if c.RequestedMemoryMB != (c.RequestedCPU * memoryMBPerCPU) {
err = errors.Join(err, invalidMemoryToCPURatio(c.RequestedMemoryMB, c.RequestedCPU))
}

return err
}

Expand Down
115 changes: 0 additions & 115 deletions internal/commands/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,118 +534,3 @@ func Test_Integration_DeploymentCommands_CreateFromLatest(t *testing.T) {
})
}
}

func Test_Integration_DeploymentCommands_CreateFromLatestWithBadMemToCPURatio(t *testing.T) {
if testing.Short() {
t.Skip("skipping integration test in short mode")
}

t.Parallel()

tests := []struct {
name string
skip string
command string
responses []mockResponse
expectErr bool
}{
{
name: "create a deployment from latest with invalid memory to cpu ratio due to overrides",
command: "create --from-latest --requested-memory-mb 2048",
responses: []mockResponse{
// get latest response
{
status: http.StatusOK,
body: `{
"idleTimeoutEnabled": true,
"env": [
{
"value": "TRUE",
"name": "EULA"
}
],
"roomsPerProcess": 3,
"additionalContainerPorts": [{
"transportType": "tcp",
"port": 4000,
"name": "debug"
}],
"defaultContainerPort": {
"transportType": "tcp",
"port": 8000,
"name": "default"
},
"createdAt": "2019-08-24T14:15:22Z",
"createdBy": "google-oauth2|107030234048588177467",
"requestedMemoryMB": 1024,
"requestedCPU": 0.5,
"deploymentId": 1,
"buildId": 1,
"appId": "app-af469a92-5b45-4565-b3c4-b79878de67d2"
}`,
},
// create deployment response
{
status: http.StatusCreated,
body: `{
"idleTimeoutEnabled": true,
"env": [
{
"value": "TRUE",
"name": "EULA"
}
],
"roomsPerProcess": 3,
"additionalContainerPorts": [
{
"transportType": "tcp",
"port": 4000,
"name": "debug"
}
],
"transportType": "tcp",
"containerPort": 8000,
"requestedMemoryMB": 1024,
"requestedCPU": 0.5
}`,
},
},
expectErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.skip != "" {
t.Skip(tt.skip)
}

var opts []mock.HathoraOption
for _, r := range tt.responses {
opts = append(opts, mock.RespondsWithStatus(r.status))
opts = append(opts, mock.RespondsWithJSON([]byte(r.body)))
}
h := mock.Hathora(t, opts...)
app := commands.App()
staticArgs := []string{
"hathora",
"-vvv",
"--app-id",
"test-app-id",
"--token",
"test-token",
"--hathora-cloud-endpoint",
h.Endpoint,
"deployment",
}
testArgs := strings.Fields(tt.command)
t.Log(append(staticArgs, testArgs...))
err := app.Run(context.Background(), append(staticArgs, testArgs...))
if tt.expectErr {
assert.NotNil(t, err, "command should have returned an error")
} else {
assert.Nil(t, err, "command returned an error")
}
})
}
}
11 changes: 0 additions & 11 deletions internal/commands/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,8 @@ package commands

import (
"fmt"
"strconv"
)

func missingRequiredFlag(flagName string) error {
return fmt.Errorf("Required flag \"%s\" is not set", flagName)
}

func invalidMemoryToCPURatio(memoryMB, cpu float64) error {
return fmt.Errorf("invalid memory to CPU ratio of %s to %s; %s and %s must be in a %s:1 ratio",
strconv.FormatFloat(memoryMB, 'f', -1, 64),
strconv.FormatFloat(cpu, 'f', -1, 64),
requestedMemoryFlag.Name,
requestedCPUFlag.Name,
strconv.FormatFloat(memoryMBPerCPU, 'f', -1, 64),
)
}

0 comments on commit a54e617

Please sign in to comment.