-
Notifications
You must be signed in to change notification settings - Fork 522
CLOUDP-58090: Create StatefulSet that starts agent image #12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
chatton
merged 3 commits into
master
from
CLOUDP-58090_create_statefulset_that_starts_agent_image
Feb 27, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -4,5 +4,5 @@ metadata: | |
| name: example-mongodb | ||
| spec: | ||
| members: 3 | ||
| kind: ReplicaSet | ||
| type: ReplicaSet | ||
| version: "4.0.6" | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,55 @@ | ||
| package resourcerequirements | ||
|
|
||
| import ( | ||
| corev1 "k8s.io/api/core/v1" | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| ) | ||
|
|
||
| const ( | ||
| resourceMemory = "memory" | ||
| resourceCpu = "cpu" | ||
| ) | ||
|
|
||
| // Defaults returns the default resource requirements for a container | ||
| func Defaults() corev1.ResourceRequirements { | ||
| // we can safely ignore the error as we are passing all valid values | ||
| req, _ := newDefaultRequirements() | ||
| return req | ||
| } | ||
|
|
||
| func newDefaultRequirements() (corev1.ResourceRequirements, error) { | ||
| return newRequirements("1.0", "500M", "0.5", "400M") | ||
| } | ||
|
|
||
| // newRequirements returns a new corev1.ResourceRequirements with the specified arguments, and an error | ||
| // which indicates if there was a problem parsing the input | ||
| func newRequirements(limitsCpu, limitsMemory, requestsCpu, requestsMemory string) (corev1.ResourceRequirements, error) { | ||
| limits, err := buildResourceList(limitsCpu, limitsMemory) | ||
| if err != nil { | ||
| return corev1.ResourceRequirements{}, err | ||
| } | ||
|
|
||
| requests, err := buildResourceList(requestsCpu, requestsMemory) | ||
| if err != nil { | ||
| return corev1.ResourceRequirements{}, err | ||
| } | ||
| return corev1.ResourceRequirements{ | ||
| Limits: limits, | ||
| Requests: requests, | ||
| }, nil | ||
| } | ||
|
|
||
| func buildResourceList(cpu, memory string) (corev1.ResourceList, error) { | ||
| cpuQuantity, err := resource.ParseQuantity(cpu) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| memoryQuantity, err := resource.ParseQuantity(memory) | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
| return corev1.ResourceList{ | ||
| resourceCpu: cpuQuantity, | ||
| resourceMemory: memoryQuantity, | ||
| }, nil | ||
| } |
27 changes: 27 additions & 0 deletions
27
pkg/kube/resourcerequirements/resource_requirements_test.go
This file contains hidden or 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,27 @@ | ||
| package resourcerequirements | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "k8s.io/apimachinery/pkg/api/resource" | ||
| ) | ||
|
|
||
| func TestNewResourceRequirements_GetsConstructedCorrectly(t *testing.T) { | ||
| requirements, err := newRequirements("0.5", "2.0", "500", "1000") | ||
| assert.NoError(t, err) | ||
| assert.Equal(t, resource.MustParse("0.5"), *requirements.Limits.Cpu()) | ||
| assert.Equal(t, resource.MustParse("2.0"), *requirements.Limits.Memory()) | ||
| assert.Equal(t, resource.MustParse("500"), *requirements.Requests.Cpu()) | ||
| assert.Equal(t, resource.MustParse("1000"), *requirements.Requests.Memory()) | ||
| } | ||
|
|
||
| func TestBadInput_ReturnsError(t *testing.T) { | ||
| _, err := newRequirements("BAD_INPUT", "2.0", "500", "1000") | ||
| assert.Error(t, err) | ||
| } | ||
|
|
||
| func TestDefaultValues_DontReturnError(t *testing.T) { | ||
| _, err := newDefaultRequirements() | ||
| assert.NoError(t, err, "default requirements should never result in an error") | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when are we getting the commit hook for gofmt and goimports?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rodrigovalin is working on it now I believe!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am, doing it right now