From eebdfab642eb92ff090f26dea9ed53fcd753e1b2 Mon Sep 17 00:00:00 2001 From: frouioui Date: Sun, 24 Dec 2023 00:04:42 +0000 Subject: [PATCH 1/4] upgrade vitess dependency to latest Signed-off-by: GitHub --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index 19907fcc..718e3d4d 100644 --- a/go.mod +++ b/go.mod @@ -21,7 +21,7 @@ require ( sigs.k8s.io/controller-runtime v0.14.3 sigs.k8s.io/controller-tools v0.11.3 sigs.k8s.io/kustomize v2.0.3+incompatible - vitess.io/vitess v0.10.3-0.20231215192727-7c9fec7205cb + vitess.io/vitess v0.10.3-0.20231222054134-d807985131ed ) require ( @@ -148,7 +148,7 @@ require ( go.uber.org/zap v1.24.0 // indirect go4.org/intern v0.0.0-20230205224052-192e9f60865c // indirect go4.org/unsafe/assume-no-moving-gc v0.0.0-20230426161633-7e06285ff160 // indirect - golang.org/x/crypto v0.16.0 // indirect + golang.org/x/crypto v0.17.0 // indirect golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect golang.org/x/mod v0.12.0 // indirect golang.org/x/net v0.19.0 // indirect diff --git a/go.sum b/go.sum index ca89f299..c5ee2b94 100644 --- a/go.sum +++ b/go.sum @@ -696,8 +696,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20211108221036-ceb1ce70b4fa/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220314234659-1baeb1ce4c0b/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= -golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= +golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k= +golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -1186,5 +1186,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.2.3/go.mod h1:qjx8mGObPmV2aSZepjQjbmb2ih sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc= sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo= sigs.k8s.io/yaml v1.3.0/go.mod h1:GeOyir5tyXNByN85N/dRIT9es5UQNerPYEKK56eTBm8= -vitess.io/vitess v0.10.3-0.20231215192727-7c9fec7205cb h1:dNI30GuQx70LgnhhJaPAOyzF1DkNuTgpypAJ2OrGM30= -vitess.io/vitess v0.10.3-0.20231215192727-7c9fec7205cb/go.mod h1:klf5QIzty1+nq+FXHFmimgRA5lh4DhP9edrrKPGDNgY= +vitess.io/vitess v0.10.3-0.20231222054134-d807985131ed h1:XHwJFwKTCWu2Mo3B8+41TOVGzGTHIzqU69yG+TmUSlM= +vitess.io/vitess v0.10.3-0.20231222054134-d807985131ed/go.mod h1:fIPsR9+FuCA/QwknylRPp0buFk41Tl9KNhOQPQTm+5Y= From dc4976bcee8a707619095e8691ce13de26c2152e Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Mon, 25 Dec 2023 16:57:30 +0530 Subject: [PATCH 2/4] feat: fix build issues Signed-off-by: Manan Gupta --- .../vitesskeyspace/reconcile_handler.go | 14 +++++++++++++- pkg/controller/vitessshard/reconcile_topo.go | 18 +++++++++++++++--- .../vitessshardreplication_controller.go | 14 +++++++++++++- pkg/operator/vitesstopo/prune_keyspaces.go | 14 +++++++++++++- pkg/operator/vitesstopo/prune_shards.go | 15 ++++++++++++++- 5 files changed, 68 insertions(+), 7 deletions(-) diff --git a/pkg/controller/vitesskeyspace/reconcile_handler.go b/pkg/controller/vitesskeyspace/reconcile_handler.go index 7ba0a0e0..516cf12f 100644 --- a/pkg/controller/vitesskeyspace/reconcile_handler.go +++ b/pkg/controller/vitesskeyspace/reconcile_handler.go @@ -24,7 +24,10 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" + "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vttablet/tmclient" "vitess.io/vitess/go/vt/wrangler" @@ -74,9 +77,18 @@ func (r *reconcileHandler) tsInit(ctx context.Context) error { r.tmc = tmclient.NewTabletManagerClient() } + collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) + parser, err := sqlparser.New(sqlparser.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + return err + } // Wrangler wraps the necessary clients and implements // multi-step Vitess cluster management workflows. - wr := wrangler.New(logutil.NewConsoleLogger(), r.ts.Server, r.tmc) + wr := wrangler.New(logutil.NewConsoleLogger(), r.ts.Server, r.tmc, collationEnv, parser) r.wr = wr return nil diff --git a/pkg/controller/vitessshard/reconcile_topo.go b/pkg/controller/vitessshard/reconcile_topo.go index 209254be..806174af 100644 --- a/pkg/controller/vitessshard/reconcile_topo.go +++ b/pkg/controller/vitessshard/reconcile_topo.go @@ -21,6 +21,9 @@ import ( "strings" "time" + "vitess.io/vitess/go/mysql/collations" + "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo/topoproto" corev1 "k8s.io/api/core/v1" @@ -63,7 +66,16 @@ func (r *ReconcileVitessShard) reconcileTopology(ctx context.Context, vts *plane return resultBuilder.RequeueAfter(topoRequeueDelay) } defer ts.Close() - wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, nil) + collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) + parser, err := sqlparser.New(sqlparser.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + return resultBuilder.Error(err) + } + wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, nil, collationEnv, parser) // Get the shard record. if shard, err := ts.GetShard(ctx, keyspaceName, vts.Spec.Name); err == nil { @@ -168,8 +180,8 @@ func (r *ReconcileVitessShard) pruneShardCells(ctx context.Context, vts *planets Keyspace: keyspaceName, ShardName: vts.Spec.Name, Cell: cellName, - Force: false /* force */, - Recursive: false /* recursive */, + Force: false, /* force */ + Recursive: false, /* recursive */ }); err != nil { r.recorder.Eventf(vts, corev1.EventTypeWarning, "TopoCleanupFailed", "unable to remove cell %s from shard: %v", cellName, err) resultBuilder.RequeueAfter(topoRequeueDelay) diff --git a/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go b/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go index f2924350..efa5a098 100644 --- a/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go +++ b/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go @@ -22,6 +22,9 @@ import ( "time" "github.com/sirupsen/logrus" + "vitess.io/vitess/go/mysql/collations" + "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/vttablet/tmclient" @@ -195,9 +198,18 @@ func (r *ReconcileVitessShard) Reconcile(cctx context.Context, request reconcile tmc := tmclient.NewTabletManagerClient() defer tmc.Close() + collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) + parser, err := sqlparser.New(sqlparser.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + return resultBuilder.Error(err) + } // Wrangler wraps the necessary clients and implements // multi-step Vitess cluster management workflows. - wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, tmc) + wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, tmc, collationEnv, parser) // Initialize replication if it has not already been started. initReplicationResult, err := r.initReplication(ctx, vts, wr) diff --git a/pkg/operator/vitesstopo/prune_keyspaces.go b/pkg/operator/vitesstopo/prune_keyspaces.go index 41e6f5a8..cbecefb8 100644 --- a/pkg/operator/vitesstopo/prune_keyspaces.go +++ b/pkg/operator/vitesstopo/prune_keyspaces.go @@ -24,7 +24,10 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/wrangler" @@ -91,9 +94,18 @@ func KeyspacesToPrune(keyspaceNames []string, desiredKeyspaces sets.String, orph func DeleteKeyspaces(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceNames []string) (reconcile.Result, error) { resultBuilder := &results.Builder{} + collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) + parser, err := sqlparser.New(sqlparser.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + return resultBuilder.Error(err) + } // We use the Vitess wrangler (multi-step command executor) to recursively delete the keyspace. // This is equivalent to `vtctl DeleteKeyspace -recursive`. - wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil) + wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv, parser) for _, name := range keyspaceNames { // Before we delete a keyspace, we must delete vschema for this operation to be idempotent. diff --git a/pkg/operator/vitesstopo/prune_shards.go b/pkg/operator/vitesstopo/prune_shards.go index e14db665..06cfc415 100644 --- a/pkg/operator/vitesstopo/prune_shards.go +++ b/pkg/operator/vitesstopo/prune_shards.go @@ -24,7 +24,10 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/reconcile" + "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/vt/logutil" + "vitess.io/vitess/go/vt/servenv" + "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/wrangler" @@ -83,9 +86,19 @@ func ShardsToPrune(currentShards []string, desiredShards sets.String, orphanedSh func DeleteShards(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceName string, shardNames []string) (reconcile.Result, error) { resultBuilder := &results.Builder{} + collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) + parser, err := sqlparser.New(sqlparser.Options{ + MySQLServerVersion: servenv.MySQLServerVersion(), + TruncateUILen: servenv.TruncateUILen, + TruncateErrLen: servenv.TruncateErrLen, + }) + if err != nil { + return resultBuilder.Error(err) + } + // We use the Vitess wrangler (multi-step command executor) to recursively delete the shard. // This is equivalent to `vtctl DeleteShard -recursive`. - wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil) + wr := wrangler.New(logutil.NewConsoleLogger(), ts, nil, collationEnv, parser) for _, name := range shardNames { // topo.NoNode is the error type returned if we can't find the shard when deleting. This ensures that this operation is idempotent. From 637d481eb4ab82ff7d6a5cd40c7964f8ee202c70 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 28 Dec 2023 14:55:16 +0530 Subject: [PATCH 3/4] feat: create a common function to be used in the operator Signed-off-by: Manan Gupta --- .../vitesskeyspace/reconcile_handler.go | 11 ++-------- pkg/controller/vitessshard/reconcile_topo.go | 11 ++-------- .../vitessshardreplication_controller.go | 11 +--------- pkg/operator/environment/environment.go | 20 ++++++++++++++++++- pkg/operator/vitesstopo/prune_keyspaces.go | 11 ++-------- pkg/operator/vitesstopo/prune_shards.go | 11 ++-------- 6 files changed, 28 insertions(+), 47 deletions(-) diff --git a/pkg/controller/vitesskeyspace/reconcile_handler.go b/pkg/controller/vitesskeyspace/reconcile_handler.go index 516cf12f..26726d88 100644 --- a/pkg/controller/vitesskeyspace/reconcile_handler.go +++ b/pkg/controller/vitesskeyspace/reconcile_handler.go @@ -24,14 +24,12 @@ import ( "k8s.io/apimachinery/pkg/api/errors" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/client" - "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/vt/logutil" - "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/vttablet/tmclient" "vitess.io/vitess/go/vt/wrangler" v2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" + "planetscale.dev/vitess-operator/pkg/operator/environment" "planetscale.dev/vitess-operator/pkg/operator/reconciler" "planetscale.dev/vitess-operator/pkg/operator/toposerver" ) @@ -77,12 +75,7 @@ func (r *reconcileHandler) tsInit(ctx context.Context) error { r.tmc = tmclient.NewTabletManagerClient() } - collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) - parser, err := sqlparser.New(sqlparser.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) + collationEnv, parser, err := environment.GetCollationEnvAndParser() if err != nil { return err } diff --git a/pkg/controller/vitessshard/reconcile_topo.go b/pkg/controller/vitessshard/reconcile_topo.go index 806174af..6ea37a39 100644 --- a/pkg/controller/vitessshard/reconcile_topo.go +++ b/pkg/controller/vitessshard/reconcile_topo.go @@ -21,9 +21,6 @@ import ( "strings" "time" - "vitess.io/vitess/go/mysql/collations" - "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo/topoproto" corev1 "k8s.io/api/core/v1" @@ -34,6 +31,7 @@ import ( "vitess.io/vitess/go/vt/wrangler" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" + "planetscale.dev/vitess-operator/pkg/operator/environment" "planetscale.dev/vitess-operator/pkg/operator/k8s" "planetscale.dev/vitess-operator/pkg/operator/results" "planetscale.dev/vitess-operator/pkg/operator/toposerver" @@ -66,12 +64,7 @@ func (r *ReconcileVitessShard) reconcileTopology(ctx context.Context, vts *plane return resultBuilder.RequeueAfter(topoRequeueDelay) } defer ts.Close() - collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) - parser, err := sqlparser.New(sqlparser.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) + collationEnv, parser, err := environment.GetCollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } diff --git a/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go b/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go index efa5a098..d70d6974 100644 --- a/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go +++ b/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go @@ -22,10 +22,6 @@ import ( "time" "github.com/sirupsen/logrus" - "vitess.io/vitess/go/mysql/collations" - "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sqlparser" - "vitess.io/vitess/go/vt/logutil" "vitess.io/vitess/go/vt/vttablet/tmclient" "vitess.io/vitess/go/vt/wrangler" @@ -198,12 +194,7 @@ func (r *ReconcileVitessShard) Reconcile(cctx context.Context, request reconcile tmc := tmclient.NewTabletManagerClient() defer tmc.Close() - collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) - parser, err := sqlparser.New(sqlparser.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) + collationEnv, parser, err := environment.GetCollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } diff --git a/pkg/operator/environment/environment.go b/pkg/operator/environment/environment.go index c3f894f0..525b132b 100644 --- a/pkg/operator/environment/environment.go +++ b/pkg/operator/environment/environment.go @@ -25,12 +25,19 @@ import ( "time" "github.com/spf13/pflag" + "vitess.io/vitess/go/mysql/collations" + "vitess.io/vitess/go/vt/sqlparser" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" ) var ( - reconcileTimeout time.Duration + reconcileTimeout time.Duration + mySQLServerVersion = "8.0.30-Vitess" + // truncateUILen truncate queries in debug UIs to the given length. 0 means unlimited. + truncateUILen = 512 + // truncateErrLen truncate queries in error logs to the given length. 0 means unlimited. + truncateErrLen = 0 ) // FlagSet returns the FlagSet for the operator. @@ -58,3 +65,14 @@ func FlagSet() *pflag.FlagSet { func ReconcileTimeout() time.Duration { return reconcileTimeout } + +// GetCollationEnvAndParser gets the collation environment and parser to be used in the operator. +func GetCollationEnvAndParser() (*collations.Environment, *sqlparser.Parser, error) { + collationEnv := collations.NewEnvironment(mySQLServerVersion) + parser, err := sqlparser.New(sqlparser.Options{ + MySQLServerVersion: mySQLServerVersion, + TruncateUILen: truncateUILen, + TruncateErrLen: truncateErrLen, + }) + return collationEnv, parser, err +} diff --git a/pkg/operator/vitesstopo/prune_keyspaces.go b/pkg/operator/vitesstopo/prune_keyspaces.go index cbecefb8..92ada35e 100644 --- a/pkg/operator/vitesstopo/prune_keyspaces.go +++ b/pkg/operator/vitesstopo/prune_keyspaces.go @@ -24,14 +24,12 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/vt/logutil" - "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/wrangler" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" + "planetscale.dev/vitess-operator/pkg/operator/environment" "planetscale.dev/vitess-operator/pkg/operator/results" vtctldatapb "vitess.io/vitess/go/vt/proto/vtctldata" @@ -94,12 +92,7 @@ func KeyspacesToPrune(keyspaceNames []string, desiredKeyspaces sets.String, orph func DeleteKeyspaces(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceNames []string) (reconcile.Result, error) { resultBuilder := &results.Builder{} - collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) - parser, err := sqlparser.New(sqlparser.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) + collationEnv, parser, err := environment.GetCollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } diff --git a/pkg/operator/vitesstopo/prune_shards.go b/pkg/operator/vitesstopo/prune_shards.go index 06cfc415..092822b4 100644 --- a/pkg/operator/vitesstopo/prune_shards.go +++ b/pkg/operator/vitesstopo/prune_shards.go @@ -24,14 +24,12 @@ import ( "k8s.io/apimachinery/pkg/util/sets" "k8s.io/client-go/tools/record" "sigs.k8s.io/controller-runtime/pkg/reconcile" - "vitess.io/vitess/go/mysql/collations" "vitess.io/vitess/go/vt/logutil" - "vitess.io/vitess/go/vt/servenv" - "vitess.io/vitess/go/vt/sqlparser" "vitess.io/vitess/go/vt/topo" "vitess.io/vitess/go/vt/wrangler" planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2" + "planetscale.dev/vitess-operator/pkg/operator/environment" "planetscale.dev/vitess-operator/pkg/operator/results" ) @@ -86,12 +84,7 @@ func ShardsToPrune(currentShards []string, desiredShards sets.String, orphanedSh func DeleteShards(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceName string, shardNames []string) (reconcile.Result, error) { resultBuilder := &results.Builder{} - collationEnv := collations.NewEnvironment(servenv.MySQLServerVersion()) - parser, err := sqlparser.New(sqlparser.Options{ - MySQLServerVersion: servenv.MySQLServerVersion(), - TruncateUILen: servenv.TruncateUILen, - TruncateErrLen: servenv.TruncateErrLen, - }) + collationEnv, parser, err := environment.GetCollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } From cd5c5d1b29087a3ca0e78ba08248ffb9171d0c33 Mon Sep 17 00:00:00 2001 From: Manan Gupta Date: Thu, 28 Dec 2023 16:06:47 +0530 Subject: [PATCH 4/4] refactor: rename function to drop Get prefix Signed-off-by: Manan Gupta --- pkg/controller/vitesskeyspace/reconcile_handler.go | 2 +- pkg/controller/vitessshard/reconcile_topo.go | 2 +- .../vitessshardreplication_controller.go | 2 +- pkg/operator/environment/environment.go | 4 ++-- pkg/operator/vitesstopo/prune_keyspaces.go | 2 +- pkg/operator/vitesstopo/prune_shards.go | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/controller/vitesskeyspace/reconcile_handler.go b/pkg/controller/vitesskeyspace/reconcile_handler.go index 26726d88..fb41cbee 100644 --- a/pkg/controller/vitesskeyspace/reconcile_handler.go +++ b/pkg/controller/vitesskeyspace/reconcile_handler.go @@ -75,7 +75,7 @@ func (r *reconcileHandler) tsInit(ctx context.Context) error { r.tmc = tmclient.NewTabletManagerClient() } - collationEnv, parser, err := environment.GetCollationEnvAndParser() + collationEnv, parser, err := environment.CollationEnvAndParser() if err != nil { return err } diff --git a/pkg/controller/vitessshard/reconcile_topo.go b/pkg/controller/vitessshard/reconcile_topo.go index 6ea37a39..9769ecc2 100644 --- a/pkg/controller/vitessshard/reconcile_topo.go +++ b/pkg/controller/vitessshard/reconcile_topo.go @@ -64,7 +64,7 @@ func (r *ReconcileVitessShard) reconcileTopology(ctx context.Context, vts *plane return resultBuilder.RequeueAfter(topoRequeueDelay) } defer ts.Close() - collationEnv, parser, err := environment.GetCollationEnvAndParser() + collationEnv, parser, err := environment.CollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } diff --git a/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go b/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go index d70d6974..644541c3 100644 --- a/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go +++ b/pkg/controller/vitessshardreplication/vitessshardreplication_controller.go @@ -194,7 +194,7 @@ func (r *ReconcileVitessShard) Reconcile(cctx context.Context, request reconcile tmc := tmclient.NewTabletManagerClient() defer tmc.Close() - collationEnv, parser, err := environment.GetCollationEnvAndParser() + collationEnv, parser, err := environment.CollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } diff --git a/pkg/operator/environment/environment.go b/pkg/operator/environment/environment.go index 525b132b..bd9404c1 100644 --- a/pkg/operator/environment/environment.go +++ b/pkg/operator/environment/environment.go @@ -66,8 +66,8 @@ func ReconcileTimeout() time.Duration { return reconcileTimeout } -// GetCollationEnvAndParser gets the collation environment and parser to be used in the operator. -func GetCollationEnvAndParser() (*collations.Environment, *sqlparser.Parser, error) { +// CollationEnvAndParser gets the collation environment and parser to be used in the operator. +func CollationEnvAndParser() (*collations.Environment, *sqlparser.Parser, error) { collationEnv := collations.NewEnvironment(mySQLServerVersion) parser, err := sqlparser.New(sqlparser.Options{ MySQLServerVersion: mySQLServerVersion, diff --git a/pkg/operator/vitesstopo/prune_keyspaces.go b/pkg/operator/vitesstopo/prune_keyspaces.go index 92ada35e..445b10a8 100644 --- a/pkg/operator/vitesstopo/prune_keyspaces.go +++ b/pkg/operator/vitesstopo/prune_keyspaces.go @@ -92,7 +92,7 @@ func KeyspacesToPrune(keyspaceNames []string, desiredKeyspaces sets.String, orph func DeleteKeyspaces(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceNames []string) (reconcile.Result, error) { resultBuilder := &results.Builder{} - collationEnv, parser, err := environment.GetCollationEnvAndParser() + collationEnv, parser, err := environment.CollationEnvAndParser() if err != nil { return resultBuilder.Error(err) } diff --git a/pkg/operator/vitesstopo/prune_shards.go b/pkg/operator/vitesstopo/prune_shards.go index 092822b4..3cb63a7c 100644 --- a/pkg/operator/vitesstopo/prune_shards.go +++ b/pkg/operator/vitesstopo/prune_shards.go @@ -84,7 +84,7 @@ func ShardsToPrune(currentShards []string, desiredShards sets.String, orphanedSh func DeleteShards(ctx context.Context, ts *topo.Server, recorder record.EventRecorder, eventObj runtime.Object, keyspaceName string, shardNames []string) (reconcile.Result, error) { resultBuilder := &results.Builder{} - collationEnv, parser, err := environment.GetCollationEnvAndParser() + collationEnv, parser, err := environment.CollationEnvAndParser() if err != nil { return resultBuilder.Error(err) }