-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Adding an extensible resource spec to the API. #3841
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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{} | ||
} |
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) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -304,6 +304,12 @@ type Capabilities struct { | |
Drop []CapabilityType `json:"drop,omitempty"` | ||
} | ||
|
||
// ResourceRequirementSpec describes the compute resource requirements. | ||
type ResourceRequirementSpec struct { | ||
// Limits describes the maximum amount of compute resources required. | ||
Limits ResourceList `json:"limits,omitempty"` | ||
} | ||
|
||
// Container represents a single container that is expected to be run on the host. | ||
type Container struct { | ||
// Required: This must be a DNS_LABEL. Each container in a pod must | ||
|
@@ -317,13 +323,11 @@ type Container struct { | |
WorkingDir string `json:"workingDir,omitempty"` | ||
Ports []Port `json:"ports,omitempty"` | ||
Env []EnvVar `json:"env,omitempty"` | ||
// Optional: Defaults to unlimited. | ||
Memory resource.Quantity `json:"memory,omitempty"` | ||
// Optional: Defaults to unlimited. | ||
CPU resource.Quantity `json:"cpu,omitempty"` | ||
VolumeMounts []VolumeMount `json:"volumeMounts,omitempty"` | ||
LivenessProbe *Probe `json:"livenessProbe,omitempty"` | ||
Lifecycle *Lifecycle `json:"lifecycle,omitempty"` | ||
// Compute resource requirements. | ||
Resources ResourceRequirementSpec `json:"resources,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: We don't say "Spec" on any other types except the ones that correspond to a "spec" field. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fair enough. I gave up on changing those. We could make this consistent. |
||
VolumeMounts []VolumeMount `json:"volumeMounts,omitempty"` | ||
LivenessProbe *Probe `json:"livenessProbe,omitempty"` | ||
Lifecycle *Lifecycle `json:"lifecycle,omitempty"` | ||
// Optional: Defaults to /dev/termination-log | ||
TerminationMessagePath string `json:"terminationMessagePath,omitempty"` | ||
// Optional: Default to false. | ||
|
@@ -775,8 +779,6 @@ type NodeResources struct { | |
type ResourceName string | ||
|
||
const ( | ||
// The default compute resource namespace for all standard resource types. | ||
DefaultResourceNamespace = "kubernetes.io" | ||
// CPU, in cores. (500m = .5 cores) | ||
ResourceCPU ResourceName = "cpu" | ||
// Memory, in bytes. (500Gi = 500GiB = 500 * 1024 * 1024 * 1024) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -252,6 +252,11 @@ type Capabilities struct { | |
Drop []CapabilityType `json:"drop,omitempty" description:"droped capabilities"` | ||
} | ||
|
||
type ResourceRequirementSpec struct { | ||
// Limits describes the maximum amount of compute resources required. | ||
Limits ResourceList `json:"limits,omitempty" description:"Maximum amount of compute resources allowed"` | ||
} | ||
|
||
// Container represents a single container that is expected to be run on the host. | ||
type Container struct { | ||
// Required: This must be a DNS_LABEL. Each container in a pod must | ||
|
@@ -262,13 +267,14 @@ type Container struct { | |
// Optional: Defaults to whatever is defined in the image. | ||
Command []string `json:"command,omitempty" description:"command argv array; not executed within a shell; defaults to entrypoint or command in the image"` | ||
// Optional: Defaults to Docker's default. | ||
WorkingDir string `json:"workingDir,omitempty" description:"container's working directory; defaults to image's default"` | ||
Ports []Port `json:"ports,omitempty" description:"list of ports to expose from the container"` | ||
Env []EnvVar `json:"env,omitempty" description:"list of environment variables to set in the container"` | ||
WorkingDir string `json:"workingDir,omitempty" description:"container's working directory; defaults to image's default"` | ||
Ports []Port `json:"ports,omitempty" description:"list of ports to expose from the container"` | ||
Env []EnvVar `json:"env,omitempty" description:"list of environment variables to set in the container"` | ||
Resources ResourceRequirementSpec `json:"resources,omitempty" description:"Compute Resources required by this container"` | ||
// Optional: Defaults to unlimited. | ||
Memory int64 `json:"memory,omitempty" description:"memory limit in bytes; defaults to unlimited"` | ||
CPU int `json:"cpu,omitempty" description:"CPU share in thousandths of a core"` | ||
// Optional: Defaults to unlimited. | ||
CPU int `json:"cpu,omitempty" description:"CPU share in thousandths of a core"` | ||
Memory int64 `json:"memory,omitempty" description:"memory limit in bytes; defaults to unlimited"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cool. This should resolve #2264, or at least the main problem. |
||
VolumeMounts []VolumeMount `json:"volumeMounts,omitempty" description:"pod volumes to mount into the container's filesystem"` | ||
LivenessProbe *LivenessProbe `json:"livenessProbe,omitempty" description:"periodic probe of container liveness; container will be restarted if the probe fails"` | ||
Lifecycle *Lifecycle `json:"lifecycle,omitempty" description:"actions that the management system should take in response to container lifecycle events"` | ||
|
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.
Why not pkg/api/resource/helpers.go?
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.
This file contains methods on structs defined in this package. That is the reason for placing them in 'package api'