Skip to content

Commit

Permalink
FEATURE: Add etcd-metrics-proxy service (#18)
Browse files Browse the repository at this point in the history
* feat: support etcd-metrics-proxy service

* chore: update CHANGELOG.md

* docs: update terraform docs
  • Loading branch information
Downager authored Dec 6, 2022
1 parent 0c2b16b commit 455d04d
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 27 deletions.
72 changes: 67 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,78 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this
project adheres to [Semantic Versioning](http://semver.org/)


<a name="v1.19.16.2"></a>
## [v1.19.16.2] - 2022-09-29
FEATURES:
- add etcd-metrics-proxy service


<a name="v1.23.10.0"></a>
## [v1.23.10.0] - 2022-08-26

- change makefile
- upgrade test terraform version
- upgrade terraform to 1.2.0


<a name="v1.19.16.1"></a>
## [v1.19.16.1] - 2022-08-10

- fmt
- set ignition_file overwrite argumrnt to true
- upgrade provider to 2.1.2


<a name="v1.19.16.0"></a>
## [v1.19.16.0] - 2022-06-01



<a name="v1.1.3"></a>
## [v1.1.3] - 2022-04-10



<a name="v1.1.2"></a>
## [v1.1.2] - 2021-09-22



<a name="v1.1.1"></a>
## [v1.1.1] - 2021-09-21



<a name="v1.1.0"></a>
## [v1.1.0] - 2021-03-24



<a name="v1.0.1"></a>
## [v1.0.1] - 2020-12-07



<a name="v1.0.0"></a>
## v1.0.0 - 2020-10-22
BUG FIXES:
- only support Terraform v0.12.x ([#7](https://github.com/getamis/terraform-ignition-etcd/issues/7))
- fix deprecated interpolation

ENHANCEMENTS:
- add v1 changelog, and update Makefile ([#8](https://github.com/getamis/terraform-ignition-etcd/issues/8))
- update changelog config.yaml
- update README.md
- update README.md ([#3](https://github.com/getamis/terraform-ignition-etcd/issues/3))

BUG FIXES:
- only support Terraform v0.12.x ([#7](https://github.com/getamis/terraform-ignition-etcd/issues/7))
- fix deprecated interpolation


[Unreleased]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.0.0...HEAD
[Unreleased]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.19.16.2...HEAD
[v1.19.16.2]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.23.10.0...v1.19.16.2
[v1.23.10.0]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.19.16.1...v1.23.10.0
[v1.19.16.1]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.19.16.0...v1.19.16.1
[v1.19.16.0]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.1.3...v1.19.16.0
[v1.1.3]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.1.2...v1.1.3
[v1.1.2]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.1.1...v1.1.2
[v1.1.1]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.1.0...v1.1.1
[v1.1.0]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.0.1...v1.1.0
[v1.0.1]: https://github.com/getamis/terraform-ignition-etcd/compare/v1.0.0...v1.0.1
36 changes: 20 additions & 16 deletions docs/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ This document gives an overview of variables used in the Ignition of the etcd mo
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.2.0 |
| <a name="requirement_ignition"></a> [ignition](#requirement\_ignition) | ~> 1.2.1 |
| <a name="requirement_ignition"></a> [ignition](#requirement\_ignition) | 2.1.2 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 2.2.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_ignition"></a> [ignition](#provider\_ignition) | ~> 1.2.1 |
| <a name="provider_ignition"></a> [ignition](#provider\_ignition) | 2.1.2 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 2.2.0 |

## Modules
Expand All @@ -26,19 +26,21 @@ No modules.
| Name | Type |
|------|------|
| [random_uuid.etcd_data_fs_uuid](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/uuid) | resource |
| [ignition_disk.ectd_data](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/disk) | data source |
| [ignition_file.etcd_ca](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_client_cert](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_client_key](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_env](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_peer_cert](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_peer_key](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_server_cert](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_server_key](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_file.etcd_wrapper_sh](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/file) | data source |
| [ignition_filesystem.ectd_data](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/filesystem) | data source |
| [ignition_systemd_unit.etcd_data_mount](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/systemd_unit) | data source |
| [ignition_systemd_unit.etcd_service](https://registry.terraform.io/providers/community-terraform-providers/ignition/latest/docs/data-sources/systemd_unit) | data source |
| [ignition_disk.ectd_data](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/disk) | data source |
| [ignition_file.etcd_ca](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_client_cert](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_client_key](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_env](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_metrics_proxy_wrapper_sh](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_peer_cert](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_peer_key](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_server_cert](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_server_key](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_file.etcd_wrapper_sh](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/file) | data source |
| [ignition_filesystem.ectd_data](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/filesystem) | data source |
| [ignition_systemd_unit.etcd_data_mount](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/systemd_unit) | data source |
| [ignition_systemd_unit.etcd_metrics_proxy_service](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/systemd_unit) | data source |
| [ignition_systemd_unit.etcd_service](https://registry.terraform.io/providers/community-terraform-providers/ignition/2.1.2/docs/data-sources/systemd_unit) | data source |

## Inputs

Expand All @@ -48,15 +50,17 @@ No modules.
| <a name="input_certs"></a> [certs](#input\_certs) | The etcd certificates. | `map(string)` | `{}` | no |
| <a name="input_client_port"></a> [client\_port](#input\_client\_port) | etcd client communication port. | `number` | `2379` | no |
| <a name="input_cloud_provider"></a> [cloud\_provider](#input\_cloud\_provider) | The name of public cloud. | `string` | `"aws"` | no |
| <a name="input_containers"></a> [containers](#input\_containers) | Desired containers(etcd) repo and tag. | <pre>map(object({<br> repo = string<br> tag = string<br> }))</pre> | `{}` | no |
| <a name="input_containers"></a> [containers](#input\_containers) | Desired containers(etcd, etcd-metrics-proxy) repo and tag. | <pre>map(object({<br> repo = string<br> tag = string<br> }))</pre> | `{}` | no |
| <a name="input_data_path"></a> [data\_path](#input\_data\_path) | The path for data store. | `string` | `"/var/lib/etcd"` | no |
| <a name="input_device_name"></a> [device\_name](#input\_device\_name) | Which block device will attach to data path. | `string` | `"/dev/nvme1n1"` | no |
| <a name="input_discovery_service_srv"></a> [discovery\_service\_srv](#input\_discovery\_service\_srv) | DNS srv domain used to bootstrap the cluster. | `string` | n/a | yes |
| <a name="input_enable_metrics_proxy"></a> [enable\_metrics\_proxy](#input\_enable\_metrics\_proxy) | enable etcd-metrics-proxy to allow scrape metrics without etcd certificates. | `bool` | `true` | no |
| <a name="input_extra_flags"></a> [extra\_flags](#input\_extra\_flags) | The extra flags of etcd. The variables need to follow https://etcd.io/docs/v3.4.0/op-guide/configuration/. Do not use underline. | `map` | `{}` | no |
| <a name="input_log_level"></a> [log\_level](#input\_log\_level) | etcd log level, supports debug, info, warn, error, panic, or fatal | `string` | `"info"` | no |
| <a name="input_name"></a> [name](#input\_name) | Human-readable name for this member. | `string` | n/a | yes |
| <a name="input_peer_port"></a> [peer\_port](#input\_peer\_port) | etcd server to server port. | `number` | `2380` | no |
| <a name="input_pki_path"></a> [pki\_path](#input\_pki\_path) | The etcd certificates path | `string` | `"/etc/ssl/etcd"` | no |
| <a name="input_proxy_port"></a> [proxy\_port](#input\_proxy\_port) | etcd-metrics-proxy expose port. | `number` | `2381` | no |

## Outputs

Expand Down
19 changes: 19 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ data "ignition_file" "etcd_env" {
content = templatefile("${path.module}/templates/config.env.tpl", {
image_repo = local.containers["etcd"].repo
image_tag = local.containers["etcd"].tag
proxy_image_repo = local.containers["etcd_metrics_proxy"].repo
proxy_image_tag = local.containers["etcd_metrics_proxy"].tag
cloud_provider = var.cloud_provider
user_id = var.cert_file_owner["uid"]
cluster_name = var.name
Expand All @@ -27,6 +29,7 @@ data "ignition_file" "etcd_env" {
scheme = "https"
client_port = var.client_port
peer_port = var.peer_port
proxy_port = var.proxy_port
extra_flags = local.extra_flags
})
}
Expand All @@ -37,3 +40,19 @@ data "ignition_systemd_unit" "etcd_service" {
enabled = true
content = templatefile("${path.module}/templates/etcd.service.tpl", {})
}

data "ignition_file" "etcd_metrics_proxy_wrapper_sh" {
overwrite = true
path = "/opt/etcd/bin/etcd-metrics-proxy-wrapper"
mode = 500

content {
content = file("${path.module}/scripts/etcd-metrics-proxy-wrapper.sh")
}
}

data "ignition_systemd_unit" "etcd_metrics_proxy_service" {
name = "etcd-metrics-proxy.service"
enabled = true
content = templatefile("${path.module}/templates/etcd-metrics-proxy.service.tpl", {})
}
17 changes: 12 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
output "systemd_units" {
value = [
value = concat([
data.ignition_systemd_unit.etcd_service.rendered,
data.ignition_systemd_unit.etcd_data_mount.rendered
]
data.ignition_systemd_unit.etcd_data_mount.rendered,
],
var.enable_metrics_proxy ? [
data.ignition_systemd_unit.etcd_metrics_proxy_service.rendered
] : []
)
}

output "files" {
value = [
value = concat([
data.ignition_file.etcd_env.rendered,
data.ignition_file.etcd_wrapper_sh.rendered,
data.ignition_file.etcd_ca.rendered,
Expand All @@ -16,7 +20,10 @@ output "files" {
data.ignition_file.etcd_server_key.rendered,
data.ignition_file.etcd_peer_cert.rendered,
data.ignition_file.etcd_peer_key.rendered
]
],
var.enable_metrics_proxy ? [
data.ignition_file.etcd_metrics_proxy_wrapper_sh.rendered
] : [])
}

output "filesystems" {
Expand Down
44 changes: 44 additions & 0 deletions scripts/etcd-metrics-proxy-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash
# Wrapper for launching etcd-metrics-proxy via docker.

set -e

function require_ev_all() {
for rev in $@ ; do
if [[ -z "${!rev}" ]]; then
echo "${rev}" is not set
exit 1
fi
done
}

ETCD_METRICS_PROXY_IMAGE=${ETCD_METRICS_PROXY_IMAGE_REPO}:${ETCD_METRICS_PROXY_IMAGE_TAG}

if [[ $CLOUD_PROVIDER == "aws" ]]; then
export HOSTNAME=$(curl -s http://169.254.169.254/latest/meta-data/local-hostname)
export HOST_IP=$(curl -s http://169.254.169.254/latest/meta-data/local-ipv4)
fi

[[ ! -n "$HOSTNAME" ]] && export HOSTNAME=$(hostname)
[[ ! -n "$HOST_IP" ]] && export HOST_IP=$(ip -o route get 8.8.8.8 | sed -e 's/^.* src \([^ ]*\) .*$/\1/')

DOCKER_RUN_ARGS="${DOCKER_RUN_ARGS} ${DOCKER_OPTS}"

DOCKER="${DOCKER:-/usr/bin/docker}"
set -x
exec ${DOCKER} run \
-v ${ETCD_CERT_PATH}:${ETCD_CERT_PATH}:ro \
--env-file=/etc/etcd/config.env \
--net=host \
--pid=host \
--user=${USER_ID} \
--name=etcd-metrics-proxy \
${DOCKER_RUN_ARGS} \
${ETCD_METRICS_PROXY_IMAGE} \
-etcd-ca="${ETCD_TRUSTED_CA_FILE}" \
-etcd-cert="${ETCD_CERT_FILE}" \
-etcd-key="${ETCD_KEY_FILE}" \
-port="${ETCD_METRICS_PROXY_PORT}" \
-upstream-host="${HOST_IP}" \
-upstream-port="${CLIENT_PORT}" \
-upstream-server-name="${HOSTNAME}"
6 changes: 6 additions & 0 deletions templates/config.env.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ SCHEME=${scheme}
USER_ID=${user_id}
CLOUD_PROVIDER=${cloud_provider}

# ETCD METRICS PROXY CONFIGURATION
ETCD_METRICS_PROXY_IMAGE_REPO=${proxy_image_repo}
ETCD_METRICS_PROXY_IMAGE_TAG=${proxy_image_tag}
ETCD_METRICS_PROXY_PORT=${proxy_port}


# ETCD OFFICIAL CONFIGURATION
ETCD_CERT_PATH=${pki_path}
ETCD_CERT_FILE=${pki_path}/server.crt
Expand Down
16 changes: 16 additions & 0 deletions templates/etcd-metrics-proxy.service.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=etcd-metrics-proxy service
Requires=network-online.target

[Service]
Environment="PATH=/opt/bin:/opt/etcd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin"
EnvironmentFile=/etc/etcd/config.env
ExecStartPre=-/usr/bin/docker rm -f etcd-metrics-proxy
ExecStart=/opt/etcd/bin/etcd-metrics-proxy-wrapper
ExecStop=-/usr/bin/docker stop etcd-metrics-proxy

Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
13 changes: 12 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ variable "name" {
}

variable "containers" {
description = "Desired containers(etcd) repo and tag."
description = "Desired containers(etcd, etcd-metrics-proxy) repo and tag."
type = map(object({
repo = string
tag = string
Expand Down Expand Up @@ -57,6 +57,11 @@ variable "peer_port" {
default = 2380
}

variable "proxy_port" {
description = "etcd-metrics-proxy expose port."
default = 2381
}

variable "data_path" {
description = "The path for data store."
type = string
Expand All @@ -78,4 +83,10 @@ variable "log_level" {
variable "extra_flags" {
description = "The extra flags of etcd. The variables need to follow https://etcd.io/docs/v3.4.0/op-guide/configuration/. Do not use underline."
default = {}
}

variable "enable_metrics_proxy" {
description = "enable etcd-metrics-proxy to allow scrape metrics without etcd certificates."
type = bool
default = true
}
4 changes: 4 additions & 0 deletions variables_defaults.tf
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ locals {
etcd = {
repo = "quay.io/coreos/etcd"
tag = "v3.5.2"
},
etcd_metrics_proxy = {
repo = "quay.io/amis/etcd-metrics-proxy"
tag = "v0.1.0"
}
}, var.containers)

Expand Down

0 comments on commit 455d04d

Please sign in to comment.