Skip to content

Commit

Permalink
Set KafkaUser as owner for its corresponding Certificate object
Browse files Browse the repository at this point in the history
  • Loading branch information
stoader authored Sep 22, 2021
1 parent 8b28f39 commit 32828b9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pkg/pki/certmanagerpki/certmanager_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *certManager) clusterCertificateForUser(
user *v1alpha1.KafkaUser, clusterDomain string) *certv1.Certificate {
caName, caKind := c.getCA(user)
cert := &certv1.Certificate{
ObjectMeta: templates.ObjectMetaWithCustomNamespaceAndWithoutLabels(user.GetName(), user.GetNamespace(), c.cluster),
ObjectMeta: templates.ObjectMetaWithKafkaUserOwnerAndWithoutLabels(user.GetName(), user),
Spec: certv1.CertificateSpec{
SecretName: user.Spec.SecretName,
PrivateKey: &certv1.CertificatePrivateKey{
Expand Down
15 changes: 8 additions & 7 deletions pkg/resources/templates/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package templates
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/banzaicloud/koperator/api/v1alpha1"
"github.com/banzaicloud/koperator/api/v1beta1"
"github.com/banzaicloud/koperator/pkg/util"
)
Expand All @@ -40,17 +41,17 @@ func ObjectMeta(name string, labels map[string]string, cluster *v1beta1.KafkaClu
}
}

// ObjectMetaWithCustomNamespaceAndWithoutLabels returns a metav1.ObjectMeta object with custom namespace, ownerReference and name
func ObjectMetaWithCustomNamespaceAndWithoutLabels(name, namespace string, cluster *v1beta1.KafkaCluster) metav1.ObjectMeta {
// ObjectMetaWithKafkaUserOwnerAndWithoutLabels returns a metav1.ObjectMeta object with ownerReference and name
func ObjectMetaWithKafkaUserOwnerAndWithoutLabels(name string, user *v1alpha1.KafkaUser) metav1.ObjectMeta {
return metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Namespace: user.GetNamespace(),
OwnerReferences: []metav1.OwnerReference{
{
APIVersion: cluster.APIVersion,
Kind: cluster.Kind,
Name: cluster.Name,
UID: cluster.UID,
APIVersion: user.APIVersion,
Kind: user.Kind,
Name: user.Name,
UID: user.UID,
Controller: util.BoolPointer(true),
BlockOwnerDeletion: util.BoolPointer(true),
},
Expand Down

0 comments on commit 32828b9

Please sign in to comment.