fix: missing UDP field in checkType (#14885)

* fix: missing UDP field in checkType

* Add changelog

* Update doc
This commit is contained in:
cskh 2022-10-05 15:57:21 -04:00 committed by GitHub
parent fbee1272e7
commit 53ff317b01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 2 deletions

4
.changelog/14885.txt Normal file
View File

@ -0,0 +1,4 @@
```release-note:bug
checks: Fixed a bug that prevented registration of UDP health checks from agent configuration files, such as service definition files with embedded health check definitions.
```

View File

@ -1562,6 +1562,7 @@ func (b *builder) checkVal(v *CheckDefinition) *structs.CheckDefinition {
Body: stringVal(v.Body), Body: stringVal(v.Body),
DisableRedirects: boolVal(v.DisableRedirects), DisableRedirects: boolVal(v.DisableRedirects),
TCP: stringVal(v.TCP), TCP: stringVal(v.TCP),
UDP: stringVal(v.UDP),
Interval: b.durationVal(fmt.Sprintf("check[%s].interval", id), v.Interval), Interval: b.durationVal(fmt.Sprintf("check[%s].interval", id), v.Interval),
DockerContainerID: stringVal(v.DockerContainerID), DockerContainerID: stringVal(v.DockerContainerID),
Shell: stringVal(v.Shell), Shell: stringVal(v.Shell),

View File

@ -326,6 +326,24 @@ func TestBuilder_ServiceVal_MultiError(t *testing.T) {
require.Contains(t, b.err.Error(), "cannot have both socket path") require.Contains(t, b.err.Error(), "cannot have both socket path")
} }
func TestBuilder_ServiceVal_with_Check(t *testing.T) {
b := builder{}
svc := b.serviceVal(&ServiceDefinition{
Name: strPtr("unbound"),
ID: strPtr("unbound"),
Port: intPtr(12345),
Checks: []CheckDefinition{
{
Interval: strPtr("5s"),
UDP: strPtr("localhost:53"),
},
},
})
require.NoError(t, b.err)
require.Equal(t, 1, len(svc.Checks))
require.Equal(t, "localhost:53", svc.Checks[0].UDP)
}
func intPtr(v int) *int { func intPtr(v int) *int {
return &v return &v
} }

View File

@ -24,10 +24,11 @@ be reviewed and tested.
on `config.Config` in [agent/config/config.go]. on `config.Config` in [agent/config/config.go].
5. Config [Service.Checks](https://www.consul.io/docs/discovery/services) - the 5. Config [Service.Checks](https://www.consul.io/docs/discovery/services) - the
`Checks` and `Check` fields on `ServiceDefinition` in [agent/config/config.go]. `Checks` and `Check` fields on `ServiceDefinition` in [agent/config/config.go].
6. CLI [consul services register](https://www.consul.io/commands/services/register) - the 6. The returned fields of `ServiceDefinition` in [agent/config/builder.go].
7. CLI [consul services register](https://www.consul.io/commands/services/register) - the
`Checks` and `Check` fields on `api.AgentServiceRegistration`. The entrypoint is `Checks` and `Check` fields on `api.AgentServiceRegistration`. The entrypoint is
`ServicesFromFiles` in [command/services/config.go]. `ServicesFromFiles` in [command/services/config.go].
7. API [/v1/txn](https://www.consul.io/api-docs/txn) - the `Transaction` API allows for registering a check. 8. API [/v1/txn](https://www.consul.io/api-docs/txn) - the `Transaction` API allows for registering a check.
[agent/catalog_endpoint.go]: https://github.com/hashicorp/consul/blob/main/agent/catalog_endpoint.go [agent/catalog_endpoint.go]: https://github.com/hashicorp/consul/blob/main/agent/catalog_endpoint.go