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

Add support for using cert manager #131

Merged
merged 2 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ driver:
projectNamespace: flowforge
cloudProvider: aws
privateCA: ff-ca-certs
certManagerIssuer: lets-encrypt
k8sDelay: 1000
k8sRetries: 10
```
Expand All @@ -28,6 +29,7 @@ should run on
- `cloudProvider` can be left unset for none `aws` deployments. This triggers the adding of
AWS EKS specific annotation for ALB Ingress.
- `privateCA` name of ConfigMap holding PEM CA Cert Bundle (file name `certs.pem`) Optional
- `certManagerIssuer` name of the ClusterIssuer to use to create HTTPS certs for instances (default not set)
- `k8sRetries` how many times to retry actions against the K8s API
- `k8sDelay` how long to wait (in ms) between retries to the K8s API

Expand Down
28 changes: 28 additions & 0 deletions kubernetes.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,18 @@ const createIngress = async (project, options) => {

const localIngress = JSON.parse(JSON.stringify(ingressTemplate))

if (this._certManagerIssuer) {
localIngress.metadata.annotations['cert-manager.io/cluster-issuer'] = this._certManagerIssuer
localIngress.spec.tls = [
{
hosts: [
url.host
],
secretName: project.safeName
}
]
}

// process annotations with potential replacements
Object.keys(localIngress.metadata.annotations).forEach((key) => {
localIngress.metadata.annotations[key] = mustache(localIngress.metadata.annotations[key], exposedData)
Expand Down Expand Up @@ -593,6 +605,7 @@ module.exports = {
this._namespace = this._app.config.driver.options.projectNamespace || 'flowforge'
this._k8sDelay = this._app.config.driver.options.k8sDelay || 1000
this._k8sRetries = this._app.config.driver.options.k8sRetries || 10
this._certManagerIssuer = this._app.config.driver.options._certManagerIssuer

const kc = new k8s.KubeConfig()

Expand Down Expand Up @@ -753,6 +766,14 @@ module.exports = {
this._app.log.error(`[k8s] Project ${project.id} - error deleting ingress: ${err.toString()}`)
}

if (this._certManagerIssuer) {
try {
await this._k8sApi.deleteNamespacedSecret(project.safeName, this._namespace)
} catch (err) {
this._app.log.error(`[k8s] Project ${project.id} - error deleting tls secret: ${err.toString()}`)
}
}

// Note that, regardless, the main objective is to delete deployment (runnable)
// Even if some k8s resources like ingress or service are still not deleted (maybe because of
// k8s service latency), the most important thing is to get to deployment.
Expand Down Expand Up @@ -851,6 +872,13 @@ module.exports = {
} catch (err) {
this._app.log.error(`[k8s] Project ${project.id} - error deleting ingress: ${err.toString()}`)
}
if (this._certManagerIssuer) {
try {
await this._k8sApi.deleteNamespacedSecret(project.safeName, this._namespace)
} catch (err) {
this._app.log.error(`[k8s] Project ${project.id} - error deleting tls secret: ${err.toString()}`)
}
}
try {
if (project.safeName.match(/^[0-9]/)) {
await this._k8sApi.deleteNamespacedService('srv-' + project.safeName, this._namespace)
Expand Down