mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
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 ```
This commit is contained in:
commit
15a8ab33b8
@ -76,7 +76,7 @@ func (DeploymentV1Beta1) Generate(genericParams map[string]interface{}) (runtime
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err := getLabels(params, true, name)
|
labels, err := getLabels(params, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -165,7 +165,7 @@ func (DeploymentAppsV1Beta1) Generate(genericParams map[string]interface{}) (run
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err := getLabels(params, true, name)
|
labels, err := getLabels(params, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -210,7 +210,7 @@ func (DeploymentAppsV1Beta1) Generate(genericParams map[string]interface{}) (run
|
|||||||
}
|
}
|
||||||
|
|
||||||
// getLabels returns map of labels.
|
// 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"]
|
labelString, found := params["labels"]
|
||||||
var labels map[string]string
|
var labels map[string]string
|
||||||
var err error
|
var err error
|
||||||
@ -219,7 +219,7 @@ func getLabels(params map[string]string, defaultRunLabel bool, name string) (map
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
} else if defaultRunLabel {
|
} else {
|
||||||
labels = map[string]string{
|
labels = map[string]string{
|
||||||
"run": name,
|
"run": name,
|
||||||
}
|
}
|
||||||
@ -330,7 +330,7 @@ func (JobV1) Generate(genericParams map[string]interface{}) (runtime.Object, err
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err := getLabels(params, true, name)
|
labels, err := getLabels(params, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -424,7 +424,7 @@ func (CronJobV2Alpha1) Generate(genericParams map[string]interface{}) (runtime.O
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err := getLabels(params, true, name)
|
labels, err := getLabels(params, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -637,7 +637,7 @@ func (BasicReplicationController) Generate(genericParams map[string]interface{})
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err := getLabels(params, true, name)
|
labels, err := getLabels(params, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -785,7 +785,7 @@ func (BasicPod) Generate(genericParams map[string]interface{}) (runtime.Object,
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
labels, err := getLabels(params, false, name)
|
labels, err := getLabels(params, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -417,7 +417,8 @@ func TestGeneratePod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: &v1.Pod{
|
expected: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Labels: map[string]string{"run": "foo"},
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
@ -451,7 +452,8 @@ func TestGeneratePod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: &v1.Pod{
|
expected: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Labels: map[string]string{"run": "foo"},
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
@ -484,7 +486,8 @@ func TestGeneratePod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: &v1.Pod{
|
expected: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Labels: map[string]string{"run": "foo"},
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
@ -513,7 +516,8 @@ func TestGeneratePod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
expected: &v1.Pod{
|
expected: &v1.Pod{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: "foo",
|
Name: "foo",
|
||||||
|
Labels: map[string]string{"run": "foo"},
|
||||||
},
|
},
|
||||||
Spec: v1.PodSpec{
|
Spec: v1.PodSpec{
|
||||||
Containers: []v1.Container{
|
Containers: []v1.Container{
|
||||||
|
Loading…
Reference in New Issue
Block a user