diff --git a/.github/workflows/terratest.yml b/.github/workflows/terratest.yml index 27ab281e..4894cd08 100644 --- a/.github/workflows/terratest.yml +++ b/.github/workflows/terratest.yml @@ -2,7 +2,7 @@ name: Intgeration tests on: schedule: - - cron: "0 0 * * *" + - cron: "0 1 * * *" workflow_dispatch: push: tags: @@ -21,7 +21,6 @@ jobs: network: ["dev"] tests: [{name: "vm", test: "go test -v ./... --tags=integration -run TestVM"}, {name: "k8s", test: "go test -v ./... --tags=integration -run TestK8s"}, - {name: "k8s-module", test: "go test -v ./... --tags=integration -run TestModuleK8s"}, {name: "gateway", test: "go test -v ./... --tags=integration -run TestGatewayDeployments"}, {name: "gateway-private", test: "go test -v ./... --tags=integration -run TestGatewayPrivate"}, {name: "wireguard", test: "go test -v ./... --tags=integration -run TestWireguard"}, @@ -30,8 +29,7 @@ jobs: {name: "peertube", test: "go test -v ./... --tags=integration -run TestPeertube"}, {name: "presearch", test: "go test -v ./... --tags=integration -run TestPresearch"}, {name: "taiga", test: "go test -v ./... --tags=integration -run TestTaiga"}, - {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}, - {name: "nomad", test: "go test -v ./... --tags=integration -run TestNomad"}] + {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}] steps: - uses: actions/setup-go@v5 @@ -85,7 +83,6 @@ jobs: network: ["qa"] tests: [{name: "vm", test: "go test -v ./... --tags=integration -run TestVM"}, {name: "k8s", test: "go test -v ./... --tags=integration -run TestK8s"}, - {name: "k8s-module", test: "go test -v ./... --tags=integration -run TestModuleK8s"}, {name: "gateway", test: "go test -v ./... --tags=integration -run TestGatewayDeployments"}, {name: "gateway-private", test: "go test -v ./... --tags=integration -run TestGatewayPrivate"}, {name: "wireguard", test: "go test -v ./... --tags=integration -run TestWireguard"}, @@ -94,8 +91,7 @@ jobs: {name: "peertube", test: "go test -v ./... --tags=integration -run TestPeertube"}, {name: "presearch", test: "go test -v ./... --tags=integration -run TestPresearch"}, {name: "taiga", test: "go test -v ./... --tags=integration -run TestTaiga"}, - {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}, - {name: "nomad", test: "go test -v ./... --tags=integration -run TestNomad"}] + {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}] steps: - uses: actions/setup-go@v5 @@ -149,7 +145,6 @@ jobs: network: ["test"] tests: [{name: "vm", test: "go test -v ./... --tags=integration -run TestVM"}, {name: "k8s", test: "go test -v ./... --tags=integration -run TestK8s"}, - {name: "k8s-module", test: "go test -v ./... --tags=integration -run TestModuleK8s"}, {name: "gateway", test: "go test -v ./... --tags=integration -run TestGatewayDeployments"}, {name: "gateway-private", test: "go test -v ./... --tags=integration -run TestGatewayPrivate"}, {name: "wireguard", test: "go test -v ./... --tags=integration -run TestWireguard"}, @@ -158,8 +153,7 @@ jobs: {name: "peertube", test: "go test -v ./... --tags=integration -run TestPeertube"}, {name: "presearch", test: "go test -v ./... --tags=integration -run TestPresearch"}, {name: "taiga", test: "go test -v ./... --tags=integration -run TestTaiga"}, - {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}, - {name: "nomad", test: "go test -v ./... --tags=integration -run TestNomad"}] + {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}] steps: - uses: actions/setup-go@v5 @@ -213,7 +207,6 @@ jobs: network: ["main"] tests: [{name: "vm", test: "go test -v ./... --tags=integration -run TestVM"}, {name: "k8s", test: "go test -v ./... --tags=integration -run TestK8s"}, - {name: "k8s-module", test: "go test -v ./... --tags=integration -run TestModuleK8s"}, {name: "gateway", test: "go test -v ./... --tags=integration -run TestGatewayDeployments"}, {name: "gateway-private", test: "go test -v ./... --tags=integration -run TestGatewayPrivate"}, {name: "wireguard", test: "go test -v ./... --tags=integration -run TestWireguard"}, @@ -222,8 +215,7 @@ jobs: {name: "peertube", test: "go test -v ./... --tags=integration -run TestPeertube"}, {name: "presearch", test: "go test -v ./... --tags=integration -run TestPresearch"}, {name: "taiga", test: "go test -v ./... --tags=integration -run TestTaiga"}, - {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}, - {name: "nomad", test: "go test -v ./... --tags=integration -run TestNomad"}] + {name: "mattermost", test: "go test -v ./... --tags=integration -run TestMattermost"}] steps: - uses: actions/setup-go@v5 diff --git a/.github/workflows/test_modules.yml b/.github/workflows/test_modules.yml new file mode 100644 index 00000000..dc52262c --- /dev/null +++ b/.github/workflows/test_modules.yml @@ -0,0 +1,70 @@ +name: Intgeration tests for modules + +on: + schedule: + - cron: "0 0 * * *" + workflow_dispatch: + +jobs: + go-tests: + name: Run Go Tests + runs-on: ubuntu-latest + timeout-minutes: 0 + strategy: + fail-fast: false + matrix: + network: ["dev", "qa", "test", "main"] + steps: + - uses: actions/setup-go@v5 + with: + go-version: 1.21 + - uses: autero1/action-terraform@v3.0.1 + env: + ACTIONS_ALLOW_UNSECURE_COMMANDS: true + with: + terraform-version: 1.8.5 + - name: install wg and yggdrasil and add peers + run: | + sudo apt-get update + sudo apt-get install -y wireguard + sudo apt-get install dirmngr + sudo apt-get install curl + gpg --fetch-keys https://neilalexander.s3.dualstack.eu-west-2.amazonaws.com/deb/key.txt + gpg --export 569130E8CA20FBC4CB3FDE555898470A764B32C9 | sudo apt-key add - + echo 'deb http://neilalexander.s3.dualstack.eu-west-2.amazonaws.com/deb/ debian yggdrasil' | sudo tee /etc/apt/sources.list.d/yggdrasil.list + sudo apt-get update + sudo apt-get install yggdrasil + sudo systemctl enable yggdrasil + PEERS=$(curl https://raw.githubusercontent.com/AhmedHanafy725/yggdrasil-config/main/config.json | jq '.yggdrasil.peers[]' -r | sed 's/\//\\\//g' | sed -z 's/\n/\\n/g') + sudo sed -i -- 's/Peers\: \[\]/Peers: [\n'"$PEERS"']/g' /etc/yggdrasil/yggdrasil.conf + sudo systemctl restart yggdrasil + - uses: actions/checkout@v4.1.1 + with: + fetch-depth: 0 + - name: Build + run: | + go mod tidy + mkdir -p ~/.terraform.d/plugins/threefoldtechdev.com/providers/grid/0.2/linux_amd64/ + go build -o terraform-provider-grid + mv terraform-provider-grid ~/.terraform.d/plugins/threefoldtechdev.com/providers/grid/0.2/linux_amd64/ + - name: Test kubernetes module + env: + MNEMONIC: ${{ secrets.MNEMONICS }} + NETWORK: ${{ matrix.network }} + working-directory: integrationtests + run: | + go test -v ./... --tags=integration -run TestModuleK8s + + - name: Test Gateways + env: + MNEMONIC: ${{ secrets.MNEMONICS }} + NETWORK: ${{ matrix.network }} + working-directory: integrationtests + run: go test -v ./... --tags=integration -run TestGatewayDeployments + + - name: Test nomad module + env: + MNEMONIC: ${{ secrets.MNEMONICS }} + NETWORK: ${{ matrix.network }} + working-directory: integrationtests + run: go test -v ./... --tags=integration -run TestNomad diff --git a/.golangci.yml b/.golangci.yml index de62aa9a..6f44f19a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,11 +5,14 @@ linters: - gofmt - govet - ineffassign - - megacheck + - gosimple + - staticcheck + - unused - misspell - unconvert enable-all: false run: timeout: 20m - skip-dirs: +issues: + exclude-dirs: - integrationtests diff --git a/docs/resources/deployment.md b/docs/resources/deployment.md index 3ed41d2f..402f4757 100644 --- a/docs/resources/deployment.md +++ b/docs/resources/deployment.md @@ -169,7 +169,7 @@ Read-Only: Required: -- `disk_name` (String) Name of QSFS or Disk to mount. +- `name` (String) Name of QSFS or Disk to mount. - `mount_point` (String) Directory to mount the disk on inside the ZMachine. diff --git a/examples/resources/deployment_resource.tf b/examples/resources/deployment_resource.tf index 01c87237..8835244b 100644 --- a/examples/resources/deployment_resource.tf +++ b/examples/resources/deployment_resource.tf @@ -101,11 +101,11 @@ resource "grid_deployment" "d2" { memory = 1024 entrypoint = "/sbin/zinit init" mounts { - disk_name = "mydisk1" + name = "mydisk1" mount_point = "/opt" } mounts { - disk_name = "mydisk2" + name = "mydisk2" mount_point = "/test" } env_vars = { @@ -120,7 +120,7 @@ resource "grid_deployment" "d2" { memory = 1024 entrypoint = "/sbin/zinit init" mounts { - disk_name = "mydisk2" + name = "mydisk2" mount_point = "/test" } env_vars = { diff --git a/examples/resources/gpu/main.tf b/examples/resources/gpu/main.tf index 181c0341..c94bd1e7 100644 --- a/examples/resources/gpu/main.tf +++ b/examples/resources/gpu/main.tf @@ -38,7 +38,7 @@ resource "grid_deployment" "d1" { SSH_KEY = file("~/.ssh/id_rsa.pub") } mounts { - disk_name = "data" + name = "data" mount_point = "/app" } planetary = true diff --git a/examples/resources/mounts/main.tf b/examples/resources/mounts/main.tf index 482803c0..016b0cfa 100644 --- a/examples/resources/mounts/main.tf +++ b/examples/resources/mounts/main.tf @@ -16,10 +16,10 @@ locals { resource "grid_scheduler" "sched" { requests { - name = "node1" - cru = 1 - sru = 1024*10 - mru = 1024 + name = "node1" + cru = 1 + sru = 1024 * 10 + mru = 1024 } } @@ -47,7 +47,7 @@ resource "grid_deployment" "d1" { memory = 1024 entrypoint = "/sbin/zinit init" mounts { - disk_name = "data" + name = "data" mount_point = "/app" } env_vars = { diff --git a/examples/resources/nixos-micro/main.tf b/examples/resources/nixos-micro/main.tf index bd3d3fb7..ac22a908 100644 --- a/examples/resources/nixos-micro/main.tf +++ b/examples/resources/nixos-micro/main.tf @@ -36,7 +36,7 @@ resource "grid_deployment" "d1" { memory = 2048 entrypoint = "/entrypoint.sh" mounts { - disk_name = "store" + name = "store" mount_point = "/nix" } diff --git a/examples/resources/presearch/main.tf b/examples/resources/presearch/main.tf index 2498657f..b9d6dcf3 100644 --- a/examples/resources/presearch/main.tf +++ b/examples/resources/presearch/main.tf @@ -58,7 +58,7 @@ resource "grid_deployment" "d1" { memory = 1024 mounts { - disk_name = "data" + name = "data" mount_point = "/var/lib/docker" } diff --git a/examples/resources/qsfs/main.tf b/examples/resources/qsfs/main.tf index 47f56e78..46468614 100644 --- a/examples/resources/qsfs/main.tf +++ b/examples/resources/qsfs/main.tf @@ -106,7 +106,7 @@ resource "grid_deployment" "qsfs" { SSH_KEY = file("~/.ssh/id_rsa.pub") } mounts { - disk_name = "qsfs" + name = "qsfs" mount_point = "/qsfs" } } diff --git a/examples/resources/taiga/main.tf b/examples/resources/taiga/main.tf index 223a51d1..ddd12212 100644 --- a/examples/resources/taiga/main.tf +++ b/examples/resources/taiga/main.tf @@ -56,7 +56,7 @@ resource "grid_deployment" "node1" { memory = 8096 rootfs_size = 51200 mounts { - disk_name = "data0" + name = "data0" mount_point = "/var/lib/docker" } env_vars = { diff --git a/go.mod b/go.mod index 2145a402..af9681c9 100644 --- a/go.mod +++ b/go.mod @@ -11,10 +11,10 @@ require ( github.com/hashicorp/terraform-plugin-sdk/v2 v2.34.0 github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.9.0 - github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.11 - github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.11 - github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.11 - github.com/threefoldtech/zos v0.5.6-0.20240611092312-66184cdeb953 + github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17-0.20240904122047-8dbb80d1d261 + github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.16 + github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.16 + github.com/threefoldtech/zos v0.5.6-0.20240902110349-172a0a29a6ee golang.org/x/crypto v0.26.0 golang.org/x/sync v0.8.0 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20210803171230-4253848d036c @@ -64,8 +64,8 @@ require ( github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/googleapis/gax-go/v2 v2.12.0 // indirect - github.com/gorilla/schema v1.3.0 // indirect - github.com/gorilla/websocket v1.5.2 // indirect + github.com/gorilla/schema v1.4.1 // indirect + github.com/gorilla/websocket v1.5.3 // indirect github.com/gtank/merlin v0.1.1 // indirect github.com/gtank/ristretto255 v0.1.2 // indirect github.com/hashicorp/cli v1.1.6 // indirect @@ -118,7 +118,7 @@ require ( github.com/rs/zerolog v1.33.0 // indirect github.com/shopspring/decimal v1.3.1 // indirect github.com/spf13/cast v1.5.0 // indirect - github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d // indirect + github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240827163226-d4e15e206974 // indirect github.com/tmccombs/hcl2json v0.3.3 // indirect github.com/ulikunitz/xz v0.5.10 // indirect github.com/vedhavyas/go-subkey v1.0.3 // indirect diff --git a/go.sum b/go.sum index 97ee0e80..4c4cbb67 100644 --- a/go.sum +++ b/go.sum @@ -442,10 +442,10 @@ github.com/googleapis/gax-go/v2 v2.6.0/go.mod h1:1mjbznJAPHFpesgE5ucqfYEscaz5kMd github.com/googleapis/gax-go/v2 v2.12.0 h1:A+gCJKdRfqXkr+BIRGtZLibNXf0m1f9E4HG56etFpas= github.com/googleapis/gax-go/v2 v2.12.0/go.mod h1:y+aIqrI5eb1YGMVJfuV3185Ts/D7qKpsEkdD5+I6QGU= github.com/googleapis/go-type-adapters v1.0.0/go.mod h1:zHW75FOG2aur7gAO2B+MLby+cLsWGBF62rFAi7WjWO4= -github.com/gorilla/schema v1.3.0 h1:rbciOzXAx3IB8stEFnfTwO3sYa6EWlQk79XdyustPDA= -github.com/gorilla/schema v1.3.0/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= -github.com/gorilla/websocket v1.5.2 h1:qoW6V1GT3aZxybsbC6oLnailWnB+qTMVwMreOso9XUw= -github.com/gorilla/websocket v1.5.2/go.mod h1:0n9H61RBAcf5/38py2MCYbxzPIY9rOkpvvMT24Rqs30= +github.com/gorilla/schema v1.4.1 h1:jUg5hUjCSDZpNGLuXQOgIWGdlgrIdYvgQ0wZtdK1M3E= +github.com/gorilla/schema v1.4.1/go.mod h1:Dg5SSm5PV60mhF2NFaTV1xuYYj8tV8NOPRo4FggUMnM= +github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg= +github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw= github.com/gruntwork-io/terratest v0.47.0 h1:xIy1pT7NbGVlMLDZEHl3+3iSnvffh8tN2pL6idn448c= github.com/gruntwork-io/terratest v0.47.0/go.mod h1:oywHw1cFKXSYvKPm27U7quZVzDUlA22H2xUrKCe26xM= @@ -670,16 +670,16 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d h1:vWHR33VfphOahBlo3aGCE/eKPlfb4BCInhKidGkdp5s= -github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240416134707-eb36aa90df2d/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ= -github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.11 h1:FmEQplYSZ6pYslmBlUNaUabScOdi6hJialeV/yq0BrY= -github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.11/go.mod h1:Obsv0kspgSSwF8jb91Z7CBY2FCQNq6RhiZXIQf26nWY= -github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.11 h1:qsSICIj5cvoVBR4GLWmdu2n3FfJG5isJ2ABnNNWykLU= -github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.11/go.mod h1:7cKHvKPpfdCpU4a/VCznRDDNMPBPI98cJ0uVJoUGrgg= -github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.11 h1:AKDj/GD88UteVWe5RqtmprQCKNy/w2kQz/l8tepfzv0= -github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.11/go.mod h1:5238AvoU1LVPQ8zgVFSfrmxMLaPm8bcnVAryo8VyclM= -github.com/threefoldtech/zos v0.5.6-0.20240611092312-66184cdeb953 h1:hzqMY2Ydb+N2TBrTJHpy5n5i5nflfre1dhoNQH/tfhI= -github.com/threefoldtech/zos v0.5.6-0.20240611092312-66184cdeb953/go.mod h1:yH6T43SiHvQBBuLgKGElECsIhqzJ6fy/dJyaxtO/X0M= +github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240827163226-d4e15e206974 h1:95Ox9WYNiwm3mVJeVF/lp7iCpVGA28AkU1atN893eDo= +github.com/threefoldtech/tfchain/clients/tfchain-client-go v0.0.0-20240827163226-d4e15e206974/go.mod h1:dtDKAPiUDxAwIkfHV7xcAFZcOm+xwNIuOI1MLFS+MeQ= +github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17-0.20240904122047-8dbb80d1d261 h1:HyVkauSes4lpRDg0zyDKkb5Tcr8nDeQYt4mqEdlqNuE= +github.com/threefoldtech/tfgrid-sdk-go/grid-client v0.15.17-0.20240904122047-8dbb80d1d261/go.mod h1:MwKEEeKN7qApCdabKRBTs18lrJ6JzA2Xx5Hd2/zb4o0= +github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.16 h1:Bnt9POje9hc9nv1YwAu13ABnl63DBMH0qL4SeVhNsIQ= +github.com/threefoldtech/tfgrid-sdk-go/grid-proxy v0.15.16/go.mod h1:2Z7uJYHeilN7bASpmkcDxtl+3AT8tim6iIvqZ08pwCg= +github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.16 h1:xe3LgMdznykz6d6cOFBt2s+sq3XooOVn20aHOZ3gbQE= +github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go v0.15.16/go.mod h1:cDTivSsUl4r1jN+H8/W6yDqByOOliY8HEGuVuL3ixV8= +github.com/threefoldtech/zos v0.5.6-0.20240902110349-172a0a29a6ee h1:pqpYVM0qkXujplHNfH6w5GDqcY5sLJAgOc4/hlR6+Xw= +github.com/threefoldtech/zos v0.5.6-0.20240902110349-172a0a29a6ee/go.mod h1:lut72yYMJhgK0QRvF0Wd/mB3+OfIoXWz04DQuXck3Sw= github.com/tklauser/go-sysconf v0.3.11 h1:89WgdJhk5SNwJfu+GKyYveZ4IaJ7xAkecBo+KdJV0CM= github.com/tklauser/go-sysconf v0.3.11/go.mod h1:GqXfhXY3kiPa0nAXPDIQIWzJbMCB7AmcWpGR8lSZfqI= github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYms= diff --git a/integrationtests/gateway_private_test.go b/integrationtests/gateway_private_test.go index 75c967b3..b2770e85 100644 --- a/integrationtests/gateway_private_test.go +++ b/integrationtests/gateway_private_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/gateway_test.go b/integrationtests/gateway_test.go index 5b1939c7..31fe5f39 100644 --- a/integrationtests/gateway_test.go +++ b/integrationtests/gateway_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/k8s_test.go b/integrationtests/k8s_test.go index df59d35a..1101216b 100644 --- a/integrationtests/k8s_test.go +++ b/integrationtests/k8s_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/k8s_using_module_test.go b/integrationtests/k8s_using_module_test.go index ef261827..c27d9ba5 100644 --- a/integrationtests/k8s_using_module_test.go +++ b/integrationtests/k8s_using_module_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( @@ -42,7 +46,7 @@ func TestModuleK8s(t *testing.T) { FarmIDs: []uint64{1}, } - nodes, err := deployer.FilterNodes(context.Background(), tfPlugin, f, []uint64{freeSRU}, []uint64{}, []uint64{uint64(1024)}) + nodes, err := deployer.FilterNodes(context.Background(), tfPlugin, f, []uint64{freeSRU}, []uint64{}, []uint64{}) require.NoError(t, err) if len(nodes) < 3 { t.Skip("couldn't find enough nodes") diff --git a/integrationtests/mattermost_test.go b/integrationtests/mattermost_test.go index fb3aac9d..2186e6e4 100644 --- a/integrationtests/mattermost_test.go +++ b/integrationtests/mattermost_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/nomad_test.go b/integrationtests/nomad_test.go index e0d3cd02..0e658971 100644 --- a/integrationtests/nomad_test.go +++ b/integrationtests/nomad_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/peertube_test.go b/integrationtests/peertube_test.go index 97a88813..13d6365f 100644 --- a/integrationtests/peertube_test.go +++ b/integrationtests/peertube_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/presearch/main.tf b/integrationtests/presearch/main.tf index 5774ce1d..ad1b2d52 100644 --- a/integrationtests/presearch/main.tf +++ b/integrationtests/presearch/main.tf @@ -68,7 +68,7 @@ resource "grid_deployment" "d1" { memory = 1024 mounts { - disk_name = "data" + name = "data" mount_point = "/var/lib/docker" } diff --git a/integrationtests/presearch_test.go b/integrationtests/presearch_test.go index 0e5d47f7..94b35e50 100644 --- a/integrationtests/presearch_test.go +++ b/integrationtests/presearch_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/qsfs/main.tf b/integrationtests/qsfs/main.tf index ef9ef22d..1bb600a3 100644 --- a/integrationtests/qsfs/main.tf +++ b/integrationtests/qsfs/main.tf @@ -117,7 +117,7 @@ resource "grid_deployment" "qsfs" { SSH_KEY = "${var.public_key}" } mounts { - disk_name = "qsfs" + name = "qsfs" mount_point = "/qsfs" } } diff --git a/integrationtests/qsfs_test.go b/integrationtests/qsfs_test.go index 404ede2b..55db6dfd 100644 --- a/integrationtests/qsfs_test.go +++ b/integrationtests/qsfs_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/taiga/main.tf b/integrationtests/taiga/main.tf index 1ea9861b..98f3a22d 100644 --- a/integrationtests/taiga/main.tf +++ b/integrationtests/taiga/main.tf @@ -62,7 +62,7 @@ resource "grid_deployment" "node1" { memory = 8096 rootfs_size = 51200 mounts { - disk_name = "data0" + name = "data0" mount_point = "/var/lib/docker" } env_vars = { diff --git a/integrationtests/taiga_test.go b/integrationtests/taiga_test.go index e649ff46..8eca4d97 100644 --- a/integrationtests/taiga_test.go +++ b/integrationtests/taiga_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/vm_mounts/main.tf b/integrationtests/vm_mounts/main.tf index f91b0450..9db4c4ec 100644 --- a/integrationtests/vm_mounts/main.tf +++ b/integrationtests/vm_mounts/main.tf @@ -58,7 +58,7 @@ resource "grid_deployment" "d1" { memory = 1024 entrypoint = "/init.sh" mounts { - disk_name = "data" + name = "data" mount_point = "/${var.mount_point}" } env_vars = { diff --git a/integrationtests/vm_test.go b/integrationtests/vm_test.go index c8844142..0eddfa17 100644 --- a/integrationtests/vm_test.go +++ b/integrationtests/vm_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/wireguard_test.go b/integrationtests/wireguard_test.go index b03a1d5b..b1a65dd3 100644 --- a/integrationtests/wireguard_test.go +++ b/integrationtests/wireguard_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/integrationtests/zdb_test.go b/integrationtests/zdb_test.go index 728e1f10..0296e7f0 100644 --- a/integrationtests/zdb_test.go +++ b/integrationtests/zdb_test.go @@ -1,3 +1,7 @@ +//go:build integration +// +build integration + +// Package integrationtests includes integration tests for deploying solutions on the tf grid, and some utilities to test these solutions. package integrationtests import ( diff --git a/internal/provider/deployment.go b/internal/provider/deployment.go index 2096ecc1..0d018722 100644 --- a/internal/provider/deployment.go +++ b/internal/provider/deployment.go @@ -56,7 +56,9 @@ func newDeploymentFromSchema(d *schema.ResourceData) (*workloads.Deployment, err return nil, errors.Wrap(err, "failed to create workload from vm map") } - vms = append(vms, *v.(*workloads.VM)) + vmWorkload := *v.(*workloads.VM) + vmWorkload.NodeID = nodeID + vms = append(vms, vmWorkload) } // TODO: ip_range diff --git a/internal/provider/k8s.go b/internal/provider/k8s.go index fd7e6b76..2647aafa 100644 --- a/internal/provider/k8s.go +++ b/internal/provider/k8s.go @@ -15,6 +15,7 @@ import ( // newK8sFromSchema reads the k8s resource configuration data from the schema.ResourceData, converts them into a new K8s instance, and returns this instance. func newK8sFromSchema(d *schema.ResourceData) (*workloads.K8sCluster, error) { + networkName := d.Get("network_name").(string) nodesIPRange := make(map[uint32]gridtypes.IPNet) masterMap := d.Get("master").([]interface{})[0].(map[string]interface{}) @@ -31,6 +32,9 @@ func newK8sFromSchema(d *schema.ResourceData) (*workloads.K8sCluster, error) { return nil, err } + master := masterI.(*workloads.K8sNode) + master.NetworkName = networkName + workers := make([]workloads.K8sNode, 0) for _, w := range d.Get("workers").([]interface{}) { @@ -47,7 +51,9 @@ func newK8sFromSchema(d *schema.ResourceData) (*workloads.K8sCluster, error) { if err != nil { return nil, err } - workers = append(workers, *data.(*workloads.K8sNode)) + workerWorkload := *data.(*workloads.K8sNode) + workerWorkload.NetworkName = networkName + workers = append(workers, workerWorkload) } nodeDeploymentIDIf := d.Get("node_deployment_id").(map[string]interface{}) @@ -60,18 +66,18 @@ func newK8sFromSchema(d *schema.ResourceData) (*workloads.K8sCluster, error) { deploymentID := uint64(id.(int)) nodeDeploymentID[uint32(nodeInt)] = deploymentID } - master := masterI.(*workloads.K8sNode) - solutionType := d.Get("solution_type").(string) + solutionType := d.Get("solution_type").(string) if solutionType == "" { solutionType = fmt.Sprintf("kubernetes/%s", master.Name) } + k8s := workloads.K8sCluster{ Master: master, Workers: workers, Token: d.Get("token").(string), SSHKey: d.Get("ssh_key").(string), - NetworkName: d.Get("network_name").(string), + NetworkName: networkName, SolutionType: solutionType, NodeDeploymentID: nodeDeploymentID, NodesIPRange: nodesIPRange, @@ -126,12 +132,16 @@ func storeK8sState(d *schema.ResourceData, k8s *workloads.K8sCluster) (errors er master["mycelium_ip_seed"] = hex.EncodeToString(k8s.Master.MyceliumIPSeed) retainChecksums(workers, master, k8s) + removeExtraFieldsFromK8sNode(master) l := []interface{}{master} err = d.Set("master", l) if err != nil { errors = multierror.Append(errors, err) } + for i := range workers { + removeExtraFieldsFromK8sNode(workers[i].(map[string]interface{})) + } err = d.Set("workers", workers) if err != nil { errors = multierror.Append(errors, err) @@ -169,3 +179,13 @@ func storeK8sState(d *schema.ResourceData, k8s *workloads.K8sCluster) (errors er return } + +func removeExtraFieldsFromK8sNode(k8sNode map[string]interface{}) { + delete(k8sNode, "zlogs") + delete(k8sNode, "gpus") + delete(k8sNode, "corex") + delete(k8sNode, "mounts") + delete(k8sNode, "rootfs_size") + delete(k8sNode, "description") + delete(k8sNode, "env_vars") +} diff --git a/internal/provider/resource_deployment.go b/internal/provider/resource_deployment.go index 1a100fca..dec2202e 100644 --- a/internal/provider/resource_deployment.go +++ b/internal/provider/resource_deployment.go @@ -162,6 +162,11 @@ func resourceDeployment() *schema.Resource { Description: "Vm (zmachine) workload name. This has to be unique within the deployment. Must contain only alphanumeric and underscore characters.", ValidateDiagFunc: validation.ToDiagFunc(validation.StringMatch(regexp.MustCompile(nameValidationRegex), nameValidationErrorMessage)), }, + "node": { + Type: schema.TypeInt, + Optional: true, + Description: "Node id to place the vm on.", + }, "flist": { Type: schema.TypeString, Required: true, @@ -245,7 +250,7 @@ func resourceDeployment() *schema.Resource { Description: "List of vm (ZMachine) mounts. Can reference QSFSs and Disks.", Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "disk_name": { + "name": { Type: schema.TypeString, Required: true, Description: "Name of QSFS or Disk to mount.", diff --git a/internal/provider/resource_k8s.go b/internal/provider/resource_k8s.go index aed39a4f..a5e25824 100644 --- a/internal/provider/resource_k8s.go +++ b/internal/provider/resource_k8s.go @@ -106,6 +106,12 @@ func resourceKubernetes() *schema.Resource { Default: "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist", Description: "Flist used on master node, e.g. https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist. All flists could be found in `https://hub.grid.tf/`", }, + "entrypoint": { + Type: schema.TypeString, + Optional: true, + Default: "/sbin/zinit init", + Description: "Command to execute as the kubernetes node init.", + }, "flist_checksum": { Type: schema.TypeString, Optional: true, @@ -200,6 +206,12 @@ func resourceKubernetes() *schema.Resource { Default: "https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist", Description: "Flist used on worker node, e.g. https://hub.grid.tf/tf-official-apps/threefoldtech-k3s-latest.flist. All flists could be found in `https://hub.grid.tf/`.", }, + "entrypoint": { + Type: schema.TypeString, + Optional: true, + Default: "/sbin/zinit init", + Description: "Command to execute as the kubernetes node init.", + }, "flist_checksum": { Type: schema.TypeString, Optional: true, diff --git a/modules/nomad-module/main.tf b/modules/nomad-module/main.tf index 726aae4a..2aedbf2c 100644 --- a/modules/nomad-module/main.tf +++ b/modules/nomad-module/main.tf @@ -39,7 +39,7 @@ resource "grid_deployment" "servers" { planetary = vms.value.planetary entrypoint = local.entrypoint mounts { - disk_name = vms.value.disk.name + name = vms.value.disk.name mount_point = vms.value.mount_point } env_vars = { @@ -77,7 +77,7 @@ resource "grid_deployment" "clients" { planetary = vms.value.planetary entrypoint = local.entrypoint mounts { - disk_name = vms.value.disk.name + name = vms.value.disk.name mount_point = vms.value.mount_point } env_vars = {