forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding ResourceRequirementSpec to v1beta1, v1beta2, and v1beta3 APIs.…
… The old resource quantities 'CPU' and 'Memory' will be preserved until support for v1beta1 and v1beta2 APIs are dropped. Improved resource validation in the process.
- Loading branch information
Showing
23 changed files
with
782 additions
and
175 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
Copyright 2014 Google Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" | ||
) | ||
|
||
// Returns string version of ResourceName. | ||
func (self ResourceName) String() string { | ||
return string(self) | ||
} | ||
|
||
// Returns the CPU limit if specified. | ||
func (self *ResourceList) Cpu() *resource.Quantity { | ||
if val, ok := (*self)[ResourceCPU]; ok { | ||
return &val | ||
} | ||
return &resource.Quantity{} | ||
} | ||
|
||
// Returns the Memory limit if specified. | ||
func (self *ResourceList) Memory() *resource.Quantity { | ||
if val, ok := (*self)[ResourceMemory]; ok { | ||
return &val | ||
} | ||
return &resource.Quantity{} | ||
} |
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,53 @@ | ||
/* | ||
Copyright 2015 Google Inc. All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource" | ||
) | ||
|
||
func TestResourceHelpers(t *testing.T) { | ||
cpuLimit := resource.MustParse("10") | ||
memoryLimit := resource.MustParse("10G") | ||
resourceSpec := ResourceRequirementSpec{ | ||
Limits: ResourceList{ | ||
"cpu": cpuLimit, | ||
"memory": memoryLimit, | ||
"kube.io/storage": memoryLimit, | ||
}, | ||
} | ||
if res := resourceSpec.Limits.Cpu(); *res != cpuLimit { | ||
t.Errorf("expected cpulimit %d, got %d", cpuLimit, res) | ||
} | ||
if res := resourceSpec.Limits.Memory(); *res != memoryLimit { | ||
t.Errorf("expected memorylimit %d, got %d", memoryLimit, res) | ||
} | ||
resourceSpec = ResourceRequirementSpec{ | ||
Limits: ResourceList{ | ||
"memory": memoryLimit, | ||
"kube.io/storage": memoryLimit, | ||
}, | ||
} | ||
if res := resourceSpec.Limits.Cpu(); res.Value() != 0 { | ||
t.Errorf("expected cpulimit %d, got %d", 0, res) | ||
} | ||
if res := resourceSpec.Limits.Memory(); *res != memoryLimit { | ||
t.Errorf("expected memorylimit %d, got %d", memoryLimit, res) | ||
} | ||
} |
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
Oops, something went wrong.