2015-01-12 23:30:52 +00:00
|
|
|
/*
|
2016-06-03 00:25:58 +00:00
|
|
|
Copyright 2014 The Kubernetes Authors.
|
2015-01-12 23:30:52 +00:00
|
|
|
|
|
|
|
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 kubectl
|
|
|
|
|
|
|
|
import (
|
2015-04-29 23:54:23 +00:00
|
|
|
"fmt"
|
2015-01-12 23:30:52 +00:00
|
|
|
"strconv"
|
2015-09-01 03:03:29 +00:00
|
|
|
"strings"
|
2015-01-12 23:30:52 +00:00
|
|
|
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api"
|
2015-09-09 21:22:56 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/resource"
|
2016-02-02 05:34:42 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/unversioned"
|
2016-03-09 23:06:49 +00:00
|
|
|
"k8s.io/kubernetes/pkg/api/v1"
|
2016-04-18 15:44:19 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/batch"
|
2016-03-09 23:06:49 +00:00
|
|
|
batchv1 "k8s.io/kubernetes/pkg/apis/batch/v1"
|
2016-05-18 08:11:35 +00:00
|
|
|
batchv2alpha1 "k8s.io/kubernetes/pkg/apis/batch/v2alpha1"
|
2015-11-13 01:07:21 +00:00
|
|
|
"k8s.io/kubernetes/pkg/apis/extensions"
|
2015-08-05 22:03:47 +00:00
|
|
|
"k8s.io/kubernetes/pkg/runtime"
|
2015-09-10 22:48:28 +00:00
|
|
|
"k8s.io/kubernetes/pkg/util/validation"
|
2015-01-12 23:30:52 +00:00
|
|
|
)
|
|
|
|
|
2015-11-13 01:07:21 +00:00
|
|
|
type DeploymentV1Beta1 struct{}
|
|
|
|
|
|
|
|
func (DeploymentV1Beta1) ParamNames() []GeneratorParam {
|
|
|
|
return []GeneratorParam{
|
|
|
|
{"labels", false},
|
|
|
|
{"default-name", false},
|
|
|
|
{"name", true},
|
|
|
|
{"replicas", true},
|
|
|
|
{"image", true},
|
2016-08-17 03:26:27 +00:00
|
|
|
{"image-pull-policy", false},
|
2015-11-13 01:07:21 +00:00
|
|
|
{"port", false},
|
|
|
|
{"hostport", false},
|
|
|
|
{"stdin", false},
|
|
|
|
{"tty", false},
|
|
|
|
{"command", false},
|
|
|
|
{"args", false},
|
|
|
|
{"env", false},
|
|
|
|
{"requests", false},
|
|
|
|
{"limits", false},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
|
|
|
|
args, err := getArgs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
envs, err := getEnvs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params, err := getParams(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := getName(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
labels, err := getLabels(params, true, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
count, err := strconv.Atoi(params["replicas"])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
podSpec, err := makePodSpec(params, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
imagePullPolicy := api.PullPolicy(params["image-pull-policy"])
|
|
|
|
if err = updatePodContainers(params, args, envs, imagePullPolicy, podSpec); err != nil {
|
2015-11-13 01:07:21 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := updatePodPorts(params, podSpec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: use versioned types for generators so that we don't need to
|
|
|
|
// set default values manually (see issue #17384)
|
|
|
|
deployment := extensions.Deployment{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: extensions.DeploymentSpec{
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(count),
|
2016-02-06 02:43:02 +00:00
|
|
|
Selector: &unversioned.LabelSelector{MatchLabels: labels},
|
2015-11-13 01:07:21 +00:00
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: *podSpec,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &deployment, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getLabels(params map[string]string, defaultRunLabel bool, name string) (map[string]string, error) {
|
|
|
|
labelString, found := params["labels"]
|
|
|
|
var labels map[string]string
|
|
|
|
var err error
|
|
|
|
if found && len(labelString) > 0 {
|
|
|
|
labels, err = ParseLabels(labelString)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
} else if defaultRunLabel {
|
|
|
|
labels = map[string]string{
|
|
|
|
"run": name,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return labels, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getName(params map[string]string) (string, error) {
|
|
|
|
name, found := params["name"]
|
|
|
|
if !found || len(name) == 0 {
|
|
|
|
name, found = params["default-name"]
|
|
|
|
if !found || len(name) == 0 {
|
|
|
|
return "", fmt.Errorf("'name' is a required parameter.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return name, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getParams(genericParams map[string]interface{}) (map[string]string, error) {
|
|
|
|
params := map[string]string{}
|
|
|
|
for key, value := range genericParams {
|
|
|
|
strVal, isString := value.(string)
|
|
|
|
if !isString {
|
|
|
|
return nil, fmt.Errorf("expected string, saw %v for '%s'", value, key)
|
|
|
|
}
|
|
|
|
params[key] = strVal
|
|
|
|
}
|
|
|
|
return params, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getArgs(genericParams map[string]interface{}) ([]string, error) {
|
|
|
|
args := []string{}
|
|
|
|
val, found := genericParams["args"]
|
|
|
|
if found {
|
|
|
|
var isArray bool
|
|
|
|
args, isArray = val.([]string)
|
|
|
|
if !isArray {
|
|
|
|
return nil, fmt.Errorf("expected []string, found: %v", val)
|
|
|
|
}
|
|
|
|
delete(genericParams, "args")
|
|
|
|
}
|
|
|
|
return args, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getEnvs(genericParams map[string]interface{}) ([]api.EnvVar, error) {
|
|
|
|
var envs []api.EnvVar
|
|
|
|
envStrings, found := genericParams["env"]
|
|
|
|
if found {
|
|
|
|
if envStringArray, isArray := envStrings.([]string); isArray {
|
|
|
|
var err error
|
|
|
|
envs, err = parseEnvs(envStringArray)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
delete(genericParams, "env")
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("expected []string, found: %v", envStrings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return envs, nil
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
func getV1Envs(genericParams map[string]interface{}) ([]v1.EnvVar, error) {
|
|
|
|
var envs []v1.EnvVar
|
|
|
|
envStrings, found := genericParams["env"]
|
|
|
|
if found {
|
|
|
|
if envStringArray, isArray := envStrings.([]string); isArray {
|
|
|
|
var err error
|
|
|
|
envs, err = parseV1Envs(envStringArray)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
delete(genericParams, "env")
|
|
|
|
} else {
|
|
|
|
return nil, fmt.Errorf("expected []string, found: %v", envStrings)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return envs, nil
|
|
|
|
}
|
|
|
|
|
2015-11-13 01:07:21 +00:00
|
|
|
type JobV1Beta1 struct{}
|
|
|
|
|
|
|
|
func (JobV1Beta1) ParamNames() []GeneratorParam {
|
|
|
|
return []GeneratorParam{
|
|
|
|
{"labels", false},
|
|
|
|
{"default-name", false},
|
|
|
|
{"name", true},
|
|
|
|
{"image", true},
|
2016-08-17 03:26:27 +00:00
|
|
|
{"image-pull-policy", false},
|
2015-11-13 01:07:21 +00:00
|
|
|
{"port", false},
|
|
|
|
{"hostport", false},
|
|
|
|
{"stdin", false},
|
|
|
|
{"leave-stdin-open", false},
|
|
|
|
{"tty", false},
|
|
|
|
{"command", false},
|
|
|
|
{"args", false},
|
|
|
|
{"env", false},
|
|
|
|
{"requests", false},
|
|
|
|
{"limits", false},
|
|
|
|
{"restart", false},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (JobV1Beta1) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
|
|
|
|
args, err := getArgs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
envs, err := getEnvs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params, err := getParams(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := getName(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
labels, err := getLabels(params, true, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
podSpec, err := makePodSpec(params, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
imagePullPolicy := api.PullPolicy(params["image-pull-policy"])
|
|
|
|
if err = updatePodContainers(params, args, envs, imagePullPolicy, podSpec); err != nil {
|
2015-11-13 01:07:21 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
leaveStdinOpen, err := GetBool(params, "leave-stdin-open", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
podSpec.Containers[0].StdinOnce = !leaveStdinOpen && podSpec.Containers[0].Stdin
|
|
|
|
|
|
|
|
if err := updatePodPorts(params, podSpec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
restartPolicy := api.RestartPolicy(params["restart"])
|
|
|
|
if len(restartPolicy) == 0 {
|
2016-03-09 23:06:49 +00:00
|
|
|
restartPolicy = api.RestartPolicyNever
|
2015-11-13 01:07:21 +00:00
|
|
|
}
|
|
|
|
podSpec.RestartPolicy = restartPolicy
|
|
|
|
|
2016-04-18 15:44:19 +00:00
|
|
|
job := batch.Job{
|
2015-11-13 01:07:21 +00:00
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
2016-04-18 15:44:19 +00:00
|
|
|
Spec: batch.JobSpec{
|
2016-02-02 05:34:42 +00:00
|
|
|
Selector: &unversioned.LabelSelector{
|
2015-11-13 01:07:21 +00:00
|
|
|
MatchLabels: labels,
|
|
|
|
},
|
Added Selector Generation to Job.
Added selector generation to Job's
strategy.Validate, right before validation.
Can't do in defaulting since UID is not known.
Added a validation to Job to ensure that the generated
labels and selector are correct when generation was requested.
This happens right after generation, but validation is in a better
place to return an error.
Adds "manualSelector" field to batch/v1 Job to control selector generation.
Adds same field to extensions/__internal. Conversion between those two
is automatic.
Adds "autoSelector" field to extensions/v1beta1 Job. Used for storing batch/v1 Jobs
- Default for v1 is to do generation.
- Default for v1beta1 is to not do it.
- In both cases, unset == false == do the default thing.
Release notes:
Added batch/v1 group, which contains just Job, and which is the next
version of extensions/v1beta1 Job.
The changes from the previous version are:
- Users no longer need to ensure labels on their pod template are unique to the enclosing
job (but may add labels as needed for categorization).
- In v1beta1, job.spec.selector was defaulted from pod labels, with the user responsible for uniqueness.
In v1, a unique label is generated and added to the pod template, and used as the selector (other
labels added by user stay on pod template, but need not be used by selector).
- a new field called "manualSelector" field exists to control whether the new behavior is used,
versus a more error-prone but more flexible "manual" (not generated) seletor. Most users
will not need to use this field and should leave it unset.
Users who are creating extensions.Job go objects and then posting them using the go client
will see a change in the default behavior. They need to either stop providing a selector (relying on
selector generation) or else specify "spec.manualSelector" until they are ready to do the former.
2016-02-08 23:55:40 +00:00
|
|
|
ManualSelector: newBool(true),
|
2015-11-13 01:07:21 +00:00
|
|
|
Template: api.PodTemplateSpec{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: *podSpec,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return &job, nil
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
type JobV1 struct{}
|
|
|
|
|
|
|
|
func (JobV1) ParamNames() []GeneratorParam {
|
|
|
|
return []GeneratorParam{
|
|
|
|
{"labels", false},
|
|
|
|
{"default-name", false},
|
|
|
|
{"name", true},
|
|
|
|
{"image", true},
|
2016-08-17 03:26:27 +00:00
|
|
|
{"image-pull-policy", false},
|
2016-03-09 23:06:49 +00:00
|
|
|
{"port", false},
|
|
|
|
{"hostport", false},
|
|
|
|
{"stdin", false},
|
|
|
|
{"leave-stdin-open", false},
|
|
|
|
{"tty", false},
|
|
|
|
{"command", false},
|
|
|
|
{"args", false},
|
|
|
|
{"env", false},
|
|
|
|
{"requests", false},
|
|
|
|
{"limits", false},
|
|
|
|
{"restart", false},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (JobV1) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
|
|
|
|
args, err := getArgs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
envs, err := getV1Envs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params, err := getParams(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := getName(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
labels, err := getLabels(params, true, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
podSpec, err := makeV1PodSpec(params, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
imagePullPolicy := v1.PullPolicy(params["image-pull-policy"])
|
|
|
|
if err = updateV1PodContainers(params, args, envs, imagePullPolicy, podSpec); err != nil {
|
2016-03-09 23:06:49 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
leaveStdinOpen, err := GetBool(params, "leave-stdin-open", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
podSpec.Containers[0].StdinOnce = !leaveStdinOpen && podSpec.Containers[0].Stdin
|
|
|
|
|
|
|
|
if err := updateV1PodPorts(params, podSpec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
restartPolicy := v1.RestartPolicy(params["restart"])
|
|
|
|
if len(restartPolicy) == 0 {
|
|
|
|
restartPolicy = v1.RestartPolicyNever
|
|
|
|
}
|
|
|
|
podSpec.RestartPolicy = restartPolicy
|
|
|
|
|
|
|
|
job := batchv1.Job{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: batchv1.JobSpec{
|
|
|
|
Template: v1.PodTemplateSpec{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: *podSpec,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
return &job, nil
|
|
|
|
}
|
|
|
|
|
2016-11-01 22:46:23 +00:00
|
|
|
type CronJobV2Alpha1 struct{}
|
2016-05-18 08:11:35 +00:00
|
|
|
|
2016-11-01 22:46:23 +00:00
|
|
|
func (CronJobV2Alpha1) ParamNames() []GeneratorParam {
|
2016-05-18 08:11:35 +00:00
|
|
|
return []GeneratorParam{
|
|
|
|
{"labels", false},
|
|
|
|
{"default-name", false},
|
|
|
|
{"name", true},
|
|
|
|
{"image", true},
|
2016-08-17 03:26:27 +00:00
|
|
|
{"image-pull-policy", false},
|
2016-05-18 08:11:35 +00:00
|
|
|
{"port", false},
|
|
|
|
{"hostport", false},
|
|
|
|
{"stdin", false},
|
|
|
|
{"leave-stdin-open", false},
|
|
|
|
{"tty", false},
|
|
|
|
{"command", false},
|
|
|
|
{"args", false},
|
|
|
|
{"env", false},
|
|
|
|
{"requests", false},
|
|
|
|
{"limits", false},
|
|
|
|
{"restart", false},
|
|
|
|
{"schedule", true},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-01 22:46:23 +00:00
|
|
|
func (CronJobV2Alpha1) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
|
2016-05-18 08:11:35 +00:00
|
|
|
args, err := getArgs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
envs, err := getV1Envs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
params, err := getParams(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
name, err := getName(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
labels, err := getLabels(params, true, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
podSpec, err := makeV1PodSpec(params, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
imagePullPolicy := v1.PullPolicy(params["image-pull-policy"])
|
|
|
|
if err = updateV1PodContainers(params, args, envs, imagePullPolicy, podSpec); err != nil {
|
2016-05-18 08:11:35 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
leaveStdinOpen, err := GetBool(params, "leave-stdin-open", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
podSpec.Containers[0].StdinOnce = !leaveStdinOpen && podSpec.Containers[0].Stdin
|
|
|
|
|
|
|
|
if err := updateV1PodPorts(params, podSpec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
restartPolicy := v1.RestartPolicy(params["restart"])
|
|
|
|
if len(restartPolicy) == 0 {
|
|
|
|
restartPolicy = v1.RestartPolicyNever
|
|
|
|
}
|
|
|
|
podSpec.RestartPolicy = restartPolicy
|
|
|
|
|
2016-11-01 22:46:23 +00:00
|
|
|
cronJob := batchv2alpha1.CronJob{
|
2016-05-18 08:11:35 +00:00
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
2016-11-01 22:46:23 +00:00
|
|
|
Spec: batchv2alpha1.CronJobSpec{
|
2016-05-18 08:11:35 +00:00
|
|
|
Schedule: params["schedule"],
|
|
|
|
ConcurrencyPolicy: batchv2alpha1.AllowConcurrent,
|
|
|
|
JobTemplate: batchv2alpha1.JobTemplateSpec{
|
|
|
|
Spec: batchv2alpha1.JobSpec{
|
|
|
|
Template: v1.PodTemplateSpec{
|
|
|
|
ObjectMeta: v1.ObjectMeta{
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: *podSpec,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2016-11-01 22:46:23 +00:00
|
|
|
return &cronJob, nil
|
2016-05-18 08:11:35 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 23:30:52 +00:00
|
|
|
type BasicReplicationController struct{}
|
|
|
|
|
|
|
|
func (BasicReplicationController) ParamNames() []GeneratorParam {
|
|
|
|
return []GeneratorParam{
|
|
|
|
{"labels", false},
|
2015-06-01 18:05:05 +00:00
|
|
|
{"default-name", false},
|
|
|
|
{"name", true},
|
2015-01-12 23:30:52 +00:00
|
|
|
{"replicas", true},
|
|
|
|
{"image", true},
|
2016-08-17 03:26:27 +00:00
|
|
|
{"image-pull-policy", false},
|
2015-01-17 01:52:27 +00:00
|
|
|
{"port", false},
|
2015-04-29 23:54:23 +00:00
|
|
|
{"hostport", false},
|
2015-08-04 19:54:17 +00:00
|
|
|
{"stdin", false},
|
|
|
|
{"tty", false},
|
2015-08-12 05:48:00 +00:00
|
|
|
{"command", false},
|
|
|
|
{"args", false},
|
2015-09-01 03:03:29 +00:00
|
|
|
{"env", false},
|
2015-09-09 21:22:56 +00:00
|
|
|
{"requests", false},
|
|
|
|
{"limits", false},
|
2015-01-12 23:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:22:56 +00:00
|
|
|
// populateResourceList takes strings of form <resourceName1>=<value1>,<resourceName1>=<value2>
|
|
|
|
func populateResourceList(spec string) (api.ResourceList, error) {
|
|
|
|
// empty input gets a nil response to preserve generator test expected behaviors
|
|
|
|
if spec == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
result := api.ResourceList{}
|
|
|
|
resourceStatements := strings.Split(spec, ",")
|
|
|
|
for _, resourceStatement := range resourceStatements {
|
|
|
|
parts := strings.Split(resourceStatement, "=")
|
|
|
|
if len(parts) != 2 {
|
|
|
|
return nil, fmt.Errorf("Invalid argument syntax %v, expected <resource>=<value>", resourceStatement)
|
|
|
|
}
|
|
|
|
resourceName := api.ResourceName(parts[0])
|
|
|
|
resourceQuantity, err := resource.ParseQuantity(parts[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-17 04:36:56 +00:00
|
|
|
result[resourceName] = resourceQuantity
|
2015-09-09 21:22:56 +00:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
// populateResourceList takes strings of form <resourceName1>=<value1>,<resourceName1>=<value2>
|
|
|
|
func populateV1ResourceList(spec string) (v1.ResourceList, error) {
|
|
|
|
// empty input gets a nil response to preserve generator test expected behaviors
|
|
|
|
if spec == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
result := v1.ResourceList{}
|
|
|
|
resourceStatements := strings.Split(spec, ",")
|
|
|
|
for _, resourceStatement := range resourceStatements {
|
|
|
|
parts := strings.Split(resourceStatement, "=")
|
|
|
|
if len(parts) != 2 {
|
|
|
|
return nil, fmt.Errorf("Invalid argument syntax %v, expected <resource>=<value>", resourceStatement)
|
|
|
|
}
|
|
|
|
resourceName := v1.ResourceName(parts[0])
|
|
|
|
resourceQuantity, err := resource.ParseQuantity(parts[1])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2016-05-17 04:36:56 +00:00
|
|
|
result[resourceName] = resourceQuantity
|
2016-03-09 23:06:49 +00:00
|
|
|
}
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:22:56 +00:00
|
|
|
// HandleResourceRequirements parses the limits and requests parameters if specified
|
|
|
|
func HandleResourceRequirements(params map[string]string) (api.ResourceRequirements, error) {
|
|
|
|
result := api.ResourceRequirements{}
|
|
|
|
limits, err := populateResourceList(params["limits"])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
result.Limits = limits
|
|
|
|
requests, err := populateResourceList(params["requests"])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
result.Requests = requests
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
// HandleResourceRequirements parses the limits and requests parameters if specified
|
|
|
|
func handleV1ResourceRequirements(params map[string]string) (v1.ResourceRequirements, error) {
|
|
|
|
result := v1.ResourceRequirements{}
|
|
|
|
limits, err := populateV1ResourceList(params["limits"])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
result.Limits = limits
|
|
|
|
requests, err := populateV1ResourceList(params["requests"])
|
|
|
|
if err != nil {
|
|
|
|
return result, err
|
|
|
|
}
|
|
|
|
result.Requests = requests
|
|
|
|
return result, nil
|
|
|
|
}
|
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
func makePodSpec(params map[string]string, name string) (*api.PodSpec, error) {
|
|
|
|
stdin, err := GetBool(params, "stdin", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tty, err := GetBool(params, "tty", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:22:56 +00:00
|
|
|
resourceRequirements, err := HandleResourceRequirements(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
spec := api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
2015-09-09 21:22:56 +00:00
|
|
|
Name: name,
|
|
|
|
Image: params["image"],
|
|
|
|
Stdin: stdin,
|
|
|
|
TTY: tty,
|
|
|
|
Resources: resourceRequirements,
|
2015-08-04 19:54:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &spec, nil
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
func makeV1PodSpec(params map[string]string, name string) (*v1.PodSpec, error) {
|
|
|
|
stdin, err := GetBool(params, "stdin", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
tty, err := GetBool(params, "tty", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
resourceRequirements, err := handleV1ResourceRequirements(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
spec := v1.PodSpec{
|
|
|
|
Containers: []v1.Container{
|
|
|
|
{
|
|
|
|
Name: name,
|
|
|
|
Image: params["image"],
|
|
|
|
Stdin: stdin,
|
|
|
|
TTY: tty,
|
|
|
|
Resources: resourceRequirements,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return &spec, nil
|
|
|
|
}
|
|
|
|
|
2015-08-12 05:48:00 +00:00
|
|
|
func (BasicReplicationController) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
|
2015-11-13 01:07:21 +00:00
|
|
|
args, err := getArgs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-08-12 05:48:00 +00:00
|
|
|
}
|
2015-09-01 03:03:29 +00:00
|
|
|
|
2015-11-13 01:07:21 +00:00
|
|
|
envs, err := getEnvs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-09-01 03:03:29 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 01:07:21 +00:00
|
|
|
params, err := getParams(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-08-12 05:48:00 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
|
|
|
name, err := getName(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-05-26 12:03:11 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
|
|
|
labels, err := getLabels(params, true, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-01-12 23:30:52 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
2015-01-12 23:30:52 +00:00
|
|
|
count, err := strconv.Atoi(params["replicas"])
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-08-04 19:54:17 +00:00
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
podSpec, err := makePodSpec(params, name)
|
2015-08-04 19:54:17 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
imagePullPolicy := api.PullPolicy(params["image-pull-policy"])
|
|
|
|
if err = updatePodContainers(params, args, envs, imagePullPolicy, podSpec); err != nil {
|
2015-11-13 01:07:21 +00:00
|
|
|
return nil, err
|
2015-08-12 05:48:00 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 01:07:21 +00:00
|
|
|
if err := updatePodPorts(params, podSpec); err != nil {
|
|
|
|
return nil, err
|
2015-09-01 03:03:29 +00:00
|
|
|
}
|
|
|
|
|
2015-01-12 23:30:52 +00:00
|
|
|
controller := api.ReplicationController{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
2015-05-26 12:03:11 +00:00
|
|
|
Name: name,
|
2015-01-12 23:30:52 +00:00
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: api.ReplicationControllerSpec{
|
2016-04-27 04:35:14 +00:00
|
|
|
Replicas: int32(count),
|
2015-01-12 23:30:52 +00:00
|
|
|
Selector: labels,
|
|
|
|
Template: &api.PodTemplateSpec{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Labels: labels,
|
|
|
|
},
|
2015-08-04 19:54:17 +00:00
|
|
|
Spec: *podSpec,
|
2015-01-12 23:30:52 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2015-08-04 19:54:17 +00:00
|
|
|
return &controller, nil
|
|
|
|
}
|
2015-01-31 04:51:40 +00:00
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
func updatePodContainers(params map[string]string, args []string, envs []api.EnvVar, imagePullPolicy api.PullPolicy, podSpec *api.PodSpec) error {
|
2015-11-13 01:07:21 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
command, err := GetBool(params, "command", false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if command {
|
|
|
|
podSpec.Containers[0].Command = args
|
|
|
|
} else {
|
|
|
|
podSpec.Containers[0].Args = args
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(envs) > 0 {
|
|
|
|
podSpec.Containers[0].Env = envs
|
|
|
|
}
|
2016-08-17 03:26:27 +00:00
|
|
|
|
|
|
|
if len(imagePullPolicy) > 0 {
|
|
|
|
// imagePullPolicy should be valid here since we have verified it before.
|
|
|
|
podSpec.Containers[0].ImagePullPolicy = imagePullPolicy
|
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-08-17 03:26:27 +00:00
|
|
|
func updateV1PodContainers(params map[string]string, args []string, envs []v1.EnvVar, imagePullPolicy v1.PullPolicy, podSpec *v1.PodSpec) error {
|
2016-03-09 23:06:49 +00:00
|
|
|
if len(args) > 0 {
|
|
|
|
command, err := GetBool(params, "command", false)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if command {
|
|
|
|
podSpec.Containers[0].Command = args
|
|
|
|
} else {
|
|
|
|
podSpec.Containers[0].Args = args
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(envs) > 0 {
|
|
|
|
podSpec.Containers[0].Env = envs
|
|
|
|
}
|
2016-08-17 03:26:27 +00:00
|
|
|
|
|
|
|
if len(imagePullPolicy) > 0 {
|
|
|
|
// imagePullPolicy should be valid here since we have verified it before.
|
|
|
|
podSpec.Containers[0].ImagePullPolicy = imagePullPolicy
|
|
|
|
}
|
2016-03-09 23:06:49 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
func updatePodPorts(params map[string]string, podSpec *api.PodSpec) (err error) {
|
2015-04-29 23:54:23 +00:00
|
|
|
port := -1
|
|
|
|
hostPort := -1
|
2015-01-31 04:51:40 +00:00
|
|
|
if len(params["port"]) > 0 {
|
2015-04-29 23:54:23 +00:00
|
|
|
port, err = strconv.Atoi(params["port"])
|
2015-01-31 04:51:40 +00:00
|
|
|
if err != nil {
|
2015-08-04 19:54:17 +00:00
|
|
|
return err
|
2015-01-31 04:51:40 +00:00
|
|
|
}
|
2015-04-29 23:54:23 +00:00
|
|
|
}
|
2015-02-11 21:20:51 +00:00
|
|
|
|
2015-04-29 23:54:23 +00:00
|
|
|
if len(params["hostport"]) > 0 {
|
|
|
|
hostPort, err = strconv.Atoi(params["hostport"])
|
|
|
|
if err != nil {
|
2015-08-04 19:54:17 +00:00
|
|
|
return err
|
2015-04-29 23:54:23 +00:00
|
|
|
}
|
|
|
|
if hostPort > 0 && port < 0 {
|
2015-08-04 19:54:17 +00:00
|
|
|
return fmt.Errorf("--hostport requires --port to be specified")
|
2015-04-29 23:54:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't include the port if it was not specified.
|
2016-07-26 09:12:10 +00:00
|
|
|
if len(params["port"]) > 0 {
|
2015-08-04 19:54:17 +00:00
|
|
|
podSpec.Containers[0].Ports = []api.ContainerPort{
|
2015-04-29 23:54:23 +00:00
|
|
|
{
|
2016-04-27 04:35:14 +00:00
|
|
|
ContainerPort: int32(port),
|
2015-04-29 23:54:23 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
if hostPort > 0 {
|
2016-04-27 04:35:14 +00:00
|
|
|
podSpec.Containers[0].Ports[0].HostPort = int32(hostPort)
|
2015-01-12 23:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
2015-08-04 19:54:17 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
func updateV1PodPorts(params map[string]string, podSpec *v1.PodSpec) (err error) {
|
|
|
|
port := -1
|
|
|
|
hostPort := -1
|
|
|
|
if len(params["port"]) > 0 {
|
|
|
|
port, err = strconv.Atoi(params["port"])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(params["hostport"]) > 0 {
|
|
|
|
hostPort, err = strconv.Atoi(params["hostport"])
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if hostPort > 0 && port < 0 {
|
|
|
|
return fmt.Errorf("--hostport requires --port to be specified")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Don't include the port if it was not specified.
|
2016-09-28 02:23:25 +00:00
|
|
|
if len(params["port"]) > 0 {
|
2016-03-09 23:06:49 +00:00
|
|
|
podSpec.Containers[0].Ports = []v1.ContainerPort{
|
|
|
|
{
|
|
|
|
ContainerPort: int32(port),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
if hostPort > 0 {
|
|
|
|
podSpec.Containers[0].Ports[0].HostPort = int32(hostPort)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
type BasicPod struct{}
|
|
|
|
|
|
|
|
func (BasicPod) ParamNames() []GeneratorParam {
|
|
|
|
return []GeneratorParam{
|
|
|
|
{"labels", false},
|
|
|
|
{"default-name", false},
|
|
|
|
{"name", true},
|
|
|
|
{"image", true},
|
2016-08-17 03:26:27 +00:00
|
|
|
{"image-pull-policy", false},
|
2015-08-04 19:54:17 +00:00
|
|
|
{"port", false},
|
|
|
|
{"hostport", false},
|
|
|
|
{"stdin", false},
|
2015-10-06 15:31:48 +00:00
|
|
|
{"leave-stdin-open", false},
|
2015-08-04 19:54:17 +00:00
|
|
|
{"tty", false},
|
|
|
|
{"restart", false},
|
2015-08-12 05:48:00 +00:00
|
|
|
{"command", false},
|
|
|
|
{"args", false},
|
2015-09-01 03:03:29 +00:00
|
|
|
{"env", false},
|
2015-09-09 21:22:56 +00:00
|
|
|
{"requests", false},
|
|
|
|
{"limits", false},
|
2015-08-04 19:54:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-08-12 05:48:00 +00:00
|
|
|
func (BasicPod) Generate(genericParams map[string]interface{}) (runtime.Object, error) {
|
2015-11-13 01:07:21 +00:00
|
|
|
args, err := getArgs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-08-12 05:48:00 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
|
|
|
envs, err := getEnvs(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-09-01 03:03:29 +00:00
|
|
|
}
|
|
|
|
|
2015-11-13 01:07:21 +00:00
|
|
|
params, err := getParams(genericParams)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-08-12 05:48:00 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
|
|
|
name, err := getName(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-08-04 19:54:17 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
|
|
|
labels, err := getLabels(params, false, name)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
2015-08-04 19:54:17 +00:00
|
|
|
}
|
2015-11-13 01:07:21 +00:00
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
stdin, err := GetBool(params, "stdin", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-10-06 15:31:48 +00:00
|
|
|
leaveStdinOpen, err := GetBool(params, "leave-stdin-open", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2015-08-04 19:54:17 +00:00
|
|
|
|
|
|
|
tty, err := GetBool(params, "tty", false)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-09-09 21:22:56 +00:00
|
|
|
resourceRequirements, err := HandleResourceRequirements(params)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
restartPolicy := api.RestartPolicy(params["restart"])
|
|
|
|
if len(restartPolicy) == 0 {
|
|
|
|
restartPolicy = api.RestartPolicyAlways
|
|
|
|
}
|
2016-08-17 03:26:27 +00:00
|
|
|
// TODO: Figure out why we set ImagePullPolicy here, whether we can make it
|
|
|
|
// consistent with the other places imagePullPolicy is set using flag.
|
2015-08-04 19:54:17 +00:00
|
|
|
pod := api.Pod{
|
|
|
|
ObjectMeta: api.ObjectMeta{
|
|
|
|
Name: name,
|
|
|
|
Labels: labels,
|
|
|
|
},
|
|
|
|
Spec: api.PodSpec{
|
|
|
|
Containers: []api.Container{
|
|
|
|
{
|
|
|
|
Name: name,
|
|
|
|
Image: params["image"],
|
|
|
|
ImagePullPolicy: api.PullIfNotPresent,
|
|
|
|
Stdin: stdin,
|
2015-10-06 15:31:48 +00:00
|
|
|
StdinOnce: !leaveStdinOpen && stdin,
|
2015-08-04 19:54:17 +00:00
|
|
|
TTY: tty,
|
2015-09-09 21:22:56 +00:00
|
|
|
Resources: resourceRequirements,
|
2015-08-04 19:54:17 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
DNSPolicy: api.DNSClusterFirst,
|
|
|
|
RestartPolicy: restartPolicy,
|
|
|
|
},
|
|
|
|
}
|
2016-08-17 03:26:27 +00:00
|
|
|
imagePullPolicy := api.PullPolicy(params["image-pull-policy"])
|
|
|
|
if err = updatePodContainers(params, args, envs, imagePullPolicy, &pod.Spec); err != nil {
|
2015-11-13 01:07:21 +00:00
|
|
|
return nil, err
|
2015-09-01 03:03:29 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 19:54:17 +00:00
|
|
|
if err := updatePodPorts(params, &pod.Spec); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return &pod, nil
|
2015-01-12 23:30:52 +00:00
|
|
|
}
|
2015-09-01 03:03:29 +00:00
|
|
|
|
|
|
|
func parseEnvs(envArray []string) ([]api.EnvVar, error) {
|
2016-05-29 09:09:39 +00:00
|
|
|
envs := make([]api.EnvVar, 0, len(envArray))
|
2015-09-01 03:03:29 +00:00
|
|
|
for _, env := range envArray {
|
2015-12-22 07:00:26 +00:00
|
|
|
pos := strings.Index(env, "=")
|
|
|
|
if pos == -1 {
|
2015-09-01 03:03:29 +00:00
|
|
|
return nil, fmt.Errorf("invalid env: %v", env)
|
|
|
|
}
|
2015-12-22 07:00:26 +00:00
|
|
|
name := env[:pos]
|
|
|
|
value := env[pos+1:]
|
2016-07-10 01:56:05 +00:00
|
|
|
if len(name) == 0 {
|
2015-12-20 06:52:48 +00:00
|
|
|
return nil, fmt.Errorf("invalid env: %v", env)
|
|
|
|
}
|
|
|
|
if len(validation.IsCIdentifier(name)) != 0 {
|
2015-12-22 07:00:26 +00:00
|
|
|
return nil, fmt.Errorf("invalid env: %v", env)
|
|
|
|
}
|
|
|
|
envVar := api.EnvVar{Name: name, Value: value}
|
2015-09-01 03:03:29 +00:00
|
|
|
envs = append(envs, envVar)
|
|
|
|
}
|
|
|
|
return envs, nil
|
|
|
|
}
|
Added Selector Generation to Job.
Added selector generation to Job's
strategy.Validate, right before validation.
Can't do in defaulting since UID is not known.
Added a validation to Job to ensure that the generated
labels and selector are correct when generation was requested.
This happens right after generation, but validation is in a better
place to return an error.
Adds "manualSelector" field to batch/v1 Job to control selector generation.
Adds same field to extensions/__internal. Conversion between those two
is automatic.
Adds "autoSelector" field to extensions/v1beta1 Job. Used for storing batch/v1 Jobs
- Default for v1 is to do generation.
- Default for v1beta1 is to not do it.
- In both cases, unset == false == do the default thing.
Release notes:
Added batch/v1 group, which contains just Job, and which is the next
version of extensions/v1beta1 Job.
The changes from the previous version are:
- Users no longer need to ensure labels on their pod template are unique to the enclosing
job (but may add labels as needed for categorization).
- In v1beta1, job.spec.selector was defaulted from pod labels, with the user responsible for uniqueness.
In v1, a unique label is generated and added to the pod template, and used as the selector (other
labels added by user stay on pod template, but need not be used by selector).
- a new field called "manualSelector" field exists to control whether the new behavior is used,
versus a more error-prone but more flexible "manual" (not generated) seletor. Most users
will not need to use this field and should leave it unset.
Users who are creating extensions.Job go objects and then posting them using the go client
will see a change in the default behavior. They need to either stop providing a selector (relying on
selector generation) or else specify "spec.manualSelector" until they are ready to do the former.
2016-02-08 23:55:40 +00:00
|
|
|
|
2016-03-09 23:06:49 +00:00
|
|
|
func parseV1Envs(envArray []string) ([]v1.EnvVar, error) {
|
|
|
|
envs := []v1.EnvVar{}
|
|
|
|
for _, env := range envArray {
|
|
|
|
pos := strings.Index(env, "=")
|
|
|
|
if pos == -1 {
|
|
|
|
return nil, fmt.Errorf("invalid env: %v", env)
|
|
|
|
}
|
|
|
|
name := env[:pos]
|
|
|
|
value := env[pos+1:]
|
2016-07-10 01:56:05 +00:00
|
|
|
if len(name) == 0 || len(validation.IsCIdentifier(name)) != 0 {
|
2016-03-09 23:06:49 +00:00
|
|
|
return nil, fmt.Errorf("invalid env: %v", env)
|
|
|
|
}
|
|
|
|
envVar := v1.EnvVar{Name: name, Value: value}
|
|
|
|
envs = append(envs, envVar)
|
|
|
|
}
|
|
|
|
return envs, nil
|
|
|
|
}
|
|
|
|
|
Added Selector Generation to Job.
Added selector generation to Job's
strategy.Validate, right before validation.
Can't do in defaulting since UID is not known.
Added a validation to Job to ensure that the generated
labels and selector are correct when generation was requested.
This happens right after generation, but validation is in a better
place to return an error.
Adds "manualSelector" field to batch/v1 Job to control selector generation.
Adds same field to extensions/__internal. Conversion between those two
is automatic.
Adds "autoSelector" field to extensions/v1beta1 Job. Used for storing batch/v1 Jobs
- Default for v1 is to do generation.
- Default for v1beta1 is to not do it.
- In both cases, unset == false == do the default thing.
Release notes:
Added batch/v1 group, which contains just Job, and which is the next
version of extensions/v1beta1 Job.
The changes from the previous version are:
- Users no longer need to ensure labels on their pod template are unique to the enclosing
job (but may add labels as needed for categorization).
- In v1beta1, job.spec.selector was defaulted from pod labels, with the user responsible for uniqueness.
In v1, a unique label is generated and added to the pod template, and used as the selector (other
labels added by user stay on pod template, but need not be used by selector).
- a new field called "manualSelector" field exists to control whether the new behavior is used,
versus a more error-prone but more flexible "manual" (not generated) seletor. Most users
will not need to use this field and should leave it unset.
Users who are creating extensions.Job go objects and then posting them using the go client
will see a change in the default behavior. They need to either stop providing a selector (relying on
selector generation) or else specify "spec.manualSelector" until they are ready to do the former.
2016-02-08 23:55:40 +00:00
|
|
|
func newBool(val bool) *bool {
|
|
|
|
p := new(bool)
|
|
|
|
*p = val
|
|
|
|
return p
|
|
|
|
}
|