Merge pull request #44915 from xiangpengzhao/fix-kubectl-run-pod-label

Automatic merge from submit-queue

Assign label to pod when exec 'kubectl run' command with flags "--expose=true" and "--restart=Never"

**What this PR does / why we need it**:
As the title says and issue #40503 mentioned.
cc @tanapoln 

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #40503

**Special notes for your reviewer**:

**Release note**:

```release-note
NONE
```
pull/6/head
Kubernetes Submit Queue 2017-05-15 21:52:45 -07:00 committed by GitHub
commit 15a8ab33b8
2 changed files with 16 additions and 12 deletions

View File

@ -76,7 +76,7 @@ func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime
return nil, err
}
labels, err := getLabels(params, true, name)
labels, err := getLabels(params, name)
if err != nil {
return nil, err
}
@ -165,7 +165,7 @@ func (DeploymentAppsV1Beta1) Generate(genericParams map[string]interface{}) (run
return nil, err
}
labels, err := getLabels(params, true, name)
labels, err := getLabels(params, name)
if err != nil {
return nil, err
}
@ -210,7 +210,7 @@ func (DeploymentAppsV1Beta1) Generate(genericParams map[string]interface{}) (run
}
// getLabels returns map of labels.
func getLabels(params map[string]string, defaultRunLabel bool, name string) (map[string]string, error) {
func getLabels(params map[string]string, name string) (map[string]string, error) {
labelString, found := params["labels"]
var labels map[string]string
var err error
@ -219,7 +219,7 @@ func getLabels(params map[string]string, defaultRunLabel bool, name string) (map
if err != nil {
return nil, err
}
} else if defaultRunLabel {
} else {
labels = map[string]string{
"run": name,
}
@ -330,7 +330,7 @@ func (JobV1) Generate(genericParams map[string]interface{}) (runtime.Object, err
return nil, err
}
labels, err := getLabels(params, true, name)
labels, err := getLabels(params, name)
if err != nil {
return nil, err
}
@ -424,7 +424,7 @@ func (CronJobV2Alpha1) Generate(genericParams map[string]interface{}) (runtime.O
return nil, err
}
labels, err := getLabels(params, true, name)
labels, err := getLabels(params, name)
if err != nil {
return nil, err
}
@ -637,7 +637,7 @@ func (BasicReplicationController) Generate(genericParams map[string]interface{})
return nil, err
}
labels, err := getLabels(params, true, name)
labels, err := getLabels(params, name)
if err != nil {
return nil, err
}
@ -785,7 +785,7 @@ func (BasicPod) Generate(genericParams map[string]interface{}) (runtime.Object,
return nil, err
}
labels, err := getLabels(params, false, name)
labels, err := getLabels(params, name)
if err != nil {
return nil, err
}

View File

@ -417,7 +417,8 @@ func TestGeneratePod(t *testing.T) {
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Name: "foo",
Labels: map[string]string{"run": "foo"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
@ -451,7 +452,8 @@ func TestGeneratePod(t *testing.T) {
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Name: "foo",
Labels: map[string]string{"run": "foo"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
@ -484,7 +486,8 @@ func TestGeneratePod(t *testing.T) {
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Name: "foo",
Labels: map[string]string{"run": "foo"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
@ -513,7 +516,8 @@ func TestGeneratePod(t *testing.T) {
},
expected: &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: "foo",
Name: "foo",
Labels: map[string]string{"run": "foo"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{