Skip to content

Commit 5775b5d

Browse files
authored
fix: enable secret support in backend (#651)
Originally, PR #240 was not merged and we wanted to at least enable the frontend to have successful API interactions with secrets - so PR #331 was raised and merged that handled the API request but did **NOT** pass the `Secrets` data into the controller. Now that #240 has merged - this commit uncomments all the code to enable full end to end behavior. Signed-off-by: Andy Stoneberg <astonebe@redhat.com>
1 parent 8baaefe commit 5775b5d

File tree

2 files changed

+21
-22
lines changed

2 files changed

+21
-22
lines changed

workspaces/backend/api/workspaces_handler_test.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -769,9 +769,7 @@ var _ = Describe("Workspaces Handler", func() {
769769
},
770770
}
771771
Expect(createdWorkspace.Spec.PodTemplate.Volumes.Data).To(Equal(expected))
772-
773-
// TODO: Verify secrets once #240 merged
774-
// Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets).To(BeEmpty())
772+
Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets).To(BeEmpty())
775773

776774
By("creating an HTTP request to delete the Workspace")
777775
path = strings.Replace(WorkspacesByNamePath, ":"+NamespacePathParam, namespaceNameCrud, 1)
@@ -808,8 +806,7 @@ var _ = Describe("Workspaces Handler", func() {
808806
Expect(apierrors.IsNotFound(err)).To(BeTrue())
809807
})
810808

811-
// TODO: Change to It when #240 merged
812-
XIt("should create a workspace with secrets", func() {
809+
It("should create a workspace with secrets", func() {
813810
// Create a workspace with secrets
814811
workspace := &models.WorkspaceCreate{
815812
Name: "test-workspace",
@@ -865,11 +862,14 @@ var _ = Describe("Workspaces Handler", func() {
865862
createdWorkspace := &kubefloworgv1beta1.Workspace{}
866863
Expect(k8sClient.Get(ctx, types.NamespacedName{Name: workspace.Name, Namespace: namespaceNameCrud}, createdWorkspace)).To(Succeed())
867864

868-
// TODO: Verify the secrets are properly set once #240 merged
869-
// Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets).To(HaveLen(1))
870-
// Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets[0].SecretName).To(Equal("test-secret"))
871-
// Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets[0].MountPath).To(Equal("/secrets"))
872-
// Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets[0].DefaultMode).To(Equal(int32(0o644)))
865+
expected := []kubefloworgv1beta1.PodSecretMount{
866+
{
867+
SecretName: workspace.PodTemplate.Volumes.Secrets[0].SecretName,
868+
MountPath: workspace.PodTemplate.Volumes.Secrets[0].MountPath,
869+
DefaultMode: workspace.PodTemplate.Volumes.Secrets[0].DefaultMode,
870+
},
871+
}
872+
Expect(createdWorkspace.Spec.PodTemplate.Volumes.Secrets).To(Equal(expected))
873873
})
874874

875875
// TODO: test when fail to create a Workspace when:

workspaces/backend/internal/repositories/workspaces/repo.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ func (r *WorkspaceRepository) CreateWorkspace(ctx context.Context, workspaceCrea
144144
}
145145

146146
// get secrets from workspace model
147-
// TODO: uncomment this once #240 is merged
148-
// secretMounts := make([]kubefloworgv1beta1.PodSecretMount, len(workspaceCreate.PodTemplate.Volumes.Secrets))
149-
// for i, secret := range workspaceCreate.PodTemplate.Volumes.Secrets {
150-
// secretMounts[i] = kubefloworgv1beta1.PodSecretMount{
151-
// SecretName: secret.SecretName,
152-
// MountPath: secret.MountPath,
153-
// DefaultMode: secret.DefaultMode,
154-
// }
155-
// }
147+
secretMounts := make([]kubefloworgv1beta1.PodSecretMount, len(workspaceCreate.PodTemplate.Volumes.Secrets))
148+
for i, secret := range workspaceCreate.PodTemplate.Volumes.Secrets {
149+
secretMounts[i] = kubefloworgv1beta1.PodSecretMount{
150+
SecretName: secret.SecretName,
151+
MountPath: secret.MountPath,
152+
DefaultMode: secret.DefaultMode,
153+
}
154+
}
156155

157156
// define workspace object from model
158157
workspaceName := workspaceCreate.Name
@@ -172,9 +171,9 @@ func (r *WorkspaceRepository) CreateWorkspace(ctx context.Context, workspaceCrea
172171
Annotations: workspaceCreate.PodTemplate.PodMetadata.Annotations,
173172
},
174173
Volumes: kubefloworgv1beta1.WorkspacePodVolumes{
175-
Home: workspaceCreate.PodTemplate.Volumes.Home,
176-
Data: dataVolumeMounts,
177-
// Secrets: secretMounts,
174+
Home: workspaceCreate.PodTemplate.Volumes.Home,
175+
Data: dataVolumeMounts,
176+
Secrets: secretMounts,
178177
},
179178
Options: kubefloworgv1beta1.WorkspacePodOptions{
180179
ImageConfig: workspaceCreate.PodTemplate.Options.ImageConfig,

0 commit comments

Comments
 (0)