-
Notifications
You must be signed in to change notification settings - Fork 351
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
host2regex: doesn't take in consideration *
#3296
base: master
Are you sure you want to change the base?
Changes from 3 commits
fab59f1
8027b99
31d4922
8e6c365
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package kubernetes | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestHostsToRegex(t *testing.T) { | ||
for _, ti := range []struct { | ||
msg string | ||
host string | ||
regex string | ||
}{ | ||
{ | ||
msg: "simple", | ||
host: "simple.example.org", | ||
regex: "^(simple[.]example[.]org[.]?(:[0-9]+)?)$", | ||
}, | ||
{ | ||
msg: "wildcard", | ||
host: "*.example.org", | ||
regex: "^([a-z0-9]+(-[a-z0-9]+)?[.]example[.]org[.]?(:[0-9]+)?)$", | ||
}, | ||
} { | ||
t.Run(ti.msg, func(t *testing.T) { | ||
regex := createHostRx(ti.host) | ||
require.Equal(t, ti.regex, regex) | ||
}) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
kube_foo__qux____example_org_____qux: | ||
Host("^([a-z0-9]+(-[a-z0-9]+)?[.]example[.]org[.]?(:[0-9]+)?)$") && PathSubtree("/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you want Better also to write down in the issue what kind of match or regexp you want to create. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I want to match a valid hostname, it can't end or start with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What about foo-bar-qux.example , that your regexp doesn't match? maybe:
Not sure if we need the capture group for the full first part of the hostname. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. updated the PR to match it, the new regex |
||
-> <roundRobin, "http://10.2.9.103:8080", "http://10.2.9.104:8080">; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
apiVersion: networking.k8s.io/v1 | ||
kind: Ingress | ||
metadata: | ||
name: qux | ||
namespace: foo | ||
spec: | ||
rules: | ||
- host: "*.example.org" | ||
http: | ||
paths: | ||
- path: "/" | ||
pathType: Prefix | ||
backend: | ||
service: | ||
name: qux | ||
port: | ||
name: baz | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: qux | ||
namespace: foo | ||
spec: | ||
clusterIP: 10.3.190.97 | ||
ports: | ||
- name: baz | ||
port: 8181 | ||
protocol: TCP | ||
targetPort: 8080 | ||
selector: | ||
application: myapp | ||
type: ClusterIP | ||
--- | ||
apiVersion: v1 | ||
kind: Endpoints | ||
metadata: | ||
labels: | ||
application: myapp | ||
name: qux | ||
namespace: foo | ||
subsets: | ||
- addresses: | ||
- ip: 10.2.9.103 | ||
- ip: 10.2.9.104 | ||
ports: | ||
- name: baz | ||
port: 8080 | ||
protocol: TCP |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another idea is to update validation webhook to say if the host regex is valid