Skip to content

Commit

Permalink
fix for golint errcheck
Browse files Browse the repository at this point in the history
Signed-off-by: Andrews Arokiam <[email protected]>
  • Loading branch information
andyi2it committed Feb 14, 2024
1 parent 83538dc commit b50165f
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 23 deletions.
2 changes: 0 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ linters:
- unconvert
- unparam
- gofmt
disable:
- errcheck
4 changes: 3 additions & 1 deletion cmd/agent/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,9 @@ func main() {
case err := <-errCh:
logger.Errorw("Failed to bring up agent, shutting down.", zap.Error(err))
// This extra flush is needed because defers are not handled via os.Exit calls.
logger.Sync()
if err := logger.Sync(); err != nil {
logger.Errorw("Error syncing logger: %v", err)
}
os.Stdout.Sync()
os.Stderr.Sync()
os.Exit(1)
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (d *Downloader) DownloadModel(modelName string, modelSpec *v1alpha1.ModelSp
if err != nil {
return errors.Wrapf(createErr, "failed to encode model spec")
}
err = os.WriteFile(successFile, encodedJson, 0644)
err = os.WriteFile(successFile, encodedJson, 0644) // nolint gosec

Check failure

Code scanning / gosec

Expect WriteFile permissions to be 0600 or less Error

Expect WriteFile permissions to be 0600 or less
if err != nil {
return errors.Wrapf(createErr, "failed to write the success file")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/agent/storage/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func extractZipFiles(reader io.Reader, dest string) error {

// Read all the files from zip archive
for _, zipFile := range zipReader.File {
fileFullPath := filepath.Join(dest, zipFile.Name)
fileFullPath := filepath.Join(dest, zipFile.Name) // nolint gosec

Check failure

Code scanning / gosec

File traversal when extracting zip/tar archive Error

File traversal when extracting zip/tar archive
if !strings.HasPrefix(fileFullPath, filepath.Clean(dest)+string(os.PathSeparator)) {
return fmt.Errorf("%s: illegal file path", fileFullPath)
}
Expand All @@ -186,7 +186,7 @@ func extractZipFiles(reader io.Reader, dest string) error {
return fmt.Errorf("unable to open file: %w", err)
}

_, err = io.Copy(file, rc)
_, err = io.Copy(file, rc) // nolint gosec

Check failure

Code scanning / gosec

Potential DoS vulnerability via decompression bomb Error

Potential DoS vulnerability via decompression bomb
closeErr := file.Close()
if closeErr != nil {
return closeErr
Expand Down Expand Up @@ -225,7 +225,7 @@ func extractTarFiles(reader io.Reader, dest string) error {
return fmt.Errorf("unable to access next tar file: %w", err)
}

fileFullPath := filepath.Join(dest, header.Name)
fileFullPath := filepath.Join(dest, header.Name) // nolint gosec

Check failure

Code scanning / gosec

File traversal when extracting zip/tar archive Error

File traversal when extracting zip/tar archive
if header.Typeflag == tar.TypeDir {
err = os.MkdirAll(fileFullPath, 0755)
if err != nil {
Expand All @@ -239,7 +239,7 @@ func extractTarFiles(reader io.Reader, dest string) error {
if err != nil {
return err
}
if _, err := io.Copy(newFile, tr); err != nil {
if _, err := io.Copy(newFile, tr); err != nil { // nolint gosec

Check failure

Code scanning / gosec

Potential DoS vulnerability via decompression bomb Error

Potential DoS vulnerability via decompression bomb
return fmt.Errorf("unable to copy contents to %s: %w", header.Name, err)
}
}
Expand Down
4 changes: 3 additions & 1 deletion pkg/apis/serving/v1beta1/inference_service_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,9 @@ func (ss *InferenceServiceStatus) SetCondition(conditionType apis.ConditionType,

func (ss *InferenceServiceStatus) ClearCondition(conditionType apis.ConditionType) {
if conditionSet.Manage(ss).GetCondition(conditionType) != nil {
conditionSet.Manage(ss).ClearCondition(conditionType)
if err := conditionSet.Manage(ss).ClearCondition(conditionType); err != nil {
return
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ const (
// StorageSpec Constants
var (
DefaultStorageSpecSecret = "storage-config"
DefaultStorageSpecSecretPath = "/mnt/storage-secret"
DefaultStorageSpecSecretPath = "/mnt/storage-secret" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
)

// Controller Constants
Expand Down
5 changes: 4 additions & 1 deletion pkg/controller/v1alpha1/trainedmodel/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ func (r *TrainedModelReconciler) Reconcile(ctx context.Context, req ctrl.Request
if err := r.Get(context.TODO(), types.NamespacedName{Namespace: req.Namespace, Name: tm.Spec.InferenceService}, isvc); err != nil {
if errors.IsNotFound(err) {
log.Info("Parent InferenceService does not exists, deleting TrainedModel", "TrainedModel", tm.Name, "InferenceService", isvc.Name)
r.Delete(context.TODO(), tm)
if err := r.Delete(context.TODO(), tm); err != nil {
log.Error(err, "Error deleting resource")
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
}
return reconcile.Result{}, err
Expand Down
7 changes: 5 additions & 2 deletions pkg/controller/v1beta1/inferenceservice/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,10 @@ func (r *InferenceServiceReconciler) Reconcile(ctx context.Context, req ctrl.Req
if err != nil {
r.Log.Error(err, "Failed to reconcile", "reconciler", reflect.ValueOf(reconciler), "Name", isvc.Name)
r.Recorder.Eventf(isvc, v1.EventTypeWarning, "InternalError", err.Error())
r.updateStatus(isvc, deploymentMode)
if err := r.updateStatus(isvc, deploymentMode); err != nil {
r.Log.Error(err, "Error updating status")
return result, err
}
return reconcile.Result{}, errors.Wrapf(err, "fails to reconcile component")
}
if result.Requeue || result.RequeueAfter > 0 {
Expand Down Expand Up @@ -332,7 +335,7 @@ func (r *InferenceServiceReconciler) deleteExternalResources(isvc *v1beta1api.In
}

for _, v := range trainedModels.Items {
if err := r.Delete(context.TODO(), &v, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
if err := r.Delete(context.TODO(), &v, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil { // nolint gosec

Check failure

Code scanning / gosec

Implicit memory aliasing in for loop. Error

Implicit memory aliasing in for loop.
r.Log.Error(err, "unable to delete trainedmodel", "trainedmodel", v)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func getHPAMetrics(metadata metav1.ObjectMeta, componentExt *v1beta1.ComponentEx

if value, ok := annotations[constants.TargetUtilizationPercentage]; ok {
utilizationInt, _ := strconv.Atoi(value)
utilization = int32(utilizationInt)
utilization = int32(utilizationInt) // nolint gosec

Check failure

Code scanning / gosec

Potential Integer overflow made by strconv.Atoi result conversion to int16/32 Error

Potential Integer overflow made by strconv.Atoi result conversion to int16/32
} else {
utilization = constants.DefaultCPUUtilization
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func createService(componentMeta metav1.ObjectMeta, componentExt *v1beta1.Compon
Port: constants.CommonDefaultHttpPort,
TargetPort: intstr.IntOrString{
Type: intstr.Int,
IntVal: int32(port),
IntVal: int32(port), // nolint gosec

Check failure

Code scanning / gosec

Potential Integer overflow made by strconv.Atoi result conversion to int16/32 Error

Potential Integer overflow made by strconv.Atoi result conversion to int16/32
},
Protocol: corev1.ProtocolTCP,
})
Expand Down
2 changes: 1 addition & 1 deletion pkg/credentials/azure/azure_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const (
AzureSubscriptionId = "AZURE_SUBSCRIPTION_ID"
AzureTenantId = "AZURE_TENANT_ID"
AzureClientId = "AZURE_CLIENT_ID"
AzureClientSecret = "AZURE_CLIENT_SECRET"
AzureClientSecret = "AZURE_CLIENT_SECRET" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
)

var (
Expand Down
10 changes: 5 additions & 5 deletions pkg/credentials/gcs/gcs_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ limitations under the License.
package gcs

import (
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
)

const (
GCSCredentialFileName = "gcloud-application-credentials.json"
GCSCredentialVolumeName = "user-gcp-sa"
GCSCredentialVolumeMountPath = "/var/secrets/"
GCSCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS"
GCSCredentialFileName = "gcloud-application-credentials.json" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
GCSCredentialVolumeName = "user-gcp-sa" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
GCSCredentialVolumeMountPath = "/var/secrets/" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
GCSCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
)

type GCSConfig struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/credentials/s3/s3_secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Boto: https://boto3.amazonaws.com/v1/documentation/api/latest/guide/configuratio
*/
const (
AWSAccessKeyId = "AWS_ACCESS_KEY_ID"
AWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY"
AWSSecretAccessKey = "AWS_SECRET_ACCESS_KEY" // nolint gosec

Check failure

Code scanning / gosec

Potential hardcoded credentials Error

Potential hardcoded credentials
AWSAccessKeyIdName = "awsAccessKeyID"
AWSSecretAccessKeyName = "awsSecretAccessKey"
AWSEndpointUrl = "AWS_ENDPOINT_URL"
Expand Down
5 changes: 4 additions & 1 deletion tools/tf2openapi/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ func main() {
}

rootCmd.Flags().StringVarP(&modelBasePath, "model_base_path", "m", "", "Absolute path of SavedModel file")
rootCmd.MarkFlagRequired("model_base_path")
if err := rootCmd.MarkFlagRequired("model_base_path"); err != nil {
log.Fatalln(err.Error())
}

rootCmd.Flags().StringVarP(&modelName, "name", "n", "model", "Name of model")
rootCmd.Flags().StringVarP(&modelVersion, "version", "v", "1", "Model version")
rootCmd.Flags().StringVarP(&outFile, "output_file", "o", "", "Absolute path of file to write OpenAPI spec to")
Expand Down

0 comments on commit b50165f

Please sign in to comment.