Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into default-mysql-server-…
Browse files Browse the repository at this point in the history
…version
  • Loading branch information
frouioui committed Jan 22, 2024
2 parents bcb703f + 826feda commit 25aac71
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 20 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/controller-tools v0.11.3
sigs.k8s.io/kustomize v2.0.3+incompatible
vitess.io/vitess v0.10.3-0.20240118194106-4c36f2aa6469
vitess.io/vitess v0.10.3-0.20240121130840-6c4c5faa7029
)

require (
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -827,5 +827,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.4.0 h1:Mk1wCc2gy/F0THH0TAp1QYyJNzRm2KCLy3o5ASXVI5E=
sigs.k8s.io/yaml v1.4.0/go.mod h1:Ejl7/uTz7PSA4eKMyQCUTnhZYNmLIl+5c2lQPGR2BPY=
vitess.io/vitess v0.10.3-0.20240118194106-4c36f2aa6469 h1:qz8sZpGZuNDVw/khgIfcRa3Pi+E1LzLilyoW/epYPFQ=
vitess.io/vitess v0.10.3-0.20240118194106-4c36f2aa6469/go.mod h1:W7loalC1u4Ke/QdTHZLKqUzmgN2Qr4+491q8ClTn7xY=
vitess.io/vitess v0.10.3-0.20240121130840-6c4c5faa7029 h1:NCyzmpKcBfJLomOgvhn1Rg7dJjcsnY511SvpPuI5ZZE=
vitess.io/vitess v0.10.3-0.20240121130840-6c4c5faa7029/go.mod h1:W7loalC1u4Ke/QdTHZLKqUzmgN2Qr4+491q8ClTn7xY=
4 changes: 2 additions & 2 deletions pkg/controller/vitesskeyspace/reconcile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ func (r *reconcileHandler) tsInit(ctx context.Context) error {
r.tmc = tmclient.NewTabletManagerClient()
}

collationEnv, parser, err := environment.CollationEnvAndParser()
vtEnv, err := environment.VtEnvironment()
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, collationEnv, parser, environment.MySQLServerVersion)
wr := wrangler.New(vtEnv, logutil.NewConsoleLogger(), r.ts.Server, r.tmc)
r.wr = wr

return nil
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/vitessshard/reconcile_topo.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,11 @@ func (r *ReconcileVitessShard) reconcileTopology(ctx context.Context, vts *plane
return resultBuilder.RequeueAfter(topoRequeueDelay)
}
defer ts.Close()
collationEnv, parser, err := environment.CollationEnvAndParser()
vtEnv, err := environment.VtEnvironment()
if err != nil {
return resultBuilder.Error(err)
}
wr := wrangler.New(logutil.NewConsoleLogger(), ts.Server, nil, collationEnv, parser, environment.MySQLServerVersion)
wr := wrangler.New(vtEnv, logutil.NewConsoleLogger(), ts.Server, nil)

// Get the shard record.
if shard, err := ts.GetShard(ctx, keyspaceName, vts.Spec.Name); err == nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,13 @@ func (r *ReconcileVitessShard) Reconcile(cctx context.Context, request reconcile
tmc := tmclient.NewTabletManagerClient()
defer tmc.Close()

collationEnv, parser, err := environment.CollationEnvAndParser()
vtEnv, err := environment.VtEnvironment()
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, collationEnv, parser, environment.MySQLServerVersion)
wr := wrangler.New(vtEnv, logutil.NewConsoleLogger(), ts.Server, tmc)

// Initialize replication if it has not already been started.
initReplicationResult, err := r.initReplication(ctx, vts, wr)
Expand Down
11 changes: 4 additions & 7 deletions pkg/operator/environment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ import (
"time"

"github.com/spf13/pflag"
"vitess.io/vitess/go/mysql/collations"
"vitess.io/vitess/go/vt/sqlparser"
"vitess.io/vitess/go/vt/vtenv"

planetscalev2 "planetscale.dev/vitess-operator/pkg/apis/planetscale/v2"
)
Expand Down Expand Up @@ -66,13 +65,11 @@ func ReconcileTimeout() time.Duration {
return reconcileTimeout
}

// 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{
// VtEnvironment gets the vitess environment to be used in the operator.
func VtEnvironment() (*vtenv.Environment, error) {
return vtenv.New(vtenv.Options{
MySQLServerVersion: MySQLServerVersion,
TruncateUILen: truncateUILen,
TruncateErrLen: truncateErrLen,
})
return collationEnv, parser, err
}
4 changes: 2 additions & 2 deletions pkg/operator/vitesstopo/prune_keyspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ 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.CollationEnvAndParser()
vtEnv, err := environment.VtEnvironment()
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, collationEnv, parser, environment.MySQLServerVersion)
wr := wrangler.New(vtEnv, logutil.NewConsoleLogger(), ts, nil)

for _, name := range keyspaceNames {
// Before we delete a keyspace, we must delete vschema for this operation to be idempotent.
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/vitesstopo/prune_shards.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ 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.CollationEnvAndParser()
vtEnv, err := environment.VtEnvironment()
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, collationEnv, parser, environment.MySQLServerVersion)
wr := wrangler.New(vtEnv, logutil.NewConsoleLogger(), ts, nil)

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.
Expand Down

0 comments on commit 25aac71

Please sign in to comment.