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

Added support for annotation substitutions #95

Merged
merged 7 commits into from Jul 24, 2023
Merged

Conversation

dfulgham
Copy link
Contributor

Added websocket annotation for nginx ingress k8s

Description

added the nginx annotation for websocket support in k8s

Related Issue(s)

(https://github.com/flowforge/flowforge-driver-k8s/issues/83)

Checklist

  • I have read the contribution guidelines
  • Suitable unit/system level tests have been added and they pass Not needed

Labels

  • Backport needed? -> add the backport label
  • Includes a DB migration? -> add the area:migration label

Added websocket annotation for nginx ingress k8s
@hardillb
Copy link
Contributor

hardillb commented Jul 14, 2023

Hi,

As mentioned in the issue you have referenced, this should be already possible by passing the annotations to the helm chart when installing.

see:

https://github.com/flowforge/flowforge-driver-k8s/blob/a3b3a44e96df18ab3f40ac4c35cf3b4874fe2696/kubernetes.js#L160

This change would always add the annotation no matter what ingress controller was used. Any solution needs to work for all possible installations and not add unnecessary annotations.

If the proposed solution mentioned in #83 please add a comment explaining why.

@hardillb
Copy link
Contributor

Sorry, I'd forgotten that the annotation needs the service name, which can't be set globally with that annotations from the helm chart.

I will try and dig at the nginx ingress docs to see if there is more global solution, I know that the kubernetes version of the nginx ingress controller doesn't need these flags so hopefully there will be something we can set at a wider scope.

@dfulgham
Copy link
Contributor Author

I scoured the nginx docs (for a long while) and could not find a way to globally turn on websocket support, this is why I had to add it here.

@dfulgham
Copy link
Contributor Author

dfulgham commented Jul 16, 2023

@hardillb
If a string replacement method could be implemented, then we could pass something like

annotations:
"nginx.org/websocket-services": "{{safeName}}"

mustache style replacement for annotations meta data
removed hardcoded nginx annotation
@hardillb
Copy link
Contributor

Hi,

Nice idea, unfortunately it's not quiet that simple.

The service name is not always just the safeName. Kubernetes has slightly different rules for something, e.g. service names are a stricter version of the hostname rules and can't start with a number, where as the project name is allowed to start with a number, so we have the srv- prefix that gets applied if the name starts with a number. (This ended up being a fix when we ran into the problem, if we had known we would have added a prefix to all).

https://github.com/flowforge/flowforge-driver-k8s/blob/a3b3a44e96df18ab3f40ac4c35cf3b4874fe2696/kubernetes.js#L335C1-L347C2

Lines 336 and 344

So it can't just be a simple substitution, I'll have a look to see if we can expand on this. e.g. we could define a list of available substitutions and then we can do the specific mapping.

@dfulgham dfulgham changed the title Added support for websockets for nginx-ingress Added support for annotation substitutions Jul 17, 2023
@dfulgham
Copy link
Contributor Author

dfulgham commented Jul 17, 2023

We can change this to

annotations:
"nginx.org/websocket-services": "{{prefix}}{{safeName}}"

@hardillb
Copy link
Contributor

So it can't just be a simple substitution, I'll have a look to see if we can expand on this. e.g. we could define a list of available substitutions and then we can do the specific mapping.

Sorry, I should have been clearer here, I think rather than expose the whole project object and expect users to know about the prefix, it would be better to just have a list of available options e.g.

  • serviceName
  • instanceURL

We can document this simpler list in the helm chart README.md

That way if/when we rename things like project (which user facing is called an instance now) it doesn't break things.

@dfulgham
Copy link
Contributor Author

I've updated the PR with specific properties that would potentially be usable in annotations.

const exposedData = {
        serviceName: `${prefix}${project.safeName}`,
        instanceURL: url.href,
        instanceHost: url.host,
        instanceProtocol: url.protocol,
    }

Which can then be used:

...
   annotations:
      "nginx.org/websocket-services": "{{serviceName}}"
      ...

@hardillb
Copy link
Contributor

I think those are a sensible start to the token names.

If you can fix up the lint errors (which should be flagged on the "Files Changed" page or the details page of the failed tests we can get this merged

@hardillb
Copy link
Contributor

hardillb commented Jul 24, 2023

Need to make sure this gets documented in flowforge/helm before release

@hardillb hardillb merged commit da7995d into FlowFuse:main Jul 24, 2023
1 check passed
@dfulgham
Copy link
Contributor Author

Need to make sure this gets documented in flowforge/helm before release

Will also need to ensure the {{ replacements }} are accepted in the FlowForge Container as well.

@hardillb
Copy link
Contributor

Ahhh, that is going to be a problem, as it will have to be done in the helm chart templating and I'm not sure we can do replacements there

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

Successfully merging this pull request may close these issues.

None yet

2 participants