Skip to content

Commit 576df4c

Browse files
committedMar 10, 2025
add namespace when required for new task token function
1 parent db71cae commit 576df4c

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed
 

‎pkg/api/resource.go

+13
Original file line numberDiff line numberDiff line change
@@ -1634,6 +1634,7 @@ func NewTaskToken(db *gorm.DB, tfoResourceSpec models.TFOResourceSpec, _tenantID
16341634
return nil, fmt.Errorf("failed to generate taskJWT: %s", err)
16351635

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

1666+
// Try and create the namespace for the tfResource. Acceptable error is if namespace already exists.
1667+
_, err = vclusterClient.CoreV1().Namespaces().Create(context.TODO(), &corev1.Namespace{
1668+
ObjectMeta: metav1.ObjectMeta{
1669+
Name: tfoResourceSpec.TFOResource.Namespace,
1670+
},
1671+
}, metav1.CreateOptions{})
1672+
if err != nil {
1673+
if !kerrors.IsAlreadyExists(err) {
1674+
return nil, fmt.Errorf("namespace/%s could not be created in vcluster: %s", tfoResourceSpec.TFOResource.Namespace, err)
1675+
}
1676+
}
1677+
16651678
// generate a secret manifest for the jwt token
16661679
secretName := util.Trunc(tfoResource.Name, 249) + "-jwt"
16671680
secretConfig := corev1.Secret{

0 commit comments

Comments
 (0)