Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat(k8sgpt-rbac.yaml): add new RBAC configuration for k8sgpt operator #274

Closed
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
2cd94bf
✨ feat(k8sgpt-rbac.yaml): add new RBAC configuration for k8sgpt operator
MateSousa Nov 25, 2023
af51fce
πŸ”₯ remove(k8sgpt.go): Remove service account, cluster role and cluster…
MateSousa Nov 25, 2023
7b5ed19
πŸ› fix(k8sgpt-rbac.yaml): correct indentation error
MateSousa Nov 25, 2023
58199da
✨ feat(k8sgpt-cluster-role-binding.yaml): add new Kubernetes ClusterR…
MateSousa Nov 30, 2023
46f4b21
✨ feat(k8sgpt-cluster-role.yaml): add new Kubernetes cluster role wit…
MateSousa Nov 30, 2023
89248c1
πŸ”₯ remove(k8sgpt-rbac.yaml): split resources between files.
MateSousa Nov 30, 2023
b7dd30c
✨ feat(k8sgpt-sa.yaml): add new ServiceAccount for k8sgpt-operator
MateSousa Nov 30, 2023
dcafac4
πŸ”₯ remove(manager-rbac.yaml): remove permissions for apiextensions.k8s.io
MateSousa Nov 30, 2023
6d79177
Merge branch 'main' into feat-migrate-all-rbac-to-helm-chart-template
MateSousa Mar 29, 2024
271a2e1
Merge branch 'main' into feat-migrate-all-rbac-to-helm-chart-template
AlexsJones Mar 29, 2024
a1d919d
fix: fixed conflict mistake
MateSousa May 2, 2024
f5a1a49
chore(deps): update gcr.io/kubebuilder/kube-rbac-proxy docker tag to …
renovate[bot] Mar 30, 2024
21aa48d
fix Amazon Bedrock instructions in README (#397)
aaroniscode Mar 31, 2024
3b4795f
bug: fixing missing details (#402)
AlexsJones Apr 4, 2024
ffcf3ae
chore: small update to fix linter (#403)
AlexsJones Apr 4, 2024
ee6651f
fix(deps): update module google.golang.org/grpc to v1.63.0 (#401)
renovate[bot] Apr 4, 2024
3d67b9f
chore(main): release 0.1.3 (#392)
github-actions[bot] Apr 4, 2024
0c81761
[feature]: add gemini to supported AI backends (#406)
VaibhavMalik4187 Apr 15, 2024
6656760
fix(deps): update module google.golang.org/grpc to v1.63.2 (#409)
renovate[bot] Apr 15, 2024
4226402
fix(deps): update module buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbu…
renovate[bot] Apr 15, 2024
c815df4
fix(deps): update module buf.build/gen/go/k8sgpt-ai/k8sgpt/grpc/go to…
renovate[bot] Apr 15, 2024
91b1692
feature: generate results in the target namespace (#399)
VaibhavMalik4187 Apr 19, 2024
7a02bf2
chore(deps): update actions/upload-artifact digest to 1746f4a (#416)
renovate[bot] Apr 19, 2024
334a945
fix(deps): update controller-gen version to 0.14.0 (#395)
VaibhavMalik4187 Apr 19, 2024
d005325
chore(deps): update azure/setup-helm digest to fe7b79c (#413)
renovate[bot] Apr 19, 2024
a8e32b1
chore(deps): bump golang.org/x/net from 0.21.0 to 0.23.0 (#418)
dependabot[bot] Apr 19, 2024
954d770
chore(deps): update docker/setup-buildx-action digest to d70bba7 (#408)
renovate[bot] Apr 19, 2024
ed4d01e
fix(deps): update module github.com/onsi/gomega to v1.33.0 (#417)
renovate[bot] Apr 19, 2024
9af5d29
fix: change deployment image reconciling (#348)
ultram4rine Apr 22, 2024
fa84906
chore(deps): update helm/kind-action action to v1.10.0 (#424)
renovate[bot] Apr 23, 2024
8c48826
fix(deps): update k8s.io/utils digest to 0849a56 (#425)
renovate[bot] Apr 24, 2024
34c9d10
chore(deps): update anchore/sbom-action action to v0.15.11 (#427)
renovate[bot] Apr 27, 2024
19dc780
chore(deps): update actions/checkout digest to 0ad4b8f (#422)
renovate[bot] Apr 27, 2024
51d2808
chore(deps): update actions/upload-artifact digest to 6546280 (#423)
renovate[bot] Apr 27, 2024
b5c6fc1
Update README.md (#429)
billabongrob Apr 30, 2024
296b8cd
fix(deps): update module buf.build/gen/go/k8sgpt-ai/k8sgpt/protocolbu…
renovate[bot] Apr 30, 2024
acb8011
chore: removed old logic
MateSousa May 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions chart/operator/templates/k8sgpt-cluster-role-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: {{ include "chart.fullname" . }}-k8sgpt
labels:
{{- include "chart.labels" . | nindent 4 }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ include "chart.fullname" . }}-k8sgpt
subjects:
- kind: ServiceAccount
name: "k8sgpt"
namespace: {{ .Release.Namespace }}
23 changes: 23 additions & 0 deletions chart/operator/templates/k8sgpt-cluster-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: {{ include "chart.fullname" . }}-k8sgpt
labels:
{{- include "chart.labels" . | nindent 4 }}
rules:
- apiGroups:
- '*'
resources:
- '*'
verbs:
- create
- list
- get
- watch
- delete
- apiGroups:
- apiextensions.k8s.io
resources:
- '*'
verbs:
- '*'
10 changes: 10 additions & 0 deletions chart/operator/templates/k8sgpt-sa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: "k8sgpt"
labels:
app.kubernetes.io/component: rbac
app.kubernetes.io/created-by: k8sgpt-operator
app.kubernetes.io/part-of: k8sgpt-operator
{{- include "chart.labels" . | nindent 4 }}

6 changes: 0 additions & 6 deletions chart/operator/templates/manager-rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- apiextensions.k8s.io
resources:
- '*'
verbs:
- '*'
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
Expand Down
129 changes: 1 addition & 128 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
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 @@ -102,108 +101,6 @@
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),
},
},
},
ImagePullSecrets: []corev1.LocalObjectReference{},
}
//Add image pull secrets to service account
for _, secret := range config.Spec.ImagePullSecrets {
serviceAccount.ImagePullSecrets = append(serviceAccount.ImagePullSecrets, corev1.LocalObjectReference{
Name: secret.Name,
})
}

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, outOfClusterMode bool, c client.Client) (*appsv1.Deployment, error) {

Expand Down Expand Up @@ -433,31 +330,7 @@
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)
}

svc, er := GetService(config)
if er != nil {
return er
}

objs = append(objs, svc)

deployment, er := GetDeployment(config, outOfClusterMode, c)
deployment, er := GetDeployment(config)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^

if er != nil {
return er
}
Expand Down Expand Up @@ -501,7 +374,7 @@
return nil
}

func doSync(ctx context.Context, clt client.Client, obj client.Object) error {

Check failure on line 377 in pkg/resources/k8sgpt.go

View workflow job for this annotation

GitHub Actions / build

syntax error: unexpected doSync, expected (
var mutateFn controllerutil.MutateFn
switch expect := obj.(type) {
case *appsv1.Deployment:
Expand Down
Loading