Skip to content

Commit 819f255

Browse files
committed
chore(license): keep the code ported from Talos under MPL-2.0
Talos is MPL-2.0 and talm is Apache-2.0. The bump carried two ports over that line: the resource walk and multi-node guard talosctl stopped exporting, and the client constructors v1.14 removed. Both are derived work, so the files holding them now carry the MPL notice. MPL-2.0 section 3.3 allows the combined work to ship under Apache-2.0 as long as those files keep their own terms. The client constructors sat in root.go next to talm's own code. They move to a file of their own so the notice covers the derived code and nothing else. WithClientNoNodes stays in root.go as the dispatcher that routes --skip-verify. Signed-off-by: Aleksei Sviridkin <[email protected]> Assisted-by: LLM
1 parent 03b4589 commit 819f255

5 files changed

Lines changed: 158 additions & 121 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ Full documentation lives at **[talm.cozystack.io](https://talm.cozystack.io/)**.
6060
- [CLI reference](https://talm.cozystack.io/reference/) — commands and flags.
6161

6262
The site is built from `docs/` in this repository; the CLI reference under `docs/reference/` is generated from the command tree.
63+
64+
## License
65+
66+
Apache-2.0, except for two files ported from [siderolabs/talos](https://github.com/siderolabs/talos), which is MPL-2.0: `pkg/engine/talos_helpers.go` and `pkg/commands/talos_client.go` carry Talos code that v1.14 stopped exporting, so they stay under MPL-2.0 and say so in their headers. MPL-2.0 section 3.3 covers distributing the combined work under Apache-2.0.

‎pkg/commands/client_wrappers_test.go‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ func TestWithClientNoNodes_UsesContextEndpointsWithoutNodes(t *testing.T) {
141141
// contract: a signal cancels the context the client call runs under. The second
142142
// half (a second Ctrl+C killing the process) follows from unregistering the
143143
// handler, which Go's default disposition then handles.
144+
//
145+
// The raise is process-scope, so this test must not run in parallel and the
146+
// package must not gain a second test that installs its own SIGTERM handler.
144147
func TestSignalContext_CancelsOnSignal(t *testing.T) {
145148
ctx, stop := signalContext()
146149
defer stop()

‎pkg/commands/root.go‎

Lines changed: 1 addition & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,8 @@ import (
1818
"context"
1919
"crypto/tls"
2020
"encoding/base64"
21-
"fmt"
2221
"os"
23-
"os/signal"
2422
"path/filepath"
25-
"syscall"
2623
"time"
2724

2825
"github.com/cockroachdb/errors"
@@ -53,38 +50,6 @@ var SkipVerify bool
5350
// talosconfig.
5451
var errContextNotFound = errors.New("context not found in talosconfig")
5552

56-
// signalContext returns a context cancelled on SIGINT/SIGTERM, mirroring the
57-
// wrappers talosctl builds its own clients with.
58-
//
59-
// It unregisters the handler on the first signal, so a second Ctrl+C kills the
60-
// process outright. signal.NotifyContext would keep the registration, and the
61-
// second signal would land in a full channel and be discarded, leaving a stuck
62-
// call with no way out from the keyboard.
63-
//
64-
// Follows siderolabs/talos pkg/cli/context.go, which is licensed under MPL-2.0:
65-
// https://github.com/siderolabs/talos/blob/v1.14.0/pkg/cli/context.go
66-
func signalContext() (context.Context, context.CancelFunc) {
67-
ctx, cancel := context.WithCancel(context.Background())
68-
69-
sigCh := make(chan os.Signal, 1)
70-
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
71-
72-
go func() {
73-
select {
74-
case <-sigCh:
75-
signal.Stop(sigCh)
76-
fmt.Fprintln(os.Stderr, "Signal received, aborting, press Ctrl+C once again to abort immediately...")
77-
cancel()
78-
case <-ctx.Done():
79-
}
80-
}()
81-
82-
return ctx, func() {
83-
signal.Stop(sigCh)
84-
cancel()
85-
}
86-
}
87-
8853
// skipVerifyTLSConfig builds a TLS config that skips server-certificate
8954
// verification while preserving client-certificate authentication taken from the
9055
// talosconfig context.
@@ -181,48 +146,7 @@ func WithClientNoNodes(action func(context.Context, *client.Client) error, dialO
181146
return WithClientSkipVerify(action, dialOptions...)
182147
}
183148

184-
ctx, stop := signalContext()
185-
defer stop()
186-
187-
// Built on pkg/machinery/client rather than the talosctl wrapper: Talos
188-
// v1.14 replaced that wrapper with a ClientFactory which refuses to
189-
// construct without nodes, which is the one thing this function allows.
190-
//
191-
// The option set follows siderolabs/talos
192-
// cmd/talosctl/pkg/talos/global/client.go (MPL-2.0):
193-
// https://github.com/siderolabs/talos/blob/v1.13.7/cmd/talosctl/pkg/talos/global/client.go
194-
cfg, err := clientconfig.Open(GlobalArgs.Talosconfig)
195-
if err != nil {
196-
return errors.Wrapf(err, "opening talosconfig %q", GlobalArgs.Talosconfig)
197-
}
198-
199-
opts := []client.OptionFunc{
200-
client.WithConfig(cfg),
201-
client.WithDefaultGRPCDialOptions(),
202-
client.WithGRPCDialOptions(dialOptions...),
203-
client.WithSideroV1KeysDir(clientconfig.CustomSideroV1KeysDirPath(GlobalArgs.SideroV1KeysDir)),
204-
}
205-
206-
if GlobalArgs.CmdContext != "" {
207-
opts = append(opts, client.WithContextName(GlobalArgs.CmdContext))
208-
}
209-
210-
if len(GlobalArgs.Endpoints) > 0 {
211-
opts = append(opts, client.WithEndpoints(GlobalArgs.Endpoints...))
212-
}
213-
214-
if GlobalArgs.Cluster != "" {
215-
opts = append(opts, client.WithCluster(GlobalArgs.Cluster))
216-
}
217-
218-
c, err := client.New(ctx, opts...)
219-
if err != nil {
220-
return errors.Wrap(err, "constructing Talos client")
221-
}
222-
223-
defer func() { _ = c.Close() }()
224-
225-
return action(ctx, c)
149+
return newClientNoNodes(action, dialOptions...)
226150
}
227151

228152
// withNodesMetadata attaches the plural "nodes" key to the request context.
@@ -263,38 +187,6 @@ func WithClient(action func(context.Context, *client.Client) error, dialOptions
263187
)
264188
}
265189

266-
// WithClientMaintenance wraps common code to initialize Talos client in maintenance (insecure mode).
267-
//
268-
// One client spans every node in GlobalArgs.Nodes, as the talosctl wrapper did
269-
// before v1.14 hid it behind a per-node ClientFactory; callers that need a
270-
// single-endpoint client narrow the list themselves (openClientPerNodeMaintenance).
271-
// GlobalArgs.Nodes is read synchronously because that narrowing restores the
272-
// saved list as soon as action returns.
273-
//
274-
// Follows the same upstream file as WithClientNoNodes above (MPL-2.0).
275-
func WithClientMaintenance(enforceFingerprints []string, action func(context.Context, *client.Client) error) error {
276-
ctx, stop := signalContext()
277-
defer stop()
278-
279-
nodes := GlobalArgs.Nodes
280-
281-
c, err := client.New(ctx,
282-
client.WithDefaultGRPCDialOptions(),
283-
// Taken for the insecure TLS config and the fingerprint pinning. Its node
284-
// argument is inert here: options are applied in order, and WithEndpoints
285-
// below overwrites the single endpoint it sets.
286-
client.WithMaintenanceMode("", enforceFingerprints),
287-
client.WithEndpoints(nodes...),
288-
)
289-
if err != nil {
290-
return errors.Wrap(err, "constructing maintenance client")
291-
}
292-
293-
defer func() { _ = c.Close() }()
294-
295-
return action(ctx, c)
296-
}
297-
298190
// skipVerifyClientOptions assembles the client options for a --skip-verify
299191
// connection. It mirrors upstream global.Args.WithClientNoNodes so the skip
300192
// path does not silently lose behavior the normal path has: it pins the

‎pkg/commands/talos_client.go‎

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
// The code in this file is derived from siderolabs/talos, which is licensed
6+
// under MPL-2.0, and is therefore kept under MPL-2.0 itself. The rest of talm
7+
// stays under Apache-2.0; MPL-2.0 §3.3 covers that combination.
8+
//
9+
// signalContext follows pkg/cli/context.go:
10+
// https://github.com/siderolabs/talos/blob/v1.14.0/pkg/cli/context.go
11+
//
12+
// newClientNoNodes and WithClientMaintenance follow
13+
// cmd/talosctl/pkg/talos/global/client.go, whose exported entry points v1.14
14+
// removed:
15+
// https://github.com/siderolabs/talos/blob/v1.13.7/cmd/talosctl/pkg/talos/global/client.go
16+
17+
package commands
18+
19+
import (
20+
"context"
21+
"fmt"
22+
"os"
23+
"os/signal"
24+
"syscall"
25+
26+
"github.com/cockroachdb/errors"
27+
"github.com/siderolabs/talos/pkg/machinery/client"
28+
clientconfig "github.com/siderolabs/talos/pkg/machinery/client/config"
29+
"google.golang.org/grpc"
30+
)
31+
32+
// signalContext returns a context cancelled on SIGINT/SIGTERM, mirroring the
33+
// wrappers talosctl builds its own clients with.
34+
//
35+
// It unregisters the handler on the first signal, so a second Ctrl+C kills the
36+
// process outright. signal.NotifyContext would keep the registration, and the
37+
// second signal would land in a full channel and be discarded, leaving a stuck
38+
// call with no way out from the keyboard.
39+
func signalContext() (context.Context, context.CancelFunc) {
40+
ctx, cancel := context.WithCancel(context.Background())
41+
42+
sigCh := make(chan os.Signal, 1)
43+
signal.Notify(sigCh, os.Interrupt, syscall.SIGTERM)
44+
45+
go func() {
46+
select {
47+
case <-sigCh:
48+
signal.Stop(sigCh)
49+
fmt.Fprintln(os.Stderr, "Signal received, aborting, press Ctrl+C once again to abort immediately...")
50+
cancel()
51+
case <-ctx.Done():
52+
}
53+
}()
54+
55+
return ctx, func() {
56+
signal.Stop(sigCh)
57+
cancel()
58+
}
59+
}
60+
61+
// newClientNoNodes constructs a client that carries no node metadata and runs
62+
// action against it.
63+
func newClientNoNodes(action func(context.Context, *client.Client) error, dialOptions ...grpc.DialOption) error {
64+
ctx, stop := signalContext()
65+
defer stop()
66+
67+
// Built on pkg/machinery/client rather than the talosctl wrapper: Talos
68+
// v1.14 replaced that wrapper with a ClientFactory which refuses to
69+
// construct without nodes, which is the one thing this function allows.
70+
cfg, err := clientconfig.Open(GlobalArgs.Talosconfig)
71+
if err != nil {
72+
return errors.Wrapf(err, "opening talosconfig %q", GlobalArgs.Talosconfig)
73+
}
74+
75+
opts := []client.OptionFunc{
76+
client.WithConfig(cfg),
77+
client.WithDefaultGRPCDialOptions(),
78+
client.WithGRPCDialOptions(dialOptions...),
79+
client.WithSideroV1KeysDir(clientconfig.CustomSideroV1KeysDirPath(GlobalArgs.SideroV1KeysDir)),
80+
}
81+
82+
if GlobalArgs.CmdContext != "" {
83+
opts = append(opts, client.WithContextName(GlobalArgs.CmdContext))
84+
}
85+
86+
if len(GlobalArgs.Endpoints) > 0 {
87+
opts = append(opts, client.WithEndpoints(GlobalArgs.Endpoints...))
88+
}
89+
90+
if GlobalArgs.Cluster != "" {
91+
opts = append(opts, client.WithCluster(GlobalArgs.Cluster))
92+
}
93+
94+
c, err := client.New(ctx, opts...)
95+
if err != nil {
96+
return errors.Wrap(err, "constructing Talos client")
97+
}
98+
99+
defer func() { _ = c.Close() }()
100+
101+
return action(ctx, c)
102+
}
103+
104+
// WithClientMaintenance wraps common code to initialize Talos client in maintenance (insecure mode).
105+
//
106+
// One client spans every node in GlobalArgs.Nodes, as the talosctl wrapper did
107+
// before v1.14 hid it behind a per-node ClientFactory; callers that need a
108+
// single-endpoint client narrow the list themselves (openClientPerNodeMaintenance).
109+
// GlobalArgs.Nodes is read synchronously because that narrowing restores the
110+
// saved list as soon as action returns.
111+
func WithClientMaintenance(enforceFingerprints []string, action func(context.Context, *client.Client) error) error {
112+
ctx, stop := signalContext()
113+
defer stop()
114+
115+
nodes := GlobalArgs.Nodes
116+
117+
c, err := client.New(ctx,
118+
client.WithDefaultGRPCDialOptions(),
119+
// Taken for the insecure TLS config and the fingerprint pinning. Its node
120+
// argument is inert here: options are applied in order, and WithEndpoints
121+
// below overwrites the single endpoint it sets.
122+
client.WithMaintenanceMode("", enforceFingerprints),
123+
client.WithEndpoints(nodes...),
124+
)
125+
if err != nil {
126+
return errors.Wrap(err, "constructing maintenance client")
127+
}
128+
129+
defer func() { _ = c.Close() }()
130+
131+
return action(ctx, c)
132+
}

‎pkg/engine/talos_helpers.go‎

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
// The code in this file is derived from siderolabs/talos, which is licensed
6+
// under MPL-2.0, and is therefore kept under MPL-2.0 itself. The rest of talm
7+
// stays under Apache-2.0; MPL-2.0 §3.3 covers that combination.
8+
//
9+
// Talos v1.14.0 dropped FailIfMultiNodes and ForEachResource from
10+
// cmd/talosctl/pkg/talos/helpers: talosctl inlined the resource loop into its
11+
// own get command and left no exported replacement. The versions here follow
12+
// resources.go (the resource walk) and checks.go (the multi-node guard) and
13+
// behave as the helpers did, which is what the callers in engine.go expect:
14+
// https://github.com/siderolabs/talos/tree/v1.13.7/cmd/talosctl/pkg/talos/helpers
15+
//
16+
// Errors here go through the stdlib rather than cockroachdb/errors as the rest
17+
// of talm does, so the bodies stay diffable against upstream when it changes.
18+
119
package engine
220

321
import (
@@ -13,18 +31,6 @@ import (
1331
"github.com/siderolabs/talos/pkg/machinery/client"
1432
)
1533

16-
// Talos v1.14.0 dropped FailIfMultiNodes and ForEachResource from
17-
// cmd/talosctl/pkg/talos/helpers: talosctl inlined the resource loop into its
18-
// own get command and left no exported replacement. Both are thin wrappers over
19-
// the public client API, so talm carries its own, the same way it carries
20-
// --skip-verify since the fork was dropped. Behaviour matches what the helpers
21-
// did before they were dropped, which is what the callers in engine.go expect.
22-
//
23-
// These follow the structure of siderolabs/talos
24-
// cmd/talosctl/pkg/talos/helpers/resources.go (the resource walk) and
25-
// checks.go (the multi-node guard), both licensed under MPL-2.0:
26-
// https://github.com/siderolabs/talos/tree/v1.13.7/cmd/talosctl/pkg/talos/helpers
27-
2834
// ErrMultiNodeUnsupported is returned for a command that only makes sense
2935
// against a single node when the context names more than one.
3036
var ErrMultiNodeUnsupported = errors.New("command is not supported with multiple nodes")

0 commit comments

Comments
 (0)