Skip to content

Commit b327a0d

Browse files
kunzesesce-taid
authored andcommitted
feat: remove ABFS data disk from the server module
With the introduction of the new GCS/Spanner backend, the 10TB data disk on the ABFS server is now obsolete. This change will delete and recreate the ABFS server. Please make sure to update to v0.5.0 first. PiperOrigin-RevId: 778541579
1 parent ba1e18d commit b327a0d

18 files changed

+176
-192
lines changed

files/cloud-init/scripts/abfs_container.env.tftpl

Lines changed: 0 additions & 50 deletions
This file was deleted.

files/cloud-init/scripts/abfs_docker_warmup.sh renamed to files/scripts/abfs_docker_warmup.sh

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@
1616
set -e
1717

1818
source "$(dirname "$0")/abfs_base.sh"
19-
# TODO: If running as a non-root user add to docker group
20-
#usermod -a -G docker abfs
21-
#chown -R -c abfs:abfs /home/abfs-server
19+
2220
# Defend against docker issues potentially causing the boot disk to fill up
2321
if [[ "$(df /mnt/stateful_partition --output=pcent | egrep -o '[0-9]+')" -ge 90 ]]; then
24-
docker system prune -a -f || echo "docker system prune failed, continuing with GCR warmup"
22+
docker system prune -a -f \
23+
|| echo "docker system prune failed, continuing with GCR warmup"
2524
fi
2625
AR_HOSTS=("us-docker.pkg.dev","europe-docker.pkg.dev","europe-north1-docker.pkg.dev","europe-west3-docker.pkg.dev")
2726
docker-credential-gcr configure-docker --registries "${AR_HOSTS[*]}"
28-
# TODO: Support pulling multiple images
29-
# TODO: Check VM region in metadata and pull from nearest repo
3027
docker pull "${ABFS_DOCKER_IMAGE_URI}"
3128

32-
if [[ "$(docker image ls -q "${ABFS_DOCKER_IMAGE_URI}")" == "" ]]; then
29+
if [[ -z "$(docker image ls -q "${ABFS_DOCKER_IMAGE_URI}")" ]]; then
3330
while ! 'docker image inspect -f true "${ABFS_DOCKER_IMAGE_URI}" &> /dev/null'; do
3431
echo "waiting for image to be fully pulled"
3532
sleep 1

files/cloud-init/scripts/abfs_server.sh renamed to files/scripts/abfs_server.sh

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,17 @@
1515

1616
source "$(dirname "$0")/abfs_base.sh"
1717

18-
# TODO: think about which additional Docker run args might be needed...
19-
# --memory, --memory-swap, --ulimit, --oom-score-adj
2018
DOCKER_RUN_ARGS=(--privileged \
2119
--cap-add=all \
2220
--pid=host \
2321
--env-file /var/run/abfs/abfs_container.env \
24-
--publish 50051:50051 \
25-
--volume ${DATADISK_MOUNTPOINT}:/abfs-storage
22+
--publish 50051:50051
2623
)
27-
# TODO: pass abfs args to the VM dynmaically
24+
25+
if [[ -n "${DATADISK_MOUNTPOINT}" ]]; then
26+
DOCKER_RUN_ARGS+=(--volume ${DATADISK_MOUNTPOINT}:/abfs-storage)
27+
fi
28+
2829
docker run --name=abfs-server --log-driver=journald \
2930
"${DOCKER_RUN_ARGS[@]}" "${ABFS_DOCKER_IMAGE_URI}" \
3031
${ABFS_CMD}

files/cloud-init/abfs-server.service renamed to files/templates/abfs-server.service.tftpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
[Unit]
1616
Description=Start an ABFS server
17+
%{ if type == "uploader" ~}
1718
Wants=abfs-datadisk-ready.target
1819
After=abfs-datadisk-ready.target
20+
%{ endif ~}
1921
Wants=abfs-docker-warmup.service
2022
After=abfs-docker-warmup.service
2123

files/cloud-init/scripts/abfs_base.sh.tftpl renamed to files/templates/abfs_base.sh.tftpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515

16-
declare -r DATADISK_MOUNTPOINT="${abfs_datadisk_mountpoint}"
17-
declare -r ABFS_DOCKER_IMAGE_URI="${abfs_docker_image_uri}"
18-
declare -r ABFS_CMD="${abfs_command}"
16+
%{ for env_key, env_value in envs ~}
17+
declare -r ${env_key}="${env_value}"
18+
%{ endfor ~}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Copyright 2025 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
# Environment variables passed to the running ABFS server container
16+
%{ for env_key, env_value in envs ~}
17+
${env_key}=${env_value}
18+
%{ endfor ~}

