@@ -10,16 +10,24 @@ import (
1010 "fmt"
1111 "path/filepath"
1212
13+ "github.com/cosi-project/runtime/pkg/resource/rtestutils"
14+ "github.com/siderolabs/go-procfs/procfs"
15+ "github.com/stretchr/testify/assert"
16+
1317 "github.com/siderolabs/talos/cmd/talosctl/pkg/mgmt/helpers"
1418 "github.com/siderolabs/talos/pkg/images"
19+ talosclient "github.com/siderolabs/talos/pkg/machinery/client"
1520 "github.com/siderolabs/talos/pkg/machinery/config/machine"
1621 "github.com/siderolabs/talos/pkg/machinery/constants"
22+ "github.com/siderolabs/talos/pkg/machinery/resources/runtime"
1723)
1824
1925//nolint:maligned
2026type upgradeSpec struct {
2127 ShortName string
2228
29+ InjectExtraKernelArgs * procfs.Cmdline
30+
2331 SourceKernelPath string
2432 SourceInitramfsPath string
2533 SourceDiskImagePath string
@@ -42,6 +50,7 @@ type upgradeSpec struct {
4250 WithEncryption bool
4351 WithBios bool
4452 WithApplyConfig bool
53+ WithEnforcing bool
4554}
4655
4756const (
@@ -226,6 +235,38 @@ func upgradeCurrentToCurrentNewCmdline() upgradeSpec {
226235 }
227236}
228237
238+ func upgradeCurrentToCurrentEnforcing () upgradeSpec {
239+ installerImage := fmt .Sprintf (
240+ "%s/%s:%s" ,
241+ DefaultSettings .TargetInstallImageRegistry ,
242+ images .DefaultInstallerImageName ,
243+ DefaultSettings .CurrentVersion ,
244+ )
245+
246+ return upgradeSpec {
247+ ShortName : fmt .Sprintf ("%s-same-ver-enforcing" , DefaultSettings .CurrentVersion ),
248+
249+ InjectExtraKernelArgs : procfs .NewCmdline ("enforcing=1" ),
250+
251+ SourceISOPath : helpers .ArtifactPath ("metal-amd64.iso" ),
252+ SourceInstallerImage : installerImage ,
253+ SourceVersion : DefaultSettings .CurrentVersion ,
254+ SourceK8sVersion : currentK8sVersion ,
255+
256+ TargetInstallerImage : installerImage ,
257+ TargetVersion : DefaultSettings .CurrentVersion ,
258+ TargetK8sVersion : currentK8sVersion ,
259+
260+ ControlplaneNodes : 1 ,
261+ WorkerNodes : 0 ,
262+
263+ TargetCmdlineContains : "enforcing=1" ,
264+
265+ WithApplyConfig : true ,
266+ WithEnforcing : true ,
267+ }
268+ }
269+
229270// UpgradeSuite ...
230271type UpgradeSuite struct {
231272 BaseSuite
@@ -264,6 +305,8 @@ func (suite *UpgradeSuite) TestRolling() {
264305 ControlplaneNodes : suite .spec .ControlplaneNodes ,
265306 WorkerNodes : suite .spec .WorkerNodes ,
266307
308+ InjectExtraKernelArgs : suite .spec .InjectExtraKernelArgs ,
309+
267310 SourceKernelPath : suite .spec .SourceKernelPath ,
268311 SourceInitramfsPath : suite .spec .SourceInitramfsPath ,
269312 SourceDiskImagePath : suite .spec .SourceDiskImagePath ,
@@ -283,6 +326,18 @@ func (suite *UpgradeSuite) TestRolling() {
283326 // verify initial cluster version
284327 suite .assertSameVersionCluster (client , suite .spec .SourceVersion )
285328
329+ // verify enforcing state
330+ for _ , node := range suite .Cluster .Info ().Nodes {
331+ rtestutils .AssertResource (
332+ talosclient .WithNode (suite .ctx , node .IPs [0 ].String ()),
333+ suite .T (), client .COSI ,
334+ runtime .SecurityStateID ,
335+ func (r * runtime.SecurityState , asrt * assert.Assertions ) {
336+ asrt .Equal (suite .spec .WithEnforcing , r .TypedSpec ().SELinuxState == runtime .SELinuxStateEnforcing )
337+ },
338+ )
339+ }
340+
286341 options := upgradeOptions {
287342 TargetInstallerImage : suite .spec .TargetInstallerImage ,
288343 UpgradeStage : suite .spec .UpgradeStage ,
@@ -306,6 +361,18 @@ func (suite *UpgradeSuite) TestRolling() {
306361 // verify final cluster version
307362 suite .assertSameVersionCluster (client , suite .spec .TargetVersion )
308363
364+ // verify enforcing state
365+ for _ , node := range suite .Cluster .Info ().Nodes {
366+ rtestutils .AssertResource (
367+ talosclient .WithNode (suite .ctx , node .IPs [0 ].String ()),
368+ suite .T (), client .COSI ,
369+ runtime .SecurityStateID ,
370+ func (r * runtime.SecurityState , asrt * assert.Assertions ) {
371+ asrt .Equal (suite .spec .WithEnforcing , r .TypedSpec ().SELinuxState == runtime .SELinuxStateEnforcing )
372+ },
373+ )
374+ }
375+
309376 // upgrade Kubernetes if required
310377 suite .upgradeKubernetes (suite .spec .SourceK8sVersion , suite .spec .TargetK8sVersion , suite .spec .SkipKubeletUpgrade )
311378
@@ -337,5 +404,6 @@ func init() {
337404 & UpgradeSuite {specGen : upgradeCurrentToCurrentBios , track : 0 },
338405 & UpgradeSuite {specGen : upgradeStableToCurrentPreserveStage , track : 1 },
339406 & UpgradeSuite {specGen : upgradeCurrentToCurrentNewCmdline , track : 2 },
407+ & UpgradeSuite {specGen : upgradeCurrentToCurrentEnforcing , track : 1 },
340408 )
341409}
0 commit comments