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

IngressURL should check annotation first, or at least should not pick url if it contains a wildcard "*" #401

Open
yelhouti opened this issue Apr 11, 2023 · 1 comment

Comments

@yelhouti
Copy link

func IngressURL(ing *nv1.Ingress) string {
if ing == nil {
log.Logger().Debug("Ingress is nil, returning empty string for url")
return ""
}
if len(ing.Spec.Rules) == 0 {
log.Logger().Debug("Ingress spec has no rules, returning empty string for url")
return ""
}
rule := ing.Spec.Rules[0]
for _, tls := range ing.Spec.TLS {
for _, h := range tls.Hosts {
if h != "" {
url := "https://" + h
log.Logger().Debugf("found service url %s", url)
return url
}
}
}
ann := ing.Annotations
hostname := rule.Host
if hostname == "" && ann != nil {
hostname = ann[kube.AnnotationHost]
}
if hostname == "" {
log.Logger().Debug("Could not find hostname from rule or ingress annotation")
return ""
}
url := "http://" + hostname
if rule.HTTP != nil {
if len(rule.HTTP.Paths) > 0 {
p := rule.HTTP.Paths[0].Path
if p != "" {
url += p
}
}
}
log.Logger().Debugf("found service url %s", url)
return url
}

This doesn't work, when you have wildcard url.

@yelhouti
Copy link
Author

workaround, update your helmfile and add a hook that add a url in tls:

  hooks:
  - events: [ "postsync" ]
    showlogs: true
    command: "kubectl"
    args:
    - -n
    - '{{ requiredEnv "PREVIEW_NAMESPACE" }}'
    - patch
    - ingress
    - '{{ requiredEnv "REPO_NAME" }}'
    - --patch
    - '{"spec":{"tls":[{"hosts": ["jhipster.{{ requiredEnv "REPO_NAME" }}-pr{{ requiredEnv "PULL_NUMBER" }}.{{ requiredEnv "DOMAIN" }}","*.{{ requiredEnv "REPO_NAME" }}-pr{{ requiredEnv "PULL_NUMBER" }}.{{ requiredEnv "DOMAIN" }}"], "secretName": "wildcard-{{ requiredEnv "REPO_NAME" }}-pr{{ requiredEnv "PULL_NUMBER" }}"}]}}'

I tried using helmfile jsonPatches and strategiyMergePatches but it didn't work, because it needed to rebuild dependencies...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant