Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix linter issues #481

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ linters:
- asciicheck
- bodyclose
- copyloopvar
- depguard
- dogsled
- dupl
- errcheck
Expand Down
5 changes: 5 additions & 0 deletions internal/client/proxy/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ J+guVb41E7ckHez4ENTEj2hrqrYifViGvOaSAG3w1d8PW+wIj3jI6vQk7vTO6mbt
ws3Up/6R4aI0ohB4wjOfUCL6x9L3pyQcDoumDuy8ToyL5Pk=
-----END CERTIFICATE-----
`
// nolint: gosec
clientKey = `
-----BEGIN RSA PRIVATE KEY-----
MIIEpQIBAAKCAQEA51mGnwWS2HJTzbfGgALTgBz69OMEgPGljrfv58lOU50V+bU2
Expand Down Expand Up @@ -281,15 +282,19 @@ func TestGetConnectorTLSConfig(t *testing.T) {
require.EqualError(t, actualErr, tc.expectedErr.Error())
return
}

require.NoError(t, actualErr)

if tc.expectedTLSConfig.GetClientCertificate != nil {
require.NotNil(t, actualTLSConfig.GetClientCertificate)
return
}

if tc.expectedTLSConfig.RootCAs != nil {
require.NotNil(t, actualTLSConfig.RootCAs)
return
}

require.Equal(t, actualTLSConfig, tc.expectedTLSConfig)
})
}
Expand Down
1 change: 1 addition & 0 deletions internal/client/transport/methods_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,6 @@ func TestConcurrentAccessOfInvokeAction(t *testing.T) {
require.Error(t, actual)
}()
}

waitGroup.Wait()
}
1 change: 1 addition & 0 deletions internal/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ func readString(input interface{}, key string) string {
return data
}

// nolint:gosec
func SetPrimitiveValue(input, model interface{}, key string) {
switch m := model.(type) {
case *float64:
Expand Down
1 change: 1 addition & 0 deletions internal/helper/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func Retry(f Retryable, interval time.Duration, attempts int) (int, error) {
}

time.Sleep(interval)

retries++
}

Expand Down
1 change: 1 addition & 0 deletions internal/resources/akscluster/resource_akscluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,7 @@ func Test_pollUntilReady(t *testing.T) {
tt.args.interval, tt.wantError, gotErr)
}
}

