Skip to content

Commit

Permalink
chore(lint): updates to latest version (opendatahub-io#1074)
Browse files Browse the repository at this point in the history
Fixes

- removed irrelavant //nolint comments (see config updates below)
- converted unused func params to blank identifier when impl does not
  need it

New linters

perfsprint

- disabled fmt.Sprintf checks for one element
- adjusted errors creation to use errors.New instead of fmt.Errorf when
  no-arg strings are used as messages

Configuration updates

- configured revive to not complain about dot-imports for testing
  libraries
- adjusted configuration yaml due to changes in the structure
  (skip-dirs)
- some deprecated linters were removed from golangci-lint toolchain so they are now gone from the config too

(cherry picked from commit 9be146f)
  • Loading branch information
bartoszmajsak authored and VaishnaviHire committed Jul 24, 2024
1 parent d6e0a72 commit 5468046
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 79 deletions.
24 changes: 1 addition & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,6 @@ linters-settings:
nolintlint:
allow-no-explanation: [ funlen, lll ]
require-specific: true
importas:
alias:
- pkg: github.com/opendatahub-io/opendatahub-operator/v2/apis/dscinitialization/v1
alias: dsciv1
- pkg: github.com/opendatahub-io/opendatahub-operator/v2/apis/datasciencecluster/v1
alias: dscv1
- pkg: github.com/opendatahub-io/opendatahub-operator/v2/apis/infrastructure/v1
alias: infrav1
- pkg: k8s.io/apimachinery/pkg/api/errors
alias: k8serr
# Ensures that i.e. k8s.io/api/rbac/v1 is aliased as rbacv1
- pkg: k8s.io/api/(\w+)/(v[\w\d]+)
alias: $1$2
- pkg: github.com/openshift/api/(\w+)/(v[\w\d]+)
alias: $1$2
revive:
rules:
- name: dot-imports
Expand All @@ -56,25 +41,18 @@ linters:
enable-all: true
disable:
- containedctx # detects struct contained context.Context field
- deadcode # deprecated
- depguard # [replaced by gomodguard] checks if package imports are in a list of acceptable packages
- exhaustruct # Prevents empty struct. We use a lot of these so I think it is safe to disable.c
- forbidigo
- gochecknoglobals # Prevents use of global vars.
- gofumpt
- golint # deprecated
- gomnd # Doesnot allow hardcoded numbers
- gomoddirectives # Doesnot allow replace in go mod file
- ifshort # deprecated
- interfacer
- maligned # deprecated
- mnd
- nestif
- nilnil
- paralleltest # [too many false positives] detects missing usage of t.Parallel() method in your Go test
- scopelint # deprecated
- structcheck # deprecated
- tagliatelle
- varcheck # deprecated
- varnamelen # doesnot allow shorter names like c,k etc. But golang prefers short named vars.
- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
- wrapcheck # check if this is required. Prevents direct return of err.
Expand Down
6 changes: 0 additions & 6 deletions components/kserve/kserve_config_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ func (k *Kserve) configureServerless(instance *dsciv1.DSCInitializationSpec) err
return errors.New("ServiceMesh is need to set to 'Managed' in DSCI CR, it is required by KServe serving field")
}

// check on dependent operators if all installed in cluster
dependOpsErrors := checkDependentOperators(cli).ErrorOrNil()
if dependOpsErrors != nil {
return dependOpsErrors
}

serverlessFeatures := feature.ComponentFeaturesHandler(k.GetComponentName(), instance, k.configureServerlessFeatures())

