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

fix: Fix health monitor and bootstrapping #7

Merged
merged 1 commit into from
Aug 8, 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: 1 addition & 1 deletion bootstrap/cloudflared/config.yml.tfpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Name of the tunnel you want to run
tunnel: example-tunnel
tunnel: ${tunnel_id}
credentials-file: /etc/cloudflared/creds/credentials.json
# Serves the metrics server under /metrics and the readiness server under /ready
metrics: 0.0.0.0:${metrics_port}
Expand Down
22 changes: 22 additions & 0 deletions bootstrap/cloudflared/credentials.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
locals {
credentials_secret_name = "tunnel-credentials"
}

resource "kubernetes_secret" "tunnel_credentials" {
metadata {
namespace = var.namespace
name = local.credentials_secret_name
}

data = {
"credentials.json" = jsonencode({
"AccountTag" : var.account_tag,
"TunnelSecret" : var.tunnel_secret,
"TunnelID" : var.tunnel_id
})
}

type = "Opaque"
}


3 changes: 2 additions & 1 deletion bootstrap/cloudflared/deployment.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resource "kubernetes_deployment" "cloudflared" {
wait_for_rollout = false
depends_on = [kubernetes_secret.tunnel_credentials]

metadata {
name = "cloudflared"
Expand Down Expand Up @@ -86,7 +87,7 @@ resource "kubernetes_deployment" "cloudflared" {
volume {
name = "creds"
secret {
secret_name = var.credentials_secret_name
secret_name = local.credentials_secret_name
}
}

Expand Down
9 changes: 7 additions & 2 deletions bootstrap/cloudflared/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ variable "resources" {
}
}

variable "credentials_secret_name" {
variable "account_tag" {
type = string
default = "Name of the K8s secret where the credentials.json is stored."
default = "AccountTag, written on credentials json."
}

variable "tunnel_secret" {
type = string
default = "TunnelSecret, written on credentials json."
}
25 changes: 13 additions & 12 deletions bootstrap/main.tf
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
resource "kubernetes_namespace" "namespace" {
resource "kubernetes_namespace_v1" "namespace" {
metadata {
name = var.namespace
}
}

module "feature" {
depends_on = [kubernetes_namespace.namespace]
depends_on = [kubernetes_namespace_v1.namespace]
source = "./feature"

namespace = var.namespace
Expand All @@ -25,7 +25,7 @@ module "configs" {
}

module "services" {
depends_on = [kubernetes_namespace.namespace]
depends_on = [kubernetes_namespace_v1.namespace]
for_each = { for network in var.networks : "${network}" => network }
source = "./service"

Expand All @@ -34,7 +34,7 @@ module "services" {
}

module "proxy" {
depends_on = [kubernetes_namespace.namespace]
depends_on = [kubernetes_namespace_v1.namespace]
source = "./proxy"

namespace = var.namespace
Expand All @@ -47,14 +47,15 @@ module "cloudflared" {
depends_on = [module.proxy]
source = "./cloudflared"

namespace = var.namespace
tunnel_id = var.cloudflared_tunnel_id
hostname = var.cloudflared_hostname
credentials_secret_name = var.cloudflared_credentials_secret_name
metrics_port = var.cloudflared_metrics_port
image_tag = var.cloudflared_image_tag
replicas = var.cloudflared_replicas
resources = var.cloudflared_resources
namespace = var.namespace
tunnel_id = var.cloudflared_tunnel_id
hostname = "${var.extension_subdomain}.${var.dns_zone}"
tunnel_secret = var.cloudflared_tunnel_secret
account_tag = var.cloudflared_account_tag
metrics_port = var.cloudflared_metrics_port
image_tag = var.cloudflared_image_tag
replicas = var.cloudflared_replicas
resources = var.cloudflared_resources
}

module "instances" {
Expand Down
9 changes: 5 additions & 4 deletions bootstrap/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ variable "cloudflared_tunnel_id" {
type = string
}

variable "cloudflared_hostname" {
type = string
variable "cloudflared_tunnel_secret" {
type = string
description = "TunnelSecret, written on credentials file."
}

variable "cloudflared_credentials_secret_name" {
variable "cloudflared_account_tag" {
type = string
description = "Name of the secret where credentials.json is saved."
description = "AccountTag, written on credentials file."
}

variable "cloudflared_metrics_port" {
Expand Down
4 changes: 2 additions & 2 deletions proxy/src/proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ impl UtxoRpcProxy {
async fn respond_health(&self, session: &mut Session, ctx: &mut Context) {
ctx.is_health_request = true;
session.set_keepalive(None);
let header = Box::new(ResponseHeader::build(200, None).unwrap());
session.write_response_header(header, true).await.unwrap();
session
.write_response_body(Some(Bytes::from("OK")), true)
.await
.unwrap();
let header = Box::new(ResponseHeader::build(200, None).unwrap());
session.write_response_header(header, true).await.unwrap();
}
}

Expand Down
Loading