mirror of
https://github.com/cozystack/cozystack.git
synced 2026-12-06 23:23:23 +09:00
Some charts keep one generated Secret per account, holding username and password, instead of one Secret keyed by username. RabbitMQ does, under names derived with sprig's kebabcase. --source-selector finds those Secrets by label and by the Helm release that rendered them, so the CLI does not re-implement the chart's name mapping, and retires them once the chart has switched. It is the second way to locate the per-account sources --source-per-account finds by name, so it shares --source-key for the password key and the same retire path, and the two are mutually exclusive. A platform account can also live in a Secret no chart renders, such as the -default-user Secret the RabbitMQ cluster operator creates. The lineage webhook stamped its visibility at admission, so dropping it from the ApplicationDefinition does not hide it. --hide-secret-suffix labels it not tenant-visible in finish, but only once the definition in the API excludes it, and waits for that within the Job's timeout. An operator's rewrite replaces the Secret's labels, and the webhook then stamps it from the definition it sees; the cluster operator's first pass after an upgrade rewrites it before rabbitmq-rd upgrades, so a label written earlier would be undone and the administrator's Secret readable again. Assisted-by: LLM Signed-off-by: Andrei Kvapil <kvapss@gmail.com>
52 lines
2.0 KiB
Go
52 lines
2.0 KiB
Go
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"time"
|
|
|
|
helmv2 "github.com/fluxcd/helm-controller/api/v2"
|
|
corev1 "k8s.io/api/core/v1"
|
|
|
|
cozyv1alpha1 "github.com/cozystack/cozystack/api/v1alpha1"
|
|
"github.com/cozystack/cozystack/internal/lineagecontrollerwebhook"
|
|
"github.com/cozystack/cozystack/internal/shared/appdefowner"
|
|
appsv1alpha1 "github.com/cozystack/cozystack/pkg/apis/apps/v1alpha1"
|
|
)
|
|
|
|
// waitDefinitionHides waits until the ApplicationDefinition of the kind, as
|
|
// it stands in the API, no longer selects sec as tenant-visible. An operator
|
|
// that rewrites the Secret replaces its labels, and the lineage webhook then
|
|
// stamps it again from that definition, so a label written while the old
|
|
// definition is in place is undone by the next such write. The definition
|
|
// comes from the kind's rd chart, which upgrades only after the operator it
|
|
// depends on is Ready: a new operator rewriting the Secret on its first pass
|
|
// lands before it. Labelling only once the new definition hides the Secret
|
|
// leaves every later rewrite stamped not tenant-visible as well.
|
|
func (m *migrator) waitDefinitionHides(ctx context.Context, hr *helmv2.HelmRelease, sec *corev1.Secret) error {
|
|
appName := hr.Labels[appsv1alpha1.ApplicationNameLabel]
|
|
deadline := m.now().Add(m.o.timeout)
|
|
for {
|
|
defs := &cozyv1alpha1.ApplicationDefinitionList{}
|
|
if err := m.c.List(ctx, defs); err != nil {
|
|
return fmt.Errorf("list ApplicationDefinitions: %w", err)
|
|
}
|
|
owner := appdefowner.Owners(defs.Items)[m.o.kind]
|
|
var def *cozyv1alpha1.ApplicationDefinition
|
|
for i := range defs.Items {
|
|
if defs.Items[i].Name == owner {
|
|
def = &defs.Items[i]
|
|
}
|
|
}
|
|
if !lineagecontrollerwebhook.SecretTenantVisible(ctx, def, appName, hr.Namespace, sec.Name, sec.Labels) {
|
|
return nil
|
|
}
|
|
if m.now().After(deadline) {
|
|
return fmt.Errorf("ApplicationDefinition %s still selects %s as tenant-visible after %s; it would be stamped visible again at the operator's next write, so it is not labelled yet", owner, sec.Name, m.o.timeout)
|
|
}
|
|
time.Sleep(10 * time.Second)
|
|
}
|
|
}
|