Skip to content

Commit 61603fe

Browse files
authored
feat(rbac): CEL(common expression language) support (#90)
1 parent cd72ec7 commit 61603fe

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

cloud/data_source_rolebinding.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ func dataSourceRoleBinding() *schema.Resource {
5757
Type: schema.TypeString,
5858
},
5959
},
60+
"cel": {
61+
Type: schema.TypeString,
62+
Computed: true,
63+
Description: descriptions["rolebinding_cel"],
64+
Elem: &schema.Schema{
65+
Type: schema.TypeString,
66+
},
67+
},
6068
},
6169
}
6270
}
@@ -101,6 +109,12 @@ func DataSourceRoleBindingRead(ctx context.Context, d *schema.ResourceData, meta
101109
}
102110
}
103111

112+
if roleBinding.Spec.CEL != nil {
113+
if err = d.Set("cel", roleBinding.Spec.CEL); err != nil {
114+
return diag.FromErr(fmt.Errorf("ERROR_SET_CEL: %w", err))
115+
}
116+
}
117+
104118
if len(roleBinding.Status.Conditions) >= 1 {
105119
for _, condition := range roleBinding.Status.Conditions {
106120
if condition.Type == "Ready" && condition.Status == "True" {

cloud/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ func init() {
172172
"rolebinding_cluster_role_name": "The predefined role name",
173173
"rolebinding_service_account_names": "The list of service accounts that are role binding names ",
174174
"dns": "The DNS ID and name. Must specify together",
175+
"rolebinding_cel": "The CEL(Common Expression Langauge) for conditional role binding",
175176
}
176177
}
177178

cloud/resource_rolebinding.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/streamnative/cloud-api-server/pkg/apis/cloud/v1alpha1"
1010
apierrors "k8s.io/apimachinery/pkg/api/errors"
1111
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12+
"k8s.io/utils/pointer"
1213
"strings"
1314
"time"
1415
)
@@ -82,6 +83,14 @@ func resourceRoleBinding() *schema.Resource {
8283
Type: schema.TypeString,
8384
},
8485
},
86+
"cel": {
87+
Type: schema.TypeString,
88+
Optional: true,
89+
Description: descriptions["rolebinding_cel"],
90+
Elem: &schema.Schema{
91+
Type: schema.TypeString,
92+
},
93+
},
8594
},
8695
}
8796
}
@@ -92,6 +101,7 @@ func resourceRoleBindingCreate(ctx context.Context, d *schema.ResourceData, m in
92101

93102
predefinedRoleName := d.Get("cluster_role_name").(string)
94103
serviceAccountNames := d.Get("service_account_names").([]interface{})
104+
cel := d.Get("cel").(string)
95105

96106
clientSet, err := getClientSet(getFactoryFromMeta(m))
97107
if err != nil {
@@ -127,6 +137,9 @@ func resourceRoleBindingCreate(ctx context.Context, d *schema.ResourceData, m in
127137
})
128138
}
129139
}
140+
if cel != "" {
141+
rb.Spec.CEL = pointer.String(cel)
142+
}
130143

131144
if _, err := clientSet.CloudV1alpha1().RoleBindings(namespace).Create(ctx, rb, metav1.CreateOptions{
132145
FieldManager: "terraform-create",

0 commit comments

Comments
 (0)