-
Notifications
You must be signed in to change notification settings - Fork 158
Reconfigure Linseed and linseed user when migrating from multi-index to single-index #5132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
d58f3a7
ff5694d
b78f680
96dc123
cba9c23
5081d5f
2fc8c40
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,8 +17,10 @@ package initializer | |
| import ( | ||
| "context" | ||
| "fmt" | ||
| "sort" | ||
| "time" | ||
|
|
||
| "k8s.io/apimachinery/pkg/api/equality" | ||
| "k8s.io/apimachinery/pkg/api/errors" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/runtime" | ||
|
|
@@ -44,6 +46,7 @@ func AddConditionsController(mgr manager.Manager, opts options.ControllerOptions | |
| client: mgr.GetClient(), | ||
| scheme: mgr.GetScheme(), | ||
| multiTenant: opts.MultiTenant, | ||
| cloud: opts.Cloud, | ||
| } | ||
|
|
||
| return ctrl.NewControllerManagedBy(mgr). | ||
|
|
@@ -62,6 +65,10 @@ type LogStorageConditions struct { | |
| client client.Client | ||
| scheme *runtime.Scheme | ||
| multiTenant bool | ||
|
|
||
| // cloud indicates that this is a Calico Cloud install, in which case the log-storage users | ||
| // controller runs in single-tenant mode too and reports status. | ||
| cloud bool | ||
| } | ||
|
|
||
| func (r *LogStorageConditions) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { | ||
|
|
@@ -88,9 +95,22 @@ func (r *LogStorageConditions) Reconcile(ctx context.Context, request reconcile. | |
| } | ||
|
|
||
| // Compare and update the current StatusCondition if there are any new changes | ||
| ls.Status.Conditions = updateConditions(currentConditions, desiredConditions) | ||
| conditions := updateConditions(currentConditions, desiredConditions) | ||
|
|
||
| // Skip the write if nothing changed. This controller watches LogStorage, so a no-op write would | ||
| // re-trigger it and spin: each reconcile would bump the resourceVersion and enqueue another one. | ||
| if equality.Semantic.DeepEqual(ls.Status.Conditions, conditions) { | ||
| return reconcile.Result{}, nil | ||
| } | ||
|
Comment on lines
+100
to
+104
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unnecessary if we're doing the sorting below - the k8s API server will notice that nothing has changed, and won't update the generation nor send an update. So I thinkwe can remove this check (not that it's a problem really, but it's another place something could go wrong if the equality check is not correct). |
||
| ls.Status.Conditions = conditions | ||
|
|
||
| if err := r.client.Status().Update(ctx, ls); err != nil { | ||
| if errors.IsConflict(err) { | ||
| // The LogStorage was modified after we read it - our cached copy is stale. Requeue and | ||
| // recompute the conditions from the updated object instead of reporting an error. | ||
| reqLogger.V(3).Info("Conflict updating LogStorage status conditions, retrying") | ||
| return reconcile.Result{Requeue: true}, nil | ||
| } | ||
| log.WithValues("reason", err).Info("Failed to update LogStorage status conditions") | ||
| return reconcile.Result{}, err | ||
| } | ||
|
|
@@ -112,6 +132,10 @@ func (r *LogStorageConditions) getDesiredConditions(ctx context.Context) (map[st | |
| expectedInstances = append(expectedInstances, TigeraStatusLogStorageUsers) | ||
| } else { | ||
| expectedInstances = append(expectedInstances, TigeraStatusLogStorageESMetrics, TigeraStatusLogStorageKubeController, TigeraStatusLogStorageDashboards) | ||
| if r.cloud { | ||
| // In Calico Cloud, the users controller runs in single-tenant mode too. | ||
| expectedInstances = append(expectedInstances, TigeraStatusLogStorageUsers) | ||
| } | ||
| } | ||
|
|
||
| // Keep track of which instances are in which state. | ||
|
|
@@ -197,5 +221,12 @@ func updateConditions(currentConditions, desiredConditions map[string]metav1.Con | |
|
|
||
| statusConditions = append(statusConditions, desired) | ||
| } | ||
|
|
||
| // desiredConditions is a map, so iteration order is random. Sort by type to keep the stored | ||
| // conditions stable across reconciles - otherwise every write reorders the list, which counts | ||
| // as a change and triggers another reconcile. | ||
| sort.Slice(statusConditions, func(i, j int) bool { | ||
| return statusConditions[i].Type < statusConditions[j].Type | ||
| }) | ||
| return statusConditions | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment suggests that this function is only applicable for migration, but the name of the function sounds more general. Perhaps this would be better named "SingleIndexMigrationDone" or similar? Or is the comment just overly specific?