Skip to content

Commit 0cec0a8

Browse files
Fix unmarshalling of config file (#53)
Use `yaml` instead of `json` for fields to make sure YAML uses the right field name. Signed-off-by: Kyle Edwards <[email protected]>
1 parent bef9ec4 commit 0cec0a8

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

examples/kubeflow.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ checks:
5656
httpGet:
5757
path: /
5858
port: 8888
59+
httpHeaders:
60+
- name: User-Agent
61+
value: container-canary/0.2.1
5962
responseHttpHeaders:
6063
- name: Access-Control-Allow-Origin
6164
value: "*"

internal/apis/v1/types.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,26 @@ func (p *Probe) UnmarshalYAML(unmarshal func(interface{}) error) error {
104104
type HTTPGetAction struct {
105105
// Path to access on the HTTP server.
106106
// +optional
107-
Path string `json:"path,omitempty"`
107+
Path string `yaml:"path,omitempty"`
108108
// Number of the port to access on the container.
109109
// Number must be in the range 1 to 65535.
110-
Port int `json:"port"`
110+
Port int `yaml:"port"`
111111
// Scheme to use for connecting to the host.
112112
// Defaults to HTTP.
113113
// +optional
114-
Scheme v1.URIScheme `json:"scheme,omitempty"`
114+
Scheme v1.URIScheme `yaml:"scheme,omitempty"`
115115
// Custom headers to set in the request. HTTP allows repeated headers.
116116
// +optional
117-
HTTPHeaders []v1.HTTPHeader `json:"httpHeaders,omitempty"`
117+
HTTPHeaders []v1.HTTPHeader `yaml:"httpHeaders,omitempty"`
118118
// Headers expected in the response. Check will fail if any are missing.
119119
// +optional
120-
ResponseHTTPHeaders []v1.HTTPHeader `json:"responseHttpHeaders,omitempty"`
120+
ResponseHTTPHeaders []v1.HTTPHeader `yaml:"responseHttpHeaders,omitempty"`
121121
}
122122

123123
type TCPSocketAction struct {
124124
// Number or name of the port to access on the container.
125125
// Number must be in the range 1 to 65535.
126-
Port int `json:"port"`
126+
Port int `yaml:"port"`
127127
}
128128

129129
type Volume struct {

internal/config/load_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,19 @@ func TestValidator(t *testing.T) {
4141

4242
assert.Equal(0, check.Probe.InitialDelaySeconds)
4343

44+
check = validator.Checks[5]
45+
46+
assert.Equal("allow-origin-all", check.Name)
47+
assert.Equal("🔓 Sets 'Access-Control-Allow-Origin: *' header", check.Description)
48+
49+
assert.Equal("/", check.Probe.HTTPGet.Path)
50+
assert.Equal(8888, check.Probe.HTTPGet.Port)
51+
52+
header := check.Probe.HTTPGet.HTTPHeaders[0]
53+
assert.Equal("User-Agent", header.Name)
54+
assert.Equal("container-canary/0.2.1", header.Value)
55+
56+
header = check.Probe.HTTPGet.ResponseHTTPHeaders[0]
57+
assert.Equal("Access-Control-Allow-Origin", header.Name)
58+
assert.Equal("*", header.Value)
4459
}

0 commit comments

Comments
 (0)