From a121b50064fd09dc88b30024116922c60226e0a2 Mon Sep 17 00:00:00 2001 From: Ankit Jain Date: Wed, 31 Jul 2024 12:55:21 +0530 Subject: [PATCH] Enable stylecheck linter (#2505) Co-authored-by: saima-s Co-authored-by: Vivek Singh Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- .golangci.yml | 5 + .goreleaser.yml | 6 +- design/kanister-prometheus-integration.md | 6 +- pkg/apis/cr/v1alpha1/types.go | 5 - pkg/app/bp.go | 4 +- pkg/app/cockroachdb.go | 12 +- pkg/app/couchbase.go | 1 + pkg/app/csi-snapshot.go | 2 +- pkg/app/elasticsearch.go | 1 + pkg/app/mongodb.go | 3 +- pkg/app/mysql.go | 2 +- pkg/app/postgresql.go | 3 +- pkg/aws/ec2/ec2.go | 18 +-- pkg/aws/rds/rds.go | 6 +- pkg/blockstorage/azure/auth.go | 8 +- pkg/blockstorage/azure/azuredisk.go | 30 ++--- pkg/blockstorage/gcepd/gcepd.go | 8 +- pkg/blockstorage/helpers.go | 4 +- pkg/consts/consts.go | 13 ++- pkg/controller/controller.go | 10 +- pkg/controller/controller_test.go | 108 +++++++++--------- pkg/controller/metrics.go | 68 +++++------ pkg/datamover/profile.go | 4 +- pkg/datamover/repository_server.go | 4 +- pkg/function/args.go | 2 +- pkg/function/export_rds_snapshot_location.go | 6 +- pkg/function/kubeops.go | 4 +- pkg/function/restore_data.go | 2 +- pkg/handler/handler.go | 2 +- pkg/jsonpath/jsonpath.go | 2 +- pkg/kancontroller/kancontroller.go | 2 +- pkg/kanctl/error.go | 8 +- pkg/kopia/cli/internal/location.go | 2 +- pkg/kopia/command/maintenance.go | 4 +- pkg/kopia/command/maintenance_test.go | 4 +- pkg/kopia/command/parse_command_output.go | 2 +- pkg/kopia/command/policy_show_global.go | 4 +- pkg/kopia/command/policy_test.go | 2 +- pkg/kopia/command/repository.go | 4 +- pkg/kopia/command/repository_test.go | 2 +- pkg/kopia/command/storage/s3_args.go | 4 +- pkg/kopia/errors/utils.go | 2 +- .../maintenance/get_maintenance_owner.go | 2 +- pkg/kube/fake_pod_command_executor.go | 1 - pkg/kube/pod.go | 16 +-- pkg/kube/pod_controller_processor.go | 1 + pkg/kube/pod_test.go | 14 +-- pkg/location/location.go | 2 +- pkg/metrics/metrics.go | 1 + pkg/output/output.go | 2 +- pkg/param/param.go | 1 - pkg/restic/restic.go | 8 +- pkg/secrets/gcp.go | 8 +- pkg/secrets/gcp_test.go | 12 +- pkg/secrets/repositoryserver/aws_secrets.go | 1 + pkg/secrets/secrets.go | 13 +-- pkg/testing/integration_register.go | 77 +++++++------ pkg/tools/grype_report_parser_tool.go | 6 +- pkg/validate/error.go | 4 +- pkg/validate/error_test.go | 6 +- pkg/validate/validate.go | 42 +++---- pkg/version/version.go | 9 +- 62 files changed, 314 insertions(+), 301 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 5828ccbfd6..5ef0ea546a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -27,6 +27,7 @@ linters: - gci - goprintffuncname - nolintlint + - stylecheck run: timeout: 10m # golangci-lint run's timeout. @@ -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 @@ -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 diff --git a/.goreleaser.yml b/.goreleaser.yml index 98b52ad652..93e8f8cedb 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -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 diff --git a/design/kanister-prometheus-integration.md b/design/kanister-prometheus-integration.md index 74957dc42a..51736bc222 100644 --- a/design/kanister-prometheus-integration.md +++ b/design/kanister-prometheus-integration.md @@ -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" ) @@ -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{ @@ -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, } } diff --git a/pkg/apis/cr/v1alpha1/types.go b/pkg/apis/cr/v1alpha1/types.go index 2f86b8dde8..c347f66863 100644 --- a/pkg/apis/cr/v1alpha1/types.go +++ b/pkg/apis/cr/v1alpha1/types.go @@ -332,7 +332,6 @@ type Profile struct { SkipSSLVerify bool `json:"skipSSLVerify"` } -// LocationType type LocationType string const ( @@ -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", @@ -359,7 +357,6 @@ type Location struct { Region string `json:"region"` } -// CredentialType type CredentialType string const ( @@ -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"` @@ -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"` diff --git a/pkg/app/bp.go b/pkg/app/bp.go index b9f5a96d4a..68cc6079cc 100644 --- a/pkg/app/bp.go +++ b/pkg/app/bp.go @@ -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 @@ -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 diff --git a/pkg/app/cockroachdb.go b/pkg/app/cockroachdb.go index 384dc7925a..68785f6b49 100644 --- a/pkg/app/cockroachdb.go +++ b/pkg/app/cockroachdb.go @@ -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) } diff --git a/pkg/app/couchbase.go b/pkg/app/couchbase.go index 29fafbf623..a6a0cc2c06 100644 --- a/pkg/app/couchbase.go +++ b/pkg/app/couchbase.go @@ -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{ diff --git a/pkg/app/csi-snapshot.go b/pkg/app/csi-snapshot.go index 447422c658..7c489f6d4a 100644 --- a/pkg/app/csi-snapshot.go +++ b/pkg/app/csi-snapshot.go @@ -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 diff --git a/pkg/app/elasticsearch.go b/pkg/app/elasticsearch.go index 5e3c4d7964..ce8b241378 100644 --- a/pkg/app/elasticsearch.go +++ b/pkg/app/elasticsearch.go @@ -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{ diff --git a/pkg/app/mongodb.go b/pkg/app/mongodb.go index 41b0bc360b..d0a608bd16 100644 --- a/pkg/app/mongodb.go +++ b/pkg/app/mongodb.go @@ -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"` } @@ -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{ diff --git a/pkg/app/mysql.go b/pkg/app/mysql.go index 6b35c2d419..109c517b1a 100644 --- a/pkg/app/mysql.go +++ b/pkg/app/mysql.go @@ -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, diff --git a/pkg/app/postgresql.go b/pkg/app/postgresql.go index 9c8cd72223..5e504f8141 100644 --- a/pkg/app/postgresql.go +++ b/pkg/app/postgresql.go @@ -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, diff --git a/pkg/aws/ec2/ec2.go b/pkg/aws/ec2/ec2.go index 4404dd197f..056bb09ffc 100644 --- a/pkg/aws/ec2/ec2.go +++ b/pkg/aws/ec2/ec2.go @@ -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 { @@ -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, @@ -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)}, }, }, } diff --git a/pkg/aws/rds/rds.go b/pkg/aws/rds/rds.go index 58a0800c6e..80b346f2df 100644 --- a/pkg/aws/rds/rds.go +++ b/pkg/aws/rds/rds.go @@ -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 { @@ -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, @@ -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{ diff --git a/pkg/blockstorage/azure/auth.go b/pkg/blockstorage/azure/auth.go index f909a1b41e..0a6000d99f 100644 --- a/pkg/blockstorage/azure/auth.go +++ b/pkg/blockstorage/azure/auth.go @@ -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, @@ -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 @@ -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 } @@ -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 } diff --git a/pkg/blockstorage/azure/azuredisk.go b/pkg/blockstorage/azure/azuredisk.go index ab93b77c93..67107d2ba9 100644 --- a/pkg/blockstorage/azure/azuredisk.go +++ b/pkg/blockstorage/azure/azuredisk.go @@ -73,11 +73,11 @@ func (s *AdStorage) VolumeGet(ctx context.Context, id string, zone string) (*blo func (s *AdStorage) VolumeCreate(ctx context.Context, volume blockstorage.Volume) (*blockstorage.Volume, error) { tags := blockstorage.SanitizeTags(blockstorage.KeyValueToMap(volume.Tags)) - diskId, err := uuid.NewV1() + diskID, err := uuid.NewV1() if err != nil { return nil, errors.Wrap(err, "Failed to create UUID") } - diskName := fmt.Sprintf(volumeNameFmt, diskId.String()) + diskName := fmt.Sprintf(volumeNameFmt, diskID.String()) diskProperties := &armcompute.DiskProperties{ CreationData: &armcompute.CreationData{ @@ -194,11 +194,11 @@ func (s *AdStorage) SnapshotCopyWithArgs(ctx context.Context, from blockstorage. if err != nil { return nil, errors.Wrapf(err, "Failed to copy disk to blob") } - snapId, err := uuid.NewV1() + snapID, err := uuid.NewV1() if err != nil { return nil, errors.Wrap(err, "Failed to create UUID") } - snapName := fmt.Sprintf(snapshotNameFmt, snapId.String()) + snapName := fmt.Sprintf(snapshotNameFmt, snapID.String()) createSnap := getSnapshotObject(blob, from, to, snapName, storageAccountID) migrateResourceGroup := s.azCli.ResourceGroup @@ -294,11 +294,11 @@ func deleteBlob(blob *storage.Blob, blobName string) { } func (s *AdStorage) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, tags map[string]string) (*blockstorage.Snapshot, error) { - snapId, err := uuid.NewV1() + snapID, err := uuid.NewV1() if err != nil { return nil, errors.Wrap(err, "Failed to create UUID") } - snapName := fmt.Sprintf(snapshotNameFmt, snapId.String()) + snapName := fmt.Sprintf(snapshotNameFmt, snapID.String()) tags = blockstorage.SanitizeTags(ktags.GetTags(tags)) region, _, err := getLocationInfo(volume.Az) if err != nil { @@ -425,9 +425,9 @@ func (s *AdStorage) VolumeParse(ctx context.Context, volume interface{}) (*block return nil, errors.New("Volume type is not available") } - volId := "" + volID := "" if vol.ID != nil { - volId = blockstorage.StringFromPtr(vol.ID) + volID = blockstorage.StringFromPtr(vol.ID) } else { return nil, errors.New("Volume Id is not available") } @@ -449,7 +449,7 @@ func (s *AdStorage) VolumeParse(ctx context.Context, volume interface{}) (*block return &blockstorage.Volume{ Type: s.Type(), - ID: volId, + ID: volID, Encrypted: encrypted, SizeInBytes: diskSize, Az: az, @@ -468,15 +468,15 @@ func (s *AdStorage) SnapshotParse(ctx context.Context, snapshot interface{}) (*b } func (s *AdStorage) snapshotParse(ctx context.Context, snap armcompute.Snapshot) (*blockstorage.Snapshot, error) { - snapId := "" + snapID := "" if snap.ID != nil { - snapId = *snap.ID + snapID = *snap.ID } else { return nil, errors.New("Snapshot ID is missing") } vol := &blockstorage.Volume{ Type: s.Type(), - ID: snapId, + ID: snapID, } snapCreationTime := time.Now() @@ -506,7 +506,7 @@ func (s *AdStorage) snapshotParse(ctx context.Context, snap armcompute.Snapshot) } return &blockstorage.Snapshot{ Encrypted: encrypted, - ID: snapId, + ID: snapID, Region: region, SizeInBytes: blockstorage.Int64(diskSize), Tags: blockstorage.MapToKeyValue(tags), @@ -575,11 +575,11 @@ func (s *AdStorage) VolumeCreateFromSnapshot(ctx context.Context, snapshot block return nil, err } - diskId, err := uuid.NewV1() + diskID, err := uuid.NewV1() if err != nil { return nil, errors.Wrap(err, "Failed to create UUID") } - diskName := fmt.Sprintf(volumeNameFmt, diskId.String()) + diskName := fmt.Sprintf(volumeNameFmt, diskID.String()) tags = blockstorage.SanitizeTags(tags) createDisk := armcompute.Disk{ Name: blockstorage.StringPtr(diskName), diff --git a/pkg/blockstorage/gcepd/gcepd.go b/pkg/blockstorage/gcepd/gcepd.go index 7e7595e0f0..bb0beb4722 100644 --- a/pkg/blockstorage/gcepd/gcepd.go +++ b/pkg/blockstorage/gcepd/gcepd.go @@ -187,12 +187,12 @@ func (s *GpdStorage) SnapshotCopyWithArgs(ctx context.Context, from blockstorage // SnapshotCreate is part of blockstorage.Provider func (s *GpdStorage) SnapshotCreate(ctx context.Context, volume blockstorage.Volume, tags map[string]string) (*blockstorage.Snapshot, error) { - rbId, uerr := uuid.NewV1() + rbID, uerr := uuid.NewV1() if uerr != nil { return nil, errors.Wrap(uerr, "Failed to create UUID") } rb := &compute.Snapshot{ - Name: fmt.Sprintf(snapshotNameFmt, rbId.String()), + Name: fmt.Sprintf(snapshotNameFmt, rbID.String()), Labels: blockstorage.SanitizeTags(ktags.GetTags(tags)), } var err error @@ -384,12 +384,12 @@ func (s *GpdStorage) VolumeCreateFromSnapshot(ctx context.Context, snapshot bloc tags[tag.Key] = tag.Value } } - createDiskId, err := uuid.NewV1() + createDiskID, err := uuid.NewV1() if err != nil { return nil, errors.Wrap(err, "Failed to create UUID") } createDisk := &compute.Disk{ - Name: fmt.Sprintf(volumeNameFmt, createDiskId.String()), + Name: fmt.Sprintf(volumeNameFmt, createDiskID.String()), SizeGb: blockstorage.SizeInGi(snapshot.Volume.SizeInBytes), Type: snapshot.Volume.VolumeType, Labels: blockstorage.SanitizeTags(ktags.GetTags(tags)), diff --git a/pkg/blockstorage/helpers.go b/pkg/blockstorage/helpers.go index ae28929b2f..58339feddb 100644 --- a/pkg/blockstorage/helpers.go +++ b/pkg/blockstorage/helpers.go @@ -185,8 +185,8 @@ func Int64(i *int64) int64 { return 0 } -// String returns a string value for the passed string pointer. It returns the empty string if the -// pointer is nil. +// StringFromPtr returns a string value for the passed string pointer. +// It returns the empty string if the pointer is nil. func StringFromPtr(s *string) string { if s != nil { return *s diff --git a/pkg/consts/consts.go b/pkg/consts/consts.go index 43549dcfea..8809950e07 100644 --- a/pkg/consts/consts.go +++ b/pkg/consts/consts.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package consts declares all the constants. package consts const ( @@ -47,11 +48,15 @@ const ( ) // These consts are used to query Repository server API objects -const RepositoryServerResourceName = "repositoryserver" -const RepositoryServerResourceNamePlural = "repositoryservers" +const ( + RepositoryServerResourceName = "repositoryserver" + RepositoryServerResourceNamePlural = "repositoryservers" +) -const LatestKanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev" -const KanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:0.109.0" +const ( + LatestKanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:v9.99.9-dev" + KanisterToolsImage = "ghcr.io/kanisterio/kanister-tools:0.109.0" +) // KanisterToolsImageEnvName is used to set up a custom kanister-tools image const KanisterToolsImageEnvName = "KANISTER_TOOLS" diff --git a/pkg/controller/controller.go b/pkg/controller/controller.go index c44d022d03..4e3c7f69a0 100644 --- a/pkg/controller/controller.go +++ b/pkg/controller/controller.go @@ -442,12 +442,12 @@ func (c *Controller) runAction(ctx context.Context, t *tomb.Tomb, as *crv1alpha1 c.logAndSuccessEvent(ctx, fmt.Sprintf("Executing action %s", action.Name), "Started Action", as) tp, err := param.New(ctx, c.clientset, c.dynClient, c.crClient, c.osClient, action) if err != nil { - c.incrementActionSetResolutionCounterVec(ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE) + c.incrementActionSetResolutionCounterVec(ActionSetCounterVecLabelResFailure) return err } phases, err := kanister.GetPhases(*bp, action.Name, action.PreferredVersion, *tp) if err != nil { - c.incrementActionSetResolutionCounterVec(ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE) + c.incrementActionSetResolutionCounterVec(ActionSetCounterVecLabelResFailure) return err } @@ -455,7 +455,7 @@ func (c *Controller) runAction(ctx context.Context, t *tomb.Tomb, as *crv1alpha1 // can be specified in blueprint using actions[name].deferPhase deferPhase, err := kanister.GetDeferPhase(*bp, action.Name, action.PreferredVersion, *tp) if err != nil { - c.incrementActionSetResolutionCounterVec(ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE) + c.incrementActionSetResolutionCounterVec(ActionSetCounterVecLabelResFailure) return err } @@ -472,9 +472,9 @@ func (c *Controller) runAction(ctx context.Context, t *tomb.Tomb, as *crv1alpha1 if deferErr == nil && coreErr == nil { c.renderActionsetArtifacts(ctx, as, aIDX, as.Namespace, as.Name, action.Name, bp, tp) c.maybeSetActionSetStateComplete(ctx, as, aIDX, bp, coreErr, deferErr) - c.incrementActionSetResolutionCounterVec(ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS) + c.incrementActionSetResolutionCounterVec(ActionSetCounterVecLabelResSuccess) } else { - c.incrementActionSetResolutionCounterVec(ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE) + c.incrementActionSetResolutionCounterVec(ActionSetCounterVecLabelResFailure) } }() diff --git a/pkg/controller/controller_test.go b/pkg/controller/controller_test.go index 00b5d684e3..a925d4c2ef 100644 --- a/pkg/controller/controller_test.go +++ b/pkg/controller/controller_test.go @@ -528,85 +528,85 @@ func (s *ControllerSuite) TestExecActionSet(c *C) { funcNames: []string{testutil.WaitFuncName}, name: "WaitFunc", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.WaitFuncName, testutil.WaitFuncName}, name: "WaitWait", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.FailFuncName}, name: "FailFunc", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + metricResolution: ActionSetCounterVecLabelResFailure, }, { funcNames: []string{testutil.WaitFuncName, testutil.FailFuncName}, name: "WaitFail", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + metricResolution: ActionSetCounterVecLabelResFailure, }, { funcNames: []string{testutil.FailFuncName, testutil.WaitFuncName}, name: "FailWait", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + metricResolution: ActionSetCounterVecLabelResFailure, }, { funcNames: []string{testutil.ArgFuncName}, name: "ArgFunc", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.ArgFuncName, testutil.FailFuncName}, name: "ArgFail", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + metricResolution: ActionSetCounterVecLabelResFailure, }, { funcNames: []string{testutil.OutputFuncName}, name: "OutputFunc", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.CancelFuncName}, name: "CancelFunc", version: kanister.DefaultVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + metricResolution: ActionSetCounterVecLabelResFailure, }, { funcNames: []string{testutil.ArgFuncName}, name: "ArgFuncVersion", version: testutil.TestVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.ArgFuncName}, name: "ArgFuncVersionFallback", version: "v1.2.3", - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.ArgFuncName}, name: "ArgFuncNoActionSetVersion", version: "", - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, { funcNames: []string{testutil.VersionMismatchFuncName}, name: "VersionMismatchFunc", version: "v1.2.3", - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + metricResolution: ActionSetCounterVecLabelResFailure, }, { funcNames: []string{testutil.ArgFuncName, testutil.OutputFuncName}, name: "ArgOutputFallbackOnlyOutput", version: testutil.TestVersion, - metricResolution: ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, + metricResolution: ActionSetCounterVecLabelResSuccess, }, } { var err error @@ -1085,77 +1085,77 @@ func (s *ControllerSuite) TestGetActionTypeBucket(c *C) { actionType string }{ { - actionType: ACTION_TYPE_BACKUP, + actionType: ActionTypeBackup, }, { - actionType: ACTION_TYPE_RESTORE, + actionType: ActionTypeRestore, }, { - actionType: ACTION_TYPE_DELETE, + actionType: ActionTypeDelete, }, { - actionType: ACTION_TYPE_BACKUP_TO_SERVER, + actionType: ActionTypeBackupToServer, }, { - actionType: ACTION_TYPE_RESTORE_FROM_SERVER, + actionType: ActionTypeRestoreFromServer, }, { - actionType: ACTION_TYPE_BEFORE_BACKUP, + actionType: ActionTypeBeforeBackup, }, { - actionType: ACTION_TYPE_ON_SUCCESS, + actionType: ActionTypeOnSuccess, }, { - actionType: ACTION_TYPE_ON_FAILURE, + actionType: ActionTypeOnFailure, }, { - actionType: ACTION_TYPE_PRE_RESTORE, + actionType: ActionTypePreRestore, }, { - actionType: ACTION_TYPE_POST_RESTORE, + actionType: ActionTypePostRestore, }, { - actionType: ACTION_TYPE_POST_RESTORE_FAILED, + actionType: ActionTypePostRestoreFailed, }, { - actionType: ACTION_TYPE_BACKUP_PREHOOK, + actionType: ActionTypeBackupPrehook, }, { - actionType: ACTION_TYPE_BACKUP_POSTHOOK, + actionType: ActionTypeBackupPosthook, }, { actionType: "random-action", }, } { switch tc.actionType { - case ACTION_TYPE_BACKUP: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_BACKUP) - case ACTION_TYPE_RESTORE: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_RESTORE) - case ACTION_TYPE_DELETE: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_DELETE) - case ACTION_TYPE_BACKUP_TO_SERVER: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_BACKUP_TO_SERVER) - case ACTION_TYPE_RESTORE_FROM_SERVER: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_RESTORE_FROM_SERVER) - case ACTION_TYPE_BEFORE_BACKUP: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_BEFORE_BACKUP) - case ACTION_TYPE_ON_SUCCESS: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_ON_SUCCESS) - case ACTION_TYPE_ON_FAILURE: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_ON_FAILURE) - case ACTION_TYPE_PRE_RESTORE: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_PRE_RESTORE) - case ACTION_TYPE_POST_RESTORE: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_POST_RESTORE) - case ACTION_TYPE_POST_RESTORE_FAILED: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_POST_RESTORE_FAILED) - case ACTION_TYPE_BACKUP_PREHOOK: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_BACKUP_PREHOOK) - case ACTION_TYPE_BACKUP_POSTHOOK: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_BACKUP_POSTHOOK) + case ActionTypeBackup: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeBackup) + case ActionTypeRestore: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeRestore) + case ActionTypeDelete: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeDelete) + case ActionTypeBackupToServer: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeBackupToServer) + case ActionTypeRestoreFromServer: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeRestoreFromServer) + case ActionTypeBeforeBackup: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeBeforeBackup) + case ActionTypeOnSuccess: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeOnSuccess) + case ActionTypeOnFailure: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeOnFailure) + case ActionTypePreRestore: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypePreRestore) + case ActionTypePostRestore: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypePostRestore) + case ActionTypePostRestoreFailed: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypePostRestoreFailed) + case ActionTypeBackupPrehook: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeBackupPrehook) + case ActionTypeBackupPosthook: + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeBackupPosthook) default: - c.Assert(getActionTypeBucket(tc.actionType), Equals, ACTION_TYPE_BACKUP_OTHER) + c.Assert(getActionTypeBucket(tc.actionType), Equals, ActionTypeBackupOther) } } } diff --git a/pkg/controller/metrics.go b/pkg/controller/metrics.go index 7928545582..9eeee7a839 100644 --- a/pkg/controller/metrics.go +++ b/pkg/controller/metrics.go @@ -27,46 +27,46 @@ type metrics struct { } const ( - ACTION_SET_COUNTER_VEC_LABEL_RES = "resolution" - ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS = "success" - ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE = "failure" + ActionSetCounterVecLabelRes = "resolution" + ActionSetCounterVecLabelResSuccess = "success" + ActionSetCounterVecLabelResFailure = "failure" ) const ( - ACTION_TYPE_BACKUP = "backup" - ACTION_TYPE_RESTORE = "restore" - ACTION_TYPE_DELETE = "delete" - ACTION_TYPE_BACKUP_TO_SERVER = "backupToServer" - ACTION_TYPE_RESTORE_FROM_SERVER = "restoreFromServer" - ACTION_TYPE_BEFORE_BACKUP = "before-backup" - ACTION_TYPE_ON_SUCCESS = "on-success" - ACTION_TYPE_ON_FAILURE = "on-failure" - ACTION_TYPE_PRE_RESTORE = "pre-restore" - ACTION_TYPE_POST_RESTORE = "post-restore" - ACTION_TYPE_POST_RESTORE_FAILED = "post-restore-failed" - ACTION_TYPE_BACKUP_PREHOOK = "backupPrehook" - ACTION_TYPE_BACKUP_POSTHOOK = "backupPosthook" - ACTION_TYPE_BACKUP_OTHER = "other" + ActionTypeBackup = "backup" + ActionTypeRestore = "restore" + ActionTypeDelete = "delete" + ActionTypeBackupToServer = "backupToServer" + ActionTypeRestoreFromServer = "restoreFromServer" + ActionTypeBeforeBackup = "before-backup" + ActionTypeOnSuccess = "on-success" + ActionTypeOnFailure = "on-failure" + ActionTypePreRestore = "pre-restore" + ActionTypePostRestore = "post-restore" + ActionTypePostRestoreFailed = "post-restore-failed" + ActionTypeBackupPrehook = "backupPrehook" + ActionTypeBackupPosthook = "backupPosthook" + ActionTypeBackupOther = "other" ) var knownActionsList = map[string]bool{ - ACTION_TYPE_BACKUP: true, - ACTION_TYPE_RESTORE: true, - ACTION_TYPE_DELETE: true, - ACTION_TYPE_BACKUP_TO_SERVER: true, - ACTION_TYPE_RESTORE_FROM_SERVER: true, - ACTION_TYPE_BEFORE_BACKUP: true, - ACTION_TYPE_ON_SUCCESS: true, - ACTION_TYPE_ON_FAILURE: true, - ACTION_TYPE_PRE_RESTORE: true, - ACTION_TYPE_POST_RESTORE: true, - ACTION_TYPE_POST_RESTORE_FAILED: true, - ACTION_TYPE_BACKUP_PREHOOK: true, - ACTION_TYPE_BACKUP_POSTHOOK: true, + ActionTypeBackup: true, + ActionTypeRestore: true, + ActionTypeDelete: true, + ActionTypeBackupToServer: true, + ActionTypeRestoreFromServer: true, + ActionTypeBeforeBackup: true, + ActionTypeOnSuccess: true, + ActionTypeOnFailure: true, + ActionTypePreRestore: true, + ActionTypePostRestore: true, + ActionTypePostRestoreFailed: true, + ActionTypeBackupPrehook: true, + ActionTypeBackupPosthook: true, } func getActionTypeBucket(aType string) string { - actionTypeBucket := ACTION_TYPE_BACKUP_OTHER + actionTypeBucket := ActionTypeBackupOther if _, ok := knownActionsList[aType]; ok { actionTypeBucket = aType } @@ -78,10 +78,10 @@ func getActionTypeBucket(aType string) string { func getActionSetCounterVecLabels() []kanistermetrics.BoundedLabel { bl := make([]kanistermetrics.BoundedLabel, 1) bl[0] = kanistermetrics.BoundedLabel{ - LabelName: ACTION_SET_COUNTER_VEC_LABEL_RES, + LabelName: ActionSetCounterVecLabelRes, LabelValues: []string{ - ACTION_SET_COUNTER_VEC_LABEL_RES_SUCCESS, - ACTION_SET_COUNTER_VEC_LABEL_RES_FAILURE, + ActionSetCounterVecLabelResSuccess, + ActionSetCounterVecLabelResFailure, }, } return bl diff --git a/pkg/datamover/profile.go b/pkg/datamover/profile.go index 6e1fe71df4..c3182208ad 100644 --- a/pkg/datamover/profile.go +++ b/pkg/datamover/profile.go @@ -108,10 +108,10 @@ func (p *profile) unmarshalKopiaSnapshot(ctx context.Context) (*snapshot.Snapsho return &kopiaSnap, nil } -func NewProfileDataMover(prof *param.Profile, outputName, snapJson string) *profile { +func NewProfileDataMover(prof *param.Profile, outputName, snapJSON string) *profile { return &profile{ outputName: outputName, profile: prof, - snapJSON: snapJson, + snapJSON: snapJSON, } } diff --git a/pkg/datamover/repository_server.go b/pkg/datamover/repository_server.go index cc1b9b5d7c..f83e422c1f 100644 --- a/pkg/datamover/repository_server.go +++ b/pkg/datamover/repository_server.go @@ -131,11 +131,11 @@ func (rs *repositoryServer) checkHostnameExistsInUserAccessMap(userAccessMap map return nil } -func NewRepositoryServerDataMover(repoServer *param.RepositoryServer, outputName, snapJson, userHostname string) *repositoryServer { +func NewRepositoryServerDataMover(repoServer *param.RepositoryServer, outputName, snapJSON, userHostname string) *repositoryServer { return &repositoryServer{ outputName: outputName, repositoryServer: repoServer, - snapJSON: snapJson, + snapJSON: snapJSON, hostName: userHostname, } } diff --git a/pkg/function/args.go b/pkg/function/args.go index 000183bf02..48be8626b0 100644 --- a/pkg/function/args.go +++ b/pkg/function/args.go @@ -62,7 +62,7 @@ func GetPodSpecOverride(tp param.TemplateParams, args map[string]interface{}, ar // Check if PodOverride specs are passed through actionset // If yes, override podOverride specs if tp.PodOverride != nil { - podOverride, err = kube.CreateAndMergeJsonPatch(podOverride, tp.PodOverride) + podOverride, err = kube.CreateAndMergeJSONPatch(podOverride, tp.PodOverride) if err != nil { return nil, err } diff --git a/pkg/function/export_rds_snapshot_location.go b/pkg/function/export_rds_snapshot_location.go index 342e31bf98..047d8f5fee 100644 --- a/pkg/function/export_rds_snapshot_location.go +++ b/pkg/function/export_rds_snapshot_location.go @@ -307,7 +307,7 @@ func prepareCommand( dbEngineVersion string, ) ([]string, string, error) { // Convert profile object into json - profileJson, err := json.Marshal(profile) + profileJSON, err := json.Marshal(profile) if err != nil { return nil, "", err } @@ -322,10 +322,10 @@ func prepareCommand( return nil, "", err } } - command, err := postgresBackupCommand(dbEndpoint, username, password, dbList, backupPrefix, backupID, profileJson) + command, err := postgresBackupCommand(dbEndpoint, username, password, dbList, backupPrefix, backupID, profileJSON) return command, postgresToolsImage, err case RestoreAction: - command, err := postgresRestoreCommand(dbEndpoint, username, password, backupPrefix, backupID, profileJson, dbEngineVersion) + command, err := postgresRestoreCommand(dbEndpoint, username, password, backupPrefix, backupID, profileJSON, dbEngineVersion) return command, postgresToolsImage, err } } diff --git a/pkg/function/kubeops.go b/pkg/function/kubeops.go index 39cfa6c57a..f7bfb14728 100644 --- a/pkg/function/kubeops.go +++ b/pkg/function/kubeops.go @@ -91,13 +91,13 @@ func (k *kubeops) Exec(ctx context.Context, tp param.TemplateParams, args map[st if err != nil { return nil, err } - objRefJson, err := json.Marshal(objRef) + objRefJSON, err := json.Marshal(objRef) if err != nil { return nil, err } // Convert objRef to map[string]interface{} var out map[string]interface{} - if err := json.Unmarshal(objRefJson, &out); err != nil { + if err := json.Unmarshal(objRefJSON, &out); err != nil { return nil, err } return out, nil diff --git a/pkg/function/restore_data.go b/pkg/function/restore_data.go index 16cf842cda..8b340e0def 100644 --- a/pkg/function/restore_data.go +++ b/pkg/function/restore_data.go @@ -232,7 +232,7 @@ func (r *restoreDataFunc) Exec(ctx context.Context, tp param.TemplateParams, arg // Check if PodOverride specs are passed through actionset // If yes, override podOverride specs if tp.PodOverride != nil { - podOverride, err = kube.CreateAndMergeJsonPatch(podOverride, tp.PodOverride) + podOverride, err = kube.CreateAndMergeJSONPatch(podOverride, tp.PodOverride) if err != nil { return nil, err } diff --git a/pkg/handler/handler.go b/pkg/handler/handler.go index ca60f19a24..53ab0c9dc6 100644 --- a/pkg/handler/handler.go +++ b/pkg/handler/handler.go @@ -51,7 +51,7 @@ var _ http.Handler = (*healthCheckHandler)(nil) type healthCheckHandler struct{} func (*healthCheckHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { - version := version.VERSION + version := version.Version info := Info{true, version} js, err := json.Marshal(info) if err != nil { diff --git a/pkg/jsonpath/jsonpath.go b/pkg/jsonpath/jsonpath.go index 108005280b..9d0575be6b 100644 --- a/pkg/jsonpath/jsonpath.go +++ b/pkg/jsonpath/jsonpath.go @@ -43,7 +43,7 @@ func FindJsonpathArgs(s string) map[string]string { return matchMap } -// ResolveJsonpath resolves jsonpath value from the k8s resource object +// ResolveJsonpathToString resolves jsonpath value from the k8s resource object func ResolveJsonpathToString(obj runtime.Object, jsonpathStr string) (string, error) { var buff bytes.Buffer jp, err := printers.NewJSONPathPrinter(jsonpathStr) diff --git a/pkg/kancontroller/kancontroller.go b/pkg/kancontroller/kancontroller.go index cb82bbf4b4..b8d9e01cfa 100644 --- a/pkg/kancontroller/kancontroller.go +++ b/pkg/kancontroller/kancontroller.go @@ -19,7 +19,7 @@ Some of the code below came from https://github.com/coreos/etcd-operator which also has the apache 2.0 license. */ -// Package for a kanister operator +// Package kancontroller is for a kanister operator. package kancontroller import ( diff --git a/pkg/kanctl/error.go b/pkg/kanctl/error.go index 89b9118cfe..cc9ea559c3 100644 --- a/pkg/kanctl/error.go +++ b/pkg/kanctl/error.go @@ -20,13 +20,13 @@ import ( "github.com/pkg/errors" ) -var argsLengthErr = fmt.Errorf("Incorrect number of arguments") +var errArgsLength = fmt.Errorf("Incorrect number of arguments") func newArgsLengthError(format string, args ...interface{}) error { - return errors.Wrapf(argsLengthErr, format, args...) + return errors.Wrapf(errArgsLength, format, args...) } -// IsArgsLengthError returns true iff the underlying cause was an argsLengthErr. +// IsArgsLengthError returns true iff the underlying cause was an errArgsLength. func IsArgsLengthError(err error) bool { - return errors.Cause(err) == argsLengthErr + return errors.Cause(err) == errArgsLength } diff --git a/pkg/kopia/cli/internal/location.go b/pkg/kopia/cli/internal/location.go index 1d01cfbae6..abbf3f4814 100644 --- a/pkg/kopia/cli/internal/location.go +++ b/pkg/kopia/cli/internal/location.go @@ -60,7 +60,7 @@ func (l Location) HasSkipSSLVerify() bool { return v } -// IsPointInTimeSupported returns true if the location supports point-in-time recovery. +// IsPointInTypeSupported returns true if the location supports point-in-time recovery. // Currently, only S3 and Azure support point-in-time recovery. func (l Location) IsPointInTypeSupported() bool { switch l.Type() { diff --git a/pkg/kopia/command/maintenance.go b/pkg/kopia/command/maintenance.go index f41ba0a850..3408dff460 100644 --- a/pkg/kopia/command/maintenance.go +++ b/pkg/kopia/command/maintenance.go @@ -16,14 +16,14 @@ package command type MaintenanceInfoCommandArgs struct { *CommandArgs - GetJsonOutput bool + GetJSONOutput bool } // MaintenanceInfo returns the kopia command to get maintenance info func MaintenanceInfo(cmdArgs MaintenanceInfoCommandArgs) []string { args := commonArgs(cmdArgs.CommandArgs) args = args.AppendLoggable(maintenanceSubCommand, infoSubCommand) - if cmdArgs.GetJsonOutput { + if cmdArgs.GetJSONOutput { args = args.AppendLoggable(jsonFlag) } diff --git a/pkg/kopia/command/maintenance_test.go b/pkg/kopia/command/maintenance_test.go index 802f4103dd..a146aab60c 100644 --- a/pkg/kopia/command/maintenance_test.go +++ b/pkg/kopia/command/maintenance_test.go @@ -39,7 +39,7 @@ func (kMaintenance *KopiaMaintenanceTestSuite) TestMaintenanceCommands(c *C) { f: func() []string { args := MaintenanceInfoCommandArgs{ CommandArgs: commandArgs, - GetJsonOutput: false, + GetJSONOutput: false, } return MaintenanceInfo(args) }, @@ -49,7 +49,7 @@ func (kMaintenance *KopiaMaintenanceTestSuite) TestMaintenanceCommands(c *C) { f: func() []string { args := MaintenanceInfoCommandArgs{ CommandArgs: commandArgs, - GetJsonOutput: true, + GetJSONOutput: true, } return MaintenanceInfo(args) }, diff --git a/pkg/kopia/command/parse_command_output.go b/pkg/kopia/command/parse_command_output.go index d0d911fc21..f7b4a24e63 100644 --- a/pkg/kopia/command/parse_command_output.go +++ b/pkg/kopia/command/parse_command_output.go @@ -501,7 +501,7 @@ func IsEqualSnapshotCreateStats(a, b *SnapshotCreateStats) bool { var ANSIEscapeCode = regexp.MustCompile(`\x1b[^m]*?m`) var kopiaErrorPattern = regexp.MustCompile(`(?:ERROR\s+|.*\\s*|error\s+)(.*)`) -// ErrorFromOutput parses the output of a kopia and returns an error, if found +// ErrorsFromOutput parses the output of a kopia and returns an error, if found func ErrorsFromOutput(output string) []error { if output == "" { return nil diff --git a/pkg/kopia/command/policy_show_global.go b/pkg/kopia/command/policy_show_global.go index 8b6f81e0b7..9f8a4c89f2 100644 --- a/pkg/kopia/command/policy_show_global.go +++ b/pkg/kopia/command/policy_show_global.go @@ -16,14 +16,14 @@ package command type PolicyShowGlobalCommandArgs struct { *CommandArgs - GetJsonOutput bool + GetJSONOutput bool } // PolicyShowGlobal returns the kopia command for showing the global policy. func PolicyShowGlobal(cmdArgs PolicyShowGlobalCommandArgs) []string { args := commonArgs(cmdArgs.CommandArgs) args = args.AppendLoggable(policySubCommand, showSubCommand, globalFlag) - if cmdArgs.GetJsonOutput { + if cmdArgs.GetJSONOutput { args = args.AppendLoggable(jsonFlag) } diff --git a/pkg/kopia/command/policy_test.go b/pkg/kopia/command/policy_test.go index 8ba7b6c837..952102be6c 100644 --- a/pkg/kopia/command/policy_test.go +++ b/pkg/kopia/command/policy_test.go @@ -62,7 +62,7 @@ func (kPolicy *KopiaPolicyTestSuite) TestPolicyShowCommands(c *C) { ConfigFilePath: "path/kopia.config", LogDirectory: "cache/log", }, - GetJsonOutput: true, + GetJSONOutput: true, } return PolicyShowGlobal(args) }, diff --git a/pkg/kopia/command/repository.go b/pkg/kopia/command/repository.go index 22ec42d2d4..3fb8707c5a 100644 --- a/pkg/kopia/command/repository.go +++ b/pkg/kopia/command/repository.go @@ -161,7 +161,7 @@ func RepositoryConnectServerCommand(cmdArgs RepositoryServerCommandArgs) []strin type RepositoryStatusCommandArgs struct { *CommandArgs - GetJsonOutput bool + GetJSONOutput bool } // RepositoryStatusCommand returns the kopia command for checking status of the Kopia repository @@ -176,7 +176,7 @@ func RepositoryStatusCommand(cmdArgs RepositoryStatusCommandArgs) []string { args := commonArgs(cmdArgs.CommandArgs) args = args.AppendLoggable(repositorySubCommand, statusSubCommand) - if cmdArgs.GetJsonOutput { + if cmdArgs.GetJSONOutput { args = args.AppendLoggable(jsonFlag) } diff --git a/pkg/kopia/command/repository_test.go b/pkg/kopia/command/repository_test.go index 171e8feac0..6e03e8ed1b 100644 --- a/pkg/kopia/command/repository_test.go +++ b/pkg/kopia/command/repository_test.go @@ -366,7 +366,7 @@ func (kRepoStatus *RepositoryUtilsSuite) TestRepositoryStatusCommand(c *check.C) ConfigFilePath: "path/kopia.config", LogDirectory: "cache/log", }, - GetJsonOutput: true, + GetJSONOutput: true, } return RepositoryStatusCommand(args) }, diff --git a/pkg/kopia/command/storage/s3_args.go b/pkg/kopia/command/storage/s3_args.go index e375e7562c..87c96fb5a6 100644 --- a/pkg/kopia/command/storage/s3_args.go +++ b/pkg/kopia/command/storage/s3_args.go @@ -38,7 +38,7 @@ func s3Args(location map[string][]byte, repoPathPrefix string) logsafe.Cmd { s3Endpoint := ResolveS3Endpoint(e) args = args.AppendLoggableKV(s3EndpointFlag, s3Endpoint) - if HttpInsecureEndpoint(e) { + if httpInsecureEndpoint(e) { args = args.AppendLoggable(s3DisableTLSFlag) } } @@ -75,6 +75,6 @@ func ResolveS3Endpoint(endpoint string) string { return sp[len(sp)-1] } -func HttpInsecureEndpoint(endpoint string) bool { +func httpInsecureEndpoint(endpoint string) bool { return strings.HasPrefix(endpoint, "http:") } diff --git a/pkg/kopia/errors/utils.go b/pkg/kopia/errors/utils.go index fbd5e0aac4..0b9451a084 100644 --- a/pkg/kopia/errors/utils.go +++ b/pkg/kopia/errors/utils.go @@ -83,7 +83,7 @@ func RepoNotInitialized(stderr string) bool { var regexpBucketDoesNotExist = regexp.MustCompile(`bucket ".*" does not exist`) -// bucketDoesNotExist returns true if the stderr logs contain either `bucket doesn't exist` +// BucketDoesNotExist returns true if the stderr logs contain either `bucket doesn't exist` // or `bucket "" does not exist` messages. func BucketDoesNotExist(stderr string) bool { return strings.Contains(stderr, ErrBucketDoesNotExistStr) || diff --git a/pkg/kopia/maintenance/get_maintenance_owner.go b/pkg/kopia/maintenance/get_maintenance_owner.go index 8299226c4b..c9d5fe551c 100644 --- a/pkg/kopia/maintenance/get_maintenance_owner.go +++ b/pkg/kopia/maintenance/get_maintenance_owner.go @@ -57,7 +57,7 @@ func GetMaintenanceOwnerForConnectedRepository( ConfigFilePath: configFilePath, LogDirectory: logDirectory, }, - GetJsonOutput: true, + GetJSONOutput: true, } cmd := command.MaintenanceInfo(args) diff --git a/pkg/kube/fake_pod_command_executor.go b/pkg/kube/fake_pod_command_executor.go index edfe7b55c5..b00437aba8 100644 --- a/pkg/kube/fake_pod_command_executor.go +++ b/pkg/kube/fake_pod_command_executor.go @@ -27,7 +27,6 @@ type FakePodCommandExecutor struct { ExecStderr string } -// Exec func (fce *FakePodCommandExecutor) Exec(_ context.Context, command []string, stdin io.Reader, stdout, stderr io.Writer) error { fce.inExecCommand = make([]string, len(command)) copy(fce.inExecCommand, command) diff --git a/pkg/kube/pod.go b/pkg/kube/pod.go index 6748b7244e..3c772b77af 100644 --- a/pkg/kube/pod.go +++ b/pkg/kube/pod.go @@ -490,7 +490,7 @@ func WaitForPodCompletion(ctx context.Context, cli kubernetes.Interface, namespa // use Strategic Merge to patch default pod specs with the passed specs func patchDefaultPodSpecs(defaultPodSpecs corev1.PodSpec, override crv1alpha1.JSONMap) (corev1.PodSpec, error) { // Merge default specs and override specs with StrategicMergePatch - mergedPatch, err := strategicMergeJsonPatch(defaultPodSpecs, override) + mergedPatch, err := strategicMergeJSONPatch(defaultPodSpecs, override) if err != nil { return corev1.PodSpec{}, err } @@ -504,10 +504,10 @@ func patchDefaultPodSpecs(defaultPodSpecs corev1.PodSpec, override crv1alpha1.JS return podSpec, err } -// CreateAndMergeJsonPatch uses Strategic Merge to merge two Pod spec configuration -func CreateAndMergeJsonPatch(original, override crv1alpha1.JSONMap) (crv1alpha1.JSONMap, error) { +// CreateAndMergeJSONPatch uses Strategic Merge to merge two Pod spec configuration +func CreateAndMergeJSONPatch(original, override crv1alpha1.JSONMap) (crv1alpha1.JSONMap, error) { // Merge json specs with StrategicMerge - mergedPatch, err := strategicMergeJsonPatch(original, override) + mergedPatch, err := strategicMergeJSONPatch(original, override) if err != nil { return nil, err } @@ -521,21 +521,21 @@ func CreateAndMergeJsonPatch(original, override crv1alpha1.JSONMap) (crv1alpha1. return merged, err } -func strategicMergeJsonPatch(original, override interface{}) ([]byte, error) { +func strategicMergeJSONPatch(original, override interface{}) ([]byte, error) { // Convert override specs to json - overrideJson, err := json.Marshal(override) + overrideJSON, err := json.Marshal(override) if err != nil { return nil, err } // Convert original specs to json - originalJson, err := json.Marshal(original) + originalJSON, err := json.Marshal(original) if err != nil { return nil, err } // Merge json specs with StrategicMerge - mergedPatch, err := sp.StrategicMergePatch(originalJson, overrideJson, corev1.PodSpec{}) + mergedPatch, err := sp.StrategicMergePatch(originalJSON, overrideJSON, corev1.PodSpec{}) if err != nil { return nil, err } diff --git a/pkg/kube/pod_controller_processor.go b/pkg/kube/pod_controller_processor.go index 34a7ff9cd6..f75e24b173 100644 --- a/pkg/kube/pod_controller_processor.go +++ b/pkg/kube/pod_controller_processor.go @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package kube import ( diff --git a/pkg/kube/pod_test.go b/pkg/kube/pod_test.go index cad80991f6..4f02b98d17 100644 --- a/pkg/kube/pod_test.go +++ b/pkg/kube/pod_test.go @@ -840,7 +840,7 @@ func (s *PodSuite) TestPatchDefaultPodSpecs(c *C) { // Run tests for _, test := range tests { - override, err := CreateAndMergeJsonPatch(test.BlueprintPodSpecs, test.ActionsetPodSpecs) + override, err := CreateAndMergeJSONPatch(test.BlueprintPodSpecs, test.ActionsetPodSpecs) c.Assert(err, IsNil) podSpec, err := patchDefaultPodSpecs(defaultSpecs, override) c.Assert(err, IsNil) @@ -875,9 +875,9 @@ func (s *PodSuite) TestSetPodSecurityContext(c *C) { c.Assert(err, IsNil) runAsNonRootExpected := true c.Assert(pod.Spec.SecurityContext.RunAsNonRoot, DeepEquals, &runAsNonRootExpected) - var uidAndGidExpected int64 = 1000 - c.Assert(*pod.Spec.SecurityContext.RunAsUser, DeepEquals, uidAndGidExpected) - c.Assert(*pod.Spec.SecurityContext.RunAsGroup, DeepEquals, uidAndGidExpected) + var uidAndGIDExpected int64 = 1000 + c.Assert(*pod.Spec.SecurityContext.RunAsUser, DeepEquals, uidAndGIDExpected) + c.Assert(*pod.Spec.SecurityContext.RunAsGroup, DeepEquals, uidAndGIDExpected) } func (s *PodSuite) TestSetPodSecurityContextOverridesPodOverride(c *C) { @@ -904,9 +904,9 @@ func (s *PodSuite) TestSetPodSecurityContextOverridesPodOverride(c *C) { c.Assert(err, IsNil) runAsNonRootExpected := true c.Assert(pod.Spec.SecurityContext.RunAsNonRoot, DeepEquals, &runAsNonRootExpected) - var uidAndGidExpected int64 = 1000 - c.Assert(*pod.Spec.SecurityContext.RunAsUser, DeepEquals, uidAndGidExpected) - c.Assert(*pod.Spec.SecurityContext.RunAsGroup, DeepEquals, uidAndGidExpected) + var uidAndGIDExpected int64 = 1000 + c.Assert(*pod.Spec.SecurityContext.RunAsUser, DeepEquals, uidAndGIDExpected) + c.Assert(*pod.Spec.SecurityContext.RunAsGroup, DeepEquals, uidAndGIDExpected) } func (s *PodSuite) TestSetLifecycleHook(c *C) { diff --git a/pkg/location/location.go b/pkg/location/location.go index f0b0617620..127e4fe797 100644 --- a/pkg/location/location.go +++ b/pkg/location/location.go @@ -34,7 +34,7 @@ const ( AWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY" AWSSessionToken = "AWS_SESSION_TOKEN" GoogleCloudCreds = "GOOGLE_APPLICATION_CREDENTIALS" - GoogleProjectId = "GOOGLE_PROJECT_ID" + GoogleProjectID = "GOOGLE_PROJECT_ID" AzureStorageAccount = "AZURE_ACCOUNT_NAME" AzureStorageKey = "AZURE_ACCOUNT_KEY" diff --git a/pkg/metrics/metrics.go b/pkg/metrics/metrics.go index c2c0350eda..7831683a47 100644 --- a/pkg/metrics/metrics.go +++ b/pkg/metrics/metrics.go @@ -11,6 +11,7 @@ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. + package metrics import ( diff --git a/pkg/output/output.go b/pkg/output/output.go index 12c14fbe22..d133a9d46a 100644 --- a/pkg/output/output.go +++ b/pkg/output/output.go @@ -71,7 +71,7 @@ func PrintOutput(key, value string) error { return fPrintOutput(os.Stdout, key, value) } -// PrintOutput prints the output of the `kando output` command to w. +// PrintOutputTo prints the output of the `kando output` command to w. func PrintOutputTo(w io.Writer, key, value string) error { return fPrintOutput(w, key, value) } diff --git a/pkg/param/param.go b/pkg/param/param.go index d48eb14ce9..bb270d9e06 100644 --- a/pkg/param/param.go +++ b/pkg/param/param.go @@ -109,7 +109,6 @@ type Profile struct { SkipSSLVerify bool } -// CredentialType type CredentialType string const ( diff --git a/pkg/restic/restic.go b/pkg/restic/restic.go index 0329bae342..fe0951f4e3 100644 --- a/pkg/restic/restic.go +++ b/pkg/restic/restic.go @@ -254,7 +254,7 @@ func resticS3CredentialSecretArgs(secret *corev1.Secret) ([]string, error) { func resticGCSArgs(profile *param.Profile, repository string) []string { return []string{ - fmt.Sprintf("export %s=%s\n", location.GoogleProjectId, profile.Credential.KeyPair.ID), + fmt.Sprintf("export %s=%s\n", location.GoogleProjectID, profile.Credential.KeyPair.ID), fmt.Sprintf("export %s=%s\n", location.GoogleCloudCreds, consts.GoogleCloudCredsFilePath), fmt.Sprintf("export %s=gs:%s/\n", ResticRepository, strings.Replace(repository, "/", ":/", 1)), } @@ -367,8 +367,8 @@ func SnapshotIDFromSnapshotLog(output string) (string, error) { if len(result) == 0 { return "", errors.New("Snapshot not found") } - snapId := result[0]["short_id"] - return snapId.(string), nil + snapID := result[0]["short_id"] + return snapID.(string), nil } // SnapshotIDFromBackupLog gets the SnapshotID from Backup Command log @@ -476,7 +476,7 @@ func IsPasswordIncorrect(output string) bool { return strings.Contains(output, "wrong password") } -// DoesRepoExists checks if repo exists from Snapshot Command log +// DoesRepoExist checks if repo exists from Snapshot Command log func DoesRepoExist(output string) bool { return strings.Contains(output, "Is there a repository at the following location?") } diff --git a/pkg/secrets/gcp.go b/pkg/secrets/gcp.go index f9758e5ea0..a074c9f90e 100644 --- a/pkg/secrets/gcp.go +++ b/pkg/secrets/gcp.go @@ -27,7 +27,7 @@ const ( // GCPServiceKey is the config map key for gcp service key data GCPServiceKey string = "gcp_service_key" // GCPServerAccountJsonKey is the key for gcp service account json - GCPServiceAccountJsonKey string = "service-account.json" + GCPServiceAccountJSONKey string = "service-account.json" // GCPSecretType represents the secret type for GCP credentials. GCPSecretType string = "secrets.kanister.io/gcp" @@ -38,7 +38,7 @@ const ( func ValidateGCPCredentials(secret *corev1.Secret) error { // Required fields for the secret are // - GCPProjectID - // - GCPServiceAccountJsonKey + // - GCPServiceAccountJSONKey if secret == nil { return errors.Wrapf(secerrors.ErrValidate, secerrors.NilSecretErrorMessage) } @@ -51,8 +51,8 @@ func ValidateGCPCredentials(secret *corev1.Secret) error { if _, ok := secret.Data[GCPProjectID]; !ok { return errors.Wrapf(secerrors.ErrValidate, secerrors.MissingRequiredFieldErrorMsg, GCPProjectID, secret.Namespace, secret.Name) } - if _, ok := secret.Data[GCPServiceAccountJsonKey]; !ok { - return errors.Wrapf(secerrors.ErrValidate, secerrors.MissingRequiredFieldErrorMsg, GCPServiceAccountJsonKey, secret.Namespace, secret.Name) + if _, ok := secret.Data[GCPServiceAccountJSONKey]; !ok { + return errors.Wrapf(secerrors.ErrValidate, secerrors.MissingRequiredFieldErrorMsg, GCPServiceAccountJSONKey, secret.Namespace, secret.Name) } return nil } diff --git a/pkg/secrets/gcp_test.go b/pkg/secrets/gcp_test.go index 6180d1a0ef..b8fbb85072 100644 --- a/pkg/secrets/gcp_test.go +++ b/pkg/secrets/gcp_test.go @@ -30,8 +30,8 @@ type GCPSecretSuite struct{} var _ = Suite(&GCPSecretSuite{}) func (s *GCPSecretSuite) TestValidateGCPCredentials(c *C) { - serviceAccountJson := make([]byte, base64.StdEncoding.EncodedLen(len([]byte("service_account_json")))) - base64.StdEncoding.Encode(serviceAccountJson, []byte("service_account_json")) + serviceAccountJSON := make([]byte, base64.StdEncoding.EncodedLen(len([]byte("service_account_json")))) + base64.StdEncoding.Encode(serviceAccountJSON, []byte("service_account_json")) for i, tc := range []struct { secret *corev1.Secret errChecker Checker @@ -46,7 +46,7 @@ func (s *GCPSecretSuite) TestValidateGCPCredentials(c *C) { }, Data: map[string][]byte{ GCPProjectID: []byte("key_id"), - GCPServiceAccountJsonKey: serviceAccountJson, + GCPServiceAccountJSONKey: serviceAccountJSON, }, }, errChecker: IsNil, @@ -61,7 +61,7 @@ func (s *GCPSecretSuite) TestValidateGCPCredentials(c *C) { }, Data: map[string][]byte{ GCPProjectID: []byte("key_id"), - GCPServiceAccountJsonKey: serviceAccountJson, + GCPServiceAccountJSONKey: serviceAccountJSON, }, }, errChecker: NotNil, @@ -78,7 +78,7 @@ func (s *GCPSecretSuite) TestValidateGCPCredentials(c *C) { GCPProjectID: []byte("key_id"), }, }, - expectedErr: errors.Wrapf(secerrors.ErrValidate, secerrors.MissingRequiredFieldErrorMsg, GCPServiceAccountJsonKey, "ns", "sec"), + expectedErr: errors.Wrapf(secerrors.ErrValidate, secerrors.MissingRequiredFieldErrorMsg, GCPServiceAccountJSONKey, "ns", "sec"), errChecker: NotNil, }, { // missing field - GCPProjectID @@ -89,7 +89,7 @@ func (s *GCPSecretSuite) TestValidateGCPCredentials(c *C) { Namespace: "ns", }, Data: map[string][]byte{ - GCPServiceAccountJsonKey: []byte("service_account_json"), + GCPServiceAccountJSONKey: []byte("service_account_json"), }, }, expectedErr: errors.Wrapf(secerrors.ErrValidate, secerrors.MissingRequiredFieldErrorMsg, GCPProjectID, "ns", "sec"), diff --git a/pkg/secrets/repositoryserver/aws_secrets.go b/pkg/secrets/repositoryserver/aws_secrets.go index 6c199eb8ee..a835224689 100644 --- a/pkg/secrets/repositoryserver/aws_secrets.go +++ b/pkg/secrets/repositoryserver/aws_secrets.go @@ -12,6 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. +// Package repositoryserver validates the secret credentials for all location profiles. package repositoryserver import ( diff --git a/pkg/secrets/secrets.go b/pkg/secrets/secrets.go index 3f4bd18804..7a2b3419de 100644 --- a/pkg/secrets/secrets.go +++ b/pkg/secrets/secrets.go @@ -19,7 +19,6 @@ import ( corev1 "k8s.io/api/core/v1" secerrors "github.com/kanisterio/kanister/pkg/secrets/errors" - "github.com/kanisterio/kanister/pkg/secrets/repositoryserver" reposerver "github.com/kanisterio/kanister/pkg/secrets/repositoryserver" ) @@ -74,19 +73,19 @@ func getLocationSecret(secret *corev1.Secret) (reposerver.Secret, error) { } func ValidateRepositoryServerSecret(repositoryServerSecret *corev1.Secret) error { - var secret repositoryserver.Secret + var secret reposerver.Secret var err error switch repositoryServerSecret.Type { - case repositoryserver.Location: + case reposerver.Location: secret, err = getLocationSecret(repositoryServerSecret) if err != nil { return err } - case repositoryserver.RepositoryPasswordSecret: - secret = repositoryserver.NewRepoPassword(repositoryServerSecret) - case repositoryserver.AdminCredentialsSecret: - secret = repositoryserver.NewRepositoryServerAdminCredentials(repositoryServerSecret) + case reposerver.RepositoryPasswordSecret: + secret = reposerver.NewRepoPassword(repositoryServerSecret) + case reposerver.AdminCredentialsSecret: + secret = reposerver.NewRepositoryServerAdminCredentials(repositoryServerSecret) default: return ValidateCredentials(repositoryServerSecret) } diff --git a/pkg/testing/integration_register.go b/pkg/testing/integration_register.go index e5233ee08a..bad3fad0be 100644 --- a/pkg/testing/integration_register.go +++ b/pkg/testing/integration_register.go @@ -25,7 +25,7 @@ import ( // Register Applications to Integration Suite -// pitr-postgresql app +// PITRPostgreSQL type is an app for postgres database for integration test. type PITRPostgreSQL struct { IntegrationSuite } @@ -40,7 +40,7 @@ var _ = Suite(&PITRPostgreSQL{ }, }) -// postgres app +// PostgreSQL type is an app for postgres database for integration test. type PostgreSQL struct { IntegrationSuite } @@ -55,7 +55,7 @@ var _ = Suite(&PostgreSQL{ }, }) -// mysql app +// MySQL type is an app for mysql database for integration test. type MySQL struct { IntegrationSuite } @@ -70,7 +70,7 @@ var _ = Suite(&MySQL{ }, }) -// cockroachdb app +// CockroachDB type is an app for cockroach DB for integration test. type CockroachDB struct { IntegrationSuite } @@ -85,7 +85,7 @@ var _ = Suite(&CockroachDB{ }, }) -// time-log app for csi volumesnapshot +// TimeLogCSI type is an app for csi volumesnapshot for integration test. type TimeLogCSI struct { IntegrationSuite } @@ -100,7 +100,7 @@ var _ = Suite(&TimeLogCSI{ }, }) -// mariaDB app +// Maria type is an app for maria DB for integration test. type Maria struct { IntegrationSuite } @@ -115,7 +115,7 @@ var _ = Suite(&Maria{ }, }) -// Elasticsearch app +// Elasticsearch type is an app for elasticsearch for integration test. type Elasticsearch struct { IntegrationSuite } @@ -130,7 +130,7 @@ var _ = Suite(&Elasticsearch{ }, }) -// MongoDB app +// MongoDB type is an app for mongo DB for integration test. type MongoDB struct { IntegrationSuite } @@ -145,7 +145,7 @@ var _ = Suite(&MongoDB{ }, }) -// Cassandra App +// Cassandra type is an app for cassandra DB for integration test. type Cassandra struct { IntegrationSuite } @@ -159,7 +159,7 @@ var _ = Suite(&Cassandra{IntegrationSuite{ }, }) -// Couchbase app +// Couchbase type is an app for couchbase DB for integration test. type Couchbase struct { IntegrationSuite } @@ -174,7 +174,7 @@ var _ = Suite(&Couchbase{ }, }) -// rds-postgres app +// RDSPostgreSQL type is an app for postgres database for integration test. type RDSPostgreSQL struct { IntegrationSuite } @@ -189,6 +189,7 @@ var _ = Suite(&RDSPostgreSQL{ }, }) +// FoundationDB type is an app for foundation database for integration test. type FoundationDB struct { IntegrationSuite } @@ -203,6 +204,7 @@ var _ = Suite(&FoundationDB{ }, }) +// RDSAuroraMySQL type is an app for mysql database for integration test. type RDSAuroraMySQL struct { IntegrationSuite } @@ -217,8 +219,8 @@ var _ = Suite(&RDSAuroraMySQL{ }, }) -// rds-postgres-dump app -// Create snapshot, export data and restore from dump +// RDSPostgreSQLDump type is an app for postgres dump for integration test. +// It creates snapshot, export data and restore from dump. type RDSPostgreSQLDump struct { IntegrationSuite } @@ -233,8 +235,8 @@ var _ = Suite(&RDSPostgreSQLDump{ }, }) -// rds-postgres-snap app -// Create snapshot and restore from snapshot +// RDSPostgreSQLSnap type is an app for postgres snap for integration test. +// It creates snapshot and restore from snapshot. type RDSPostgreSQLSnap struct { IntegrationSuite } @@ -249,6 +251,7 @@ var _ = Suite(&RDSPostgreSQLSnap{ }, }) +// MSSQL type is an app for mssql database for integration test. type MSSQL struct { IntegrationSuite } @@ -263,8 +266,8 @@ var _ = Suite(&MSSQL{ }, }) -// OpenShift apps for version 3.11 -// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster +// MysqlDBDepConfig type is an app for mysql database for integration test that is deployed through DeploymentConfig on OpenShift cluster. +// OpenShifts apps for version 3.11. type MysqlDBDepConfig struct { IntegrationSuite } @@ -279,7 +282,7 @@ var _ = Suite(&MysqlDBDepConfig{ }, }) -// MongoDB deployed on openshift cluster +// MongoDBDepConfig type is an app for mongo DB for integration test on openshift cluster type MongoDBDepConfig struct { IntegrationSuite } @@ -294,7 +297,7 @@ var _ = Suite(&MongoDBDepConfig{ }, }) -// PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig type is an app for postgresdepconf for integration test on openshift cluster. type PostgreSQLDepConfig struct { IntegrationSuite } @@ -309,8 +312,8 @@ var _ = Suite(&PostgreSQLDepConfig{ }, }) +// MysqlDBDepConfig4_4 type is an app for mysql database for integration test through DeploymentConfig on OpenShift cluster. // OpenShift apps for version 4.4 -// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster type MysqlDBDepConfig4_4 struct { IntegrationSuite } @@ -325,7 +328,7 @@ var _ = Suite(&MysqlDBDepConfig4_4{ }, }) -// MongoDB deployed on openshift cluster +// MongoDBDepConfig4_4 type is an app for mongo database for integration test on openshift cluster type MongoDBDepConfig4_4 struct { IntegrationSuite } @@ -340,7 +343,7 @@ var _ = Suite(&MongoDBDepConfig4_4{ }, }) -// PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_4 type is an app for postgres database for integration test on openshift cluster type PostgreSQLDepConfig4_4 struct { IntegrationSuite } @@ -355,8 +358,8 @@ var _ = Suite(&PostgreSQLDepConfig4_4{ }, }) +// MysqlDBDepConfig4_5 type is an app for mysql database for integration test through DeploymentConfig on OpenShift cluster. // OpenShift apps for version 4.5 -// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster type MysqlDBDepConfig4_5 struct { IntegrationSuite } @@ -371,7 +374,7 @@ var _ = Suite(&MysqlDBDepConfig4_5{ }, }) -// MongoDB deployed on openshift cluster +// MongoDBDepConfig4_5 type is an app for mongo database for integration test on OpenShift cluster type MongoDBDepConfig4_5 struct { IntegrationSuite } @@ -386,7 +389,7 @@ var _ = Suite(&MongoDBDepConfig4_5{ }, }) -// PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_5 type is an app for postgres database for integration test on OpenShift cluster type PostgreSQLDepConfig4_5 struct { IntegrationSuite } @@ -401,7 +404,7 @@ var _ = Suite(&PostgreSQLDepConfig4_5{ }, }) -// Kafka deployed on kubernetes cluster +// Kafka type is an app for kafka for integration test on kubernetes cluster type Kafka struct { IntegrationSuite } @@ -416,7 +419,7 @@ var _ = Suite(&Kafka{ }, }) -// Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster +// MysqlDBDepConfig4_10 type is an app for mysql database for integration test on OpenShift cluster type MysqlDBDepConfig4_10 struct { IntegrationSuite } @@ -431,7 +434,7 @@ var _ = Suite(&MysqlDBDepConfig4_10{ }, }) -// MongoDB deployed on openshift cluster +// MongoDBDepConfig4_10 type is an app for mongo database for integration test on OpenShift cluster type MongoDBDepConfig4_10 struct { IntegrationSuite } @@ -446,7 +449,7 @@ var _ = Suite(&MongoDBDepConfig4_10{ }, }) -// PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_10 type is an app for postgres database for integration test on OpenShift cluster type PostgreSQLDepConfig4_10 struct { IntegrationSuite } @@ -461,7 +464,7 @@ var _ = Suite(&PostgreSQLDepConfig4_10{ }, }) -// MysqlDBDepConfig4_11 for Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster +// MysqlDBDepConfig4_11 type is an app for mysql database for integration test through DeploymentConfig on OpenShift cluster type MysqlDBDepConfig4_11 struct { IntegrationSuite } @@ -476,7 +479,7 @@ var _ = Suite(&MysqlDBDepConfig4_11{ }, }) -// PostgreSQLDepConfig4_11 for PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_11 type is an app for postgres database for integration test on openshift cluster type PostgreSQLDepConfig4_11 struct { IntegrationSuite } @@ -491,7 +494,7 @@ var _ = Suite(&PostgreSQLDepConfig4_11{ }, }) -// MysqlDBDepConfig4_12 for Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster +// MysqlDBDepConfig4_12 type is an app for mysql database for integration test on openshift cluster type MysqlDBDepConfig4_12 struct { IntegrationSuite } @@ -506,7 +509,7 @@ var _ = Suite(&MysqlDBDepConfig4_12{ }, }) -// PostgreSQLDepConfig4_12 for PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_12 type is an app for postgres database for integration test on openshift cluster type PostgreSQLDepConfig4_12 struct { IntegrationSuite } @@ -521,7 +524,7 @@ var _ = Suite(&PostgreSQLDepConfig4_12{ }, }) -// MysqlDBDepConfig4_13 for Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster +// MysqlDBDepConfig4_13 type is an app for mysql database for integration test on openshift cluster type MysqlDBDepConfig4_13 struct { IntegrationSuite } @@ -536,7 +539,7 @@ var _ = Suite(&MysqlDBDepConfig4_13{ }, }) -// PostgreSQLDepConfig4_13 for PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_13 type is an app for postgres database for integration test on openshift cluster type PostgreSQLDepConfig4_13 struct { IntegrationSuite } @@ -551,7 +554,7 @@ var _ = Suite(&PostgreSQLDepConfig4_13{ }, }) -// MysqlDBDepConfig4_14 for Mysql Instance that is deployed through DeploymentConfig on OpenShift cluster +// MysqlDBDepConfig4_14 type is an app for mysql database for integration test on openshift cluster type MysqlDBDepConfig4_14 struct { IntegrationSuite } @@ -566,7 +569,7 @@ var _ = Suite(&MysqlDBDepConfig4_14{ }, }) -// PostgreSQLDepConfig4_14 for PostgreSQL deployed on openshift cluster +// PostgreSQLDepConfig4_14 type is an app for postgres database for integration test on openshift cluster type PostgreSQLDepConfig4_14 struct { IntegrationSuite } diff --git a/pkg/tools/grype_report_parser_tool.go b/pkg/tools/grype_report_parser_tool.go index 4aa90801e6..5a9579f650 100644 --- a/pkg/tools/grype_report_parser_tool.go +++ b/pkg/tools/grype_report_parser_tool.go @@ -116,17 +116,17 @@ func printResult(mr []matchResponse, githubActionOutput bool) { func main() { validSeverityLevels := []string{"Negliable", "Low", "Medium", "High", "Critical"} severityInputList := flag.String("s", "High,Critical", "Comma separated list of severity levels to scan. Valid severity levels are: "+strings.Join(validSeverityLevels, ",")) - reportJsonFilePath := flag.String("p", "", "Path to the JSON file containing the vulnerabilities report") githubActionOutput := flag.Bool("github", false, "Whether to use github action output format") + reportJSONFilePath := flag.String("p", "", "Path to the JSON file containing the vulnerabilities report") flag.Parse() // passing file path is compulsory - if *reportJsonFilePath == "" { + if *reportJSONFilePath == "" { flag.PrintDefaults() os.Exit(1) } severityLevels := strings.Split(*severityInputList, ",") - mr, err := parseVulerabilitiesReport(*reportJsonFilePath, severityLevels) + mr, err := parseVulerabilitiesReport(*reportJSONFilePath, severityLevels) if err != nil { fmt.Printf("Failed to parse vulnerabilities report: %v\n", err) os.Exit(1) diff --git a/pkg/validate/error.go b/pkg/validate/error.go index 5a30bf450b..5011e94a25 100644 --- a/pkg/validate/error.go +++ b/pkg/validate/error.go @@ -20,7 +20,7 @@ import ( "github.com/pkg/errors" ) -var validateErr = fmt.Errorf("Validation Failed") +var errValidate = fmt.Errorf("Validation Failed") func errorf(err error, format string, args ...interface{}) error { return errors.Wrapf(err, format, args...) @@ -28,5 +28,5 @@ func errorf(err error, format string, args ...interface{}) error { // IsError returns true iff the underlying cause was a validation error. func IsError(err error) bool { - return errors.Cause(err) == validateErr + return errors.Cause(err) == errValidate } diff --git a/pkg/validate/error_test.go b/pkg/validate/error_test.go index 1688f0c040..7de4ab1c8d 100644 --- a/pkg/validate/error_test.go +++ b/pkg/validate/error_test.go @@ -39,7 +39,7 @@ func (s *ErrorSuite) TestIsError(c *C) { is: false, }, { - err: validateErr, + err: errValidate, is: true, }, { @@ -51,11 +51,11 @@ func (s *ErrorSuite) TestIsError(c *C) { is: false, }, { - err: errors.Wrap(validateErr, "test"), + err: errors.Wrap(errValidate, "test"), is: true, }, { - err: errors.WithStack(validateErr), + err: errors.WithStack(errValidate), is: true, }, { diff --git a/pkg/validate/validate.go b/pkg/validate/validate.go index 1d6a5102b8..4c5680f402 100644 --- a/pkg/validate/validate.go +++ b/pkg/validate/validate.go @@ -35,7 +35,7 @@ func ActionSet(as *crv1alpha1.ActionSet) error { } if as.Status != nil { if len(as.Spec.Actions) != len(as.Status.Actions) { - return errorf(validateErr, "Number of actions in status actions and spec must match") + return errorf(errValidate, "Number of actions in status actions and spec must match") } if err := actionSetStatus(as.Status); err != nil { return err @@ -46,7 +46,7 @@ func ActionSet(as *crv1alpha1.ActionSet) error { func actionSetSpec(as *crv1alpha1.ActionSetSpec) error { if as == nil { - return errorf(validateErr, "Spec must be non-nil") + return errorf(errValidate, "Spec must be non-nil") } for _, a := range as.Actions { if err := actionSpec(a); err != nil { @@ -72,7 +72,7 @@ func actionSpec(s crv1alpha1.ActionSpec) error { // Not a known type. ActionSet must specify API group and resource // name in order to populate `Object` TemplateParam if s.Object.APIVersion == "" || s.Object.Resource == "" { - return errorf(validateErr, "Not a known object Kind %s. Action %s must specify Resource name and API version", s.Object.Kind, s.Name) + return errorf(errValidate, "Not a known object Kind %s. Action %s must specify Resource name and API version", s.Object.Kind, s.Name) } } return nil @@ -94,7 +94,7 @@ func actionSetStatus(as *crv1alpha1.ActionSetStatus) error { for _, a := range as.Actions { for _, p := range a.Phases { if _, ok := saw[p.State]; !ok { - return errorf(validateErr, "Action has unknown state '%s'", p.State) + return errorf(errValidate, "Action has unknown state '%s'", p.State) } for s := range saw { saw[s] = saw[s] || (p.State == s) @@ -102,11 +102,11 @@ func actionSetStatus(as *crv1alpha1.ActionSetStatus) error { } } if _, ok := saw[as.State]; !ok { - return errorf(validateErr, "ActionSet has unknown state '%s'", as.State) + return errorf(errValidate, "ActionSet has unknown state '%s'", as.State) } if saw[crv1alpha1.StateRunning] || saw[crv1alpha1.StatePending] { if as.State == crv1alpha1.StateComplete { - return errorf(validateErr, "ActionSet cannot be complete if any actions are not complete") + return errorf(errValidate, "ActionSet cannot be complete if any actions are not complete") } } return nil @@ -118,7 +118,7 @@ func actionSetStatusActions(as []crv1alpha1.ActionStatus) error { var lastNonComplete crv1alpha1.State for _, p := range a.Phases { if sawNotComplete && p.State != crv1alpha1.StatePending { - return errorf(validateErr, "Phases after a %s one must be pending", lastNonComplete) + return errorf(errValidate, "Phases after a %s one must be pending", lastNonComplete) } if !sawNotComplete { lastNonComplete = p.State @@ -137,14 +137,14 @@ func Blueprint(bp *crv1alpha1.Blueprint) error { func ProfileSchema(p *crv1alpha1.Profile) error { if !supported(p.Location.Type) { - return errorf(validateErr, "unknown or unsupported location type '%s'", p.Location.Type) + return errorf(errValidate, "unknown or unsupported location type '%s'", p.Location.Type) } if err := validateCredentialType(&p.Credential); err != nil { return err } if p.Location.Type == crv1alpha1.LocationTypeS3Compliant { if p.Location.Bucket != "" && p.Location.Endpoint == "" && p.Location.Region == "" { - return errorf(validateErr, "Bucket region not specified") + return errorf(errValidate, "Bucket region not specified") } } return nil @@ -154,22 +154,22 @@ func validateCredentialType(creds *crv1alpha1.Credential) error { switch creds.Type { case crv1alpha1.CredentialTypeKeyPair: if creds.KeyPair.Secret.Name == "" { - return errorf(validateErr, "Secret for bucket credentials not specified") + return errorf(errValidate, "Secret for bucket credentials not specified") } if creds.KeyPair.SecretField == "" || creds.KeyPair.IDField == "" { - return errorf(validateErr, "Secret field or id field empty") + return errorf(errValidate, "Secret field or id field empty") } return nil case crv1alpha1.CredentialTypeSecret: if creds.Secret.Name == "" { - return errorf(validateErr, "Secret name is empty") + return errorf(errValidate, "Secret name is empty") } if creds.Secret.Namespace == "" { - return errorf(validateErr, "Secret namespace is empty") + return errorf(errValidate, "Secret namespace is empty") } return nil default: - return errorf(validateErr, "Unsupported credential type '%s'", creds.Type) + return errorf(errValidate, "Unsupported credential type '%s'", creds.Type) } } @@ -189,7 +189,7 @@ func ProfileBucket(ctx context.Context, p *crv1alpha1.Profile, cli kubernetes.In case crv1alpha1.LocationTypeAzure: pType = objectstore.ProviderTypeAzure default: - return errorf(validateErr, "unknown or unsupported location type '%s'", p.Location.Type) + return errorf(errValidate, "unknown or unsupported location type '%s'", p.Location.Type) } pc := objectstore.ProviderConfig{ Type: pType, @@ -224,7 +224,7 @@ func ReadAccess(ctx context.Context, p *crv1alpha1.Profile, cli kubernetes.Inter case crv1alpha1.LocationTypeAzure: pType = objectstore.ProviderTypeAzure default: - return errorf(validateErr, "unknown or unsupported location type '%s'", p.Location.Type) + return errorf(errValidate, "unknown or unsupported location type '%s'", p.Location.Type) } secret, err = osSecretFromProfile(ctx, pType, p, cli) if err != nil { @@ -262,7 +262,7 @@ func WriteAccess(ctx context.Context, p *crv1alpha1.Profile, cli kubernetes.Inte case crv1alpha1.LocationTypeAzure: pType = objectstore.ProviderTypeAzure default: - return errorf(validateErr, "unknown or unsupported location type '%s'", p.Location.Type) + return errorf(errValidate, "unknown or unsupported location type '%s'", p.Location.Type) } secret, err = osSecretFromProfile(ctx, pType, p, cli) if err != nil { @@ -330,17 +330,17 @@ func osSecretFromProfile(ctx context.Context, pType objectstore.ProviderType, p // The following is KeyPair codepath kp := p.Credential.KeyPair if kp == nil { - return nil, errorf(validateErr, "Invalid credentials kp cannot be nil") + return nil, errorf(errValidate, "Invalid credentials kp cannot be nil") } s, err := cli.CoreV1().Secrets(kp.Secret.Namespace).Get(ctx, kp.Secret.Name, metav1.GetOptions{}) if err != nil { return nil, errorf(err, "Could not fetch the secret specified in credential") } if key, ok = s.Data[kp.IDField]; !ok { - return nil, errorf(validateErr, "Key '%s' not found in secret '%s:%s'", kp.IDField, s.GetNamespace(), s.GetName()) + return nil, errorf(errValidate, "Key '%s' not found in secret '%s:%s'", kp.IDField, s.GetNamespace(), s.GetName()) } if value, ok = s.Data[kp.SecretField]; !ok { - return nil, errorf(validateErr, "Value '%s' not found in secret '%s:%s'", kp.SecretField, s.GetNamespace(), s.GetName()) + return nil, errorf(errValidate, "Value '%s' not found in secret '%s:%s'", kp.SecretField, s.GetNamespace(), s.GetName()) } switch pType { @@ -363,7 +363,7 @@ func osSecretFromProfile(ctx context.Context, pType objectstore.ProviderType, p StorageKey: string(value), } default: - return nil, errorf(validateErr, "unknown or unsupported provider type '%s'", pType) + return nil, errorf(errValidate, "unknown or unsupported provider type '%s'", pType) } return secret, nil } diff --git a/pkg/version/version.go b/pkg/version/version.go index d6d187bec4..78ea816a6b 100644 --- a/pkg/version/version.go +++ b/pkg/version/version.go @@ -19,12 +19,13 @@ package version import "fmt" // The below variables will be overrriden using ldflags set by goreleaser during the build process -var VERSION = "DEV" -var GIT_COMMIT = "NONE" -var BUILD_DATE = "UNKNOWN" + +var Version = "DEV" +var GitCommit = "NONE" +var BuildDate = "UNKNOWN" const versionStringFmt = `{"version": "%s", "gitCommit": "%s", "buildDate": "%s"}` func VersionString() string { - return fmt.Sprintf(versionStringFmt, VERSION, GIT_COMMIT, BUILD_DATE) + return fmt.Sprintf(versionStringFmt, Version, GitCommit, BuildDate) }