modules/server/README.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ For example usage, please check the following [example](../../examples/simple/ma
1111

1212
| Name | Description | Type | Default | Required |
1313
|------|-------------|------|---------|:--------:|
14+
| abfs\_bootdisk\_size\_gb | Size in GB for the ABFS bootdisk that will be attached to the VM | `number` | `100` | no |
15+
| abfs\_bootdisk\_type | The PD regional disk type to use for the ABFS bootdisk | `string` | `"pd-ssd"` | no |
1416
| abfs\_bucket\_location | The location of the ABFS bucket (https://cloud.google.com/storage/docs/locations). | `string` | n/a | yes |
1517
| abfs\_bucket\_name | The name of the ABFS bucket. | `string` | `"abfs"` | no |
16-
| abfs\_datadisk\_mountpoint | Location for mounting the ABFS datadisk on the host VM | `string` | `"/mnt/disks/abfs-data"` | no |
17-
| abfs\_datadisk\_name | A name for the ABFS datadisk that will be attached to the VM. Note, this does not affect the mounting of the disk - the device name is always set to "abfs-server-storage" | `string` | `"abfs-datadisk"` | no |
18-
| abfs\_datadisk\_size\_gb | Size in GB for the ABFS datadisk that will be attached to the VM | `number` | `10000` | no |
19-
| abfs\_datadisk\_type | The PD regional disk type to use for the ABFS datadisk | `string` | `"pd-ssd"` | no |
2018
| abfs\_docker\_image\_uri | Docker image URI for the ABFS server | `string` | n/a | yes |
2119
| abfs\_license | ABFS license (JSON) | `string` | n/a | yes |
2220
| abfs\_server\_cos\_image\_ref | Reference to the COS boot image to use for the ABFS server | `string` | `"projects/cos-cloud/global/images/family/cos-109-lts"` | no |

modules/server/main.tf

Lines changed: 67 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -13,41 +13,60 @@
1313
# limitations under the License.
1414

1515
locals {
16-
cloud_init_path = "${path.module}/../../files/cloud-init"
17-
goog_cm_deployment_name = var.goog_cm_deployment_name == "" ? "" : "${var.goog_cm_deployment_name}-"
18-
abfs_datadisk_device_name = "abfs-server-storage"
19-
static_script_files = [for filename in fileset("${local.cloud_init_path}/scripts/", "*.sh") :
20-
{
21-
path = "/var/lib/abfs/bin/${filename}"
22-
permissions = "0755"
23-
owner = "root"
24-
encoding = "gzip+base64"
25-
content = base64gzip(file("${local.cloud_init_path}/scripts/${filename}"))
26-
}]
27-
systemd_files = [for filename in fileset(local.cloud_init_path, "abfs*") :
28-
{
29-
path = "/etc/systemd/system/${filename}"
30-
permissions = "0644"
31-
owner = "root"
32-
encoding = "gzip+base64"
33-
content = base64gzip(file("${local.cloud_init_path}/${filename}"))
34-
}]
16+
common_files_root = "${path.module}/../../files"
17+
goog_cm_deployment_name = var.goog_cm_deployment_name == "" ? "" : "${var.goog_cm_deployment_name}-"
18+
abfs_server_name = "${local.goog_cm_deployment_name}${var.abfs_server_name}"
19+
20+
static_script_files = flatten([
21+
for folder in ["${local.common_files_root}/scripts", "${path.module}/files/scripts"] : [
22+
for filename in fileset(folder, "*.sh") :
23+
{
24+
path = "/var/lib/abfs/bin/${filename}"
25+
permissions = "0755"
26+
owner = "root"
27+
encoding = "gzip+base64"
28+
content = base64gzip(file("${folder}/${filename}"))
29+
}
30+
]
31+
])
32+
33+
systemd_files = flatten([
34+
for folder in ["${local.common_files_root}/systemd", "${path.module}/files/systemd"] : [
35+
for filename in fileset(folder, "*") :
36+
{
37+
path = "/etc/systemd/system/${filename}"
38+
permissions = "0644"
39+
owner = "root"
40+
encoding = "gzip+base64"
41+
content = base64gzip(file("${folder}/${filename}"))
42+
}
43+
]
44+
])
45+
3546
runcmd = [
3647
"systemctl daemon-reload",
37-
"systemctl enable abfs-datadisk.path",
3848
"systemctl restart abfs-docker-warmup.service",
3949
"systemctl is-active -q abfs-server.service || systemctl start --no-block abfs-server.service",
4050
"systemctl is-active -q fluent-bit.service || systemctl start --no-block fluent-bit.service",
4151
"systemctl is-active -q node-problem-detector.service || systemctl start --no-block node-problem-detector.service"
4252
]
53+
4354
bootcmd = [
4455
"echo 'cloud-init bootcmd'"
4556
]
4657
}
4758

59+
resource "google_compute_disk" "abfs_server_bootdisk" {
60+
name = "${local.abfs_server_name}-bootdisk"
61+
zone = var.zone
62+
image = var.abfs_server_cos_image_ref
63+
size = var.abfs_bootdisk_size_gb
64+
type = var.abfs_bootdisk_type
65+
}
66+
4867
resource "google_compute_instance" "abfs_server" {
4968
project = var.project_id
50-
name = "${local.goog_cm_deployment_name}${var.abfs_server_name}"
69+
name = local.abfs_server_name
5170
machine_type = var.abfs_server_machine_type
5271
zone = var.zone
5372

@@ -58,9 +77,7 @@ resource "google_compute_instance" "abfs_server" {
5877
}
5978

6079
boot_disk {
61-
initialize_params {
62-
image = var.abfs_server_cos_image_ref
63-
}
80+
source = google_compute_disk.abfs_server_bootdisk.name
6481
}
6582

6683
network_interface {
@@ -76,29 +93,6 @@ resource "google_compute_instance" "abfs_server" {
7693
abfs-license = base64encode(var.abfs_license)
7794
user-data = data.cloudinit_config.abfs_server.rendered
7895
}
79-
80-
lifecycle {
81-
ignore_changes = [attached_disk]
82-
}
83-
}
84-
85-
resource "google_compute_disk" "abfs_datadisk" {
86-
project = var.project_id
87-
name = "${local.goog_cm_deployment_name}${var.abfs_datadisk_name}"
88-
size = var.abfs_datadisk_size_gb
89-
zone = var.zone
90-
type = var.abfs_datadisk_type
91-
92-
lifecycle {
93-
# prevent_destroy = true
94-
}
95-
}
96-
97-
resource "google_compute_attached_disk" "abfs_datadisk_attachment" {
98-
project = var.project_id
99-
disk = google_compute_disk.abfs_datadisk.id
100-
instance = google_compute_instance.abfs_server.id
101-
device_name = local.abfs_datadisk_device_name
10296
}
10397

10498
data "cloudinit_config" "abfs_server" {
@@ -118,9 +112,11 @@ data "cloudinit_config" "abfs_server" {
118112
permissions = "0644"
119113
owner = "root"
120114
encoding = "gzip+base64"
121-
content = base64gzip(templatefile("${local.cloud_init_path}/scripts/abfs_container.env.tftpl",
115+
content = base64gzip(templatefile("${local.common_files_root}/templates/abfs_container.env.tftpl",
122116
{
123-
needs_git = "false"
117+
envs = {
118+
"NEEDS_GIT" = false
119+
}
124120
}))
125121
}
126122
],
@@ -133,16 +129,29 @@ data "cloudinit_config" "abfs_server" {
133129
permissions = "0755"
134130
owner = "root"
135131
encoding = "gzip+base64"
136-
content = base64gzip(templatefile("${local.cloud_init_path}/scripts/abfs_base.sh.tftpl",
132+
content = base64gzip(templatefile("${local.common_files_root}/templates/abfs_base.sh.tftpl",
133+
{
134+
envs = {
135+
"ABFS_CMD" = <<-EOT
136+
--project ${google_spanner_instance.abfs.project} \
137+
--bucket ${google_storage_bucket.abfs.name} \
138+
--instance ${google_spanner_instance.abfs.name} \
139+
--db ${google_spanner_database.abfs.name}
140+
EOT
141+
"ABFS_DOCKER_IMAGE_URI" = var.abfs_docker_image_uri,
142+
}
143+
}))
144+
}
145+
],
146+
[
147+
{
148+
path = "/etc/systemd/system/abfs-server.service"
149+
permissions = "0644"
150+
owner = "root"
151+
encoding = "gzip+base64"
152+
content = base64gzip(templatefile("${local.common_files_root}/templates/abfs-server.service.tftpl",
137153
{
138-
abfs_docker_image_uri = var.abfs_docker_image_uri
139-
abfs_datadisk_mountpoint = var.abfs_datadisk_mountpoint
140-
abfs_command = <<-EOT
141-
--project ${google_spanner_instance.abfs.project} \
142-
--bucket ${google_storage_bucket.abfs.name} \
143-
--instance ${google_spanner_instance.abfs.name} \
144-
--db ${google_spanner_database.abfs.name}
145-
EOT
154+
type = "server"
146155
}))
147156
}
148157
],

modules/server/metadata.yaml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,12 @@ spec:
6868
description: Docker image URI for the ABFS server
6969
varType: string
7070
required: true
71-
- name: abfs_datadisk_mountpoint
72-
description: Location for mounting the ABFS datadisk on the host VM
73-
varType: string
74-
defaultValue: /mnt/disks/abfs-data
75-
- name: abfs_datadisk_name
76-
description: A name for the ABFS datadisk that will be attached to the VM. Note, this does not affect the mounting of the disk - the device name is always set to "abfs-server-storage"
77-
varType: string
78-
defaultValue: abfs-datadisk
79-
- name: abfs_datadisk_size_gb
80-
description: Size in GB for the ABFS datadisk that will be attached to the VM
71+
- name: abfs_bootdisk_size_gb
72+
description: Size in GB for the ABFS bootdisk that will be attached to the VM
8173
varType: number
82-
defaultValue: 10000
83-
- name: abfs_datadisk_type
84-
description: The PD regional disk type to use for the ABFS datadisk
74+
defaultValue: 100
75+
- name: abfs_bootdisk_type
76+
description: The PD regional disk type to use for the ABFS bootdisk
8577
varType: string
8678
defaultValue: pd-ssd
8779
- name: abfs_bucket_name

0 commit comments

Comments
 (0)