From 1027c556c6383f7dfd847d5953defd31910ea176 Mon Sep 17 00:00:00 2001 From: yy Date: Tue, 22 Oct 2024 15:04:04 +0800 Subject: [PATCH] feat: add jwt secret in devbox secret. --- .../devbox/internal/controller/devbox_controller.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controllers/devbox/internal/controller/devbox_controller.go b/controllers/devbox/internal/controller/devbox_controller.go index 8cef15bade5..5fb887bd0fc 100644 --- a/controllers/devbox/internal/controller/devbox_controller.go +++ b/controllers/devbox/internal/controller/devbox_controller.go @@ -170,6 +170,15 @@ func (r *DevboxReconciler) syncSecret(ctx context.Context, devbox *devboxv1alpha err := r.Get(ctx, client.ObjectKey{Namespace: devbox.Namespace, Name: devbox.Name}, devboxSecret) if err == nil { // Secret already exists, no need to create + + // TODO: delete this code after we have a way to sync secret to devbox + // check if SEALOS_DEVBOX_JWT_SECRET is exist, if not exist, create it + if _, ok := devboxSecret.Data["SEALOS_DEVBOX_JWT_SECRET"]; !ok { + devboxSecret.Data["SEALOS_DEVBOX_JWT_SECRET"] = []byte(rand.String(32)) + if err := r.Update(ctx, devboxSecret); err != nil { + return fmt.Errorf("failed to update secret: %w", err) + } + } return nil } if client.IgnoreNotFound(err) != nil { @@ -186,6 +195,7 @@ func (r *DevboxReconciler) syncSecret(ctx context.Context, devbox *devboxv1alpha ObjectMeta: objectMeta, Data: map[string][]byte{ "SEALOS_DEVBOX_PASSWORD": []byte(rand.String(12)), + "SEALOS_DEVBOX_JWT_SECRET": []byte(rand.String(32)), "SEALOS_DEVBOX_PUBLIC_KEY": publicKey, "SEALOS_DEVBOX_PRIVATE_KEY": privateKey, },