diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index a6b24f27f..8f01f825e 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -5,10 +5,10 @@ jobs: test: runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - uses: actions/checkout@v4 + - uses: actions/setup-go@v5 with: - go-version: 1.22 - - uses: actions/checkout@v3 + go-version-file: 'go.mod' - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: diff --git a/.github/workflows/golangci-ut.yml b/.github/workflows/golangci-ut.yml index 54454959e..89c61c47c 100644 --- a/.github/workflows/golangci-ut.yml +++ b/.github/workflows/golangci-ut.yml @@ -5,10 +5,10 @@ jobs: test: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v4 - uses: actions/setup-go@v5 with: - go-version: 1.22 - - uses: actions/checkout@v4 + go-version-file: 'go.mod' - name: Install dependencies run: | go get . diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f7125ece9..abe1a9481 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,27 +14,29 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: 1.22 + go-version-file: 'go.mod' - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - version: v1.50 - args: --issues-exit-code=1 + version: v1.61 + args: --issues-exit-code=1 --timeout=30m + skip-pkg-cache: true + skip-build-cache: true - name: Import GPG key id: import_gpg uses: crazy-max/ghaction-import-gpg@v6 with: - gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} - passphrase: ${{ secrets.GPG_PASSPHRASE }} + gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY2 }} + passphrase: ${{ secrets.GPG_PASSPHRASE2 }} - name: Run GoReleaser uses: goreleaser/goreleaser-action@v5 diff --git a/.golangci.yml b/.golangci.yml index 029987e12..9c0135ba7 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -6,10 +6,11 @@ issues: - SA1019 - G402 - G404 + - G115 - GetOkExists run: - deadline: 5m + deadline: 30m linters: disable-all: true @@ -20,8 +21,7 @@ linters: - staticcheck - gosec - goimports - - vet - - revive + - govet - misspell - gosimple - staticcheck diff --git a/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go b/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go index ed94566c1..07f4c9715 100644 --- a/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go +++ b/nsxt/data_source_nsxt_policy_host_transport_node_collection_realization.go @@ -4,6 +4,7 @@ package nsxt import ( + "errors" "fmt" "log" "time" @@ -122,5 +123,5 @@ func getErrorFromState(state *model.TransportNodeCollectionState) error { result += fmt.Sprintf("VCLM transition error: %v\n", *state.VlcmTransitionError) } - return fmt.Errorf(result) + return errors.New(result) } diff --git a/nsxt/data_source_nsxt_policy_uplink_host_switch_profile.go b/nsxt/data_source_nsxt_policy_uplink_host_switch_profile.go index 6447ffd67..79f711398 100644 --- a/nsxt/data_source_nsxt_policy_uplink_host_switch_profile.go +++ b/nsxt/data_source_nsxt_policy_uplink_host_switch_profile.go @@ -5,6 +5,7 @@ package nsxt import ( "fmt" + "github.com/vmware/vsphere-automation-sdk-go/runtime/bindings" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" diff --git a/nsxt/data_source_nsxt_upgrade_prepare_ready.go b/nsxt/data_source_nsxt_upgrade_prepare_ready.go index fafa67737..16e6922be 100644 --- a/nsxt/data_source_nsxt_upgrade_prepare_ready.go +++ b/nsxt/data_source_nsxt_upgrade_prepare_ready.go @@ -4,7 +4,9 @@ package nsxt import ( + "errors" "fmt" + "github.com/vmware/terraform-provider-nsxt/nsxt/util" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -84,7 +86,7 @@ func dataSourceNsxtUpgradePrepareReadyRead(d *schema.ResourceData, m interface{} errMessage += fmt.Sprintf("\nThere are unacknowledged warnings in prechecks:\n%s\nPlease address these errors from NSX or using nsxt_upgrade_precheck_acknowledge resource", preCheckText) } if len(errMessage) > 0 { - return fmt.Errorf(errMessage) + return errors.New(errMessage) } objID := util.GetVerifiableID(newUUID(), "nsxt_upgrade_prepare_ready") d.SetId(objID) diff --git a/nsxt/policy_errors.go b/nsxt/policy_errors.go index 79c4db4da..b5175693c 100644 --- a/nsxt/policy_errors.go +++ b/nsxt/policy_errors.go @@ -4,6 +4,7 @@ package nsxt import ( + liberrors "errors" "fmt" "log" @@ -104,7 +105,7 @@ func logVapiErrorData(message string, vapiMessages []std.LocalizableMessage, vap } } log.Printf("[ERROR]: %s", details) - return fmt.Errorf(details) + return liberrors.New(details) } func logAPIError(message string, err error) error { diff --git a/nsxt/resource_nsxt_lb_pool.go b/nsxt/resource_nsxt_lb_pool.go index b834807e0..93ce0ff39 100644 --- a/nsxt/resource_nsxt_lb_pool.go +++ b/nsxt/resource_nsxt_lb_pool.go @@ -251,7 +251,7 @@ func setSnatTranslationInSchema(d *schema.ResourceData, snatTranslation *loadbal if snatTranslation != nil { if snatTranslation.Type_ == "LbSnatIpPool" { elem["type"] = "SNAT_IP_POOL" - if snatTranslation.IpAddresses != nil && len(snatTranslation.IpAddresses) > 0 { + if len(snatTranslation.IpAddresses) > 0 { elem["ip"] = snatTranslation.IpAddresses[0].IpAddress } } else { @@ -421,7 +421,7 @@ func resourceNsxtLbPoolRead(d *schema.ResourceData, m interface{}) error { d.Set("description", lbPool.Description) d.Set("display_name", lbPool.DisplayName) setTagsInSchema(d, lbPool.Tags) - if lbPool.ActiveMonitorIds != nil && len(lbPool.ActiveMonitorIds) > 0 { + if len(lbPool.ActiveMonitorIds) > 0 { d.Set("active_monitor_id", lbPool.ActiveMonitorIds[0]) } else { d.Set("active_monitor_id", "") diff --git a/nsxt/resource_nsxt_policy_ipsec_vpn_session.go b/nsxt/resource_nsxt_policy_ipsec_vpn_session.go index c636bcc98..5a7e1fa72 100644 --- a/nsxt/resource_nsxt_policy_ipsec_vpn_session.go +++ b/nsxt/resource_nsxt_policy_ipsec_vpn_session.go @@ -638,7 +638,7 @@ func resourceNsxtPolicyIPSecVpnSessionRead(d *schema.ResourceData, m interface{} } var subnets []string var prefixLength int64 - if blockVPN.TunnelInterfaces != nil && len(blockVPN.TunnelInterfaces) > 0 { + if len(blockVPN.TunnelInterfaces) > 0 { for _, tunnelInterface := range blockVPN.TunnelInterfaces { ipSubnets := tunnelInterface.IpSubnets for _, ipSubnet := range ipSubnets { diff --git a/nsxt/resource_nsxt_upgrade_prepare.go b/nsxt/resource_nsxt_upgrade_prepare.go index 092c982e3..fc68e9bb2 100644 --- a/nsxt/resource_nsxt_upgrade_prepare.go +++ b/nsxt/resource_nsxt_upgrade_prepare.go @@ -4,6 +4,7 @@ package nsxt import ( + liberrors "errors" "fmt" "log" "strings" @@ -454,7 +455,7 @@ func waitForBundleUpload(m interface{}, bundleID string, timeout int) error { log.Printf("[DEBUG] Current status for uploading bundle %s is %s", bundleID, *state.Status) if *state.Status == nsxModel.UpgradeBundleUploadStatus_STATUS_FAILED { - return state, nsxModel.UpgradeBundleUploadStatus_STATUS_FAILED, fmt.Errorf(*state.DetailedStatus) + return state, nsxModel.UpgradeBundleUploadStatus_STATUS_FAILED, liberrors.New(*state.DetailedStatus) } return state, *state.Status, nil diff --git a/nsxt/resource_nsxt_upgrade_run.go b/nsxt/resource_nsxt_upgrade_run.go index 0783c35cd..e172e8345 100644 --- a/nsxt/resource_nsxt_upgrade_run.go +++ b/nsxt/resource_nsxt_upgrade_run.go @@ -452,6 +452,7 @@ func prepareUpgrade(upgradeClientSet *upgradeClientSet, d *schema.ResourceData, continue } + //#nosec G601 Ignore implicit memory aliasing in for loop temporarily status, err := getUpgradeStatus(upgradeClientSet.StatusClient, &component) if err != nil { return err @@ -466,6 +467,7 @@ func prepareUpgrade(upgradeClientSet *upgradeClientSet, d *schema.ResourceData, if status.Status == model.ComponentUpgradeStatus_STATUS_IN_PROGRESS { upgradeClientSet.PlanClient.Pause() } + //#nosec G601 Ignore implicit memory aliasing in for loop temporarily err = waitUpgradeForStatus(upgradeClientSet, &component, inFlightComponentUpgradeStatus, staticComponentUpgradeStatus) if err != nil { return err @@ -473,6 +475,7 @@ func prepareUpgrade(upgradeClientSet *upgradeClientSet, d *schema.ResourceData, // Cache the group list before reset as group IDs change by reset operation. References for some types of groups // could be affected here + //#nosec G601 Ignore implicit memory aliasing in for loop temporarily preResetGroupList, err := upgradeClientSet.GroupClient.List(&component, nil, nil, nil, nil, nil, nil, nil) if err != nil { return err @@ -820,6 +823,7 @@ func runUpgrade(upgradeClientSet *upgradeClientSet, partialUpgradeMap map[string prevComponent = component completeLog = fmt.Sprintf("[INFO] %s upgrade is partially completed.", component) } + //#nosec G601 Ignore implicit memory aliasing in for loop temporarily err = upgradeClientSet.PlanClient.Upgrade(&component) if err != nil { return err