if tt.validation != nil {
tt.validation(t, tt.args)
}
Expand Down
1 change: 1 addition & 0 deletions internal/resources/cluster/tkgaws/resource_tkg_aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func expandTKGAWSClusterNetwork(data []interface{}) (cluster *tkgawsmodel.Vmware

if v, ok := lookUpCluster[apiServerPortKey]; ok {
apiServerPort := v.(int)
// nolint:gosec
cluster.APIServerPort = int32(apiServerPort)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func dataSourceClusterClassRead(ctx context.Context, data *schema.ResourceData,
switch {
case err != nil:
return diag.FromErr(errors.Wrap(err, "Couldn't read cluster class"))
case resp.ClusterClasses == nil || len(resp.ClusterClasses) == 0:
case len(resp.ClusterClasses) == 0:
data.SetId("NO_DATA")
default:
clusterClass := resp.ClusterClasses[0]
Expand Down
1 change: 1 addition & 0 deletions internal/resources/ekscluster/ekscluster_flatten_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,7 @@ func TestFlattenClusterSpec(t *testing.T) {
t.Run(test.description, func(t *testing.T) {
spec, nps := test.getInput()
output := flattenClusterSpec(spec, nps)

print(test.expected)
print(output)
require.Equal(t, test.expected, output)
Expand Down
6 changes: 4 additions & 2 deletions internal/resources/ekscluster/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,9 @@ func TestNodepoolSpecEqual(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
spec1 := getNodepoolSpec()
spec2 := getNodepoolSpec()
test.modifySpec1(spec1)

spec2 := getNodepoolSpec()
test.modifySpec2(spec2)

require.Equal(t, test.result, nodepoolSpecEqual(spec1, spec2), "return didn't match the expected output")
Expand Down Expand Up @@ -693,8 +694,9 @@ func TestClusterSpecEqual(t *testing.T) {
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
spec1, _ := getClusterSpec()
spec2, _ := getClusterSpec()
test.modifySpec1(spec1)

spec2, _ := getClusterSpec()
test.modifySpec2(spec2)

require.Equal(t, test.result, clusterSpecEqual(spec1, spec2), "return didn't match the expected output")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func dataSourceGitRepositoryRead(ctx context.Context, d *schema.ResourceData, m
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
return diags
}

return diag.FromErr(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ func resourceGitRepositoryInPlaceUpdate(ctx context.Context, d *schema.ResourceD

if !updateAvailable {
log.Printf("[INFO] git repository update is not required")
return
return diags
}

switch scopedFullnameData.Scope {
Expand Down
14 changes: 7 additions & 7 deletions internal/resources/helmcharts/helm_charts_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ import (
objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta"
)

const (
https = "https:/"
clAPIVersionAndGroup = "v1alpha1/organization/fluxcd/helm/repositories"
apiSubGroup = "chartmetadatas"
apiKind = "charts"
)

// nolint: unused
func bodyInspectingResponder(t *testing.T, expectedContent interface{}, successResponse int, successResponseBody interface{}) httpmock.Responder {
return func(r *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -120,6 +113,13 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
},
}

const (
https = "https:/"
clAPIVersionAndGroup = "v1alpha1/organization/fluxcd/helm/repositories"
apiSubGroup = "chartmetadatas"
apiKind = "charts"
)

getPkgEndpoint := (helper.ConstructRequestURL(https, endpoint, clAPIVersionAndGroup, "*", apiSubGroup, testConfig.ChartMetadataName, apiKind)).String()

httpmock.RegisterResponder("GET", getPkgEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/helmfeature/data_source_helm_feature.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func dataSourceHelmRead(ctx context.Context, d *schema.ResourceData, m interface
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
return diags
}

return diag.FromErr(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/helmrelease/data_source_helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func dataSourceHelmReleaseRead(ctx context.Context, d *schema.ResourceData, m in
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
return diags
}

return diag.FromErr(err)
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/helmrelease/resource_helm_release.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ func resourceHelmReleaseInPlaceUpdate(ctx context.Context, d *schema.ResourceDat

if !updateAvailable {
log.Printf("[INFO] helm release update is not required")
return
return diags
}

switch scopedFullnameData.Scope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func dataSourceHelmRepositoryRead(ctx context.Context, d *schema.ResourceData, m
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
return diags
}

return diag.FromErr(err)
Expand Down
14 changes: 7 additions & 7 deletions internal/resources/helmrepository/helm_repository_mock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,6 @@ import (
objectmetamodel "github.com/vmware/terraform-provider-tanzu-mission-control/internal/models/objectmeta"
)

const (
https = "https:/"
clAPIVersionAndGroup = "v1alpha1/clusters"
apiSubGroup = "namespaces"
apiKind = "fluxcd/helm/repositories"
)

// nolint: unused
func bodyInspectingResponder(t *testing.T, expectedContent interface{}, successResponse int, successResponseBody interface{}) httpmock.Responder {
return func(r *http.Request) (*http.Response, error) {
Expand Down Expand Up @@ -124,6 +117,13 @@ func (testConfig *testAcceptanceConfig) setupHTTPMocks(t *testing.T) {
},
}

const (
https = "https:/"
clAPIVersionAndGroup = "v1alpha1/clusters"
apiSubGroup = "namespaces"
apiKind = "fluxcd/helm/repositories"
)

getPkgEndpoint := (helper.ConstructRequestURL(https, endpoint, clAPIVersionAndGroup, testConfig.ScopeHelperResources.Cluster.Name, apiSubGroup, testConfig.Namespace, apiKind)).String()

httpmock.RegisterResponder("GET", getPkgEndpoint,
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/iampolicy/resource_iam_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func resourceIAMPolicyRead(_ context.Context, d *schema.ResourceData, m interfac
// when iam policy resource is empty: no role bindings are existing, this is equivalent to not found condition.
if len(policyList) == 0 {
_ = schema.RemoveFromState(d, m)
return
return diags
}

d.SetId(d.State().ID)
Expand Down
4 changes: 2 additions & 2 deletions internal/resources/kustomization/resource_kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func resourceKustomizationRead(ctx context.Context, d *schema.ResourceData, m in
if err != nil {
if clienterrors.IsNotFoundError(err) {
_ = schema.RemoveFromState(d, m)
return
return diags
}

return diag.FromErr(err)
Expand Down Expand Up @@ -346,7 +346,7 @@ func resourceKustomizationInPlaceUpdate(ctx context.Context, d *schema.ResourceD

if !updateAvailable {
log.Printf("[INFO] kustomization update is not required")
return
return diags
}

switch scopedFullnameData.Scope {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func dataSourcePermissionTemplateRead(ctx context.Context, data *schema.Resource
}
}

if response.TemplateValues != nil && len(response.TemplateValues) > 0 {
if len(response.TemplateValues) > 0 {
// This is necessary because sometimes the template parameters definition and the template values returned from the API do not match.
err = removeUndefinedTemplateValues(response)

Expand Down
1 change: 1 addition & 0 deletions internal/resources/permissiontemplate/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ func buildCapabilityProviderDescription(schemaKey string) (description string) {
for k, v := range capabilityProviderMap {
valueDescription := fmt.Sprintf("When %s is set to '%s' %s must be set to '%s'.", ProviderKey, v, CapabilityKey, k)
description = fmt.Sprintf("%s\n%s", description, valueDescription)

validValues = append(validValues, v)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ func flattenCustomRule(rule *policyrecipenetworkcommonmodel.V1alpha1CommonPolicy
var ports []interface{}

for _, port := range *rule.Ports {
port := port
ports = append(ports, flattenPort(&port))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func FlattenCustomEgress(customEgress *policyrecipenetworkmodel.V1alpha1CommonPo
var rules []interface{}

for _, rule := range customEgress.Rules {
rule := rule
rules = append(rules, flattenCustomRule(&rule))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ func FlattenCustomIngress(customIngress *policyrecipenetworkmodel.V1alpha1Common
var rules []interface{}

for _, rule := range customIngress.Rules {
rule := rule
rules = append(rules, flattenCustomRule(&rule))
}

Expand Down
2 changes: 1 addition & 1 deletion internal/resources/policy/operations/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func ResourcePolicyInPlaceUpdate(ctx context.Context, d *schema.ResourceData, m
if !updateAvailable {
log.Printf("[INFO] %s policy update is not required", rn)

return
return diags
}

switch scopedFullnameData.Scope {
Expand Down
9 changes: 5 additions & 4 deletions internal/resources/provisioner/data_source_provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,19 +75,20 @@ func dataSourceProvisionerRead(ctx context.Context, d *schema.ResourceData, m in
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
return diags
}

return
return diags
}
} else {
getResp, err := config.TMCConnection.ProvisionerResourceService.ProvisionerResourceServiceGet(model.Provisioners[0].FullName)
if err != nil {
if clienterrors.IsNotFoundError(err) && !helper.IsDataRead(ctx) {
_ = schema.RemoveFromState(d, m)
return
return diags
}
return

return diags
}

p := &provisioner.VmwareTanzuManageV1alpha1ManagementclusterProvisionerListprovisionersResponse{
Expand Down
2 changes: 1 addition & 1 deletion internal/resources/sourcesecret/resource_sourcesecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func resourceSourcesecretInPlaceUpdate(ctx context.Context, d *schema.ResourceDa
}

if !updateAvailable {
return
return diags
}

switch scopedFullnameData.Scope {
Expand Down
3 changes: 2 additions & 1 deletion internal/resources/tanzukubernetescluster/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func waitNodePoolsReady(ctx context.Context, config *authctx.TanzuContext, clust
errMsg = fmt.Sprintf("%s\n%s", errMsg, npStatusMsg)
}

err = errors.Wrapf(err, errMsg)
err = errors.Wrapf(err, "%s", errMsg)
}

return err
Expand Down Expand Up @@ -461,6 +461,7 @@ func removeModelVariable(clusterClassSchema interface{}, modelVariable interface
} else {
modelVarAdditionalProperties, additionalPropertiesExist := clusterClassSchema.(map[string]interface{})[string(openapiv3.AdditionalPropertiesKey)]
preserve, preserveExists := clusterClassSchema.(map[string]interface{})[string(openapiv3.PreserveUnknownFieldKey)]

if additionalPropertiesExist {
_, propertiesExist := modelVarAdditionalProperties.(map[string]interface{})[string(openapiv3.PropertiesKey)]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ func validateSchema(_ context.Context, data *schema.ResourceDiff, value interfac
if err != nil {
return errors.Wrapf(err, "Couldn't find cluster class.\nManagement Cluster Name: %s, Provisioner: %s, Cluster Class Name: %s.",
clusterClassFn.ManagementClusterName, clusterClassFn.ProvisionerName, clusterClassFn.Name)
} else if resp.ClusterClasses == nil || len(resp.ClusterClasses) == 0 {
} else if len(resp.ClusterClasses) == 0 {
return errors.Errorf("Couldn't find cluster class.\nManagement Cluster Name: %s, Provisioner: %s, Cluster Class Name: %s.",
clusterClassFn.ManagementClusterName, clusterClassFn.ProvisionerName, clusterClassFn.Name)
}
Expand Down
5 changes: 4 additions & 1 deletion internal/resources/tanzupackageinstall/spec/cluster_scope.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ import (
"github.com/vmware/terraform-provider-tanzu-mission-control/internal/resources/common"
)

func ConstructSpecForClusterScope(d *schema.ResourceData) (spec *packageinstallmodel.VmwareTanzuManageV1alpha1ClusterNamespaceTanzupackageInstallSpec, err error) {
// nolint: gocognit
func ConstructSpecForClusterScope(d *schema.ResourceData) (
spec *packageinstallmodel.VmwareTanzuManageV1alpha1ClusterNamespaceTanzupackageInstallSpec,
err error) {
value, ok := d.GetOk(SpecKey)
if !ok {
return spec, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func resourcePackageRepositoryInPlaceUpdate(ctx context.Context, d *schema.Resou
}

if !updateCheckForMeta(d, pkgRepoDataFromServer.meta) && !updateCheckForSpec(d, pkgRepoDataFromServer.spec) && !d.HasChange(disabledKey) {
return
return diags
}

return dataPackageRepositoryRead(ctx, d, m)
Expand Down
Loading