@@ -57,7 +57,7 @@ var _ = Describe("Cmd", func() {
57
57
DefaultPort : 9900 ,
58
58
}},
59
59
},
60
- Rbac : []rbacv1.PolicyRule {{
60
+ ClusterRbac : []rbacv1.PolicyRule {{
61
61
Verbs : []string {"*" },
62
62
APIGroups : []string {"coordination.k8s.io" },
63
63
Resources : []string {"leases" },
@@ -1230,7 +1230,7 @@ var _ = Describe("Cmd", func() {
1230
1230
{
1231
1231
Name : "painter" ,
1232
1232
CustomEnableCondition : "and $painter.enabled $.Values.test1.enabled $.Values.test2.enabled" ,
1233
- Rbac : []rbacv1.PolicyRule {
1233
+ ClusterRbac : []rbacv1.PolicyRule {
1234
1234
{
1235
1235
Verbs : []string {"GET" },
1236
1236
},
@@ -1337,7 +1337,7 @@ var _ = Describe("Cmd", func() {
1337
1337
{
1338
1338
Name : "painter" ,
1339
1339
NamespaceFromValuePath : "$.Values.common.namespace" ,
1340
- Rbac : []rbacv1.PolicyRule {
1340
+ ClusterRbac : []rbacv1.PolicyRule {
1341
1341
{
1342
1342
Verbs : []string {"GET" },
1343
1343
},
@@ -1816,6 +1816,115 @@ roleRef:
1816
1816
map [string ]interface {}{"FOO" : map [string ]interface {}{"valueFrom" : map [string ]interface {}{"secretKeyRef" : map [string ]interface {}{"name" : "bar" , "key" : "baz" }}}},
1817
1817
[]v1.EnvVar {{Name : "FOO" , ValueFrom : & v1.EnvVarSource {SecretKeyRef : & v1.SecretKeySelector {LocalObjectReference : v1.LocalObjectReference {Name : "bar" }, Key : "baz" }}}}),
1818
1818
)
1819
+
1820
+ It ("can configure cluster-scoped and namespace-scoped RBAC" , func () {
1821
+ cmd := & Command {
1822
+ RenderProtos : false ,
1823
+ Chart : & Chart {
1824
+ Operators : []Operator {
1825
+ {
1826
+ Name : "painter" ,
1827
+ CustomEnableCondition : "$painter.enabled" ,
1828
+ ClusterRbac : []rbacv1.PolicyRule {
1829
+ {
1830
+ Verbs : []string {"GET" },
1831
+ },
1832
+ },
1833
+ NamespaceRbac : []rbacv1.PolicyRule {
1834
+ {
1835
+ Verbs : []string {"GET" , "LIST" , "WATCH" },
1836
+ APIGroups : []string {"" },
1837
+ Resources : []string {"secrets" },
1838
+ },
1839
+ },
1840
+ },
1841
+ },
1842
+ Values : nil ,
1843
+ Data : Data {
1844
+ ApiVersion : "v1" ,
1845
+ Description : "" ,
1846
+ Name : "Painting Operator" ,
1847
+ Version : "v0.0.1" ,
1848
+ Home : "https://docs.solo.io/skv2/latest" ,
1849
+ Sources : []string {
1850
+ "https://github.com/solo-io/skv2" ,
1851
+ },
1852
+ },
1853
+ },
1854
+
1855
+ ManifestRoot : "codegen/test/chart" ,
1856
+ }
1857
+
1858
+ Expect (cmd .Execute ()).NotTo (HaveOccurred (), "failed to execute command" )
1859
+
1860
+ absPath , err := filepath .Abs ("./codegen/test/chart/templates/rbac.yaml" )
1861
+ Expect (err ).NotTo (HaveOccurred (), "failed to get abs path" )
1862
+
1863
+ rbac , err := os .ReadFile (absPath )
1864
+ Expect (err ).NotTo (HaveOccurred (), "failed to read rbac.yaml" )
1865
+ roleTmpl := `
1866
+ kind: Role
1867
+ apiVersion: rbac.authorization.k8s.io/v1
1868
+ metadata:
1869
+ name: painter
1870
+ namespace: {{ default .Release.Namespace $.Values.painter.namespace }}
1871
+ labels:
1872
+ app: painter
1873
+ rules:
1874
+ - apiGroups:
1875
+ - ""
1876
+ resources:
1877
+ - secrets
1878
+ verbs:
1879
+ - GET
1880
+ - LIST
1881
+ - WATCH`
1882
+ roleBindingTmpl := `
1883
+ kind: RoleBinding
1884
+ apiVersion: rbac.authorization.k8s.io/v1
1885
+ metadata:
1886
+ name: painter
1887
+ namespace: {{ default .Release.Namespace $.Values.painter.namespace }}
1888
+ labels:
1889
+ app: painter
1890
+ subjects:
1891
+ - kind: ServiceAccount
1892
+ name: painter
1893
+ namespace: {{ default .Release.Namespace $.Values.painter.namespace }}
1894
+ roleRef:
1895
+ kind: Role
1896
+ name: painter
1897
+ apiGroup: rbac.authorization.k8s.io`
1898
+ clusterRoleTmpl := `
1899
+ kind: ClusterRole
1900
+ apiVersion: rbac.authorization.k8s.io/v1
1901
+ metadata:
1902
+ name: painter-{{ default .Release.Namespace $.Values.painter.namespace }}
1903
+ labels:
1904
+ app: painter
1905
+ rules:
1906
+ - verbs:
1907
+ - GET`
1908
+ clusterRoleBindingTmpl := `
1909
+ kind: ClusterRoleBinding
1910
+ apiVersion: rbac.authorization.k8s.io/v1
1911
+ metadata:
1912
+ name: painter-{{ default .Release.Namespace $.Values.painter.namespace }}
1913
+ labels:
1914
+ app: painter
1915
+ subjects:
1916
+ - kind: ServiceAccount
1917
+ name: painter
1918
+ namespace: {{ default .Release.Namespace $.Values.painter.namespace }}
1919
+ roleRef:
1920
+ kind: ClusterRole
1921
+ name: painter-{{ default .Release.Namespace $.Values.painter.namespace }}
1922
+ apiGroup: rbac.authorization.k8s.io`
1923
+ Expect (rbac ).To (ContainSubstring (roleTmpl ))
1924
+ Expect (rbac ).To (ContainSubstring (roleBindingTmpl ))
1925
+ Expect (rbac ).To (ContainSubstring (clusterRoleTmpl ))
1926
+ Expect (rbac ).To (ContainSubstring (clusterRoleBindingTmpl ))
1927
+ })
1819
1928
})
1820
1929
1821
1930
func helmTemplate (path string , values interface {}) []byte {
0 commit comments