Skip to content

Commit

Permalink
Enable stylecheck linter (#2505)
Browse files Browse the repository at this point in the history
Co-authored-by: saima-s <[email protected]>
Co-authored-by: Vivek Singh <[email protected]>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 31, 2024
1 parent 2f6590c commit a121b50
Show file tree
Hide file tree
Showing 62 changed files with 314 additions and 301 deletions.
5 changes: 5 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ linters:
- gci
- goprintffuncname
- nolintlint
- stylecheck

run:
timeout: 10m # golangci-lint run's timeout.
Expand All @@ -46,6 +47,8 @@ issues:
- misspell
- nestif
- gci
- stylecheck

- text: "`ctx` is unused" # Context might not be in use in places, but for consistency, we pass it.
linters:
- unparam
Expand Down Expand Up @@ -78,6 +81,8 @@ linters-settings:
- blank
- dot
skip-generated: true
stylecheck:
checks: [ "all", "-ST1001", "-ST1005", "-ST1016", "-ST1023", "-ST1000"]

exclude-dirs:
- pkg/client/applyconfiguration/cr/v1alpha1 # generated from code-gen
Expand Down
6 changes: 3 additions & 3 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ builds:
main: cmd/kanctl/main.go
ldflags: &ldflags
- -extldflags "-static"
-X github.com/kanisterio/kanister/pkg/version.VERSION={{.Version}}
-X github.com/kanisterio/kanister/pkg/version.GIT_COMMIT={{.Commit}}
-X github.com/kanisterio/kanister/pkg/version.BUILD_DATE={{.Date}}
-X github.com/kanisterio/kanister/pkg/version.Version={{.Version}}
-X github.com/kanisterio/kanister/pkg/version.GitCommit={{.Commit}}
-X github.com/kanisterio/kanister/pkg/version.BuildDate={{.Date}}
env: &env
- GO111MODULE=on
- CGO_ENABLED=1
Expand Down
6 changes: 3 additions & 3 deletions design/kanister-prometheus-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ controller/metrics.go

```golang
const (
ACTION_SET_COUNTER_VEC_LABEL_RES = "resolution"
ActionSetCounterVecLabelRes = "resolution"
ACTION_SET_COUNTER_VEC_LABEL_OP_TYPE = "operation_type"
)

Expand All @@ -228,7 +228,7 @@ type metrics struct {
func getActionSetCounterVecLabels() []kanistermetrics.BoundedLabel {
bl := make([]kanistermetrics.BoundedLabel, 2)
bl[0] = kanistermetrics.BoundedLabel{
LabelName: ACTION_SET_COUNTER_VEC_LABEL_RES,
LabelName: ActionSetCounterVecLabelRes,
LabelValues: []string{"success", "failure"},
}
bl[1] = kanistermetrics.BoundedLabel{
Expand All @@ -244,7 +244,7 @@ func getActionSetCounterVecLabels() []kanistermetrics.BoundedLabel {
func constructActionSetCounterVecLabels(operation_type string, resolution string) prometheus.Labels {
return prometheus.Labels{
ACTION_SET_COUNTER_VEC_LABEL_OP_TYPE: operation_type,
ACTION_SET_COUNTER_VEC_LABEL_RES: resolution,
ActionSetCounterVecLabelRes: resolution,
}
}

Expand Down
5 changes: 0 additions & 5 deletions pkg/apis/cr/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ type Profile struct {
SkipSSLVerify bool `json:"skipSSLVerify"`
}

// LocationType
type LocationType string

const (
Expand All @@ -342,7 +341,6 @@ const (
LocationTypeKopia LocationType = "kopia"
)

// Location
type Location struct {
// Type specifies the kind of object storage that would be used to upload the
// backup objects. Currently supported values are: "GCS", "S3Compliant",
Expand All @@ -359,7 +357,6 @@ type Location struct {
Region string `json:"region"`
}

// CredentialType
type CredentialType string

const (
Expand All @@ -368,7 +365,6 @@ const (
CredentialTypeKopia CredentialType = "kopia"
)

// Credential
type Credential struct {
// Type represents the information about how the credentials are provided for the respective object storage.
Type CredentialType `json:"type"`
Expand All @@ -380,7 +376,6 @@ type Credential struct {
KopiaServerSecret *KopiaServerSecret `json:"kopiaServerSecret,omitempty"`
}

// KeyPair
type KeyPair struct {
// IDField specifies the corresponding key in the secret where the AWS Key ID value is stored.
IDField string `json:"idField"`
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/bp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const (
imagePrefix = "ghcr.io/kanisterio"
)

// Blueprint implements Blueprint() to return Blueprint specs for the app
// AppBlueprint implements Blueprint() to return Blueprint specs for the app
// Blueprint() returns Blueprint placed at ./blueprints/{app-name}-blueprint.yaml
type AppBlueprint struct {
App string
Expand Down Expand Up @@ -109,7 +109,7 @@ func updateImageTags(bp *crv1alpha1.Blueprint) {
}
}

// Blueprint returns Blueprint placed at ./blueprints/{app-name}-blueprint.yaml
// NewPITRBlueprint returns blueprint placed at ./blueprints/{app-name}-blueprint.yaml
func NewPITRBlueprint(app string, bpReposPath string, useDevImages bool) Blueprinter {
if bpReposPath == "" {
bpReposPath = blueprintsRepo
Expand Down
12 changes: 6 additions & 6 deletions pkg/app/cockroachdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ func (c *CockroachDB) IsReady(ctx context.Context) (bool, error) {
return false, errkit.Wrap(err, "Error while Creating ca.crt", "stderr", stderr)
}

createTlsCrtCmd := fmt.Sprintf("echo '%s'>> /cockroach/cockroach-client-certs/client.root.crt", c.tlscrt)
createTlsCrt := []string{"sh", "-c", createTlsCrtCmd}
_, stderr, err = c.execCommand(ctx, createTlsCrt)
createTLSCrtCmd := fmt.Sprintf("echo '%s'>> /cockroach/cockroach-client-certs/client.root.crt", c.tlscrt)
createTLSCrt := []string{"sh", "-c", createTLSCrtCmd}
_, stderr, err = c.execCommand(ctx, createTLSCrt)
if err != nil {
return false, errkit.Wrap(err, "Error while Creating tls.crt", "stderr", stderr)
}

createTlsKeyCmd := fmt.Sprintf("echo '%s' >> /cockroach/cockroach-client-certs/client.root.key", c.tlskey)
createTlsKey := []string{"sh", "-c", createTlsKeyCmd}
_, stderr, err = c.execCommand(ctx, createTlsKey)
createTLSKeyCmd := fmt.Sprintf("echo '%s' >> /cockroach/cockroach-client-certs/client.root.key", c.tlskey)
createTLSKey := []string{"sh", "-c", createTLSKeyCmd}
_, stderr, err = c.execCommand(ctx, createTLSKey)
if err != nil {
return false, errkit.Wrap(err, "Error while Creating tls.key", "stderr", stderr)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/app/couchbase.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ type CouchbaseDB struct {
chart helm.ChartInfo
}

// NewCouchbaseDB initialises an instance of Couchbase DB
// Last tested woking version "2.3.0"
func NewCouchbaseDB(name string) App {
return &CouchbaseDB{
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/csi-snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/kanisterio/kanister/pkg/log"
)

// Integration test app for CSI Snapshot functions
// TimeLogCSI is integration test app for CSI Snapshot functions.
type TimeLogCSI struct {
cli kubernetes.Interface
namespace string
Expand Down
1 change: 1 addition & 0 deletions pkg/app/elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type ElasticsearchInstance struct {
elasticsearchURL string
}

// NewElasticsearchInstance initialises an instance of Elasticsearch
// Last tested on 8.5.1
func NewElasticsearchInstance(name string) App {
return &ElasticsearchInstance{
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/mongodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
mongoWaitTimeout = 5 * time.Minute
)

// IsMaster struct gets mapped to the output of the mongo command that checks if node is master or not.
// IsMasterOutput struct gets mapped to the output of the mongo command that checks if node is master or not.
type IsMasterOutput struct {
Ismaster bool `json:"ismaster"`
}
Expand All @@ -51,6 +51,7 @@ type MongoDB struct {
chart helm.ChartInfo
}

// NewMongoDB initialises an instance of Mongo DB
// Last tested working version "9.0.0"
func NewMongoDB(name string) HelmApp {
return &MongoDB{
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type MysqlDB struct {

var _ HelmApp = &MysqlDB{}

// Last tested working version "6.14.11"
// NewMysqlDB was last tested with working version "6.14.11"
func NewMysqlDB(name string) HelmApp {
return &MysqlDB{
name: name,
Expand Down
3 changes: 2 additions & 1 deletion pkg/app/postgresql.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ type PostgresDB struct {
namespace string
}

// Last tested chart version "10.12.3". Also we are using postgres version 13.4
// NewPostgresDB initialises an instance of Postgres DB
// Last tested chart version "10.12.3". Also, we are using postgres version 13.4
func NewPostgresDB(name string, subPath string) App {
return &PostgresDB{
name: name,
Expand Down
18 changes: 9 additions & 9 deletions pkg/aws/ec2/ec2.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type EC2 struct {
DryRun bool
}

// NewEC2Client returns ec2 client struct.
// NewClient returns ec2 client struct.
func NewClient(ctx context.Context, awsConfig *aws.Config, region string) (*EC2, error) {
s, err := session.NewSession(awsConfig)
if err != nil {
Expand All @@ -50,20 +50,20 @@ func (e EC2) DescribeSecurityGroup(ctx context.Context, groupName string) (*ec2.
return e.DescribeSecurityGroupsWithContext(ctx, sgi)
}

func (e EC2) CreateSecurityGroup(ctx context.Context, groupName, description, vpcId string) (*ec2.CreateSecurityGroupOutput, error) {
func (e EC2) CreateSecurityGroup(ctx context.Context, groupName, description, vpcID string) (*ec2.CreateSecurityGroupOutput, error) {
sgi := &ec2.CreateSecurityGroupInput{
DryRun: &e.DryRun,
Description: &description,
GroupName: &groupName,
VpcId: aws.String(vpcId),
VpcId: aws.String(vpcID),
}
return e.CreateSecurityGroupWithContext(ctx, sgi)
}

func (e EC2) AuthorizeSecurityGroupIngress(ctx context.Context, groupId, cidr, protocol string, port int64) (*ec2.AuthorizeSecurityGroupIngressOutput, error) {
func (e EC2) AuthorizeSecurityGroupIngress(ctx context.Context, groupID, cidr, protocol string, port int64) (*ec2.AuthorizeSecurityGroupIngressOutput, error) {
sgi := &ec2.AuthorizeSecurityGroupIngressInput{
DryRun: &e.DryRun,
GroupId: &groupId,
GroupId: &groupID,
CidrIp: &cidr,
IpProtocol: &protocol,
ToPort: &port,
Expand All @@ -72,20 +72,20 @@ func (e EC2) AuthorizeSecurityGroupIngress(ctx context.Context, groupId, cidr, p
return e.AuthorizeSecurityGroupIngressWithContext(ctx, sgi)
}

func (e EC2) DeleteSecurityGroup(ctx context.Context, groupId string) (*ec2.DeleteSecurityGroupOutput, error) {
func (e EC2) DeleteSecurityGroup(ctx context.Context, groupID string) (*ec2.DeleteSecurityGroupOutput, error) {
sgi := &ec2.DeleteSecurityGroupInput{
DryRun: &e.DryRun,
GroupId: aws.String(groupId),
GroupId: aws.String(groupID),
}
return e.DeleteSecurityGroupWithContext(ctx, sgi)
}

func (e EC2) DescribeSubnets(ctx context.Context, vpcId string) (*ec2.DescribeSubnetsOutput, error) {
func (e EC2) DescribeSubnets(ctx context.Context, vpcID string) (*ec2.DescribeSubnetsOutput, error) {
paramsEC2 := &ec2.DescribeSubnetsInput{
Filters: []*ec2.Filter{
{
Name: aws.String("vpc-id"),
Values: []*string{aws.String(vpcId)},
Values: []*string{aws.String(vpcID)},
},
},
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/aws/rds/rds.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RDS struct {
*rds.RDS
}

// NewRDSClient returns ec2 client struct.
// NewClient returns ec2 client struct.
func NewClient(ctx context.Context, awsConfig *aws.Config, region string) (*RDS, error) {
s, err := session.NewSession(awsConfig)
if err != nil {
Expand All @@ -48,7 +48,7 @@ func NewClient(ctx context.Context, awsConfig *aws.Config, region string) (*RDS,
return &RDS{RDS: rds.New(s, awsConfig.WithMaxRetries(maxRetries).WithRegion(region).WithCredentials(awsConfig.Credentials))}, nil
}

// CreateDBInstanceWithContext
// CreateDBInstance return DBInstance with context
func (r RDS) CreateDBInstance(
ctx context.Context,
storage *int64,
Expand Down Expand Up @@ -129,7 +129,7 @@ func (r RDS) WaitUntilDBClusterAvailable(ctx context.Context, dbClusterID string
})
}

// WaitDBCluster waits for DB cluster with instanceID
// WaitOnDBCluster waits for DB cluster with instanceID
func (r RDS) WaitOnDBCluster(ctx context.Context, dbClusterID, status string) error {
// describe the cluster return err if status is !Available
dci := &rds.DescribeDBClustersInput{
Expand Down
8 changes: 4 additions & 4 deletions pkg/blockstorage/azure/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type ClientCredentialsConfig struct {
Resource string
}

// Defaults to Public Cloud and Resource Manager Endpoint.
// NewClientCredentialsConfig defaults to Public Cloud and Resource Manager Endpoint.
func NewClientCredentialsConfig(clientID string, clientSecret string, tenantID string) ClientCredentialsConfig {
return ClientCredentialsConfig{
ClientID: clientID,
Expand All @@ -49,7 +49,7 @@ func NewClientCredentialsConfig(clientID string, clientSecret string, tenantID s
}
}

// Public interface to authenticate with different Azure credentials type
// AzureAuthenticator is a public interface to authenticate with different Azure credentials type
type AzureAuthenticator interface {
Authenticate(creds map[string]string) error
GetAuthorizer() azcore.TokenCredential
Expand All @@ -66,7 +66,7 @@ func NewAzureAuthenticator(config map[string]string) (AzureAuthenticator, error)
}
}

// authenticate with MSI creds
// MsiAuthenticator authenticates with MSI credentials
type MsiAuthenticator struct {
azcore.TokenCredential
}
Expand All @@ -91,7 +91,7 @@ func (m *MsiAuthenticator) Authenticate(config map[string]string) error {
return nil
}

// authenticate with client secret creds
// ClientSecretAuthenticator authenticates with client secret credentials
type ClientSecretAuthenticator struct {
azcore.TokenCredential
}
Expand Down
Loading

0 comments on commit a121b50

Please sign in to comment.