Skip to content
This repository has been archived by the owner on Mar 1, 2023. It is now read-only.

Commit

Permalink
golangci-lint config added
Browse files Browse the repository at this point in the history
some fix after running linters
some fix in test, skipping k8s's tests in short mode
  • Loading branch information
[Partner] Alexander Sokolov committed Apr 27, 2022
1 parent 1724f2c commit be203d0
Show file tree
Hide file tree
Showing 27 changed files with 126 additions and 102 deletions.
41 changes: 41 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
run:
timeout: 60m
go: 1.17

issues:
exclude-rules:
- linters:
- gosimple
text: "S1034"

max-per-linter: 0
max-same-issues: 0

linters:
disable-all: true
enable:
- asciicheck
- deadcode
- errcheck
- gocritic
- goimports
- gosimple
- govet
- ineffassign
- nakedret
- misspell
- staticcheck
- structcheck
- typecheck
- unused
- unconvert
- unparam
- varcheck
- vet
- vetshadow

linters-settings:
errcheck:
ignore: github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema:ForceNew|Set,fmt:.*,io:Close,io:WriteString
nakedret:
max-func-lines: 40
3 changes: 3 additions & 0 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ doc-generate:
fmt:
gofmt -w $(GOFMT_FILES)

linters:
golangci-lint run ./...

fmtcheck:
@sh -c "'$(CURDIR)/scripts/gofmtcheck.sh'"

