-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
parse memory from a potentially humanized string to mb
- Loading branch information
1 parent
00a73b9
commit 08eafb4
Showing
11 changed files
with
193 additions
and
47 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package state_utils | ||
|
||
import ( | ||
"errors" | ||
"strconv" | ||
|
||
"github.com/hashicorp/go-cty/cty" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
|
||
pkgutil "k8s.io/minikube/pkg/util" | ||
) | ||
|
||
func MemoryConverter() schema.SchemaStateFunc { | ||
return func(val interface{}) string { | ||
memory, ok := val.(string) | ||
if !ok { | ||
panic(errors.New("memory flag is not a string")) | ||
} | ||
memoryMb, err := pkgutil.CalculateSizeInMB(memory) | ||
if err != nil { | ||
panic(errors.New("invalid memory value")) | ||
} | ||
|
||
return strconv.Itoa(memoryMb) + "mb" | ||
|
||
} | ||
|
||
} | ||
|
||
func MemoryValidator() schema.SchemaValidateDiagFunc { | ||
return schema.SchemaValidateDiagFunc(func(val interface{}, path cty.Path) diag.Diagnostics { | ||
memory, ok := val.(string) | ||
if !ok { | ||
diag := diag.FromErr(errors.New("memory flag is not a string")) | ||
return diag | ||
} | ||
_, err := pkgutil.CalculateSizeInMB(memory) | ||
if err != nil { | ||
diag := diag.FromErr(errors.New("invalid memory value")) | ||
return diag | ||
} | ||
return nil | ||
}) | ||
} |
Oops, something went wrong.