|
9 | 9 | "fmt" |
10 | 10 | "net/http" |
11 | 11 | "os" |
| 12 | + "path/filepath" |
12 | 13 | "time" |
13 | 14 |
|
14 | 15 | "golang.org/x/crypto/bcrypt" |
@@ -193,37 +194,16 @@ var _ = Describe("Server Controller", func() { |
193 | 194 | err = bcrypt.CompareHashAndPassword([]byte(passwordHash), sshSecret.Data[SSHKeyPairSecretPasswordKeyName]) |
194 | 195 | Expect(err).ToNot(HaveOccurred(), "passwordHash should match the expected password") |
195 | 196 |
|
196 | | - // Create a temporary ignition template file for testing |
197 | | - tmpIgnitionFile, err := os.CreateTemp("", "ignition-test-*.yaml") |
198 | | - Expect(err).NotTo(HaveOccurred()) |
199 | | - defer func() { |
200 | | - Expect(os.Remove(tmpIgnitionFile.Name())).To(Succeed()) |
201 | | - }() |
202 | | - |
203 | | - defaultTemplate := `variant: fcos |
204 | | -version: "1.3.0" |
205 | | -systemd: |
206 | | - units: |
207 | | - - name: metalprobe.service |
208 | | - enabled: true |
209 | | - contents: |- |
210 | | - [Service] |
211 | | - ExecStart=/usr/bin/docker run {{.Image}} {{.Flags}} |
212 | | -passwd: |
213 | | - users: |
214 | | - - name: metal |
215 | | - password_hash: {{.PasswordHash}} |
216 | | - ssh_authorized_keys: [ {{.SSHPublicKey}} ]` |
217 | | - _, err = tmpIgnitionFile.WriteString(defaultTemplate) |
218 | | - Expect(err).NotTo(HaveOccurred()) |
219 | | - Expect(tmpIgnitionFile.Close()).To(Succeed()) |
220 | | - |
221 | | - ignitionData, err := ignition.GenerateIgnitionDataFromFile(tmpIgnitionFile.Name(), ignition.Config{ |
222 | | - Image: "foo:latest", |
223 | | - Flags: "--registry-url=http://localhost:30000 --server-uuid=38947555-7742-3448-3784-823347823834", |
224 | | - SSHPublicKey: string(sshSecret.Data[SSHKeyPairSecretPublicKeyName]), |
225 | | - PasswordHash: passwordHash, |
226 | | - }) |
| 197 | + // Generate expected ignition data using the same template file the controller uses |
| 198 | + ignitionData, err := ignition.GenerateIgnitionDataFromFile( |
| 199 | + filepath.Join("..", "..", "config", "manager", "ignition-template.yaml"), |
| 200 | + ignition.Config{ |
| 201 | + Image: "foo:latest", |
| 202 | + Flags: "--registry-url=http://localhost:30000 --server-uuid=38947555-7742-3448-3784-823347823834", |
| 203 | + SSHPublicKey: string(sshSecret.Data[SSHKeyPairSecretPublicKeyName]), |
| 204 | + PasswordHash: passwordHash, |
| 205 | + }, |
| 206 | + ) |
227 | 207 | Expect(err).NotTo(HaveOccurred()) |
228 | 208 |
|
229 | 209 | Eventually(Object(ignitionSecret)).Should(SatisfyAll( |
@@ -885,11 +865,6 @@ passwd: |
885 | 865 | Expect(k8sClient.Create(ctx, server)).To(Succeed()) |
886 | 866 | }) |
887 | 867 |
|
888 | | - AfterEach(func(ctx SpecContext) { |
889 | | - Expect(k8sClient.Delete(ctx, server)).Should(Succeed()) |
890 | | - Expect(k8sClient.Delete(ctx, bmcSecret)).Should(Succeed()) |
891 | | - }) |
892 | | - |
893 | 868 | It("Should use custom file template when available", func(ctx SpecContext) { |
894 | 869 | By("Creating a custom ignition template file") |
895 | 870 | customTemplate := `variant: fcos |
@@ -1068,6 +1043,66 @@ passwd: |
1068 | 1043 | Expect(ignitionStr).To(ContainSubstring("metalprobe.service")) |
1069 | 1044 | Expect(ignitionStr).To(ContainSubstring("name: metal")) |
1070 | 1045 | }) |
| 1046 | + |
| 1047 | + It("Should create server with custom ignition template file end-to-end", func(ctx SpecContext) { |
| 1048 | + By("Creating a custom ignition template file") |
| 1049 | + customTemplate := `variant: fcos |
| 1050 | +version: "1.5.0" |
| 1051 | +systemd: |
| 1052 | + units: |
| 1053 | + - name: e2e-custom-probe.service |
| 1054 | + enabled: true |
| 1055 | + contents: |- |
| 1056 | + [Unit] |
| 1057 | + Description=E2E Custom Probe Service |
| 1058 | + [Service] |
| 1059 | + Restart=always |
| 1060 | + ExecStart=/usr/bin/docker run --name e2e-probe {{.Image}} {{.Flags}} |
| 1061 | + [Install] |
| 1062 | + WantedBy=multi-user.target |
| 1063 | +passwd: |
| 1064 | + users: |
| 1065 | + - name: e2e-user |
| 1066 | + password_hash: {{.PasswordHash}} |
| 1067 | + ssh_authorized_keys: [ {{.SSHPublicKey}} ]` |
| 1068 | + |
| 1069 | + tmpFile, err := os.CreateTemp("", "e2e-ignition-*.yaml") |
| 1070 | + Expect(err).NotTo(HaveOccurred()) |
| 1071 | + defer func() { |
| 1072 | + Expect(os.Remove(tmpFile.Name())).To(Succeed()) |
| 1073 | + }() |
| 1074 | + |
| 1075 | + _, err = tmpFile.WriteString(customTemplate) |
| 1076 | + Expect(err).NotTo(HaveOccurred()) |
| 1077 | + Expect(tmpFile.Close()).To(Succeed()) |
| 1078 | + |
| 1079 | + By("Creating a reconciler with custom ignition template path") |
| 1080 | + customReconciler := &ServerReconciler{ |
| 1081 | + Client: k8sClient, |
| 1082 | + Scheme: k8sClient.Scheme(), |
| 1083 | + RegistryURL: registryURL, |
| 1084 | + ManagerNamespace: ns.Name, |
| 1085 | + ProbeImage: "custom-probe:v1.0.0", |
| 1086 | + Insecure: true, |
| 1087 | + IgnitionConfigPath: tmpFile.Name(), |
| 1088 | + } |
| 1089 | + |
| 1090 | + By("Generating ignition data with custom template") |
| 1091 | + ignitionData, err := customReconciler.generateDefaultIgnitionDataForServer( |
| 1092 | + "--registry-url=http://localhost:30000 --server-uuid=e2e-test-12345", |
| 1093 | + [] byte( "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQC [email protected]"), |
| 1094 | + []byte("testpassword"), |
| 1095 | + ) |
| 1096 | + Expect(err).NotTo(HaveOccurred()) |
| 1097 | + Expect(ignitionData).NotTo(BeEmpty()) |
| 1098 | + |
| 1099 | + ignitionStr := string(ignitionData) |
| 1100 | + Expect(ignitionStr).To(ContainSubstring("version: \"1.5.0\""), "Should use custom template version") |
| 1101 | + Expect(ignitionStr).To(ContainSubstring("e2e-custom-probe.service"), "Should use custom service name") |
| 1102 | + Expect(ignitionStr).To(ContainSubstring("E2E Custom Probe Service"), "Should use custom description") |
| 1103 | + Expect(ignitionStr).To(ContainSubstring("e2e-user"), "Should use custom username") |
| 1104 | + Expect(ignitionStr).To(ContainSubstring("custom-probe:v1.0.0"), "Should include custom probe image") |
| 1105 | + }) |
1071 | 1106 | }) |
1072 | 1107 | }) |
1073 | 1108 |
|
|
0 commit comments