From b50165ffd95bb4320a1269659d2ab857e2332141 Mon Sep 17 00:00:00 2001 From: Andrews Arokiam Date: Wed, 14 Feb 2024 16:09:57 +0530 Subject: [PATCH] fix for golint errcheck Signed-off-by: Andrews Arokiam --- .golangci.yml | 2 -- cmd/agent/main.go | 4 +++- pkg/agent/downloader.go | 2 +- pkg/agent/storage/https.go | 8 ++++---- pkg/apis/serving/v1beta1/inference_service_status.go | 4 +++- pkg/constants/constants.go | 2 +- pkg/controller/v1alpha1/trainedmodel/controller.go | 5 ++++- pkg/controller/v1beta1/inferenceservice/controller.go | 7 +++++-- .../inferenceservice/reconcilers/hpa/hpa_reconciler.go | 2 +- .../reconcilers/service/service_reconciler.go | 2 +- pkg/credentials/azure/azure_secret.go | 2 +- pkg/credentials/gcs/gcs_secret.go | 10 +++++----- pkg/credentials/s3/s3_secret.go | 2 +- tools/tf2openapi/cmd/main.go | 5 ++++- 14 files changed, 34 insertions(+), 23 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 2c310a4107d..8ad22fed36b 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -26,5 +26,3 @@ linters: - unconvert - unparam - gofmt - disable: - - errcheck diff --git a/cmd/agent/main.go b/cmd/agent/main.go index c2770986201..d45abfffb9f 100644 --- a/cmd/agent/main.go +++ b/cmd/agent/main.go @@ -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) diff --git a/pkg/agent/downloader.go b/pkg/agent/downloader.go index e8f3e9bd460..09625f06482 100644 --- a/pkg/agent/downloader.go +++ b/pkg/agent/downloader.go @@ -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 if err != nil { return errors.Wrapf(createErr, "failed to write the success file") } diff --git a/pkg/agent/storage/https.go b/pkg/agent/storage/https.go index f318a7e09ca..221ba43e341 100644 --- a/pkg/agent/storage/https.go +++ b/pkg/agent/storage/https.go @@ -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 if !strings.HasPrefix(fileFullPath, filepath.Clean(dest)+string(os.PathSeparator)) { return fmt.Errorf("%s: illegal file path", fileFullPath) } @@ -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 closeErr := file.Close() if closeErr != nil { return closeErr @@ -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 if header.Typeflag == tar.TypeDir { err = os.MkdirAll(fileFullPath, 0755) if err != nil { @@ -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 return fmt.Errorf("unable to copy contents to %s: %w", header.Name, err) } } diff --git a/pkg/apis/serving/v1beta1/inference_service_status.go b/pkg/apis/serving/v1beta1/inference_service_status.go index ac4000aaaf8..f390a0e5452 100644 --- a/pkg/apis/serving/v1beta1/inference_service_status.go +++ b/pkg/apis/serving/v1beta1/inference_service_status.go @@ -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 + } } } diff --git a/pkg/constants/constants.go b/pkg/constants/constants.go index e0a44fa041b..b3d3ec35fef 100644 --- a/pkg/constants/constants.go +++ b/pkg/constants/constants.go @@ -127,7 +127,7 @@ const ( // StorageSpec Constants var ( DefaultStorageSpecSecret = "storage-config" - DefaultStorageSpecSecretPath = "/mnt/storage-secret" + DefaultStorageSpecSecretPath = "/mnt/storage-secret" // nolint gosec ) // Controller Constants diff --git a/pkg/controller/v1alpha1/trainedmodel/controller.go b/pkg/controller/v1alpha1/trainedmodel/controller.go index e840acfef5c..f9430a8a3fb 100644 --- a/pkg/controller/v1alpha1/trainedmodel/controller.go +++ b/pkg/controller/v1alpha1/trainedmodel/controller.go @@ -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 diff --git a/pkg/controller/v1beta1/inferenceservice/controller.go b/pkg/controller/v1beta1/inferenceservice/controller.go index 1fa4f5a19f4..b51d3dbc27f 100644 --- a/pkg/controller/v1beta1/inferenceservice/controller.go +++ b/pkg/controller/v1beta1/inferenceservice/controller.go @@ -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 { @@ -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 r.Log.Error(err, "unable to delete trainedmodel", "trainedmodel", v) } } diff --git a/pkg/controller/v1beta1/inferenceservice/reconcilers/hpa/hpa_reconciler.go b/pkg/controller/v1beta1/inferenceservice/reconcilers/hpa/hpa_reconciler.go index 76834471663..9ed30cdd3fb 100644 --- a/pkg/controller/v1beta1/inferenceservice/reconcilers/hpa/hpa_reconciler.go +++ b/pkg/controller/v1beta1/inferenceservice/reconcilers/hpa/hpa_reconciler.go @@ -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 } else { utilization = constants.DefaultCPUUtilization } diff --git a/pkg/controller/v1beta1/inferenceservice/reconcilers/service/service_reconciler.go b/pkg/controller/v1beta1/inferenceservice/reconcilers/service/service_reconciler.go index 45ec3781e92..bcb1211648f 100644 --- a/pkg/controller/v1beta1/inferenceservice/reconcilers/service/service_reconciler.go +++ b/pkg/controller/v1beta1/inferenceservice/reconcilers/service/service_reconciler.go @@ -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 }, Protocol: corev1.ProtocolTCP, }) diff --git a/pkg/credentials/azure/azure_secret.go b/pkg/credentials/azure/azure_secret.go index c5b627bf436..b0b3a853dc9 100644 --- a/pkg/credentials/azure/azure_secret.go +++ b/pkg/credentials/azure/azure_secret.go @@ -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 ) var ( diff --git a/pkg/credentials/gcs/gcs_secret.go b/pkg/credentials/gcs/gcs_secret.go index d9f93f4f234..85c5af4bb01 100644 --- a/pkg/credentials/gcs/gcs_secret.go +++ b/pkg/credentials/gcs/gcs_secret.go @@ -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 + GCSCredentialVolumeName = "user-gcp-sa" // nolint gosec + GCSCredentialVolumeMountPath = "/var/secrets/" // nolint gosec + GCSCredentialEnvKey = "GOOGLE_APPLICATION_CREDENTIALS" // nolint gosec ) type GCSConfig struct { diff --git a/pkg/credentials/s3/s3_secret.go b/pkg/credentials/s3/s3_secret.go index 5c953b5d70f..f5fd30666c4 100644 --- a/pkg/credentials/s3/s3_secret.go +++ b/pkg/credentials/s3/s3_secret.go @@ -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 AWSAccessKeyIdName = "awsAccessKeyID" AWSSecretAccessKeyName = "awsSecretAccessKey" AWSEndpointUrl = "AWS_ENDPOINT_URL" diff --git a/tools/tf2openapi/cmd/main.go b/tools/tf2openapi/cmd/main.go index 089bd0461ef..ca2a71d9262 100644 --- a/tools/tf2openapi/cmd/main.go +++ b/tools/tf2openapi/cmd/main.go @@ -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")