Merge pull request #42902 from louyihua/allow-tcp-probe-host

Automatic merge from submit-queue (batch tested with PRs 42998, 42902, 42959, 43020, 42948)

Add Host field to TCPSocketAction

Currently, TCPSocketAction always uses Pod's IP in connection. But when a pod uses the host network, sometimes firewall rules may prevent kubelet from connecting through the Pod's IP.

This PR introduces the 'Host' field for TCPSocketAction, and if it is set to non-empty string, the probe will be performed on the configured host rather than the Pod's IP. This gives users an opportunity to explicitly specify 'localhost' as the target for the above situations.

```release-note
Add Host field to TCPSocketAction
```
This commit is contained in:
Kubernetes Submit Queue 2017-03-25 17:17:23 -07:00 committed by GitHub
commit f9e87e1dc2
27 changed files with 1408 additions and 1125 deletions

View File

@ -41178,6 +41178,10 @@
"port"
],
"properties": {
"host": {
"description": "Optional: Host name to connect to, defaults to the pod IP.",
"type": "string"
},
"port": {
"description": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.",
"$ref": "#/definitions/io.k8s.apimachinery.pkg.util.intstr.IntOrString"

View File

@ -3982,6 +3982,10 @@
"port": {
"type": "string",
"description": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME."
},
"host": {
"type": "string",
"description": "Optional: Host name to connect to, defaults to the pod IP."
}
}
},

View File

@ -2765,6 +2765,10 @@
"port": {
"type": "string",
"description": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME."
},
"host": {
"type": "string",
"description": "Optional: Host name to connect to, defaults to the pod IP."
}
}
},

View File

@ -8229,6 +8229,10 @@
"port": {
"type": "string",
"description": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME."
},
"host": {
"type": "string",
"description": "Optional: Host name to connect to, defaults to the pod IP."
}
}
},

View File

@ -19580,6 +19580,10 @@
"port": {
"type": "string",
"description": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME."
},
"host": {
"type": "string",
"description": "Optional: Host name to connect to, defaults to the pod IP."
}
}
},

View File

@ -4837,6 +4837,13 @@ Examples:<br>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">host</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Host name to connect to, defaults to the pod IP.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>

View File

@ -1438,6 +1438,13 @@ span.icon > [class^="icon-"], span.icon > [class*=" icon-"] { cursor: default; }
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">host</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Host name to connect to, defaults to the pod IP.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>

View File

@ -5770,6 +5770,13 @@ Examples:<br>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">host</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Host name to connect to, defaults to the pod IP.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>

View File

@ -6589,6 +6589,13 @@ Examples:<br>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
<tr>
<td class="tableblock halign-left valign-top"><p class="tableblock">host</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">Optional: Host name to connect to, defaults to the pod IP.</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">false</p></td>
<td class="tableblock halign-left valign-top"><p class="tableblock">string</p></td>
<td class="tableblock halign-left valign-top"></td>
</tr>
</tbody>
</table>

View File

