@@ -23,7 +23,6 @@ import (
2323 appsv1 "k8s.io/api/apps/v1"
2424 corev1 "k8s.io/api/core/v1"
2525 v1 "k8s.io/api/core/v1"
26- r1 "k8s.io/api/rbac/v1"
2726 "k8s.io/apimachinery/pkg/api/errors"
2827 "k8s.io/apimachinery/pkg/api/resource"
2928 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -75,101 +74,6 @@ func GetService(config v1alpha1.K8sGPT) (*corev1.Service, error) {
7574 return & service , nil
7675}
7776
78- // GetServiceAccount Create Service Account for K8sGPT and bind it to K8sGPT role
79- func GetServiceAccount (config v1alpha1.K8sGPT ) (* corev1.ServiceAccount , error ) {
80- // Create service account
81- serviceAccount := corev1.ServiceAccount {
82- ObjectMeta : metav1.ObjectMeta {
83- Name : "k8sgpt" ,
84- Namespace : config .Namespace ,
85- OwnerReferences : []metav1.OwnerReference {
86- {
87- Kind : config .Kind ,
88- Name : config .Name ,
89- UID : config .UID ,
90- APIVersion : config .APIVersion ,
91- BlockOwnerDeletion : utils .PtrBool (true ),
92- Controller : utils .PtrBool (true ),
93- },
94- },
95- },
96- }
97-
98- return & serviceAccount , nil
99- }
100-
101- // GetClusterRoleBinding Create cluster role binding for K8sGPT
102- func GetClusterRoleBinding (config v1alpha1.K8sGPT ) (* r1.ClusterRoleBinding , error ) {
103-
104- // Create cluster role binding
105- clusterRoleBinding := r1.ClusterRoleBinding {
106- ObjectMeta : metav1.ObjectMeta {
107- Name : "k8sgpt" ,
108- OwnerReferences : []metav1.OwnerReference {
109- {
110- Kind : config .Kind ,
111- Name : config .Name ,
112- UID : config .UID ,
113- APIVersion : config .APIVersion ,
114- BlockOwnerDeletion : utils .PtrBool (true ),
115- Controller : utils .PtrBool (true ),
116- },
117- },
118- },
119- Subjects : []r1.Subject {
120- {
121- Kind : "ServiceAccount" ,
122- Name : "k8sgpt" ,
123- Namespace : config .Namespace ,
124- },
125- },
126- RoleRef : r1.RoleRef {
127- Kind : "ClusterRole" ,
128- Name : "k8sgpt" ,
129- APIGroup : "rbac.authorization.k8s.io" ,
130- },
131- }
132-
133- return & clusterRoleBinding , nil
134- }
135-
136- // GetClusterRole Create ClusterRole for K8sGPT with cluster read all
137- func GetClusterRole (config v1alpha1.K8sGPT ) (* r1.ClusterRole , error ) {
138-
139- // Create cluster role
140- clusterRole := r1.ClusterRole {
141- ObjectMeta : metav1.ObjectMeta {
142- Name : "k8sgpt" ,
143- OwnerReferences : []metav1.OwnerReference {
144- {
145- Kind : config .Kind ,
146- Name : config .Name ,
147- UID : config .UID ,
148- APIVersion : config .APIVersion ,
149- BlockOwnerDeletion : utils .PtrBool (true ),
150- Controller : utils .PtrBool (true ),
151- },
152- },
153- },
154- Rules : []r1.PolicyRule {
155- {
156- APIGroups : []string {"*" },
157- Resources : []string {"*" },
158- // This is necessary for the creation of integrations
159- Verbs : []string {"create" , "list" , "get" , "watch" , "delete" },
160- },
161- // Allow creation of custom resources
162- {
163- APIGroups : []string {"apiextensions.k8s.io" },
164- Resources : []string {"*" },
165- Verbs : []string {"*" },
166- },
167- },
168- }
169-
170- return & clusterRole , nil
171- }
172-
17377// GetDeployment Create deployment with the latest K8sGPT image
17478func GetDeployment (config v1alpha1.K8sGPT ) (* appsv1.Deployment , error ) {
17579
@@ -345,27 +249,6 @@ func Sync(ctx context.Context, c client.Client,
345249
346250 objs = append (objs , svc )
347251
348- svcAcc , er := GetServiceAccount (config )
349- if er != nil {
350- return er
351- }
352-
353- objs = append (objs , svcAcc )
354-
355- clusterRole , er := GetClusterRole (config )
356- if er != nil {
357- return er
358- }
359-
360- objs = append (objs , clusterRole )
361-
362- clusterRoleBinding , er := GetClusterRoleBinding (config )
363- if er != nil {
364- return er
365- }
366-
367- objs = append (objs , clusterRoleBinding )
368-
369252 deployment , er := GetDeployment (config )
370253 if er != nil {
371254 return er
0 commit comments