Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allowing for HTTPS Probes #9965

Merged
merged 2 commits into from
Jun 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/swagger-spec/v1.json
Expand Up @@ -12722,6 +12722,10 @@
"host": {
"type": "string",
"description": "hostname to connect to; defaults to pod IP"
},
"scheme": {
"type": "string",
"description": "scheme to connect with, must be HTTP or HTTPS, defaults to HTTP"
}
}
},
Expand Down
4 changes: 4 additions & 0 deletions api/swagger-spec/v1beta3.json
Expand Up @@ -12724,6 +12724,10 @@
"host": {
"type": "string",
"description": "hostname to connect to; defaults to pod IP"
},
"scheme": {
"type": "string",
"description": "scheme to connect with, must be HTTP or HTTPS, defaults to HTTP"
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions cluster/gce/util.sh
Expand Up @@ -933,12 +933,12 @@ function check-resources {
fi

if gcloud compute firewall-rules describe --project "${PROJECT}" "${MASTER_NAME}-https" &>/dev/null; then
KUBE_RESOURCE_FOUND="Firewal rules for ${MASTER_NAME}-https"
KUBE_RESOURCE_FOUND="Firewall rules for ${MASTER_NAME}-https"
return 1
fi

if gcloud compute firewall-rules describe --project "${PROJECT}" "${MINION_TAG}-all" &>/dev/null; then
KUBE_RESOURCE_FOUND="Firewal rules for ${MASTER_NAME}-all"
KUBE_RESOURCE_FOUND="Firewall rules for ${MASTER_NAME}-all"
return 1
fi

Expand Down
2 changes: 1 addition & 1 deletion cmd/kubernetes/kubernetes.go
Expand Up @@ -88,7 +88,7 @@ func runApiServer(etcdClient tools.EtcdClient, addr net.IP, port int, masterServ
EtcdHelper: helper,
KubeletClient: &client.HTTPKubeletClient{
Client: http.DefaultClient,
Port: 10250,
Config: &client.KubeletConfig{Port: 10250},
},
EnableCoreControllers: true,
EnableLogsSupport: false,
Expand Down
1 change: 1 addition & 0 deletions examples/openshift-origin/.gitignore
@@ -1,2 +1,3 @@
config/
secret.json
*.log
Empty file.
1 change: 1 addition & 0 deletions pkg/api/deep_copy_generated.go
Expand Up @@ -505,6 +505,7 @@ func deepCopy_api_HTTPGetAction(in HTTPGetAction, out *HTTPGetAction, c *convers
return err
}
out.Host = in.Host
out.Scheme = in.Scheme
return nil
}

Expand Down
5 changes: 3 additions & 2 deletions pkg/api/testing/fuzzer.go
Expand Up @@ -252,8 +252,9 @@ func FuzzerFor(t *testing.T, version string, src rand.Source) *fuzz.Fuzzer {
s.Phase = api.NamespaceActive
},
func(http *api.HTTPGetAction, c fuzz.Continue) {
c.FuzzNoCustom(http) // fuzz self without calling this function again
http.Path = "/" + http.Path // can't be blank
c.FuzzNoCustom(http) // fuzz self without calling this function again
http.Path = "/" + http.Path // can't be blank
http.Scheme = "x" + http.Scheme // can't be blank
},
func(ss *api.ServiceSpec, c fuzz.Continue) {
c.FuzzNoCustom(ss) // fuzz self without calling this function again
Expand Down
12 changes: 12 additions & 0 deletions pkg/api/types.go
Expand Up @@ -610,8 +610,20 @@ type HTTPGetAction struct {
Port util.IntOrString `json:"port,omitempty"`
// Optional: Host name to connect to, defaults to the pod IP.
Host string `json:"host,omitempty"`
// Optional: Scheme to use for connecting to the host, defaults to HTTP.
Scheme URIScheme `json:"scheme,omitempty"`
}

// URIScheme identifies the scheme used for connection to a host for Get actions
type URIScheme string

const (
// URISchemeHTTP means that the scheme used will be http://
URISchemeHTTP URIScheme = "HTTP"
// URISchemeHTTPS means that the scheme used will be https://
URISchemeHTTPS URIScheme = "HTTPS"
)

// TCPSocketAction describes an action based on opening a socket
type TCPSocketAction struct {
// Required: Port to connect to.
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1/conversion_generated.go
Expand Up @@ -592,6 +592,7 @@ func convert_api_HTTPGetAction_To_v1_HTTPGetAction(in *api.HTTPGetAction, out *H
return err
}
out.Host = in.Host
out.Scheme = URIScheme(in.Scheme)
return nil
}

Expand Down Expand Up @@ -2903,6 +2904,7 @@ func convert_v1_HTTPGetAction_To_api_HTTPGetAction(in *HTTPGetAction, out *api.H
return err
}
out.Host = in.Host
out.Scheme = api.URIScheme(in.Scheme)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/deep_copy_generated.go
Expand Up @@ -518,6 +518,7 @@ func deepCopy_v1_HTTPGetAction(in HTTPGetAction, out *HTTPGetAction, c *conversi
return err
}
out.Host = in.Host
out.Scheme = in.Scheme
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1/defaults.go
Expand Up @@ -137,6 +137,9 @@ func addDefaultingFuncs() {
if obj.Path == "" {
obj.Path = "/"
}
if obj.Scheme == "" {
obj.Scheme = URISchemeHTTP
}
},
func(obj *NamespaceStatus) {
if obj.Phase == "" {
Expand Down
12 changes: 12 additions & 0 deletions pkg/api/v1/types.go
Expand Up @@ -586,8 +586,20 @@ type HTTPGetAction struct {
Port util.IntOrString `json:"port" description:"number or name of the port to access on the container"`
// Optional: Host name to connect to, defaults to the pod IP.
Host string `json:"host,omitempty" description:"hostname to connect to; defaults to pod IP"`
// Optional: Scheme to use for connecting to the host, defaults to HTTP.
Scheme URIScheme `json:"scheme,omitempty" description:"scheme to connect with, must be HTTP or HTTPS, defaults to HTTP"`
}

// URIScheme identifies the scheme used for connection to a host for Get actions
type URIScheme string

const (
// URISchemeHTTP means that the scheme used will be http://
URISchemeHTTP URIScheme = "HTTP"
// URISchemeHTTPS means that the scheme used will be https://
URISchemeHTTPS URIScheme = "HTTPS"
)

// TCPSocketAction describes an action based on opening a socket
type TCPSocketAction struct {
// Required: Port to connect to.
Expand Down
2 changes: 2 additions & 0 deletions pkg/api/v1beta3/conversion_generated.go
Expand Up @@ -450,6 +450,7 @@ func convert_api_HTTPGetAction_To_v1beta3_HTTPGetAction(in *api.HTTPGetAction, o
return err
}
out.Host = in.Host
out.Scheme = URIScheme(in.Scheme)
return nil
}

Expand Down Expand Up @@ -2515,6 +2516,7 @@ func convert_v1beta3_HTTPGetAction_To_api_HTTPGetAction(in *HTTPGetAction, out *
return err
}
out.Host = in.Host
out.Scheme = api.URIScheme(in.Scheme)
return nil
}

Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1beta3/deep_copy_generated.go
Expand Up @@ -522,6 +522,7 @@ func deepCopy_v1beta3_HTTPGetAction(in HTTPGetAction, out *HTTPGetAction, c *con
return err
}
out.Host = in.Host
out.Scheme = in.Scheme
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions pkg/api/v1beta3/defaults.go
Expand Up @@ -141,6 +141,9 @@ func addDefaultingFuncs() {
if obj.Path == "" {
obj.Path = "/"
}
if obj.Scheme == "" {
obj.Scheme = URISchemeHTTP
}
},
func(obj *NamespaceStatus) {
if obj.Phase == "" {
Expand Down
12 changes: 12 additions & 0 deletions pkg/api/v1beta3/types.go
Expand Up @@ -586,8 +586,20 @@ type HTTPGetAction struct {
Port util.IntOrString `json:"port" description:"number or name of the port to access on the container"`
// Optional: Host name to connect to, defaults to the pod IP.
Host string `json:"host,omitempty" description:"hostname to connect to; defaults to pod IP"`
// Optional: Scheme to use for connecting to the host, defaults to HTTP.
Scheme URIScheme `json:"scheme,omitempty" description:"scheme to connect with, must be HTTP or HTTPS, defaults to HTTP"`
}

// URIScheme identifies the scheme used for connection to a host for Get actions
type URIScheme string

const (
// URISchemeHTTP means that the scheme used will be http://
URISchemeHTTP URIScheme = "HTTP"
// URISchemeHTTPS means that the scheme used will be https://
URISchemeHTTPS URIScheme = "HTTPS"
)

// TCPSocketAction describes an action based on opening a socket
type TCPSocketAction struct {
// Required: Port to connect to.
Expand Down
4 changes: 4 additions & 0 deletions pkg/api/validation/validation.go
Expand Up @@ -762,6 +762,10 @@ func validateHTTPGetAction(http *api.HTTPGetAction) errs.ValidationErrorList {
} else if http.Port.Kind == util.IntstrString && len(http.Port.StrVal) == 0 {
allErrors = append(allErrors, errs.NewFieldRequired("port"))
}
supportedSchemes := util.NewStringSet(string(api.URISchemeHTTP), string(api.URISchemeHTTPS))
if !supportedSchemes.Has(string(http.Scheme)) {
allErrors = append(allErrors, errs.NewFieldInvalid("scheme", http.Scheme, fmt.Sprintf("must be one of %v", supportedSchemes.List())))
}
return allErrors
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/api/validation/validation_test.go
Expand Up @@ -712,9 +712,9 @@ func TestValidateProbe(t *testing.T) {
func TestValidateHandler(t *testing.T) {
successCases := []api.Handler{
{Exec: &api.ExecAction{Command: []string{"echo"}}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: util.NewIntOrStringFromInt(1), Host: ""}},
{HTTPGet: &api.HTTPGetAction{Path: "/foo", Port: util.NewIntOrStringFromInt(65535), Host: "host"}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: util.NewIntOrStringFromString("port"), Host: ""}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: util.NewIntOrStringFromInt(1), Host: "", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/foo", Port: util.NewIntOrStringFromInt(65535), Host: "host", Scheme: "HTTP"}},
{HTTPGet: &api.HTTPGetAction{Path: "/", Port: util.NewIntOrStringFromString("port"), Host: "", Scheme: "HTTP"}},
}
for _, h := range successCases {
if errs := validateHandler(&h); len(errs) != 0 {
Expand Down
26 changes: 11 additions & 15 deletions pkg/client/kubelet.go
Expand Up @@ -44,10 +44,8 @@ type ConnectionInfoGetter interface {

// HTTPKubeletClient is the default implementation of KubeletHealthchecker, accesses the kubelet over HTTP.
type HTTPKubeletClient struct {
Client *http.Client
Config *KubeletConfig
Port uint
EnableHttps bool
Client *http.Client
Config *KubeletConfig
}

func MakeTransport(config *KubeletConfig) (http.RoundTripper, error) {
Expand Down Expand Up @@ -83,33 +81,31 @@ func NewKubeletClient(config *KubeletConfig) (KubeletClient, error) {
Timeout: config.HTTPTimeout,
}
return &HTTPKubeletClient{
Client: c,
Config: config,
Port: config.Port,
EnableHttps: config.EnableHttps,
Client: c,
Config: config,
}, nil
}

func (c *HTTPKubeletClient) GetConnectionInfo(host string) (string, uint, http.RoundTripper, error) {
scheme := "http"
if c.EnableHttps {
if c.Config.EnableHttps {
scheme = "https"
}
return scheme, c.Port, c.Client.Transport, nil
return scheme, c.Config.Port, c.Client.Transport, nil
}

func (c *HTTPKubeletClient) url(host, path, query string) string {
func (c *HTTPKubeletClient) url(host, path, query string) *url.URL {
scheme := "http"
if c.EnableHttps {
if c.Config.EnableHttps {
scheme = "https"
}

return (&url.URL{
return &url.URL{
Scheme: scheme,
Host: net.JoinHostPort(host, strconv.FormatUint(uint64(c.Port), 10)),
Host: net.JoinHostPort(host, strconv.FormatUint(uint64(c.Config.Port), 10)),
Path: path,
RawQuery: query,
}).String()
}
}

func (c *HTTPKubeletClient) HealthCheck(host string) (probe.Result, string, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/client/kubelet_test.go
Expand Up @@ -57,7 +57,7 @@ func TestHTTPKubeletClient(t *testing.T) {

c := &HTTPKubeletClient{
Client: http.DefaultClient,
Port: uint(port),
Config: &KubeletConfig{Port: uint(port)},
}
gotObj, _, err := c.HealthCheck(parts[0])
if err != nil {
Expand Down Expand Up @@ -91,7 +91,7 @@ func TestHTTPKubeletClientError(t *testing.T) {

c := &HTTPKubeletClient{
Client: http.DefaultClient,
Port: uint(port),
Config: &KubeletConfig{Port: uint(port)},
}
gotObj, _, err := c.HealthCheck(parts[0])
if gotObj != expectObj {
Expand Down