From df8da54cf8923b62321023a4000083bd57acc7de Mon Sep 17 00:00:00 2001 From: Aris Boutselis Date: Wed, 24 May 2023 18:04:38 +0100 Subject: [PATCH 1/2] feat: add controller reference to resources Signed-off-by: Aris Boutselis --- pkg/resources/k8sgpt.go | 31 +++++++++++++++++++------------ pkg/utils/utils.go | 5 +++++ 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/pkg/resources/k8sgpt.go b/pkg/resources/k8sgpt.go index 26e797d5..2c333b41 100644 --- a/pkg/resources/k8sgpt.go +++ b/pkg/resources/k8sgpt.go @@ -19,6 +19,7 @@ import ( err "errors" "github.com/k8sgpt-ai/k8sgpt-operator/api/v1alpha1" + "github.com/k8sgpt-ai/k8sgpt-operator/pkg/utils" appsv1 "k8s.io/api/apps/v1" v1 "k8s.io/api/core/v1" r1 "k8s.io/api/rbac/v1" @@ -85,10 +86,12 @@ func GetClusterRoleBinding(config v1alpha1.K8sGPT) (*r1.ClusterRoleBinding, erro Name: "k8sgpt", OwnerReferences: []metav1.OwnerReference{ { - Kind: config.Kind, - Name: config.Name, - UID: config.UID, - APIVersion: config.APIVersion, + Kind: config.Kind, + Name: config.Name, + UID: config.UID, + APIVersion: config.APIVersion, + BlockOwnerDeletion: utils.PtrBool(true), + Controller: utils.PtrBool(true), }, }, }, @@ -118,10 +121,12 @@ func GetClusterRole(config v1alpha1.K8sGPT) (*r1.ClusterRole, error) { Name: "k8sgpt", OwnerReferences: []metav1.OwnerReference{ { - Kind: config.Kind, - Name: config.Name, - UID: config.UID, - APIVersion: config.APIVersion, + Kind: config.Kind, + Name: config.Name, + UID: config.UID, + APIVersion: config.APIVersion, + BlockOwnerDeletion: utils.PtrBool(true), + Controller: utils.PtrBool(true), }, }, }, @@ -148,10 +153,12 @@ func GetDeployment(config v1alpha1.K8sGPT) (*appsv1.Deployment, error) { Namespace: config.Namespace, OwnerReferences: []metav1.OwnerReference{ { - Kind: config.Kind, - Name: config.Name, - UID: config.UID, - APIVersion: config.APIVersion, + Kind: config.Kind, + Name: config.Name, + UID: config.UID, + APIVersion: config.APIVersion, + BlockOwnerDeletion: utils.PtrBool(true), + Controller: utils.PtrBool(true), }, }, }, diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 4df73311..06b160e1 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -8,3 +8,8 @@ func ContainsString(slice []string, s string) bool { } return false } + +// Bool returns a pointer to a bool. +func PtrBool(b bool) *bool { + return &b +} From 46a7d36a1e3b2f4c54edf0b44957dcdca6fc69d3 Mon Sep 17 00:00:00 2001 From: Aris Boutselis Date: Wed, 24 May 2023 18:08:17 +0100 Subject: [PATCH 2/2] chore: fix func's comment Signed-off-by: Aris Boutselis --- pkg/utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go index 06b160e1..9b6476c1 100644 --- a/pkg/utils/utils.go +++ b/pkg/utils/utils.go @@ -9,7 +9,7 @@ func ContainsString(slice []string, s string) bool { return false } -// Bool returns a pointer to a bool. +// PtrBool returns a pointer to a bool. func PtrBool(b bool) *bool { return &b }