Skip to content

Commit

Permalink
fix API call to get the VitessShard information in vtgate reconcile loop
Browse files Browse the repository at this point in the history
Signed-off-by: Florent Poinsard <[email protected]>
  • Loading branch information
frouioui committed Jan 18, 2024
1 parent fcc688f commit 524e7ee
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
34 changes: 22 additions & 12 deletions pkg/controller/vitesscell/vitesscell_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"time"

"github.com/sirupsen/logrus"
apilabels "k8s.io/apimachinery/pkg/labels"

appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -181,17 +182,6 @@ func (r *ReconcileVitessCell) Reconcile(cctx context.Context, request reconcile.
return resultBuilder.Error(err)
}

// Fetch the VitessShard instance
vts := &planetscalev2.VitessShard{}
err = r.client.Get(ctx, request.NamespacedName, vts)
if err != nil {
if apierrors.IsNotFound(err) {
return resultBuilder.Result()
}
// Error reading the object - requeue the request.
return resultBuilder.Error(err)
}

// Reset status so it's all based on the latest observed state.
oldStatus := vtc.Status
vtc.Status = planetscalev2.NewVitessCellStatus()
Expand All @@ -206,8 +196,28 @@ func (r *ReconcileVitessCell) Reconcile(cctx context.Context, request reconcile.
resultBuilder.Error(err)
}

// List all VitessShard in the same cluster, we do this to determine what is the image used for the mysqld container
// Note that this is cheap because it comes from the local cache.
labels := map[string]string{
planetscalev2.ClusterLabel: vtc.Labels[planetscalev2.ClusterLabel],
}
opts := &client.ListOptions{
Namespace: vtc.Namespace,
LabelSelector: apilabels.SelectorFromSet(labels),
}
vts := &planetscalev2.VitessShardList{}
if err := r.client.List(ctx, vts, opts); err != nil {
r.recorder.Eventf(vtc, corev1.EventTypeWarning, "ListFailed", "failed to list VitessShard objects: %v", err)
return resultBuilder.Error(err)
}

var mysqldImage string
if len(vts.Items) > 0 {
mysqldImage = vts.Items[0].Spec.Images.Mysqld.Image()
}

// Create/update vtgate deployments.
vtgateResult, err := r.reconcileVtgate(ctx, vtc, vts.Spec.Images.Mysqld.Image())
vtgateResult, err := r.reconcileVtgate(ctx, vtc, mysqldImage)
resultBuilder.Merge(vtgateResult, err)

// Check which VitessKeyspaces are deployed to this cell.
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/vitesskeyspace/reconcile_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (r *reconcileHandler) tsInit(ctx context.Context) error {
}
// 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)
wr := wrangler.New(logutil.NewConsoleLogger(), r.ts.Server, r.tmc, collationEnv, parser, environment.MySQLServerVersion)
r.wr = wr

return nil
Expand Down

0 comments on commit 524e7ee

Please sign in to comment.