Skip to content

Commit

Permalink
feat: add controller reference to resources (#120)
Browse files Browse the repository at this point in the history
* feat: add controller reference to resources

Signed-off-by: Aris Boutselis <aris.boutselis@senseon.io>

* chore: fix func's comment

Signed-off-by: Aris Boutselis <aris.boutselis@senseon.io>

---------

Signed-off-by: Aris Boutselis <aris.boutselis@senseon.io>
  • Loading branch information
Aris Boutselis authored May 24, 2023
1 parent 37d146f commit 293c07f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 12 deletions.
31 changes: 19 additions & 12 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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),
},
},
},
Expand Down Expand Up @@ -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),
},
},
},
Expand All @@ -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),
},
},
},
Expand Down
5 changes: 5 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,8 @@ func ContainsString(slice []string, s string) bool {
}
return false
}

// PtrBool returns a pointer to a bool.
func PtrBool(b bool) *bool {
return &b
}

0 comments on commit 293c07f

Please sign in to comment.