Skip to content

Commit

Permalink
Merge branch 'main' into feature/support-serverless-cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
tuteng authored Oct 31, 2024
2 parents 23c615d + 8961cde commit 3d8c684
Showing 1 changed file with 44 additions and 1 deletion.
45 changes: 44 additions & 1 deletion cloud/resource_service_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,46 @@ func resourceServiceAccountCreate(ctx context.Context, d *schema.ResourceData, m
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_CREATE_SERVICE_ACCOUNT: %w", err))
}

if admin {
_, err := clientSet.CloudV1alpha1().RoleBindings(namespace).Create(ctx, &v1alpha1.RoleBinding{
TypeMeta: metav1.TypeMeta{
Kind: "RoleBinding",
APIVersion: v1alpha1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: v1alpha1.SchemeGroupVersion.String(),
Kind: "ServiceAccount",
Name: serviceAccount.Name,
UID: serviceAccount.UID,
},
},
},
Spec: v1alpha1.RoleBindingSpec{
RoleRef: v1alpha1.RoleRef{
APIGroup: "cloud.streamnative.io",
Kind: "Role",
Name: "admin",
},
Subjects: []v1alpha1.Subject{
{
Kind: "ServiceAccount",
APIGroup: "cloud.streamnative.io",
Name: name,
},
},
},
}, metav1.CreateOptions{
FieldManager: "terraform-create",
})
if err != nil {
return diag.FromErr(fmt.Errorf("ERROR_CREATE_ROLE_BINDING: %w", err))
}
}
privateKeyData := ""
if len(serviceAccount.Status.Conditions) > 0 && serviceAccount.Status.Conditions[0].Type == "Ready" {
privateKeyData = serviceAccount.Status.PrivateKeyData
Expand Down Expand Up @@ -172,7 +212,10 @@ func resourceServiceAccountDelete(ctx context.Context, d *schema.ResourceData, m
}
namespace := d.Get("organization").(string)
name := d.Get("name").(string)
err = clientSet.CloudV1alpha1().ServiceAccounts(namespace).Delete(ctx, name, metav1.DeleteOptions{})
foreground := metav1.DeletePropagationForeground
err = clientSet.CloudV1alpha1().ServiceAccounts(namespace).Delete(ctx, name, metav1.DeleteOptions{
PropagationPolicy: &foreground,
})
if err != nil {
return diag.FromErr(fmt.Errorf("DELETE_SERVICE_ACCOUNT: %w", err))
}
Expand Down

0 comments on commit 3d8c684

Please sign in to comment.