-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update keda terraform to latest patterns (#2623)
* update keda terraform to latest patterns Signed-off-by: James Petersen <[email protected]> * use tfgen with keda Signed-off-by: James Petersen <[email protected]> * cross product Signed-off-by: James Petersen <[email protected]> * add some comments on locals Signed-off-by: James Petersen <[email protected]> * properly set target repo Signed-off-by: James Petersen <[email protected]> * remove hard coded bounds Signed-off-by: James Petersen <[email protected]> --------- Signed-off-by: James Petersen <[email protected]>
- Loading branch information
Showing
11 changed files
with
229 additions
and
144 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,39 @@ | ||
variable "name" { | ||
description = "Component name (e.g. keda, keda-adapter, keda-admission-webhooks)" | ||
} | ||
|
||
variable "package" { | ||
description = "Package name (e.g. keda-2.14)" | ||
} | ||
|
||
variable "extra_packages" { | ||
description = "Additional packages to install." | ||
type = list(string) | ||
default = [] | ||
} | ||
|
||
locals { | ||
entrypoints = { | ||
"keda" = "/usr/bin/keda --zap-log-level=info --zap-encoder=console", | ||
"keda-adapter" = "/usr/bin/keda-adapter --secure-port=6443 --logtostderr=true --v=0", | ||
"keda-admission-webhooks" = "/usr/bin/keda-admission-webhooks --zap-log-level=info --zap-encoder=console", | ||
} | ||
} | ||
|
||
module "accts" { source = "../../../tflib/accts" } | ||
|
||
output "config" { | ||
value = jsonencode({ | ||
contents = { | ||
packages = concat([ | ||
var.package, // keda, keda-adapter, keda-admission-webhooks | ||
"busybox", | ||
"keda-compat", | ||
], var.extra_packages) | ||
} | ||
accounts = module.accts.block | ||
entrypoint = { | ||
command = local.entrypoints[var.name] | ||
} | ||
}) | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,55 +1,127 @@ | ||
locals { | ||
# List of all components | ||
components = toset([ | ||
"controller", | ||
"adapter", | ||
"webhooks", | ||
"keda", | ||
"keda-adapter", | ||
"keda-admission-webhooks", | ||
]) | ||
|
||
packages = merge( | ||
{ for k in local.components : k => k }, | ||
{ | ||
"controller" = "keda" | ||
"adapter" = "keda-adapter" | ||
"webhooks" = "keda-admission-webhooks" | ||
}, | ||
) | ||
# List of versions. | ||
# | ||
# When version metadata is not available this will look like | ||
# "versions" = [""] | ||
# | ||
# When version metadata is available this will look like | ||
# "versions" = ["2.13", "2.14"] | ||
# | ||
# Order matters here, we want the latest version to be the last element in | ||
# the list so it's tagged with latest. | ||
versions = [ | ||
for _, version_metadata in module.versions.versions : lookup(version_metadata, "version", "") | ||
] | ||
|
||
repositories = merge( | ||
{ for k in local.components : k => k }, | ||
{ | ||
"controller" = var.target_repository | ||
"adapter" = "${var.target_repository}-adapter" | ||
"webhooks" = "${var.target_repository}-admission-webhooks" | ||
}, | ||
) | ||
# Cross product of versions and components | ||
# | ||
# When version metadata is not available this will look like | ||
# "component_versions" = { | ||
# "keda" = { | ||
# "component" = "keda" | ||
# "is_latest" = true | ||
# "main" = "keda" | ||
# } | ||
# "keda-adapter" = { | ||
# "component" = "keda-adapter" | ||
# "is_latest" = true | ||
# "main" = "keda-adapter" | ||
# } | ||
# ... | ||
# } | ||
# | ||
# When version metadata is not available this will look like | ||
# "component_versions" = { | ||
# "keda2.14" = { | ||
# "component" = "keda" | ||
# "is_latest" = true | ||
# "main" = "keda-2.14" | ||
# } | ||
# "keda-adapter2.14" = { | ||
# "component" = "keda-adapter" | ||
# "is_latest" = true | ||
# "main" = "keda-2.14-adapter" | ||
# } | ||
# ... | ||
# } | ||
component_versions = merge([ | ||
for component in local.components : merge([ | ||
for key, version_metadata in module.versions.versions : { | ||
|
||
# This sets the key to `$component` when version data does not exist and | ||
# `$component$version` when version data exists. We just smash the two | ||
# together to make it easier to access in subsequent modules. | ||
format("%s%s", component, lookup(version_metadata, "version", "")) : { | ||
is_latest = version_metadata.is_latest | ||
component = component | ||
|
||
# Strips off `keda` or `keda-` from the components and joins with the | ||
# version_metadata key which will be `keda` when version data does not | ||
# exist and `keda-$version` when version data exists | ||
main = join("-", compact([key, trimprefix(replace(component, "keda", ""), "-")])) | ||
} | ||
} | ||
]...) | ||
]...) | ||
} | ||
|
||
variable "target_repository" { | ||
description = "The docker repo into which the image and attestations should be published." | ||
} | ||
|
||
module "latest" { | ||
for_each = local.repositories | ||
# Versions module plugs into to the version metadata for the top-level package | ||
module "versions" { | ||
source = "../../tflib/versions" | ||
package = basename(path.module) | ||
} | ||
|
||
# Need a config for every version of every component | ||
module "config" { | ||
for_each = local.component_versions | ||
source = "./config" | ||
name = each.value.component | ||
package = each.value.main | ||
} | ||
|
||
# Need a publisher invocation for every version of every component | ||
module "versioned" { | ||
for_each = local.component_versions | ||
source = "../../tflib/publisher" | ||
name = basename(path.module) | ||
target_repository = each.value | ||
config = file("${path.module}/configs/latest.${each.key}.apko.yaml") | ||
target_repository = replace(var.target_repository, "/keda", "/${each.value.component}") | ||
config = module.config[each.key].config | ||
build-dev = true | ||
|
||
main_package = each.value.main | ||
update-repo = each.value.is_latest | ||
} | ||
|
||
module "test-latest" { | ||
source = "./tests" | ||
digests = { for k, v in module.latest : k => v.image_ref } | ||
# Tests need to be grouped by version. We want to test all components of | ||
# the same version at the same time. | ||
module "test" { | ||
for_each = toset(local.versions) | ||
source = "./tests" | ||
|
||
digests = { for component in local.components : component => module.versioned["${component}${each.value}"].image_ref } | ||
name = "${basename(path.module)}${each.value}" | ||
} | ||
|
||
# Tagger should be grouped by components. We want to tag multiple versions of | ||
# the same component so we iterate over the versions list for each component | ||
module "tagger" { | ||
for_each = local.components | ||
source = "../../tflib/tagger" | ||
|
||
depends_on = [module.test-latest] | ||
depends_on = [module.test] | ||
|
||
tags = { | ||
"latest" = module.latest[each.key].image_ref | ||
"latest-dev" = module.latest[each.key].dev_ref | ||
} | ||
tags = merge( | ||
[for version in local.versions : module.versioned["${each.value}${version}"].latest_tag_map]... | ||
) | ||
} |
Oops, something went wrong.