Skip to content

Commit

Permalink
update go sdk and fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
rawdaGastan committed Sep 4, 2024
1 parent 7d2016b commit f7842c5
Show file tree
Hide file tree
Showing 19 changed files with 97 additions and 29 deletions.
7 changes: 5 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 7 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
28 changes: 14 additions & 14 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/gateway_private_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/gateway_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/k8s_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
6 changes: 5 additions & 1 deletion integrationtests/k8s_using_module_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down Expand Up @@ -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")
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/mattermost_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/nomad_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/peertube_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/presearch_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/qsfs_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/taiga_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/vm_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/wireguard_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 4 additions & 0 deletions integrationtests/zdb_test.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
4 changes: 3 additions & 1 deletion internal/provider/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions internal/provider/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -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{}) {
Expand All @@ -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{})
Expand All @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions internal/provider/resource_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f7842c5

Please sign in to comment.