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

feat: updated Traefik config rule matcher in order to use a HostRegex matcher instead of Host #2269

Merged
merged 5 commits into from Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -30,6 +30,8 @@ const (
logsCollectorFragment = "kurtosis-logs-collector"
// The collector is per enclave so this is a suffix
logsCollectorVolumeFragment = logsCollectorFragment + "-vol"

anyCharacterPrefixRegexToken = ".*"
)

type DockerEnclaveObjectAttributesProvider interface {
Expand Down Expand Up @@ -524,10 +526,10 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) getLabelsForEnclaveOb
// the following labels are returned:
//
// "traefik.enable": "true",
// "traefik.http.routers.65d2fb6d6732-3771c85af16a-80.rule": "Host(`80-3771c85af16a-65d2fb6d6732`)",
// "traefik.http.routers.65d2fb6d6732-3771c85af16a-80.rule": "HostRegexp(`{name:80-3771c85af16a-65d2fb6d6732.*}`)",
// "traefik.http.routers.65d2fb6d6732-3771c85af16a-80.service": "65d2fb6d6732-3771c85af16a-80",
// "traefik.http.services.65d2fb6d6732-3771c85af16a-80.loadbalancer.server.port": "80"
// "traefik.http.routers.65d2fb6d6732-3771c85af16a-80.rule": "Host(`81-3771c85af16a-65d2fb6d6732`)",
// "traefik.http.routers.65d2fb6d6732-3771c85af16a-81.rule": "HostRegexp(`{name:81-3771c85af16a-65d2fb6d6732.*}`)",
// "traefik.http.routers.65d2fb6d6732-3771c85af16a-81.service": "65d2fb6d6732-3771c85af16a-81",
// "traefik.http.services.65d2fb6d6732-3771c85af16a-81.loadbalancer.server.port": "81"
func (provider *dockerEnclaveObjectAttributesProviderImpl) getTraefikLabelsForEnclaveObject(serviceUuid string, ports map[string]*port_spec.PortSpec) (map[*docker_label_key.DockerLabelKey]*docker_label_value.DockerLabelValue, error) {
Expand All @@ -544,7 +546,7 @@ func (provider *dockerEnclaveObjectAttributesProviderImpl) getTraefikLabelsForEn
shortServiceUuid := uuid_generator.ShortenedUUIDString(serviceUuid)
servicePortStr := fmt.Sprintf("%s-%s-%d", shortEnclaveUuid, shortServiceUuid, portSpec.GetNumber())

labelKeyValuePairs[fmt.Sprintf("http.routers.%s.rule", servicePortStr)] = fmt.Sprintf("Host(`%d-%s-%s`)", portSpec.GetNumber(), shortServiceUuid, shortEnclaveUuid)
labelKeyValuePairs[fmt.Sprintf("http.routers.%s.rule", servicePortStr)] = fmt.Sprintf("HostRegexp(`{name:%d-%s-%s%s}`)", portSpec.GetNumber(), shortServiceUuid, shortEnclaveUuid, anyCharacterPrefixRegexToken)
leoporoli marked this conversation as resolved.
Show resolved Hide resolved
labelKeyValuePairs[fmt.Sprintf("http.routers.%s.service", servicePortStr)] = servicePortStr
labelKeyValuePairs[fmt.Sprintf("http.services.%s.loadbalancer.server.port", servicePortStr)] = strconv.Itoa(int(portSpec.GetNumber()))
}
Expand Down
Expand Up @@ -68,7 +68,7 @@ func TestForUserServiceContainer(t *testing.T) {
case "traefik.http.routers.65d2fb6d6732-3771c85af16a-23.rule":
require.Fail(t, "A traefik label for port 23 should not be present")
case "traefik.http.routers.65d2fb6d6732-3771c85af16a-45.rule":
require.Equal(t, labelValue.GetString(), "Host(`45-3771c85af16a-65d2fb6d6732`)")
require.Equal(t, labelValue.GetString(), "HostRegexp(`{name:45-3771c85af16a-65d2fb6d6732.*}`)")
case "traefik.http.routers.65d2fb6d6732-3771c85af16a-45.service":
require.Equal(t, labelValue.GetString(), "65d2fb6d6732-3771c85af16a-45")
case "traefik.http.services.65d2fb6d6732-3771c85af16a-45.loadbalancer.server.port":
Expand Down