fix(action): avoid copylocks when copying Configuration for client-only

Configuration embeds sync.Mutex and logging.LogHolder (atomic.Pointer),
so a value copy (*i.cfg) fails govet copylocks under golangci-lint.
Build a local Configuration by copying fields explicitly and reattaching
the logger via SetLogger instead.

Signed-off-by: Dean Chen <862469039@qq.com>
pull/32431/head
Dean Chen 2 months ago
parent 4458a191b3
commit 8ac25c5c8d
No known key found for this signature in database
GPG Key ID: 03656C0AA9B7E279

@ -332,9 +332,22 @@ func (i *Install) RunWithContext(ctx context.Context, ch ci.Charter, vals map[st
// not mutate the shared *Configuration passed to NewInstall.
// Callers that reuse the same cfg for a later real install must
// still observe the original client and storage. See #11463.
//
// Copy fields explicitly: Configuration embeds sync.Mutex and
// logging.LogHolder (atomic.Pointer), which must not be copied
// by value (govet copylocks).
origCfg := i.cfg
cfgCopy := *i.cfg
i.cfg = &cfgCopy
cfgCopy := &Configuration{
RESTClientGetter: origCfg.RESTClientGetter,
Releases: origCfg.Releases,
KubeClient: origCfg.KubeClient,
RegistryClient: origCfg.RegistryClient,
Capabilities: origCfg.Capabilities,
CustomTemplateFuncs: origCfg.CustomTemplateFuncs,
HookOutputFunc: origCfg.HookOutputFunc,
}
cfgCopy.SetLogger(origCfg.Logger().Handler())
i.cfg = cfgCopy
defer func() { i.cfg = origCfg }()
// Add mock objects in here so it doesn't use Kube API server

Loading…
Cancel
Save