-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/polyseam/cndi
- Loading branch information
Showing
8 changed files
with
173 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
src/outputs/core-applications/external-dns.application.yaml.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { getYAMLString } from "src/utils.ts"; | ||
import { CNDIConfig } from "src/types.ts"; | ||
import type { CNDIProvider, ExternalDNSProvider } from "src/types.ts"; | ||
import { EXTERNAL_DNS_VERSION } from "consts"; | ||
|
||
const DEFAULT_DESTINATION_SERVER = "https://kubernetes.default.svc"; | ||
const DEFAULT_ARGOCD_API_VERSION = "argoproj.io/v1alpha1"; | ||
const DEFAULT_HELM_VERSION = "v3"; | ||
const DEFAULT_PROJECT = "default"; | ||
const DEFAULT_FINALIZERS = ["resources-finalizer.argocd.argoproj.io"]; | ||
|
||
const getDefaultExternalDNSProviderForCNDIProvider = ( | ||
cndiProvider: CNDIProvider, | ||
): ExternalDNSProvider => { | ||
if (cndiProvider === "gcp") return "google"; | ||
if (cndiProvider === "dev") return "aws"; | ||
return cndiProvider; | ||
}; | ||
|
||
export default function getExternalDNSApplicationManifest( | ||
cndi_config: CNDIConfig, | ||
): string { | ||
const releaseName = "external-dns"; | ||
const cndiProvider = cndi_config.provider; | ||
|
||
const domain_filters = | ||
cndi_config?.infrastructure?.cndi?.external_dns?.domain_filters || []; | ||
|
||
const externalDNSProvider = // aws | ||
cndi_config?.infrastructure?.cndi?.external_dns?.provider || | ||
getDefaultExternalDNSProviderForCNDIProvider(cndiProvider); | ||
|
||
const externalDNSCannotUseEnvVars = [ | ||
"alibaba", | ||
"azure", | ||
"azure-private-dns", | ||
"transip", | ||
"oci", | ||
]; | ||
|
||
type ExternalDNSValues = { | ||
provider: ExternalDNSProvider; | ||
domainFilters: Array<string>; | ||
[key: string]: unknown; | ||
extraEnvVarsSecret?: string; | ||
}; | ||
|
||
const values: ExternalDNSValues = { | ||
...cndi_config?.infrastructure?.cndi?.external_dns?.values, | ||
provider: externalDNSProvider, | ||
domainFilters: domain_filters, | ||
}; | ||
|
||
if (externalDNSCannotUseEnvVars.includes(externalDNSProvider)) { | ||
// this dns provider uses another method for authentication, probably volume mounts | ||
values[externalDNSProvider] = { | ||
secretName: "external-dns", | ||
}; | ||
} else { | ||
values.extraEnvVarsSecret = "external-dns"; | ||
} | ||
|
||
const manifest = { | ||
apiVersion: DEFAULT_ARGOCD_API_VERSION, | ||
kind: "Application", | ||
metadata: { | ||
name: releaseName, | ||
finalizers: DEFAULT_FINALIZERS, | ||
labels: { name: releaseName }, | ||
}, | ||
spec: { | ||
project: DEFAULT_PROJECT, | ||
source: { | ||
repoURL: "https://charts.bitnami.com/bitnami", | ||
chart: "external-dns", | ||
helm: { | ||
version: DEFAULT_HELM_VERSION, | ||
values: getYAMLString(values), | ||
}, | ||
targetRevision: EXTERNAL_DNS_VERSION, | ||
}, | ||
destination: { | ||
server: DEFAULT_DESTINATION_SERVER, | ||
namespace: "external-dns", | ||
}, | ||
syncPolicy: { | ||
automated: { | ||
prune: true, | ||
selfHeal: true, | ||
allowEmpty: false, | ||
}, | ||
syncOptions: [ | ||
"Validate=false", | ||
"CreateNamespace=true", | ||
"PrunePropagationPolicy=foreground", | ||
"PruneLast=false", | ||
], | ||
retry: { | ||
limit: 10, | ||
backoff: { | ||
duration: "5s", | ||
factor: 2, | ||
maxDuration: "4m", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
return getYAMLString(manifest); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters