@@ -8,12 +8,14 @@ package api
8
8
9
9
import (
10
10
"context"
11
+ "net/url"
11
12
"os"
12
- "sort "
13
+ "slices "
13
14
"testing"
14
15
"time"
15
16
16
17
"github.com/cosi-project/runtime/pkg/safe"
18
+ "github.com/siderolabs/gen/ensure"
17
19
"github.com/siderolabs/go-pointer"
18
20
"github.com/siderolabs/go-retry/retry"
19
21
"google.golang.org/grpc/codes"
@@ -23,7 +25,9 @@ import (
23
25
machineapi "github.com/siderolabs/talos/pkg/machinery/api/machine"
24
26
"github.com/siderolabs/talos/pkg/machinery/client"
25
27
"github.com/siderolabs/talos/pkg/machinery/config"
28
+ "github.com/siderolabs/talos/pkg/machinery/config/container"
26
29
"github.com/siderolabs/talos/pkg/machinery/config/machine"
30
+ "github.com/siderolabs/talos/pkg/machinery/config/types/runtime"
27
31
"github.com/siderolabs/talos/pkg/machinery/config/types/v1alpha1"
28
32
"github.com/siderolabs/talos/pkg/machinery/constants"
29
33
mc "github.com/siderolabs/talos/pkg/machinery/resources/config"
@@ -88,14 +92,13 @@ func (suite *ApplyConfigSuite) TestApply() {
88
92
89
93
suite .WaitForBootDone (suite .ctx )
90
94
91
- sort . Strings (nodes )
95
+ slices . Sort (nodes )
92
96
93
97
node := nodes [0 ]
94
-
95
98
nodeCtx := client .WithNode (suite .ctx , node )
96
99
97
100
provider , err := suite .ReadConfigFromNode (nodeCtx )
98
- suite .Assert ().Nilf (err , "failed to read existing config from node %q: %w" , node , err )
101
+ suite .Assert ().NoErrorf (err , "failed to read existing config from node %q: %w" , node , err )
99
102
100
103
cfgDataOut := suite .PatchV1Alpha1Config (provider , func (cfg * v1alpha1.Config ) {
101
104
if cfg .MachineConfig .MachineSysctls == nil {
@@ -115,7 +118,7 @@ func (suite *ApplyConfigSuite) TestApply() {
115
118
)
116
119
if err != nil {
117
120
// It is expected that the connection will EOF here, so just log the error
118
- suite .Assert ().Nilf (err , "failed to apply configuration (node %q): %w" , node , err )
121
+ suite .Assert ().NoErrorf (err , "failed to apply configuration (node %q): %w" , node , err )
119
122
}
120
123
121
124
return nil
@@ -125,7 +128,7 @@ func (suite *ApplyConfigSuite) TestApply() {
125
128
// Verify configuration change
126
129
var newProvider config.Provider
127
130
128
- suite .Require ().Nilf (
131
+ suite .Require ().NoErrorf (
129
132
retry .Constant (time .Minute , retry .WithUnits (time .Second )).Retry (
130
133
func () error {
131
134
newProvider , err = suite .ReadConfigFromNode (nodeCtx )
@@ -300,7 +303,7 @@ func (suite *ApplyConfigSuite) TestApplyConfigRotateEncryptionSecrets() {
300
303
)
301
304
if err != nil {
302
305
// It is expected that the connection will EOF here, so just log the error
303
- suite .Assert ().Nilf (err , "failed to apply configuration (node %q): %w" , node , err )
306
+ suite .Assert ().Errorf (err , "failed to apply configuration (node %q): %w" , node , err )
304
307
}
305
308
306
309
return nil
@@ -312,7 +315,7 @@ func (suite *ApplyConfigSuite) TestApplyConfigRotateEncryptionSecrets() {
312
315
// Verify configuration change
313
316
var newProvider config.Provider
314
317
315
- suite .Require ().Nilf (
318
+ suite .Require ().Errorf (
316
319
retry .Constant (time .Minute , retry .WithUnits (time .Second )).Retry (
317
320
func () error {
318
321
newProvider , err = suite .ReadConfigFromNode (nodeCtx )
@@ -355,14 +358,13 @@ func (suite *ApplyConfigSuite) TestApplyNoReboot() {
355
358
356
359
suite .WaitForBootDone (suite .ctx )
357
360
358
- sort . Strings (nodes )
361
+ slices . Sort (nodes )
359
362
360
363
node := nodes [0 ]
361
-
362
364
nodeCtx := client .WithNode (suite .ctx , node )
363
365
364
366
provider , err := suite .ReadConfigFromNode (nodeCtx )
365
- suite .Require ().Nilf (err , "failed to read existing config from node %q: %s" , node , err )
367
+ suite .Require ().NoErrorf (err , "failed to read existing config from node %q: %s" , node , err )
366
368
367
369
cfgDataOut := suite .PatchV1Alpha1Config (provider , func (cfg * v1alpha1.Config ) {
368
370
// this won't be possible without a reboot
@@ -387,14 +389,13 @@ func (suite *ApplyConfigSuite) TestApplyDryRun() {
387
389
388
390
suite .WaitForBootDone (suite .ctx )
389
391
390
- sort . Strings (nodes )
392
+ slices . Sort (nodes )
391
393
392
394
node := nodes [0 ]
393
-
394
395
nodeCtx := client .WithNode (suite .ctx , node )
395
396
396
397
provider , err := suite .ReadConfigFromNode (nodeCtx )
397
- suite .Require ().Nilf (err , "failed to read existing config from node %q: %s" , node , err )
398
+ suite .Require ().NoErrorf (err , "failed to read existing config from node %q: %s" , node , err )
398
399
399
400
cfgDataOut := suite .PatchV1Alpha1Config (provider , func (cfg * v1alpha1.Config ) {
400
401
// this won't be possible without a reboot
@@ -416,21 +417,59 @@ func (suite *ApplyConfigSuite) TestApplyDryRun() {
416
417
},
417
418
)
418
419
419
- suite .Require ().Nilf (err , "failed to apply configuration (node %q): %s" , node , err )
420
+ suite .Require ().NoErrorf (err , "failed to apply configuration (node %q): %s" , node , err )
420
421
suite .Assert ().Contains (reply .Messages [0 ].ModeDetails , "Dry run summary" )
421
422
}
422
423
424
+ // TestApplyDryRunDocuments verifies the apply config API with multi doc and dry run enabled.
425
+ func (suite * ApplyConfigSuite ) TestApplyDryRunDocuments () {
426
+ nodes := suite .DiscoverNodeInternalIPsByType (suite .ctx , machine .TypeWorker )
427
+ suite .Require ().NotEmpty (nodes )
428
+
429
+ suite .WaitForBootDone (suite .ctx )
430
+
431
+ slices .Sort (nodes )
432
+
433
+ node := nodes [0 ]
434
+ nodeCtx := client .WithNode (suite .ctx , node )
435
+
436
+ provider , err := suite .ReadConfigFromNode (nodeCtx )
437
+ suite .Require ().NoErrorf (err , "failed to read existing config from node %q: %s" , node , err )
438
+
439
+ kmsg := runtime .NewKmsgLogV1Alpha1 ()
440
+ kmsg .MetaName = "omni-kmsg"
441
+ kmsg .KmsgLogURL .URL = ensure .Value (url .Parse ("tcp://[fdae:41e4:649b:9303::1]:8092" ))
442
+
443
+ cont , err := container .New (provider .RawV1Alpha1 (), kmsg )
444
+ suite .Require ().NoErrorf (err , "failed to create container: %s" , err )
445
+
446
+ cfgDataOut , err := cont .Bytes ()
447
+ suite .Require ().NoErrorf (err , "failed to marshal container: %s" , err )
448
+
449
+ reply , err := suite .Client .ApplyConfiguration (
450
+ nodeCtx , & machineapi.ApplyConfigurationRequest {
451
+ Data : cfgDataOut ,
452
+ Mode : machineapi .ApplyConfigurationRequest_AUTO ,
453
+ DryRun : true ,
454
+ },
455
+ )
456
+
457
+ suite .Require ().NoErrorf (err , "failed to apply configuration (node %q): %s" , node , err )
458
+ suite .Assert ().Contains (reply .Messages [0 ].ModeDetails , "Dry run summary" )
459
+ suite .Assert ().Contains (reply .Messages [0 ].ModeDetails , "omni-kmsg" )
460
+ suite .Assert ().Contains (reply .Messages [0 ].ModeDetails , "tcp://[fdae:41e4:649b:9303::1]:8092" )
461
+ }
462
+
423
463
// TestApplyTry applies the config in try mode with a short timeout.
424
464
func (suite * ApplyConfigSuite ) TestApplyTry () {
425
465
nodes := suite .DiscoverNodeInternalIPsByType (suite .ctx , machine .TypeWorker )
426
466
suite .Require ().NotEmpty (nodes )
427
467
428
468
suite .WaitForBootDone (suite .ctx )
429
469
430
- sort . Strings (nodes )
470
+ slices . Sort (nodes )
431
471
432
472
node := nodes [0 ]
433
-
434
473
nodeCtx := client .WithNode (suite .ctx , node )
435
474
436
475
getMachineConfig := func (ctx context.Context ) (* mc.MachineConfig , error ) {
@@ -443,7 +482,7 @@ func (suite *ApplyConfigSuite) TestApplyTry() {
443
482
}
444
483
445
484
provider , err := getMachineConfig (nodeCtx )
446
- suite .Require ().Nilf (err , "failed to read existing config from node %q: %s" , node , err )
485
+ suite .Require ().NoErrorf (err , "failed to read existing config from node %q: %s" , node , err )
447
486
448
487
cfgDataOut := suite .PatchV1Alpha1Config (provider .Provider (), func (cfg * v1alpha1.Config ) {
449
488
if cfg .MachineConfig .MachineNetwork == nil {
@@ -465,10 +504,10 @@ func (suite *ApplyConfigSuite) TestApplyTry() {
465
504
TryModeTimeout : durationpb .New (time .Second * 1 ),
466
505
},
467
506
)
468
- suite .Assert ().Nilf (err , "failed to apply configuration (node %q): %s" , node , err )
507
+ suite .Assert ().NoErrorf (err , "failed to apply configuration (node %q): %s" , node , err )
469
508
470
509
provider , err = getMachineConfig (nodeCtx )
471
- suite .Require ().Nilf (err , "failed to read existing config from node %q: %w" , node , err )
510
+ suite .Require ().NoErrorf (err , "failed to read existing config from node %q: %w" , node , err )
472
511
473
512
suite .Assert ().NotNil (provider .Config ().Machine ().Network ())
474
513
suite .Assert ().NotNil (provider .Config ().Machine ().Network ().Devices ())
@@ -487,7 +526,7 @@ func (suite *ApplyConfigSuite) TestApplyTry() {
487
526
488
527
for range 100 {
489
528
provider , err = getMachineConfig (nodeCtx )
490
- suite .Assert ().Nilf (err , "failed to read existing config from node %q: %s" , node , err )
529
+ suite .Assert ().NoErrorf (err , "failed to read existing config from node %q: %s" , node , err )
491
530
492
531
if provider .Config ().Machine ().Network () == nil {
493
532
return
0 commit comments