Expand Down
1 change: 1 addition & 0 deletions docs/data-sources/gcore_k8s.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ data "gcore_k8s" "v" {
- `container_version` (String)
- `created_at` (String)
- `discovery_url` (String)
- `external_dns_enabled` (Boolean)
- `faults` (Map of String)
- `fixed_network` (String)
- `fixed_subnet` (String)
Expand Down
10 changes: 5 additions & 5 deletions gcore/data_source_gcore_k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ func dataSourceK8s() *schema.Resource {
Type: schema.TypeBool,
Computed: true,
},
//"external_dns_enabled": &schema.Schema{
// Type: schema.TypeBool,
// Computed: true,
//},
"external_dns_enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
},
"master_lb_floating_ip_enabled": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -233,7 +233,7 @@ func dataSourceK8sRead(ctx context.Context, d *schema.ResourceData, m interface{
d.Set("node_count", cluster.NodeCount)
d.Set("status", cluster.Status)
d.Set("status_reason", cluster.StatusReason)
//d.Set("external_dns_enabled", cluster.ExternalDNSEnabled)
d.Set("external_dns_enabled", cluster.ExternalDNSEnabled)

masterAddresses := make([]string, len(cluster.MasterAddresses))
for i, addr := range cluster.MasterAddresses {
Expand Down
3 changes: 3 additions & 0 deletions gcore/data_source_gcore_k8s_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import (
)

func TestAccK8sPoolDataSource(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
cfg, err := createTestConfig()
if err != nil {
t.Fatal(err)
Expand Down
5 changes: 4 additions & 1 deletion gcore/data_source_gcore_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

const (
testClusterName = "test-cluster"
testClusterVersion = "1.20.6"
testClusterVersion = "1.20.15"
testClusterPoolName = "test-pool"
testPoolFlavor = "g1-standard-1-2"
testNodeCount = 1
Expand All @@ -39,6 +39,9 @@ const (
)

func TestAccK8sDataSource(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}
fullName := "data.gcore_k8s.acctest"

cfg, err := createTestConfig()
Expand Down
4 changes: 2 additions & 2 deletions gcore/data_source_gcore_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ func dataSourceNetworkRead(ctx context.Context, d *schema.ResourceData, m interf
return diag.FromErr(err)
}

//todo refactor, also refactor inner func
// todo refactor, also refactor inner func
var rawNetwork map[string]interface{}
network, found := findNetworkByName(name, nets)
if !found {
//trying to find among shared networks
// trying to find among shared networks
nets, err := availablenetworks.ListAll(clientShared, nil)
if err != nil {
return diag.FromErr(err)
Expand Down
2 changes: 1 addition & 1 deletion gcore/data_source_gcore_reservedfixedip.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func dataSourceReservedFixedIPRead(ctx context.Context, d *schema.ResourceData,
return diag.Errorf("reserved fixed ip %s not found", ipAddr)
}

//should we use PortID as id?
// should we use PortID as id?
d.SetId(reservedFixedIP.PortID)
d.Set("project_id", reservedFixedIP.ProjectID)
d.Set("region_id", reservedFixedIP.RegionID)
Expand Down
3 changes: 2 additions & 1 deletion gcore/data_source_gcore_storage_s3.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gcore

import (
"regexp"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"regexp"
)

func dataSourceStorageS3() *schema.Resource {
Expand Down
3 changes: 2 additions & 1 deletion gcore/data_source_gcore_storage_sftp.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gcore

import (
"regexp"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"regexp"
)

func dataSourceStorageSFTP() *schema.Resource {
Expand Down
3 changes: 2 additions & 1 deletion gcore/data_source_gcore_storage_sftp_key.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package gcore

import (
"regexp"

"github.com/hashicorp/go-cty/cty"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"regexp"
)

func dataSourceStorageSFTPKey() *schema.Resource {
Expand Down
5 changes: 5 additions & 0 deletions gcore/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ func TestProvider(t *testing.T) {
}
}

// nolint: deadcode,unused
func testAccPreCheck(t *testing.T) {
vars := map[string]interface{}{
"GCORE_USERNAME": GCORE_USERNAME,
Expand All @@ -135,6 +136,7 @@ func testAccPreCheck(t *testing.T) {
checkNameAndID("REGION", t)
}

// nolint: unused
func checkNameAndID(resourceType string, t *testing.T) {
// resourceType is a word in capital letters
keyID := fmt.Sprintf("TEST_%s_ID", resourceType)
Expand All @@ -149,14 +151,17 @@ func checkNameAndID(resourceType string, t *testing.T) {
}
}

// nolint: deadcode,unused
func regionInfo() string {
return objectInfo("REGION")
}

// nolint: deadcode,unused
func projectInfo() string {
return objectInfo("PROJECT")
}

// nolint: unused
func objectInfo(resourceType string) string {
// resourceType is a word in capital letters
keyID := fmt.Sprintf("TEST_%s_ID", resourceType)
Expand Down
13 changes: 5 additions & 8 deletions gcore/resource_gcore_baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func resourceBmInstance() *schema.Resource {
Description: "required if type is 'reserved_fixed_ip'",
Optional: true,
},
//nested map is not supported, in this case, you do not need to use the list for the map
// nested map is not supported, in this case, you do not need to use the list for the map
"fip_source": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -280,7 +280,7 @@ func resourceBmInstanceCreate(ctx context.Context, d *schema.ResourceData, m int
}

ifs := d.Get("interface").([]interface{})
//sort interfaces by 'is_parent' at first and by 'order' key to attach it in right order
// sort interfaces by 'is_parent' at first and by 'order' key to attach it in right order
sort.Sort(instanceInterfaces(ifs))
newInterface := make([]bminstances.InterfaceOpts, len(ifs))
for i, iface := range ifs {
Expand Down Expand Up @@ -335,10 +335,7 @@ func resourceBmInstanceCreate(ctx context.Context, d *schema.ResourceData, m int
opts.Metadata = &md
}
} else if metadataRaw, ok := d.GetOk("metadata_map"); ok {
md, err := extractMetadataMap(metadataRaw.(map[string]interface{}))
if err != nil {
return diag.FromErr(err)
}
md := extractMetadataMap(metadataRaw.(map[string]interface{}))
opts.Metadata = &md
}

Expand Down Expand Up @@ -422,7 +419,7 @@ func resourceBmInstanceRead(ctx context.Context, d *schema.ResourceData, m inter
for _, assignment := range iface.IPAssignments {
subnetID := assignment.SubnetID

//bad idea, but what to do
// bad idea, but what to do
var iOpts OrderedInterfaceOpts
var orderedIOpts OrderedInterfaceOpts
var ok bool
Expand Down Expand Up @@ -460,7 +457,7 @@ func resourceBmInstanceRead(ctx context.Context, d *schema.ResourceData, m inter
for _, assignment := range iface1.IPAssignments {
subnetID := assignment.SubnetID

//bad idea, but what to do
// bad idea, but what to do
var iOpts OrderedInterfaceOpts
var orderedIOpts OrderedInterfaceOpts
var ok bool
Expand Down
2 changes: 1 addition & 1 deletion gcore/resource_gcore_baremetal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

func TestAccBaremetal(t *testing.T) {
if os.Getenv("LOCAL_TEST") != "" {
if os.Getenv("LOCAL_TEST") == "" {
t.Skip("skip test in ci")
}

Expand Down
36 changes: 11 additions & 25 deletions gcore/resource_gcore_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ func resourceInstance() *schema.Resource {
Description: "Currently available only 'existing-volume' value",
ValidateDiagFunc: func(val interface{}, key cty.Path) diag.Diagnostics {
v := val.(string)
switch types.VolumeSource(v) {
case types.ExistingVolume:
if types.VolumeSource(v) == types.ExistingVolume {
return diag.Diagnostics{}
}
return diag.Errorf("wrong source type %s, now available values is '%s'", v, types.ExistingVolume)
Expand Down Expand Up @@ -187,7 +186,7 @@ func resourceInstance() *schema.Resource {
Optional: true,
Computed: true,
},
//nested map is not supported, in this case, you do not need to use the list for the map
// nested map is not supported, in this case, you do not need to use the list for the map
"fip_source": {
Type: schema.TypeString,
Optional: true,
Expand Down Expand Up @@ -397,7 +396,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
}

ifs := d.Get("interface").([]interface{})
//sort interfaces by 'order' key to attach it in right order
// sort interfaces by 'order' key to attach it in right order
sort.Sort(instanceInterfaces(ifs))
if len(ifs) > 0 {
ifaces, err := extractInstanceInterfacesMap(ifs)
Expand Down Expand Up @@ -425,10 +424,7 @@ func resourceInstanceCreate(ctx context.Context, d *schema.ResourceData, m inter
createOpts.Metadata = &md
}
} else if metadataRaw, ok := d.GetOk("metadata_map"); ok {
md, err := extractMetadataMap(metadataRaw.(map[string]interface{}))
if err != nil {
return diag.FromErr(err)
}
md := extractMetadataMap(metadataRaw.(map[string]interface{}))
createOpts.Metadata = &md
}

Expand Down Expand Up @@ -503,20 +499,16 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interfa
flavor["vcpus"] = strconv.Itoa(instance.Flavor.VCPUS)
d.Set("flavor", flavor)

currentVolumes, err := extractVolumesIntoMap(d.Get("volume").(*schema.Set).List())
if err != nil {
return diag.FromErr(err)
}
currentVolumes := extractVolumesIntoMap(d.Get("volume").(*schema.Set).List())

extVolumes := make([]interface{}, 0)
for _, vol := range instance.Volumes {
v, ok := currentVolumes[vol.ID]
//todo fix it
// todo fix it
if !ok {
v = make(map[string]interface{})
v["volume_id"] = vol.ID
v["source"] = types.ExistingVolume.String()
//return diag.Errorf("cant find volume %s in state", vol.ID)
}

v["id"] = vol.ID
Expand Down Expand Up @@ -547,7 +539,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, m interfa
for _, assignment := range iface.IPAssignments {
subnetID := assignment.SubnetID

//bad idea, but what to do
// bad idea, but what to do
var iOpts instances.InterfaceOpts
var orderedIOpts OrderedInterfaceOpts
var ok bool
Expand Down Expand Up @@ -847,19 +839,13 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
}

oldVolumesRaw, newVolumesRaw := d.GetChange("volume")
oldVolumes, err := extractInstanceVolumesMap(oldVolumesRaw.(*schema.Set).List())
if err != nil {
return diag.FromErr(err)
}
newVolumes, err := extractInstanceVolumesMap(newVolumesRaw.(*schema.Set).List())
if err != nil {
return diag.FromErr(err)
}
oldVolumes := extractInstanceVolumesMap(oldVolumesRaw.(*schema.Set).List())
newVolumes := extractInstanceVolumesMap(newVolumesRaw.(*schema.Set).List())

vOpts := volumes.InstanceOperationOpts{InstanceID: d.Id()}
for vid := range oldVolumes {
if isAttached := newVolumes[vid]; isAttached {
//mark as already attached
// mark as already attached
newVolumes[vid] = false
continue
}
Expand All @@ -868,7 +854,7 @@ func resourceInstanceUpdate(ctx context.Context, d *schema.ResourceData, m inter
}
}

//range over not attached volumes
// range over not attached volumes
for vid, ok := range newVolumes {
if ok {
if _, err := volumes.Attach(vClient, vid, vOpts).Extract(); err != nil {
Expand Down
4 changes: 4 additions & 0 deletions gcore/resource_gcore_k8s_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ import (
)

func TestAccK8sPool(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}

cfg, err := createTestConfig()
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 4 additions & 0 deletions gcore/resource_gcore_k8s_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ import (
)

func TestAccK8s(t *testing.T) {
if testing.Short() {
t.Skip("skipping test in short mode")
}

cfg, err := createTestConfig()
if err != nil {
t.Fatal(err)
Expand Down
Loading

0 comments on commit be203d0

Please sign in to comment.