Skip to content

Commit

Permalink
🔥 remove(k8sgpt.go): Remove service account, cluster role and cluster…
Browse files Browse the repository at this point in the history
… role binding functions

The service account, cluster role, and cluster role binding functions were removed from the k8sgpt.go file. These functions were creating a service account, cluster role, and cluster role binding for K8sGPT, but they are no longer needed.

Signed-off-by: MateSousa <[email protected]>
  • Loading branch information
MateSousa committed Nov 25, 2023
1 parent 40b4daf commit 6f8189f
Showing 1 changed file with 0 additions and 117 deletions.
117 changes: 0 additions & 117 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
r1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -75,101 +74,6 @@ func GetService(config v1alpha1.K8sGPT) (*corev1.Service, error) {
return &service, nil
}

// GetServiceAccount Create Service Account for K8sGPT and bind it to K8sGPT role
func GetServiceAccount(config v1alpha1.K8sGPT) (*corev1.ServiceAccount, error) {
// Create service account
serviceAccount := corev1.ServiceAccount{
ObjectMeta: metav1.ObjectMeta{
Name: "k8sgpt",
Namespace: config.Namespace,
OwnerReferences: []metav1.OwnerReference{
{
Kind: config.Kind,
Name: config.Name,
UID: config.UID,
APIVersion: config.APIVersion,
BlockOwnerDeletion: utils.PtrBool(true),
Controller: utils.PtrBool(true),
},
},
},
}

return &serviceAccount, nil
}

// GetClusterRoleBinding Create cluster role binding for K8sGPT
func GetClusterRoleBinding(config v1alpha1.K8sGPT) (*r1.ClusterRoleBinding, error) {

// Create cluster role binding
clusterRoleBinding := r1.ClusterRoleBinding{
ObjectMeta: metav1.ObjectMeta{
Name: "k8sgpt",
OwnerReferences: []metav1.OwnerReference{
{
Kind: config.Kind,
Name: config.Name,
UID: config.UID,
APIVersion: config.APIVersion,
BlockOwnerDeletion: utils.PtrBool(true),
Controller: utils.PtrBool(true),
},
},
},
Subjects: []r1.Subject{
{
Kind: "ServiceAccount",
Name: "k8sgpt",
Namespace: config.Namespace,
},
},
RoleRef: r1.RoleRef{
Kind: "ClusterRole",
Name: "k8sgpt",
APIGroup: "rbac.authorization.k8s.io",
},
}

return &clusterRoleBinding, nil
}

// GetClusterRole Create ClusterRole for K8sGPT with cluster read all
func GetClusterRole(config v1alpha1.K8sGPT) (*r1.ClusterRole, error) {

// Create cluster role
clusterRole := r1.ClusterRole{
ObjectMeta: metav1.ObjectMeta{
Name: "k8sgpt",
OwnerReferences: []metav1.OwnerReference{
{
Kind: config.Kind,
Name: config.Name,
UID: config.UID,
APIVersion: config.APIVersion,
BlockOwnerDeletion: utils.PtrBool(true),
Controller: utils.PtrBool(true),
},
},
},
Rules: []r1.PolicyRule{
{
APIGroups: []string{"*"},
Resources: []string{"*"},
// This is necessary for the creation of integrations
Verbs: []string{"create", "list", "get", "watch", "delete"},
},
// Allow creation of custom resources
{
APIGroups: []string{"apiextensions.k8s.io"},
Resources: []string{"*"},
Verbs: []string{"*"},
},
},
}

return &clusterRole, nil
}

// GetDeployment Create deployment with the latest K8sGPT image
func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) {

Expand Down Expand Up @@ -345,27 +249,6 @@ func Sync(ctx context.Context, c client.Client,

objs = append(objs, svc)

svcAcc, er := GetServiceAccount(config)
if er != nil {
return er
}

objs = append(objs, svcAcc)

clusterRole, er := GetClusterRole(config)
if er != nil {
return er
}

objs = append(objs, clusterRole)

clusterRoleBinding, er := GetClusterRoleBinding(config)
if er != nil {
return er
}

objs = append(objs, clusterRoleBinding)

deployment, er := GetDeployment(config)
if er != nil {
return er
Expand Down

0 comments on commit 6f8189f

Please sign in to comment.