Skip to content

Commit

Permalink
add owner reference (#185)
Browse files Browse the repository at this point in the history
Signed-off-by: adam <wjw3323@live>
  • Loading branch information
wujunwei committed Jul 22, 2023
1 parent afe44a6 commit 4ec8d1e
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions pkg/resources/k8sgpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,24 @@ const (
DeploymentName = "k8sgpt-deployment"
)

// Create service for K8sGPT
// GetService Create service for K8sGPT
func GetService(config v1alpha1.K8sGPT) (*v1.Service, error) {

// Create service
service := v1.Service{
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),
},
},
},
Spec: v1.ServiceSpec{
Selector: map[string]string{
Expand All @@ -63,21 +73,31 @@ func GetService(config v1alpha1.K8sGPT) (*v1.Service, error) {
return &service, nil
}

// Create Service Account for K8sGPT and bind it to K8sGPT role
// GetServiceAccount Create a Service Account for K8sGPT and bind it to K8sGPT role
func GetServiceAccount(config v1alpha1.K8sGPT) (*v1.ServiceAccount, error) {

// Create service account
serviceAccount := v1.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
}

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

// Create cluster role binding
Expand Down Expand Up @@ -112,7 +132,7 @@ func GetClusterRoleBinding(config v1alpha1.K8sGPT) (*r1.ClusterRoleBinding, erro
return &clusterRoleBinding, nil
}

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

// Create cluster role
Expand Down Expand Up @@ -142,7 +162,7 @@ func GetClusterRole(config v1alpha1.K8sGPT) (*r1.ClusterRole, error) {
return &clusterRole, nil
}

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

// Create deployment
Expand Down

0 comments on commit 4ec8d1e

Please sign in to comment.