diff --git a/internal/models/ocp_sandbox.go b/internal/models/ocp_sandbox.go index f8af486..9b53703 100644 --- a/internal/models/ocp_sandbox.go +++ b/internal/models/ocp_sandbox.go @@ -1362,6 +1362,30 @@ func (a *OcpSandboxProvider) Request(serviceUuid string, cloud_selector map[stri } } } + + // Create secret to generate a token, for the clusters without image registry and for future versions of OCP + secret := &v1.Secret{ + ObjectMeta: metav1.ObjectMeta{ + Name: serviceAccountName + "-token", + Namespace: namespaceName, + Annotations: map[string]string{ + "kubernetes.io/service-account.name": serviceAccountName, + }, + }, + Type: v1.SecretTypeServiceAccountToken, + } + _, err = clientset.CoreV1().Secrets(namespaceName).Create(context.TODO(), secret, metav1.CreateOptions{}) + + if err != nil { + log.Logger.Error("Error creating secret for SA", "error", err) + // Delete the namespace + if err := clientset.CoreV1().Namespaces().Delete(context.TODO(), namespaceName, metav1.DeleteOptions{}); err != nil { + log.Logger.Error("Error creating OCP secret for SA", "error", err) + } + rnew.SetStatus("error") + return + } + secrets, err := clientset.CoreV1().Secrets(namespaceName).List(context.TODO(), metav1.ListOptions{}) if err != nil {