Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 362a6c0

Browse files
committed
Merge pull request kubernetes#17984 from liggitt/automated-cherry-pick-of-#17973-upstream-release-1.0
Automated cherry pick of kubernetes#17973
2 parents 242c0d1 + 4becda5 commit 362a6c0

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

pkg/api/validation/validation.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -956,6 +956,12 @@ func ValidatePodSpec(spec *api.PodSpec) errs.ValidationErrorList {
956956
}
957957
}
958958

959+
if len(spec.NodeName) > 0 {
960+
if ok, msg := ValidateNodeName(spec.NodeName, false); !ok {
961+
allErrs = append(allErrs, errs.NewFieldInvalid("nodeName", spec.NodeName, msg))
962+
}
963+
}
964+
959965
if spec.ActiveDeadlineSeconds != nil {
960966
if *spec.ActiveDeadlineSeconds <= 0 {
961967
allErrs = append(allErrs, errs.NewFieldInvalid("activeDeadlineSeconds", spec.ActiveDeadlineSeconds, "activeDeadlineSeconds must be a positive integer greater than 0"))

pkg/api/validation/validation_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,13 @@ func TestValidatePodSpec(t *testing.T) {
11291129
DNSPolicy: api.DNSClusterFirst,
11301130
ActiveDeadlineSeconds: &activeDeadlineSeconds,
11311131
},
1132+
"bad nodeName": {
1133+
NodeName: "node name",
1134+
Volumes: []api.Volume{{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
1135+
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
1136+
RestartPolicy: api.RestartPolicyAlways,
1137+
DNSPolicy: api.DNSClusterFirst,
1138+
},
11321139
}
11331140
for k, v := range failureCases {
11341141
if errs := ValidatePodSpec(&v); len(errs) == 0 {

pkg/client/kubelet.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ package client
1818

1919
import (
2020
"errors"
21+
"fmt"
2122
"net"
2223
"net/http"
2324
"net/url"
2425
"strconv"
2526

27+
"k8s.io/kubernetes/pkg/api/validation"
2628
"k8s.io/kubernetes/pkg/probe"
2729
httprobe "k8s.io/kubernetes/pkg/probe/http"
2830
)
@@ -87,6 +89,9 @@ func NewKubeletClient(config *KubeletConfig) (KubeletClient, error) {
8789
}
8890

8991
func (c *HTTPKubeletClient) GetConnectionInfo(host string) (string, uint, http.RoundTripper, error) {
92+
if ok, msg := validation.ValidateNodeName(host, false); !ok {
93+
return "", 0, nil, fmt.Errorf("invalid node name: %s", msg)
94+
}
9095
scheme := "http"
9196
if c.Config.EnableHttps {
9297
scheme = "https"

pkg/client/kubelet_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,27 @@ func TestNewKubeletClientTLSValid(t *testing.T) {
164164
if client == nil {
165165
t.Error("client should not be nil")
166166
}
167+
168+
{
169+
scheme, port, transport, err := client.GetConnectionInfo("foo")
170+
if err != nil {
171+
t.Errorf("Error getting info: %v", err)
172+
}
173+
if scheme != "https" {
174+
t.Errorf("Expected https, got %s", scheme)
175+
}
176+
if port != 9000 {
177+
t.Errorf("Expected 9000, got %d", port)
178+
}
179+
if transport == nil {
180+
t.Errorf("Expected transport, got nil")
181+
}
182+
}
183+
184+
{
185+
_, _, _, err := client.GetConnectionInfo("foo bar")
186+
if err == nil {
187+
t.Errorf("Expected error getting connection info for invalid node name, got none")
188+
}
189+
}
167190
}

0 commit comments

Comments
 (0)