MCPcopy Create free account
hub / github.com/cozystack/cozystack / stamp

Method stamp

internal/fluxshardoperator/controller.go:314–330  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
314func (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.
333func (r *PlacementReconciler) patchLabel(ctx context.Context, gvk schema.GroupVersionKind, namespace, name, label, value string) error {

Callers 1

applyMethod · 0.95

Calls 3

patchLabelMethod · 0.95
GetNamespaceMethod · 0.65
GetNameMethod · 0.65

Tested by

no test coverage detected