stamp records the assignment on the tenant namespace and relabels every HelmRelease of the tenant that does not carry it yet. Patches the namespace first so the webhook hands out the new shard before the HRs settle.
(ctx context.Context, v *tenantView, target string)
| 312 | // HelmRelease of the tenant that does not carry it yet. Patches the namespace |
| 313 | // first so the webhook hands out the new shard before the HRs settle. |
| 314 | func (r *PlacementReconciler) stamp(ctx context.Context, v *tenantView, target string) error { |
| 315 | var errs []error |
| 316 | if v.nsExists && v.nsLabel != target { |
| 317 | if err := r.patchLabel(ctx, NamespaceGVK, "", v.info.Namespace, TenantShardLabel, target); err != nil { |
| 318 | errs = append(errs, fmt.Errorf("namespace %s: %w", v.info.Namespace, err)) |
| 319 | } |
| 320 | } |
| 321 | for _, hr := range v.hrs { |
| 322 | if hr.GetLabels()[ShardKeyLabel] == target { |
| 323 | continue |
| 324 | } |
| 325 | if err := r.patchLabel(ctx, HelmReleaseGVK, hr.GetNamespace(), hr.GetName(), ShardKeyLabel, target); err != nil { |
| 326 | errs = append(errs, fmt.Errorf("helmrelease %s/%s: %w", hr.GetNamespace(), hr.GetName(), err)) |
| 327 | } |
| 328 | } |
| 329 | return utilerrors.NewAggregate(errs) |
| 330 | } |
| 331 | |
| 332 | // patchLabel merge-patches a single label on an object, touching nothing else. |
| 333 | func (r *PlacementReconciler) patchLabel(ctx context.Context, gvk schema.GroupVersionKind, namespace, name, label, value string) error { |
no test coverage detected