Repository: rancher-sandbox/cluster-api-provider-rke2
Pull request #211 (2023-11-29 15:28:33)

[release-0.2] Create bootstrap-success before setting selinux to enforcing mode
<!--
Label the PR with the kind of change this for:

kind/feature
kind/bug
kind/documentation
kind/regression
kind/*
-->

**What this PR does / why we need it**:

Cherry pick of https://github.com/rancher-sandbox/cluster-api-provider-rke2/pull/209

<!-- Enter a description of the change and why this change is needed -->

**Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*:
Fixes #

**Special notes for your reviewer**:

**Checklist**:
<!-- Put an "X" character inside the brackets of each completed task. Some may be optional depending on the PR in which case these can be deleted -->

- [ ] squashed commits into logical changes
- [ ] includes documentation
- [ ] adds unit tests
- [ ] adds or updates e2e tests



Patch:
diff --git a/bootstrap/internal/ignition/butane/butane.go b/bootstrap/internal/ignition/butane/butane.go
index 376323c..c06c19a 100644
--- a/bootstrap/internal/ignition/butane/butane.go
+++ b/bootstrap/internal/ignition/butane/butane.go
@@ -121,7 +121,6 @@ storage:
           {{ . | Indent 10 }}
           {{- end }}
 
-          mkdir -p /run/cluster-api && echo success > /run/cluster-api/bootstrap-success.complete
           {{range .PostRKE2Commands }}
           {{ . | Indent 10 }}
           {{- end }}
diff --git a/bootstrap/internal/ignition/ignition.go b/bootstrap/internal/ignition/ignition.go
index b7af6ba..7390546 100644
--- a/bootstrap/internal/ignition/ignition.go
+++ b/bootstrap/internal/ignition/ignition.go
@@ -31,21 +31,23 @@ const (
 )
 
 var (
-	serverSystemdServices = []string{
+	serverDeployCommands = []string{
 		"semanage fcontext -a -t systemd_unit_file_t  /usr/lib/systemd/system/rke2-server.service",
 		"setenforce 0",
 		"systemctl enable rke2-server.service",
 		"systemctl start rke2-server.service",
 		"restorecon /etc/systemd/system/rke2-server.service",
+		"mkdir -p /run/cluster-api && echo success > /run/cluster-api/bootstrap-success.complete",
 		"setenforce 1",
 	}
 
-	workerSystemdServices = []string{
+	workerDeployCommands = []string{
 		"semanage fcontext -a -t systemd_unit_file_t  /usr/lib/systemd/system/rke2-agent.service",
 		"setenforce 0",
 		"systemctl enable rke2-agent.service",
 		"systemctl start rke2-agent.service",
 		"restorecon /etc/systemd/system/rke2-agent.service",
+		"mkdir -p /run/cluster-api && echo success > /run/cluster-api/bootstrap-success.complete",
 		"setenforce 1",
 	}
 )
@@ -136,11 +138,11 @@ func render(input *cloudinit.BaseUserData, ignitionConfig *bootstrapv1.Additiona
 }
 
 func getControlPlaneRKE2Commands(baseUserData *cloudinit.BaseUserData) ([]string, error) {
-	return getRKE2Commands(baseUserData, controlPlaneCommand, airGappedControlPlaneCommand, serverSystemdServices)
+	return getRKE2Commands(baseUserData, controlPlaneCommand, airGappedControlPlaneCommand, serverDeployCommands)
 }
 
 func getWorkerRKE2Commands(baseUserData *cloudinit.BaseUserData) ([]string, error) {
-	return getRKE2Commands(baseUserData, workerCommand, airGappedWorkerCommand, workerSystemdServices)
+	return getRKE2Commands(baseUserData, workerCommand, airGappedWorkerCommand, workerDeployCommands)
 }
 
 func getRKE2Commands(baseUserData *cloudinit.BaseUserData, command, airgappedCommand string, systemdServices []string) ([]string, error) {


Test patch:
diff --git a/bootstrap/internal/ignition/ignition_test.go b/bootstrap/internal/ignition/ignition_test.go
index 7d281a8..1e3fa5c 100644
--- a/bootstrap/internal/ignition/ignition_test.go
+++ b/bootstrap/internal/ignition/ignition_test.go
@@ -207,16 +207,16 @@ var _ = Describe("getControlPlaneRKE2Commands", func() {
 	It("should return slice of control plane commands", func() {
 		commands, err := getControlPlaneRKE2Commands(baseUserData)
 		Expect(err).ToNot(HaveOccurred())
-		Expect(commands).To(HaveLen(7))
-		Expect(commands).To(ContainElements(fmt.Sprintf(controlPlaneCommand, baseUserData.RKE2Version), serverSystemdServices[0], serverSystemdServices[1]))
+		Expect(commands).To(HaveLen(8))
+		Expect(commands).To(ContainElements(fmt.Sprintf(controlPlaneCommand, baseUserData.RKE2Version), serverDeployCommands[0], serverDeployCommands[1]))
 	})
 
 	It("should return slice of control plane commands with air gapped", func() {
 		baseUserData.AirGapped = true
 		commands, err := getControlPlaneRKE2Commands(baseUserData)
 		Expect(err).ToNot(HaveOccurred())
-		Expect(commands).To(HaveLen(7))
-		Expect(commands).To(ContainElements(airGappedControlPlaneCommand, serverSystemdServices[0], serverSystemdServices[1]))
+		Expect(commands).To(HaveLen(8))
+		Expect(commands).To(ContainElements(airGappedControlPlaneCommand, serverDeployCommands[0], serverDeployCommands[1]))
 	})
 
 	It("should return error if base userdata is nil", func() {
@@ -247,16 +247,16 @@ var _ = Describe("getWorkerRKE2Commands", func() {
 	It("should return slice of worker commands", func() {
 		commands, err := getWorkerRKE2Commands(baseUserData)
 		Expect(err).ToNot(HaveOccurred())
-		Expect(commands).To(HaveLen(7))
-		Expect(commands).To(ContainElements(fmt.Sprintf(workerCommand, baseUserData.RKE2Version), workerSystemdServices[0], workerSystemdServices[1]))
+		Expect(commands).To(HaveLen(8))
+		Expect(commands).To(ContainElements(fmt.Sprintf(workerCommand, baseUserData.RKE2Version), workerDeployCommands[0], workerDeployCommands[1]))
 	})
 
 	It("should return slice of worker commands with air gapped", func() {
 		baseUserData.AirGapped = true
 		commands, err := getWorkerRKE2Commands(baseUserData)
 		Expect(err).ToNot(HaveOccurred())
-		Expect(commands).To(HaveLen(7))
-		Expect(commands).To(ContainElements(airGappedWorkerCommand, workerSystemdServices[0], workerSystemdServices[1]))
+		Expect(commands).To(HaveLen(8))
+		Expect(commands).To(ContainElements(airGappedWorkerCommand, workerDeployCommands[0], workerDeployCommands[1]))
 	})
 
 	It("should return error if base userdata is nil", func() {