Skip to content
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
9 changes: 8 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ linters:
- unparam
- unused
- whitespace
- wsl
- wsl_v5
settings:
funlen:
lines: 150
Expand All @@ -72,6 +72,10 @@ linters:
min-complexity: 60
nestif:
min-complexity: 14
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
exclusions:
generated: lax
presets:
Expand Down Expand Up @@ -105,6 +109,9 @@ linters:
- linters:
- staticcheck
text: QF1011
- linters:
- staticcheck
text: SA1019
paths:
- third_party$
- builtin$
Expand Down
4 changes: 1 addition & 3 deletions internal/authctx/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,8 @@ func ProviderConfigureContextWithDefaultTransportForTesting(_ context.Context, d
config.TLSConfig.CaCert, _ = d.Get(caCert).(string)

var err error
config.TMCConnection, err = client.NewHTTPClient(config.TLSConfig)

config.TMCConnection, err = client.NewHTTPClient(config.TLSConfig)
if err != nil {
panic(err)
}
Expand All @@ -214,7 +214,6 @@ func setContext(config *TanzuContext) (TanzuContext, diag.Diagnostics) {
}

err := config.Setup()

if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down Expand Up @@ -242,7 +241,6 @@ func setContextWithDefaultTransport(config *TanzuContext) (TanzuContext, diag.Di
}

err := config.SetupWithDefaultTransportForTesting()

if err != nil {
diags = append(diags, diag.Diagnostic{
Severity: diag.Error,
Expand Down
1 change: 0 additions & 1 deletion internal/authctx/saas.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ func getBearerToken(cspEndpoint, cspToken string, config *proxy.TLSConfig) (stri
"application/x-www-form-urlencoded",
encodedToken,
)

if err == nil {
defer resp.Body.Close()
break
Expand Down
2 changes: 2 additions & 0 deletions internal/client/proxy/tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ func TestGetConnectorTLSConfig(t *testing.T) {
caCert1, _ := os.ReadFile(clientCertPath)
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert1)

return caCertPool
}(),
},
Expand All @@ -268,6 +269,7 @@ func TestGetConnectorTLSConfig(t *testing.T) {
RootCAs: func() *x509.CertPool {
caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM([]byte(caCert))

return caCertPool
}(),
},
Expand Down
3 changes: 0 additions & 3 deletions internal/client/targetlocation/targetlocation_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ func (c *Client) TargetLocationResourceServiceList(request *targetlocationsmodel
}

requestURL, err := buildTargetLocationsRequestURL(request)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -128,7 +127,6 @@ func buildTargetLocationsRequestURL(request *targetlocationsmodel.ListBackupLoca
}

err := buildQueryParams(&queryParams, "", requestMap)

if err != nil {
return "", errors.New("couldn't create request url")
}
Expand All @@ -152,7 +150,6 @@ func buildQueryParams(queryParams *url.Values, parentParam string, request map[s
switch value := value.(type) {
case map[string]interface{}:
err = buildQueryParams(queryParams, parent, value)

if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/client/transport/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func (c *Client) Patch(url string, request Request, response Response) error {

func (c *Client) invokeAction(httpMethodType string, url string, request Request, response Response) error {
requestURL := fmt.Sprintf("%s/%s", c.Host, strings.TrimPrefix(url, "/"))
body, err := request.MarshalBinary()

body, err := request.MarshalBinary()
if err != nil {
return errors.Wrap(err, "marshall request body")
}
Expand Down
2 changes: 1 addition & 1 deletion internal/helper/converter/construct_tf_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (converter *TFSchemaModelConverter[T]) buildTFValue(modelJSONData *map[stri
var modelValue interface{}

modelField := mapValue.Field
modelValue, err = converter.getModelValue(modelJSONData, modelField, arrIndexer)

modelValue, err = converter.getModelValue(modelJSONData, modelField, arrIndexer)
if err == nil {
tfSchemaValue = mapValue.EvalFunc(ConstructTFSchema, modelValue)
} else if strings.Contains(err.Error(), arrayCannotBeReachedMsg) && strings.HasSuffix(modelField, ArrayFieldMarker) {
Expand Down
4 changes: 0 additions & 4 deletions internal/helper/converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,27 +76,23 @@ func (converter *TFSchemaModelConverter[T]) FillTFSchema(modelPtr T, data *schem
)

jsonBytes, err := modelPtr.MarshalBinary()

if err != nil {
return err
}

err = json.Unmarshal(jsonBytes, &modelJSONData)

if err != nil {
return err
}

for mapKey, mapValue := range *converter.TFModelMap {
tfValue, err = converter.buildTFValue(&modelJSONData, mapValue, &arrIndexer)

if err != nil {
return err
}

if tfValue != nil {
err = data.Set(mapKey, tfValue)

if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ func validateStringFormat(parentKey string, variableValue interface{}, variableS

if regexPattern, ok := variableSchema[string(PatternKey)]; ok {
regex, err := regexp.Compile(regexPattern.(string))

if err == nil {
if !regex.MatchString(variableValue.(string)) {
errs = append(errs, errors.Errorf("Key '%s' doesn't match regular expression '%s', value provided: '%s'", parentKey, regexPattern, variableValue))
Expand Down
2 changes: 1 addition & 1 deletion internal/helper/yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func ReadYamlFile(filePath string) (string, error) {
}(inputFile)

buf := bytes.NewBuffer(nil)
_, err = io.Copy(buf, inputFile)

_, err = io.Copy(buf, inputFile)
if err != nil {
return "", err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package clustergroupsecret

import "github.com/go-openapi/swag"
import (
"github.com/go-openapi/swag"
)

// VmwareTanzuManageV1alpha1ClustergroupNamespaceSecretRequest Request to create a Secret.
//
Expand Down
4 changes: 3 additions & 1 deletion internal/models/kubernetessecret/clustergroup/fullname.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

package clustergroupsecret

import "github.com/go-openapi/swag"
import (
"github.com/go-openapi/swag"
)

// VmwareTanzuManageV1alpha1ClustergroupNamespaceSecretFullName Full name of the Secret.
//
Expand Down
1 change: 0 additions & 1 deletion internal/resources/akscluster/data_source_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build akscluster
// +build akscluster

// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build akscluster
// +build akscluster

// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
Expand Down Expand Up @@ -266,6 +265,7 @@ func TestAccAksCluster_basics(t *testing.T) {
if err != nil {
return err
}

_, err = config.TMCConnection.AKSClusterResourceService.AksClusterResourceServiceGet(fn)
if !clienterrors.IsNotFoundError(err) {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func dataSourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData
case commonscope.ClusterScope:
if scopedFullnameData.FullnameCluster != nil {
request, err := tfModelDataSourceRequestConverter.ConvertTFSchemaToAPIModel(data, []string{})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't read Tanzu Mission Control backup schedule."))
}
Expand All @@ -62,7 +61,6 @@ func dataSourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData
data.SetId("NO_DATA")
default:
err = tfModelDataSourceResponseConverter.FillTFSchema(resp, data)

if err != nil {
diags = diag.FromErr(err)
}
Expand All @@ -75,7 +73,6 @@ func dataSourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData
case commonscope.ClusterGroupScope:
if scopedFullnameData.FullnameClusterGroup != nil {
request, err := tfModelCGDataSourceRequestConverter.ConvertTFSchemaToAPIModel(data, []string{})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't read Tanzu Mission Control backup schedule."))
}
Expand All @@ -89,7 +86,6 @@ func dataSourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData
data.SetId("NO_DATA")
default:
err = tfModelCGDataSourceResponseConverter.FillTFSchema(resp, data)

if err != nil {
diags = diag.FromErr(err)
}
Expand Down
14 changes: 0 additions & 14 deletions internal/resources/backupschedule/resource_backup_schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func resourceBackupScheduleCreate(ctx context.Context, data *schema.ResourceData
case commonscope.ClusterScope:
if scopedFullnameData.FullnameCluster != nil {
model, err := tfModelResourceConverter.ConvertTFSchemaToAPIModel(data, []string{})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't create Tanzu Mission Control backup schedule."))
}
Expand All @@ -71,7 +70,6 @@ func resourceBackupScheduleCreate(ctx context.Context, data *schema.ResourceData
}

_, err = config.TMCConnection.BackupScheduleService.BackupScheduleResourceServiceCreate(request)

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't create Tanzu Mission Control backup schedule.\nManagement Cluster Name: %s, Provisioner Name: %s, Cluster Name: %s, Schedule Name: %s,"+
"Template %v",
Expand All @@ -96,7 +94,6 @@ func resourceBackupScheduleCreate(ctx context.Context, data *schema.ResourceData
}

_, err = config.TMCConnection.ClusterGroupBackupScheduleService.VmwareTanzuManageV1alpha1ClustergroupBackupScheduleResourceServiceCreate(request)

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't create Tanzu Mission Control backup schedule.\nClusterGroup Name: %s, Schedule Name: %s, Template: %v",
model.FullName.ClusterGroupName, model.FullName.Name,
Expand Down Expand Up @@ -165,7 +162,6 @@ func resourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData,
}

err = tfModelResourceConverter.FillTFSchema(resp.Schedule, data)

if err != nil {
return diag.Errorf("Couldn't read backup schedule.\nManagement Cluster Name: %s, Provisioner Name: %s, Cluster Name: %s, Schedule Name: %s",
backupScheduleFn.ManagementClusterName, backupScheduleFn.ProvisionerName, backupScheduleFn.ClusterName, backupScheduleFn.Name)
Expand All @@ -178,7 +174,6 @@ func resourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData,
}
case commonscope.ClusterGroupScope:
model, err := tfModelCGResourceConverter.ConvertTFSchemaToAPIModel(data, []string{ScopeKey, ClusterGroupScopeKey, ClusterGroupNameKey})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't read Tanzu Mission Control backup schedule."))
}
Expand All @@ -188,7 +183,6 @@ func resourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData,
backupScheduleFn.Name = backupScheduleName

resp, err := readCGResourceWait(ctx, &config, backupScheduleFn)

if err != nil {
if clienterrors.IsNotFoundError(err) {
if !helper.IsContextCallerSet(ctx) {
Expand Down Expand Up @@ -216,7 +210,6 @@ func resourceBackupScheduleRead(ctx context.Context, data *schema.ResourceData,
}

err = tfModelCGResourceConverter.FillTFSchema(resp.Schedule, data)

if err != nil {
return diag.Errorf("Couldn't read backup schedule.\n Cluster Group Name: %s, Schedule Name: %s",
backupScheduleFn.ClusterGroupName, backupScheduleFn.Name)
Expand Down Expand Up @@ -252,7 +245,6 @@ func resourceBackupScheduleDelete(ctx context.Context, data *schema.ResourceData
case commonscope.ClusterScope:
if scopedFullnameData.FullnameCluster != nil {
model, err := tfModelResourceConverter.ConvertTFSchemaToAPIModel(data, []string{ScopeKey, ClusterScopeKey, ClusterNameKey, ManagementClusterNameKey, ProvisionerNameKey})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't delete Tanzu Mission Control backup schedule."))
}
Expand Down Expand Up @@ -308,7 +300,6 @@ func resourceBackupScheduleUpdate(ctx context.Context, data *schema.ResourceData
case commonscope.ClusterScope:
if scopedFullnameData.FullnameCluster != nil {
model, err := tfModelResourceConverter.ConvertTFSchemaToAPIModel(data, []string{})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't update Tanzu Mission Control backup schedule."))
}
Expand All @@ -327,7 +318,6 @@ func resourceBackupScheduleUpdate(ctx context.Context, data *schema.ResourceData
}

_, err = config.TMCConnection.BackupScheduleService.BackupScheduleResourceServiceUpdate(request)

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't update Tanzu Mission Control backup schedule.\nManagement Cluster Name: %s, Provisioner Name: %s, Cluster Name: %s, Schedule Name: %s",
model.FullName.ManagementClusterName, model.FullName.ProvisionerName, model.FullName.ClusterName, model.FullName.Name))
Expand All @@ -336,7 +326,6 @@ func resourceBackupScheduleUpdate(ctx context.Context, data *schema.ResourceData
case commonscope.ClusterGroupScope:
if scopedFullnameData.FullnameClusterGroup != nil {
model, err := tfModelCGResourceConverter.ConvertTFSchemaToAPIModel(data, []string{})

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't update Tanzu Mission Control backup schedule."))
}
Expand All @@ -355,7 +344,6 @@ func resourceBackupScheduleUpdate(ctx context.Context, data *schema.ResourceData
}

_, err = config.TMCConnection.ClusterGroupBackupScheduleService.VmwareTanzuManageV1alpha1ClustergroupBackupScheduleResourceServiceUpdate(request)

if err != nil {
return diag.FromErr(errors.Wrapf(err, "Couldn't update Tanzu Mission Control backup schedule.\nClusterGroup Name: %s, Schedule Name: %s",
model.FullName.ClusterGroupName, model.FullName.Name))
Expand Down Expand Up @@ -393,7 +381,6 @@ func resourceBackupScheduleImporter(ctx context.Context, data *schema.ResourceDa
backupScheduleFn.ManagementClusterName, backupScheduleFn.ProvisionerName, backupScheduleFn.ClusterName, backupScheduleFn.Name)
} else {
err = tfModelResourceConverter.FillTFSchema(resp.Schedule, data)

if err != nil {
return nil, err
}
Expand Down Expand Up @@ -421,7 +408,6 @@ func resourceBackupScheduleImporter(ctx context.Context, data *schema.ResourceDa
backupScheduleFn.ClusterGroupName, backupScheduleFn.Name)
} else {
err = tfModelCGResourceConverter.FillTFSchema(resp.Schedule, data)

if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build backupschedule
// +build backupschedule

// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
Expand Down
1 change: 0 additions & 1 deletion internal/resources/backupschedule/tests/helper_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build backupschedule
// +build backupschedule

// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
Expand Down
1 change: 0 additions & 1 deletion internal/resources/cluster/data_source_cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//go:build cluster
// +build cluster

// © Broadcom. All Rights Reserved.
// The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
Expand Down
1 change: 0 additions & 1 deletion internal/resources/cluster/manifest/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func getManifests(manifestsBlob string) (manifests []manifest, err error) {
}

namespace, ok, err := unstructured.NestedString(usObj, "metadata", "namespace")

if err != nil {
return nil, fmt.Errorf("provided value for namespace in the metadata of kind %v is not of type string, error :%v", gvk, err)
}
Expand Down
1 change: 0 additions & 1 deletion internal/resources/cluster/nodepools/resource_node_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,6 @@ func resourceNodePoolCreate(ctx context.Context, d *schema.ResourceData, m inter
}

nodePoolResponse, err := config.TMCConnection.NodePoolResourceService.ManageV1alpha1ClusterNodePoolResourceServiceCreate(nodePoolRequest)

if err != nil {
return diag.FromErr(errors.Wrapf(err, "unable to create tanzu node pool entry"))
}
Expand Down
Loading
Loading