From 6a6f34317d2e75c782f1f8030af83ce420a8fc30 Mon Sep 17 00:00:00 2001 From: Konstantin Khlebnikov Date: Thu, 27 Jun 2024 10:49:46 +0200 Subject: [PATCH] Fix formatting and enable more linters for that --- .golangci.yaml | 4 ++-- api/v1/ytsaurus_webhook.go | 1 - controllers/chyt_controller.go | 3 ++- controllers/chyt_sync.go | 3 ++- controllers/spyt_controller.go | 3 ++- controllers/spyt_sync.go | 3 ++- controllers/ytsaurus_controller.go | 1 + main.go | 3 ++- pkg/apiproxy/chyt.go | 1 + pkg/apiproxy/proxy.go | 1 + pkg/apiproxy/spyt.go | 1 + pkg/apiproxy/ytsaurus.go | 10 +++++----- pkg/components/chyt.go | 1 - pkg/components/helpers.go | 2 -- pkg/components/httpproxy.go | 1 - pkg/components/spyt.go | 1 - pkg/components/ui.go | 2 -- pkg/components/volume.go | 3 ++- pkg/components/ytsaurus_client.go | 2 -- pkg/resources/deployment.go | 1 + pkg/testutil/testhelper.go | 1 - pkg/ytconfig/cri.go | 1 - pkg/ytconfig/logging.go | 3 ++- test/e2e/ytsaurus_controller_test.go | 1 - 24 files changed, 26 insertions(+), 27 deletions(-) diff --git a/.golangci.yaml b/.golangci.yaml index e701c219..6e8b50ca 100644 --- a/.golangci.yaml +++ b/.golangci.yaml @@ -78,7 +78,7 @@ linters: # - goconst # finds repeated strings that could be replaced by a constant - gocritic # provides diagnostics that check for bugs, performance and style issues # - godot # checks if comments end in a period - # - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt + - goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt # - gomnd # detects magic numbers - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod - gomodguard # allow and block lists linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations @@ -110,7 +110,7 @@ linters: # - unparam # reports unused function parameters - usestdlibvars # detects the possibility to use variables/constants from the Go standard library - wastedassign # finds wasted assignment statements - # - whitespace # detects leading and trailing whitespace + - whitespace # detects leading and trailing whitespace # - wrapcheck # checks that errors returned from external packages are wrapped # - wsl # add or remove empty lines diff --git a/api/v1/ytsaurus_webhook.go b/api/v1/ytsaurus_webhook.go index 55ec569a..281c7973 100644 --- a/api/v1/ytsaurus_webhook.go +++ b/api/v1/ytsaurus_webhook.go @@ -430,7 +430,6 @@ func (r *Ytsaurus) validateInstanceSpec(instanceSpec InstanceSpec, path *field.P if instanceSpec.Locations != nil { for locationIdx, location := range instanceSpec.Locations { - inVolumeMount := false for _, volumeMount := range instanceSpec.VolumeMounts { if strings.HasPrefix(location.Path, volumeMount.MountPath) { diff --git a/controllers/chyt_controller.go b/controllers/chyt_controller.go index b3764b79..d82de1b2 100644 --- a/controllers/chyt_controller.go +++ b/controllers/chyt_controller.go @@ -18,10 +18,11 @@ package controllers import ( "context" + "time" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" - "time" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" diff --git a/controllers/chyt_sync.go b/controllers/chyt_sync.go index 890bb91b..322ee2e4 100644 --- a/controllers/chyt_sync.go +++ b/controllers/chyt_sync.go @@ -2,13 +2,14 @@ package controllers import ( "context" + "time" + ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1" "github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy" "github.com/ytsaurus/yt-k8s-operator/pkg/components" "github.com/ytsaurus/yt-k8s-operator/pkg/ytconfig" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" - "time" ) func (r *ChytReconciler) Sync(ctx context.Context, resource *ytv1.Chyt, ytsaurus *ytv1.Ytsaurus) (ctrl.Result, error) { diff --git a/controllers/spyt_controller.go b/controllers/spyt_controller.go index e7590a97..a911bc69 100644 --- a/controllers/spyt_controller.go +++ b/controllers/spyt_controller.go @@ -18,10 +18,11 @@ package controllers import ( "context" + "time" + corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/tools/record" - "time" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" diff --git a/controllers/spyt_sync.go b/controllers/spyt_sync.go index 7f8c6d64..776a4a74 100644 --- a/controllers/spyt_sync.go +++ b/controllers/spyt_sync.go @@ -2,13 +2,14 @@ package controllers import ( "context" + "time" + ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1" "github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy" "github.com/ytsaurus/yt-k8s-operator/pkg/components" "github.com/ytsaurus/yt-k8s-operator/pkg/ytconfig" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/log" - "time" ) func (r *SpytReconciler) Sync(ctx context.Context, resource *ytv1.Spyt, ytsaurus *ytv1.Ytsaurus) (ctrl.Result, error) { diff --git a/controllers/ytsaurus_controller.go b/controllers/ytsaurus_controller.go index 621dd4b8..0f509674 100644 --- a/controllers/ytsaurus_controller.go +++ b/controllers/ytsaurus_controller.go @@ -18,6 +18,7 @@ package controllers import ( "context" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/runtime" diff --git a/main.go b/main.go index da65fee1..e7b1cdce 100644 --- a/main.go +++ b/main.go @@ -18,10 +18,11 @@ package main import ( "flag" - "go.uber.org/zap/zapcore" "os" "strings" + "go.uber.org/zap/zapcore" + "github.com/ytsaurus/yt-k8s-operator/controllers" metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server" "sigs.k8s.io/controller-runtime/pkg/webhook" diff --git a/pkg/apiproxy/chyt.go b/pkg/apiproxy/chyt.go index 0d35a561..09c50451 100644 --- a/pkg/apiproxy/chyt.go +++ b/pkg/apiproxy/chyt.go @@ -2,6 +2,7 @@ package apiproxy import ( "context" + ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/apiproxy/proxy.go b/pkg/apiproxy/proxy.go index d1bc9645..a11ac038 100644 --- a/pkg/apiproxy/proxy.go +++ b/pkg/apiproxy/proxy.go @@ -3,6 +3,7 @@ package apiproxy import ( "context" "fmt" + corev1 "k8s.io/api/core/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/apiproxy/spyt.go b/pkg/apiproxy/spyt.go index 5bbbb211..f617663c 100644 --- a/pkg/apiproxy/spyt.go +++ b/pkg/apiproxy/spyt.go @@ -2,6 +2,7 @@ package apiproxy import ( "context" + ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1" "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" diff --git a/pkg/apiproxy/ytsaurus.go b/pkg/apiproxy/ytsaurus.go index 7c769828..48b8e844 100644 --- a/pkg/apiproxy/ytsaurus.go +++ b/pkg/apiproxy/ytsaurus.go @@ -140,10 +140,10 @@ func (c *Ytsaurus) IsStatusConditionFalse(conditionType string) bool { func sortConditions(conditions []metav1.Condition) { slices.SortStableFunc(conditions, func(a, b metav1.Condition) int { - statusOrder := []metav1.ConditionStatus{metav1.ConditionTrue, metav1.ConditionFalse, metav1.ConditionUnknown} - if diff := cmp.Compare(slices.Index(statusOrder, a.Status), slices.Index(statusOrder, b.Status)); diff != 0 { - return diff - } - return a.LastTransitionTime.Compare(b.LastTransitionTime.Time) + statusOrder := []metav1.ConditionStatus{metav1.ConditionTrue, metav1.ConditionFalse, metav1.ConditionUnknown} + if diff := cmp.Compare(slices.Index(statusOrder, a.Status), slices.Index(statusOrder, b.Status)); diff != 0 { + return diff + } + return a.LastTransitionTime.Compare(b.LastTransitionTime.Time) }) } diff --git a/pkg/components/chyt.go b/pkg/components/chyt.go index 6adc5dc2..17a56ce8 100644 --- a/pkg/components/chyt.go +++ b/pkg/components/chyt.go @@ -33,7 +33,6 @@ func NewChyt( cfgen *ytconfig.Generator, chyt *apiproxy.Chyt, ytsaurus *ytv1.Ytsaurus) *Chyt { - l := labeller.Labeller{ ObjectMeta: &chyt.GetResource().ObjectMeta, APIProxy: chyt.APIProxy(), diff --git a/pkg/components/helpers.go b/pkg/components/helpers.go index f9bc518b..ae0723e2 100644 --- a/pkg/components/helpers.go +++ b/pkg/components/helpers.go @@ -31,7 +31,6 @@ func CreateTabletCells(ctx context.Context, ytClient yt.Client, bundle string, t ypath.Path(fmt.Sprintf("//sys/tablet_cell_bundles/%s/@tablet_cell_count", bundle)), &initTabletCellCount, nil); err != nil { - logger.Error(err, "Getting table_cell_count failed") return err } @@ -176,7 +175,6 @@ func SetWithIgnoreExisting(path string, value string) string { func AddAffinity(statefulSet *appsv1.StatefulSet, nodeSelectorRequirementKey string, nodeSelectorRequirementValues []string) { - affinity := &corev1.Affinity{} if statefulSet.Spec.Template.Spec.Affinity != nil { affinity = statefulSet.Spec.Template.Spec.Affinity diff --git a/pkg/components/httpproxy.go b/pkg/components/httpproxy.go index fc7671fa..0dd7a72a 100644 --- a/pkg/components/httpproxy.go +++ b/pkg/components/httpproxy.go @@ -31,7 +31,6 @@ func NewHTTPProxy( ytsaurus *apiproxy.Ytsaurus, masterReconciler Component, spec ytv1.HTTPProxiesSpec) *HttpProxy { - resource := ytsaurus.GetResource() l := labeller.Labeller{ ObjectMeta: &resource.ObjectMeta, diff --git a/pkg/components/spyt.go b/pkg/components/spyt.go index 09d88249..c9a81427 100644 --- a/pkg/components/spyt.go +++ b/pkg/components/spyt.go @@ -32,7 +32,6 @@ func NewSpyt( cfgen *ytconfig.Generator, spyt *apiproxy.Spyt, ytsaurus *ytv1.Ytsaurus) *Spyt { - l := labeller.Labeller{ ObjectMeta: &spyt.GetResource().ObjectMeta, APIProxy: spyt.APIProxy(), diff --git a/pkg/components/ui.go b/pkg/components/ui.go index 1730365d..2af15c33 100644 --- a/pkg/components/ui.go +++ b/pkg/components/ui.go @@ -93,7 +93,6 @@ func (u *UI) IsUpdatable() bool { func (u *UI) GetType() consts.ComponentType { return consts.UIType } func (u *UI) Fetch(ctx context.Context) error { - return resources.Fetch(ctx, u.microservice, u.initJob, @@ -254,7 +253,6 @@ func (u *UI) doSync(ctx context.Context, dry bool) (ComponentStatus, error) { if u.ytsaurus.GetClusterState() == ytv1.ClusterStateUpdating { if IsUpdatingComponent(u.ytsaurus, u) { - if u.ytsaurus.GetUpdateState() == ytv1.UpdateStateWaitingForPodsRemoval { if !dry { err = removePods(ctx, u.microservice, &u.localComponent) diff --git a/pkg/components/volume.go b/pkg/components/volume.go index 0aa6ab69..b195db9a 100644 --- a/pkg/components/volume.go +++ b/pkg/components/volume.go @@ -2,11 +2,12 @@ package components import ( "fmt" + "path" + ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1" "github.com/ytsaurus/yt-k8s-operator/pkg/consts" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "path" ) func createVolumeClaims(specVolumeClaimTemplates []ytv1.EmbeddedPersistentVolumeClaim) []corev1.PersistentVolumeClaim { diff --git a/pkg/components/ytsaurus_client.go b/pkg/components/ytsaurus_client.go index 6d14303b..8336eb9a 100644 --- a/pkg/components/ytsaurus_client.go +++ b/pkg/components/ytsaurus_client.go @@ -155,7 +155,6 @@ func (yc *YtsaurusClient) handleUpdatingState(ctx context.Context) (ComponentSta case ytv1.UpdateStatePossibilityCheck: if !yc.ytsaurus.IsUpdateStatusConditionTrue(consts.ConditionHasPossibility) && !yc.ytsaurus.IsUpdateStatusConditionTrue(consts.ConditionNoPossibility) { - ok, msg, err := yc.HandlePossibilityCheck(ctx) if err != nil { return SimpleStatus(SyncStatusUpdating), err @@ -301,7 +300,6 @@ func (yc *YtsaurusClient) handleUpdatingState(ctx context.Context) (ComponentSta case ytv1.UpdateStateWaitingForTabletCellsRecovery: if !yc.ytsaurus.IsUpdateStatusConditionTrue(consts.ConditionTabletCellsRecovered) { - err = yc.RecoverTableCells(ctx, yc.ytsaurus.GetResource().Status.UpdateStatus.TabletCellBundles) if err != nil { return SimpleStatus(SyncStatusUpdating), err diff --git a/pkg/resources/deployment.go b/pkg/resources/deployment.go index cf14146f..895cc9c6 100644 --- a/pkg/resources/deployment.go +++ b/pkg/resources/deployment.go @@ -2,6 +2,7 @@ package resources import ( "context" + "github.com/ytsaurus/yt-k8s-operator/pkg/apiproxy" labeller2 "github.com/ytsaurus/yt-k8s-operator/pkg/labeller" appsv1 "k8s.io/api/apps/v1" diff --git a/pkg/testutil/testhelper.go b/pkg/testutil/testhelper.go index df1ba00a..ed07eafc 100644 --- a/pkg/testutil/testhelper.go +++ b/pkg/testutil/testhelper.go @@ -280,7 +280,6 @@ func FetchAndCheckConfigMapContainsEventually(h *TestHelper, objectKey, cmKey, e require.Contains(h.t, cmData, cmKey) ysonContent := cmData[cmKey] require.Contains(h.t, ysonContent, expectSubstr) - } func FetchConfigMapData(h *TestHelper, objectKey, mapKey string) string { diff --git a/pkg/ytconfig/cri.go b/pkg/ytconfig/cri.go index 5b8fdfea..6399c88e 100644 --- a/pkg/ytconfig/cri.go +++ b/pkg/ytconfig/cri.go @@ -17,7 +17,6 @@ func GetContainerdSocketPath(spec *ytv1.ExecNodesSpec) string { } func (g *NodeGenerator) GetContainerdConfig(spec *ytv1.ExecNodesSpec) ([]byte, error) { - criSpec := spec.JobEnvironment.CRI var rootPath *string diff --git a/pkg/ytconfig/logging.go b/pkg/ytconfig/logging.go index cea71d6e..214a52fa 100644 --- a/pkg/ytconfig/logging.go +++ b/pkg/ytconfig/logging.go @@ -2,9 +2,10 @@ package ytconfig import ( "fmt" - "go.ytsaurus.tech/library/go/ptr" "path" + "go.ytsaurus.tech/library/go/ptr" + ytv1 "github.com/ytsaurus/yt-k8s-operator/api/v1" ) diff --git a/test/e2e/ytsaurus_controller_test.go b/test/e2e/ytsaurus_controller_test.go index 282ae664..68cf708c 100644 --- a/test/e2e/ytsaurus_controller_test.go +++ b/test/e2e/ytsaurus_controller_test.go @@ -125,7 +125,6 @@ func getMasterPod(name, namespace string) corev1.Pod { } func deleteYtsaurus(ctx context.Context, ytsaurus *ytv1.Ytsaurus) { - if err := k8sClient.Delete(ctx, ytsaurus); err != nil { log.Error(err, "Deleting ytsaurus failed") }