if err := serverlessFeatures.Apply(); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ type DataScienceClusterReconciler struct {

// DataScienceClusterConfig passing Spec of DSCI for reconcile DataScienceCluster.
type DataScienceClusterConfig struct {
<<<<<<< HEAD
DSCISpec *dsciv1.DSCInitializationSpec
=======
DSCISpec *dsci.DSCInitializationSpec
>>>>>>> 9be146f7 (chore(lint): updates to latest version (#1074))
}

const (
Expand Down
85 changes: 39 additions & 46 deletions tests/e2e/dsc_creation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ import (
"context"
"errors"
"fmt"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"log"
"reflect"
"strings"
Expand All @@ -14,7 +17,7 @@ import (
"github.com/stretchr/testify/require"
autoscalingv1 "k8s.io/api/autoscaling/v1"
corev1 "k8s.io/api/core/v1"
k8serr "k8s.io/apimachinery/pkg/api/errors"
k8serrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/wait"
Expand Down Expand Up @@ -104,7 +107,7 @@ func (tc *testContext) testDSCICreation() error {
// create one for you
err = tc.customClient.Get(tc.ctx, dscLookupKey, createdDSCI)
if err != nil {
if k8serr.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
nberr := wait.PollUntilContextTimeout(tc.ctx, tc.resourceRetryInterval, tc.resourceCreationTimeout, false, func(ctx context.Context) (bool, error) {
creationErr := tc.customClient.Create(tc.ctx, tc.testDSCI)
if creationErr != nil {
Expand Down Expand Up @@ -162,7 +165,7 @@ func (tc *testContext) testDSCCreation() error {

err = tc.customClient.Get(tc.ctx, dscLookupKey, createdDSC)
if err != nil {
if k8serr.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
nberr := wait.PollUntilContextTimeout(tc.ctx, tc.resourceRetryInterval, tc.resourceCreationTimeout, false, func(ctx context.Context) (bool, error) {
creationErr := tc.customClient.Create(tc.ctx, tc.testDsc)
if creationErr != nil {
Expand All @@ -183,48 +186,38 @@ func (tc *testContext) testDSCCreation() error {
return waitDSCReady(tc)
}

// func (tc *testContext) requireInstalled(t *testing.T, gvk schema.GroupVersionKind) {
// t.Helper()
// list := &unstructured.UnstructuredList{}
// list.SetGroupVersionKind(gvk)
// err := tc.customClient.List(tc.ctx, list)
// require.NoErrorf(t, err, "Could not get %s list", gvk.Kind)
// require.Greaterf(t, len(list.Items), 0, "%s has not been installed", gvk.Kind)
// }

// func (tc *testContext) testDuplication(t *testing.T, gvk schema.GroupVersionKind, o any) {
// t.Helper()
// tc.requireInstalled(t, gvk)
// u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(o)
// require.NoErrorf(t, err, "Could not unstructure %s", gvk.Kind)
// obj := &unstructured.Unstructured{
// Object: u,
// }
// obj.SetGroupVersionKind(gvk)
// err = tc.customClient.Create(tc.ctx, obj)
// require.Errorf(t, err, "Could create second %s", gvk.Kind)
// }

// func (tc *testContext) testDSCIDuplication(t *testing.T) { //nolint:thelper
// gvk := schema.GroupVersionKind{
// Group: "dscinitialization.opendatahub.io",
// Version: "v1",
// Kind: "DSCInitialization",
// }
// dup := setupDSCICR("e2e-test-dsci-dup")
// tc.testDuplication(t, gvk, dup)
// }

// func (tc *testContext) testDSCDuplication(t *testing.T) { //nolint:thelper
// gvk := schema.GroupVersionKind{
// Group: "datasciencecluster.opendatahub.io",
// Version: "v1",
// Kind: "DataScienceCluster",
// }

// dup := setupDSCInstance("e2e-test-dsc-dup")
// tc.testDuplication(t, gvk, dup)
// }
func (tc *testContext) requireInstalled(t *testing.T, gvk schema.GroupVersionKind) {
t.Helper()
list := &unstructured.UnstructuredList{}
list.SetGroupVersionKind(gvk)
err := tc.customClient.List(tc.ctx, list)
require.NoErrorf(t, err, "Could not get %s list", gvk.Kind)
require.Greaterf(t, len(list.Items), 0, "%s has not been installed", gvk.Kind)
}

func (tc *testContext) testDuplication(t *testing.T, gvk schema.GroupVersionKind, o any) {
t.Helper()
tc.requireInstalled(t, gvk)
u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(o)
require.NoErrorf(t, err, "Could not unstructure %s", gvk.Kind)
obj := &unstructured.Unstructured{
Object: u,
}
obj.SetGroupVersionKind(gvk)
err = tc.customClient.Create(tc.ctx, obj)
require.Errorf(t, err, "Could create second %s", gvk.Kind)
}

func (tc *testContext) testDSCDuplication(t *testing.T) { //nolint:thelper
gvk := schema.GroupVersionKind{
Group: "datasciencecluster.opendatahub.io",
Version: "v1",
Kind: "DataScienceCluster",
}

dup := setupDSCInstance("e2e-test-dsc-dup")
tc.testDuplication(t, gvk, dup)
}

func (tc *testContext) testAllApplicationCreation(t *testing.T) error { //nolint:funlen,thelper
// Validate test instance is in Ready state
Expand Down Expand Up @@ -510,7 +503,7 @@ func (tc *testContext) testUpdateDSCComponentEnabled() error {
time.Sleep(4 * tc.resourceRetryInterval)
_, err = tc.kubeClient.AppsV1().Deployments(tc.applicationsNamespace).Get(context.TODO(), dashboardDeploymentName, metav1.GetOptions{})
if err != nil {
if k8serr.IsNotFound(err) {
if k8serrors.IsNotFound(err) {
return nil // correct result: should not find deployment after we disable it already
}
return fmt.Errorf("error getting component resource after reconcile: %w", err)
Expand Down
4 changes: 0 additions & 4 deletions tests/e2e/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,7 @@ func setupDSCICR(name string) *dsciv1.DSCInitialization {
ManagementState: "Managed",
Namespace: "redhat-ods-monitoring",
},
<<<<<<< HEAD
TrustedCABundle: &dsciv1.TrustedCABundleSpec{
=======
TrustedCABundle: &dsci.TrustedCABundleSpec{
>>>>>>> 7afb0cf9 (fix(DSCI): change serviceMesh and trustCAbundle to pointer type (#885))
ManagementState: "Managed",
CustomCABundle: "",
},
Expand Down

0 comments on commit 5468046

Please sign in to comment.