From 089df0ff7f929ef78138a85e374b2ae6114a2a86 Mon Sep 17 00:00:00 2001 From: Tobias Trabelsi Date: Tue, 7 Nov 2023 21:05:28 +0100 Subject: [PATCH] reenable ipv4 and added userdata test --- internal/hetzner/hetzneragent.go | 2 +- internal/hetzner/hetzneragent_test.go | 55 +++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 internal/hetzner/hetzneragent_test.go diff --git a/internal/hetzner/hetzneragent.go b/internal/hetzner/hetzneragent.go index 66eb091..cca9605 100644 --- a/internal/hetzner/hetzneragent.go +++ b/internal/hetzner/hetzneragent.go @@ -94,7 +94,7 @@ func CreateNewAgent(cfg *config.Config) (*hcloud.Server, error) { } networkConf := hcloud.ServerCreatePublicNet{ - EnableIPv4: false, + EnableIPv4: true, EnableIPv6: true, } diff --git a/internal/hetzner/hetzneragent_test.go b/internal/hetzner/hetzneragent_test.go new file mode 100644 index 0000000..0b337b1 --- /dev/null +++ b/internal/hetzner/hetzneragent_test.go @@ -0,0 +1,55 @@ +package hetzner + +import ( + "testing" + + "git.uploadfilter24.eu/covidnetes/woodpecker-autoscaler/internal/config" +) + +func TestGenerateUserData(t *testing.T) { + cfg := config.Config{ + LogLevel: "Info", + CheckInterval: 5, + DryRun: false, + WoodpeckerLabelSelector: "uploadfilter24.eu/instance-role=WoodpeckerTest", + WoodpeckerInstance: "http://woodpecker.test.tld", + WoodpeckerGrpc: "grpc-test.woodpecker.test.tld:443", + WoodpeckerAgentSecret: "Geheim1!", + WoodpeckerApiToken: "VeryGeheim1!", + HcloudToken: "EvenMoreGeheim1!", + HcloudInstanceType: "cpx21", + HcloudRegion: "eu-central", + HcloudDatacenter: "fsn1-dc14", + HcloudSSHKeys: "test-key", + } + wanted := ` +#cloud-config +write_files: +- content: | + # docker-compose.yml + version: '3' + services: + woodpecker-agent: + image: woodpeckerci/woodpecker-agent:latest + command: agent + restart: always + volumes: + - /var/run/docker.sock:/var/run/docker.sock + environment: + - WOODPECKER_AGENT_SECRET="Geheim1!" + - WOODPECKER_FILTER_LABELS="uploadfilter24.eu/instance-role=WoodpeckerTest" + - WOODPECKER_GRPC_SECURE=true + - WOODPECKER_HOSTNAME="test-instance" + - WOODPECKER_SERVER="grpc-test.woodpecker.test.tld:443" + path: /root/docker-compose.yml +runcmd: +- [ sh, -xc, "cd /root; docker run --rm --privileged multiarch/qemu-user-static --reset -p yes; docker compose up -d" ] +` + got, err := generateConfig(&cfg, "test-instance") + if err != nil { + t.Errorf("Error in generating Config: %v", err) + } + if wanted != got { + t.Errorf("got:\n%v\n, wanted:\n%v", got, wanted) + } +}