mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 13:37:30 +00:00
Merge pull request #17973 from liggitt/validate_node_name
Auto commit by PR queue bot
This commit is contained in:
commit
fc92833238
@ -1156,6 +1156,12 @@ func ValidatePodSpec(spec *api.PodSpec, fldPath *validation.FieldPath) validatio
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(spec.NodeName) > 0 {
|
||||||
|
if ok, msg := ValidateNodeName(spec.NodeName, false); !ok {
|
||||||
|
allErrs = append(allErrs, validation.NewInvalidError(fldPath.Child("nodeName"), spec.NodeName, msg))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if spec.ActiveDeadlineSeconds != nil {
|
if spec.ActiveDeadlineSeconds != nil {
|
||||||
if *spec.ActiveDeadlineSeconds <= 0 {
|
if *spec.ActiveDeadlineSeconds <= 0 {
|
||||||
allErrs = append(allErrs, validation.NewInvalidError(fldPath.Child("activeDeadlineSeconds"), spec.ActiveDeadlineSeconds, "must be greater than 0"))
|
allErrs = append(allErrs, validation.NewInvalidError(fldPath.Child("activeDeadlineSeconds"), spec.ActiveDeadlineSeconds, "must be greater than 0"))
|
||||||
|
@ -1507,6 +1507,13 @@ func TestValidatePodSpec(t *testing.T) {
|
|||||||
DNSPolicy: api.DNSClusterFirst,
|
DNSPolicy: api.DNSClusterFirst,
|
||||||
ActiveDeadlineSeconds: &activeDeadlineSeconds,
|
ActiveDeadlineSeconds: &activeDeadlineSeconds,
|
||||||
},
|
},
|
||||||
|
"bad nodeName": {
|
||||||
|
NodeName: "node name",
|
||||||
|
Volumes: []api.Volume{{Name: "vol", VolumeSource: api.VolumeSource{EmptyDir: &api.EmptyDirVolumeSource{}}}},
|
||||||
|
Containers: []api.Container{{Name: "ctr", Image: "image", ImagePullPolicy: "IfNotPresent"}},
|
||||||
|
RestartPolicy: api.RestartPolicyAlways,
|
||||||
|
DNSPolicy: api.DNSClusterFirst,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
for k, v := range failureCases {
|
for k, v := range failureCases {
|
||||||
if errs := ValidatePodSpec(&v, validation.NewFieldPath("field")); len(errs) == 0 {
|
if errs := ValidatePodSpec(&v, validation.NewFieldPath("field")); len(errs) == 0 {
|
||||||
|
@ -18,11 +18,13 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"k8s.io/kubernetes/pkg/api"
|
"k8s.io/kubernetes/pkg/api"
|
||||||
|
"k8s.io/kubernetes/pkg/api/validation"
|
||||||
"k8s.io/kubernetes/pkg/client/transport"
|
"k8s.io/kubernetes/pkg/client/transport"
|
||||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||||
"k8s.io/kubernetes/pkg/util"
|
"k8s.io/kubernetes/pkg/util"
|
||||||
@ -96,6 +98,9 @@ func NewStaticKubeletClient(config *KubeletClientConfig) (KubeletClient, error)
|
|||||||
|
|
||||||
// In default HTTPKubeletClient ctx is unused.
|
// In default HTTPKubeletClient ctx is unused.
|
||||||
func (c *HTTPKubeletClient) GetConnectionInfo(ctx api.Context, nodeName string) (string, uint, http.RoundTripper, error) {
|
func (c *HTTPKubeletClient) GetConnectionInfo(ctx api.Context, nodeName string) (string, uint, http.RoundTripper, error) {
|
||||||
|
if ok, msg := validation.ValidateNodeName(nodeName, false); !ok {
|
||||||
|
return "", 0, nil, fmt.Errorf("invalid node name: %s", msg)
|
||||||
|
}
|
||||||
scheme := "http"
|
scheme := "http"
|
||||||
if c.Config.EnableHttps {
|
if c.Config.EnableHttps {
|
||||||
scheme = "https"
|
scheme = "https"
|
||||||
|
@ -82,6 +82,7 @@ func TestNewKubeletClientTLSInvalid(t *testing.T) {
|
|||||||
|
|
||||||
func TestNewKubeletClientTLSValid(t *testing.T) {
|
func TestNewKubeletClientTLSValid(t *testing.T) {
|
||||||
config := &KubeletClientConfig{
|
config := &KubeletClientConfig{
|
||||||
|
Port: 1234,
|
||||||
EnableHttps: true,
|
EnableHttps: true,
|
||||||
TLSClientConfig: client.TLSClientConfig{
|
TLSClientConfig: client.TLSClientConfig{
|
||||||
CertFile: "../../client/testdata/mycertvalid.cer",
|
CertFile: "../../client/testdata/mycertvalid.cer",
|
||||||
@ -99,4 +100,27 @@ func TestNewKubeletClientTLSValid(t *testing.T) {
|
|||||||
if client == nil {
|
if client == nil {
|
||||||
t.Error("client should not be nil")
|
t.Error("client should not be nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
scheme, port, transport, err := client.GetConnectionInfo(nil, "foo")
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Error getting info: %v", err)
|
||||||
|
}
|
||||||
|
if scheme != "https" {
|
||||||
|
t.Errorf("Expected https, got %s", scheme)
|
||||||
|
}
|
||||||
|
if port != 1234 {
|
||||||
|
t.Errorf("Expected 1234, got %d", port)
|
||||||
|
}
|
||||||
|
if transport == nil {
|
||||||
|
t.Errorf("Expected transport, got nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
_, _, _, err := client.GetConnectionInfo(nil, "foo bar")
|
||||||
|
if err == nil {
|
||||||
|
t.Errorf("Expected error getting connection info for invalid node name, got none")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user