Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add namespace when required for new task token function #34

Merged
merged 1 commit into from
Mar 10, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/api/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1634,6 +1634,7 @@ func NewTaskToken(db *gorm.DB, tfoResourceSpec models.TFOResourceSpec, _tenantID
return nil, fmt.Errorf("failed to generate taskJWT: %s", err)

} else {

result := db.Raw("SELECT * FROM tfo_resources WHERE uuid = ?", tfoResourceSpec.TFOResourceUUID).Scan(&tfoResource)
if result.Error != nil {
return nil, fmt.Errorf("failed to find TFO Resource: %s", result.Error)
Expand Down Expand Up @@ -1662,6 +1663,18 @@ func NewTaskToken(db *gorm.DB, tfoResourceSpec models.TFOResourceSpec, _tenantID
}
vclusterClient := kubernetes.NewForConfigOrDie(config)

// Try and create the namespace for the tfResource. Acceptable error is if namespace already exists.
_, err = vclusterClient.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: tfoResource.Namespace,
},
}, metav1.CreateOptions{})
if err != nil {
if !kerrors.IsAlreadyExists(err) {
return nil, fmt.Errorf("namespace/%s could not be created in vcluster: %s", tfoResource.Namespace, err)
}
}

// generate a secret manifest for the jwt token
secretName := util.Trunc(tfoResource.Name, 249) + "-jwt"
secretConfig := corev1.Secret{
Expand Down