Skip to content

Commit

Permalink
Add secret to generate a token (#82)
Browse files Browse the repository at this point in the history
* Add secret to generate a token

* Add secret to generate a token
  • Loading branch information
agonzalezrh authored Sep 25, 2024
1 parent ce11bcb commit 5081ea6
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions internal/models/ocp_sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 5081ea6

Please sign in to comment.