mirror of https://github.com/k3s-io/k3s
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 <= 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,
|
||||
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 {
|
||||
if errs := ValidatePodSpec(&v, validation.NewFieldPath("field")); len(errs) == 0 {
|
||||
|
|
|
@ -18,11 +18,13 @@ package client
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"k8s.io/kubernetes/pkg/api"
|
||||
"k8s.io/kubernetes/pkg/api/validation"
|
||||
"k8s.io/kubernetes/pkg/client/transport"
|
||||
client "k8s.io/kubernetes/pkg/client/unversioned"
|
||||
"k8s.io/kubernetes/pkg/util"
|
||||
|
@ -96,6 +98,9 @@ func NewStaticKubeletClient(config *KubeletClientConfig) (KubeletClient, error)
|
|||
|
||||
// In default HTTPKubeletClient ctx is unused.
|
||||
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"
|
||||
if c.Config.EnableHttps {
|
||||
scheme = "https"
|
||||
|
|
|
@ -82,6 +82,7 @@ func TestNewKubeletClientTLSInvalid(t *testing.T) {
|
|||
|
||||
func TestNewKubeletClientTLSValid(t *testing.T) {
|
||||
config := &KubeletClientConfig{
|
||||
Port: 1234,
|
||||
EnableHttps: true,
|
||||
TLSClientConfig: client.TLSClientConfig{
|
||||
CertFile: "../../client/testdata/mycertvalid.cer",
|
||||
|
@ -99,4 +100,27 @@ func TestNewKubeletClientTLSValid(t *testing.T) {
|
|||
if client == 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