@ -11422,6 +11422,10 @@
"port"
],
"properties": {
"host": {
"description": "Optional: Host name to connect to, defaults to the pod IP.",
"type": "string"
},
"port": {
"description": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.",
"$ref": "#/definitions/io.k8s.apimachinery.pkg.util.intstr.IntOrString"

View File

@ -1391,6 +1391,9 @@ type TCPSocketAction struct {
// Required: Port to connect to.
// +optional
Port intstr.IntOrString
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
Host string
}
// ExecAction describes a "run in container" action.

File diff suppressed because it is too large Load Diff

View File

@ -3668,6 +3668,10 @@ message TCPSocketAction {
// Number must be in the range 1 to 65535.
// Name must be an IANA_SVC_NAME.
optional k8s.io.apimachinery.pkg.util.intstr.IntOrString port = 1;
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
optional string host = 2;
}
// The node this Taint is attached to has the effect "effect" on

View File

@ -24679,12 +24679,13 @@ func (x *TCPSocketAction) CodecEncodeSelf(e *codec1978.Encoder) {
} else {
yysep2 := !z.EncBinary()
yy2arr2 := z.EncBasicHandle().StructToArray
var yyq2 [1]bool
var yyq2 [2]bool
_, _, _ = yysep2, yyq2, yy2arr2
const yyr2 bool = false
yyq2[1] = x.Host != ""
var yynn2 int
if yyr2 || yy2arr2 {
r.EncodeArrayStart(1)
r.EncodeArrayStart(2)
} else {
yynn2 = 1
for _, b := range yyq2 {
@ -24722,6 +24723,31 @@ func (x *TCPSocketAction) CodecEncodeSelf(e *codec1978.Encoder) {
z.EncFallback(yy6)
}
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if yyq2[1] {
yym9 := z.EncBinary()
_ = yym9
if false {
} else {
r.EncodeString(codecSelferC_UTF81234, string(x.Host))
}
} else {
r.EncodeString(codecSelferC_UTF81234, "")
}
} else {
if yyq2[1] {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("host"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
yym10 := z.EncBinary()
_ = yym10
if false {
} else {
r.EncodeString(codecSelferC_UTF81234, string(x.Host))
}
}
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayEnd1234)
} else {
@ -24798,6 +24824,18 @@ func (x *TCPSocketAction) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
z.DecFallback(yyv4, false)
}
}
case "host":
if r.TryDecodeAsNil() {
x.Host = ""
} else {
yyv6 := &x.Host
yym7 := z.DecBinary()
_ = yym7
if false {
} else {
*((*string)(yyv6)) = r.DecodeString()
}
}
default:
z.DecStructFieldNotFound(-1, yys3)
} // end switch yys3
@ -24809,16 +24847,16 @@ func (x *TCPSocketAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder)
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
var yyj6 int
var yyb6 bool
var yyhl6 bool = l >= 0
yyj6++
if yyhl6 {
yyb6 = yyj6 > l
var yyj8 int
var yyb8 bool
var yyhl8 bool = l >= 0
yyj8++
if yyhl8 {
yyb8 = yyj8 > l
} else {
yyb6 = r.CheckBreak()
yyb8 = r.CheckBreak()
}
if yyb6 {
if yyb8 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return
}
@ -24826,29 +24864,51 @@ func (x *TCPSocketAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder)
if r.TryDecodeAsNil() {
x.Port = pkg4_intstr.IntOrString{}
} else {
yyv7 := &x.Port
yym8 := z.DecBinary()
_ = yym8
yyv9 := &x.Port
yym10 := z.DecBinary()
_ = yym10
if false {
} else if z.HasExtensions() && z.DecExt(yyv7) {
} else if !yym8 && z.IsJSONHandle() {
z.DecJSONUnmarshal(yyv7)
} else if z.HasExtensions() && z.DecExt(yyv9) {
} else if !yym10 && z.IsJSONHandle() {
z.DecJSONUnmarshal(yyv9)
} else {
z.DecFallback(yyv7, false)
z.DecFallback(yyv9, false)
}
}
yyj8++
if yyhl8 {
yyb8 = yyj8 > l
} else {
yyb8 = r.CheckBreak()
}
if yyb8 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
if r.TryDecodeAsNil() {
x.Host = ""
} else {
yyv11 := &x.Host
yym12 := z.DecBinary()
_ = yym12
if false {
} else {
*((*string)(yyv11)) = r.DecodeString()
}
}
for {
yyj6++
if yyhl6 {
yyb6 = yyj6 > l
yyj8++
if yyhl8 {
yyb8 = yyj8 > l
} else {
yyb6 = r.CheckBreak()
yyb8 = r.CheckBreak()
}
if yyb6 {
if yyb8 {
break
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
z.DecStructFieldNotFound(yyj6-1, "")
z.DecStructFieldNotFound(yyj8-1, "")
}
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
}

View File

@ -1492,6 +1492,9 @@ type TCPSocketAction struct {
// Number must be in the range 1 to 65535.
// Name must be an IANA_SVC_NAME.
Port intstr.IntOrString `json:"port" protobuf:"bytes,1,opt,name=port"`
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
Host string `json:"host,omitempty" protobuf:"bytes,2,opt,name=host"`
}
// ExecAction describes a "run in container" action.

View File

@ -1840,6 +1840,7 @@ func (ServiceStatus) SwaggerDoc() map[string]string {
var map_TCPSocketAction = map[string]string{
"": "TCPSocketAction describes an action based on opening a socket",
"port": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.",
"host": "Optional: Host name to connect to, defaults to the pod IP.",
}
func (TCPSocketAction) SwaggerDoc() map[string]string {

View File

@ -4453,6 +4453,7 @@ func Convert_api_Sysctl_To_v1_Sysctl(in *api.Sysctl, out *Sysctl, s conversion.S
func autoConvert_v1_TCPSocketAction_To_api_TCPSocketAction(in *TCPSocketAction, out *api.TCPSocketAction, s conversion.Scope) error {
out.Port = in.Port
out.Host = in.Host
return nil
}
@ -4462,6 +4463,7 @@ func Convert_v1_TCPSocketAction_To_api_TCPSocketAction(in *TCPSocketAction, out
func autoConvert_api_TCPSocketAction_To_v1_TCPSocketAction(in *api.TCPSocketAction, out *TCPSocketAction, s conversion.Scope) error {
out.Port = in.Port
out.Host = in.Host
return nil
}

View File

@ -8594,6 +8594,13 @@ func GetOpenAPIDefinitions(ref openapi.ReferenceCallback) map[string]openapi.Ope
Ref: ref("k8s.io/apimachinery/pkg/util/intstr.IntOrString"),
},
},
"host": {
SchemaProps: spec.SchemaProps{
Description: "Optional: Host name to connect to, defaults to the pod IP.",
Type: []string{"string"},
Format: "",
},
},
},
Required: []string{"port"},
},

View File

@ -168,8 +168,12 @@ func (pb *prober) runProbe(p *v1.Probe, pod *v1.Pod, status v1.PodStatus, contai
if err != nil {
return probe.Unknown, "", err
}
glog.V(4).Infof("TCP-Probe PodIP: %v, Port: %v, Timeout: %v", status.PodIP, port, timeout)
return pb.tcp.Probe(status.PodIP, port, timeout)
host := p.TCPSocket.Host
if host == "" {
host = status.PodIP
}
glog.V(4).Infof("TCP-Probe Host: %v, Port: %v, Timeout: %v", host, port, timeout)
return pb.tcp.Probe(host, port, timeout)
}
glog.Warningf("Failed to find probe builder for container: %v", container)
return probe.Unknown, "", fmt.Errorf("Missing probe handler for %s:%s", format.Pod(pod), container.Name)

View File

@ -1148,7 +1148,7 @@ func DescribeProbe(probe *api.Probe) string {
url.Path = probe.HTTPGet.Path
return fmt.Sprintf("http-get %s %s", url.String(), attrs)
case probe.TCPSocket != nil:
return fmt.Sprintf("tcp-socket :%s %s", probe.TCPSocket.Port.String(), attrs)
return fmt.Sprintf("tcp-socket %s:%s %s", probe.TCPSocket.Host, probe.TCPSocket.Port.String(), attrs)
}
return fmt.Sprintf("unknown %s", attrs)
}

View File

@ -1391,6 +1391,9 @@ type TCPSocketAction struct {
// Required: Port to connect to.
// +optional
Port intstr.IntOrString
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
Host string
}
// ExecAction describes a "run in container" action.

File diff suppressed because it is too large Load Diff

View File

@ -3668,6 +3668,10 @@ message TCPSocketAction {
// Number must be in the range 1 to 65535.
// Name must be an IANA_SVC_NAME.
optional k8s.io.apimachinery.pkg.util.intstr.IntOrString port = 1;
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
optional string host = 2;
}
// The node this Taint is attached to has the effect "effect" on

View File

@ -24679,12 +24679,13 @@ func (x *TCPSocketAction) CodecEncodeSelf(e *codec1978.Encoder) {
} else {
yysep2 := !z.EncBinary()
yy2arr2 := z.EncBasicHandle().StructToArray
var yyq2 [1]bool
var yyq2 [2]bool
_, _, _ = yysep2, yyq2, yy2arr2
const yyr2 bool = false
yyq2[1] = x.Host != ""
var yynn2 int
if yyr2 || yy2arr2 {
r.EncodeArrayStart(1)
r.EncodeArrayStart(2)
} else {
yynn2 = 1
for _, b := range yyq2 {
@ -24722,6 +24723,31 @@ func (x *TCPSocketAction) CodecEncodeSelf(e *codec1978.Encoder) {
z.EncFallback(yy6)
}
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayElem1234)
if yyq2[1] {
yym9 := z.EncBinary()
_ = yym9
if false {
} else {
r.EncodeString(codecSelferC_UTF81234, string(x.Host))
}
} else {
r.EncodeString(codecSelferC_UTF81234, "")
}
} else {
if yyq2[1] {
z.EncSendContainerState(codecSelfer_containerMapKey1234)
r.EncodeString(codecSelferC_UTF81234, string("host"))
z.EncSendContainerState(codecSelfer_containerMapValue1234)
yym10 := z.EncBinary()
_ = yym10
if false {
} else {
r.EncodeString(codecSelferC_UTF81234, string(x.Host))
}
}
}
if yyr2 || yy2arr2 {
z.EncSendContainerState(codecSelfer_containerArrayEnd1234)
} else {
@ -24798,6 +24824,18 @@ func (x *TCPSocketAction) codecDecodeSelfFromMap(l int, d *codec1978.Decoder) {
z.DecFallback(yyv4, false)
}
}
case "host":
if r.TryDecodeAsNil() {
x.Host = ""
} else {
yyv6 := &x.Host
yym7 := z.DecBinary()
_ = yym7
if false {
} else {
*((*string)(yyv6)) = r.DecodeString()
}
}
default:
z.DecStructFieldNotFound(-1, yys3)
} // end switch yys3
@ -24809,16 +24847,16 @@ func (x *TCPSocketAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder)
var h codecSelfer1234
z, r := codec1978.GenHelperDecoder(d)
_, _, _ = h, z, r
var yyj6 int
var yyb6 bool
var yyhl6 bool = l >= 0
yyj6++
if yyhl6 {
yyb6 = yyj6 > l
var yyj8 int
var yyb8 bool
var yyhl8 bool = l >= 0
yyj8++
if yyhl8 {
yyb8 = yyj8 > l
} else {
yyb6 = r.CheckBreak()
yyb8 = r.CheckBreak()
}
if yyb6 {
if yyb8 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return
}
@ -24826,29 +24864,51 @@ func (x *TCPSocketAction) codecDecodeSelfFromArray(l int, d *codec1978.Decoder)
if r.TryDecodeAsNil() {
x.Port = pkg4_intstr.IntOrString{}
} else {
yyv7 := &x.Port
yym8 := z.DecBinary()
_ = yym8
yyv9 := &x.Port
yym10 := z.DecBinary()
_ = yym10
if false {
} else if z.HasExtensions() && z.DecExt(yyv7) {
} else if !yym8 && z.IsJSONHandle() {
z.DecJSONUnmarshal(yyv7)
} else if z.HasExtensions() && z.DecExt(yyv9) {
} else if !yym10 && z.IsJSONHandle() {
z.DecJSONUnmarshal(yyv9)
} else {
z.DecFallback(yyv7, false)
z.DecFallback(yyv9, false)
}
}
yyj8++
if yyhl8 {
yyb8 = yyj8 > l
} else {
yyb8 = r.CheckBreak()
}
if yyb8 {
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
return
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
if r.TryDecodeAsNil() {
x.Host = ""
} else {
yyv11 := &x.Host
yym12 := z.DecBinary()
_ = yym12
if false {
} else {
*((*string)(yyv11)) = r.DecodeString()
}
}
for {
yyj6++
if yyhl6 {
yyb6 = yyj6 > l
yyj8++
if yyhl8 {
yyb8 = yyj8 > l
} else {
yyb6 = r.CheckBreak()
yyb8 = r.CheckBreak()
}
if yyb6 {
if yyb8 {
break
}
z.DecSendContainerState(codecSelfer_containerArrayElem1234)
z.DecStructFieldNotFound(yyj6-1, "")
z.DecStructFieldNotFound(yyj8-1, "")
}
z.DecSendContainerState(codecSelfer_containerArrayEnd1234)
}

View File

@ -1492,6 +1492,9 @@ type TCPSocketAction struct {
// Number must be in the range 1 to 65535.
// Name must be an IANA_SVC_NAME.
Port intstr.IntOrString `json:"port" protobuf:"bytes,1,opt,name=port"`
// Optional: Host name to connect to, defaults to the pod IP.
// +optional
Host string `json:"host,omitempty" protobuf:"bytes,2,opt,name=host"`
}
// ExecAction describes a "run in container" action.

View File

@ -1840,6 +1840,7 @@ func (ServiceStatus) SwaggerDoc() map[string]string {
var map_TCPSocketAction = map[string]string{
"": "TCPSocketAction describes an action based on opening a socket",
"port": "Number or name of the port to access on the container. Number must be in the range 1 to 65535. Name must be an IANA_SVC_NAME.",
"host": "Optional: Host name to connect to, defaults to the pod IP.",
}
func (TCPSocketAction) SwaggerDoc() map[string]string {

View File

@ -4453,6 +4453,7 @@ func Convert_api_Sysctl_To_v1_Sysctl(in *api.Sysctl, out *Sysctl, s conversion.S
func autoConvert_v1_TCPSocketAction_To_api_TCPSocketAction(in *TCPSocketAction, out *api.TCPSocketAction, s conversion.Scope) error {
out.Port = in.Port
out.Host = in.Host
return nil
}
@ -4462,6 +4463,7 @@ func Convert_v1_TCPSocketAction_To_api_TCPSocketAction(in *TCPSocketAction, out
func autoConvert_api_TCPSocketAction_To_v1_TCPSocketAction(in *api.TCPSocketAction, out *TCPSocketAction, s conversion.Scope) error {
out.Port = in.Port
out.Host = in.Host
return nil
}