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/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_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_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_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_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..86364e57 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, diff --git a/internal/provider/resource_deployment.go b/internal/provider/resource_deployment.go index 1a100fca..99d23b80 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,