Skip to content

Commit

Permalink
Add ownerRef to cert
Browse files Browse the repository at this point in the history
  • Loading branch information
sl1pm4t committed Aug 12, 2024
1 parent 480c5da commit 659e0e7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pkg/cloud/services/iam/oidc.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
stderr "errors"
"fmt"
"github.com/aws/aws-sdk-go/aws/awserr"
"k8s.io/utils/ptr"
"path"
"strings"

Expand Down Expand Up @@ -38,7 +39,7 @@ const (
opendIDConfigurationKey = "/.well-known/openid-configuration"
)

func certificateSecret(ctx context.Context, name, namespace, issuer string, dnsNames []string, client client.Client) (*corev1.Secret, error) {
func (s *Service) certificateSecret(ctx context.Context, name, namespace, issuer string, dnsNames []string, client client.Client) (*corev1.Secret, error) {
// check if the secret was already created
certSecret := &corev1.Secret{}
if err := client.Get(ctx, types.NamespacedName{
Expand All @@ -58,8 +59,9 @@ func certificateSecret(ctx context.Context, name, namespace, issuer string, dnsN
Labels: map[string]string{
clusterv1.ProviderNameLabel: "infrastructure-aws",
},
Name: name,
Namespace: namespace,
Name: name,
Namespace: namespace,
OwnerReferences: s.ownerRef(),
},
Spec: v1certmanager.CertificateSpec{
SecretName: name,
Expand Down Expand Up @@ -390,3 +392,18 @@ func (s *Service) reconcileKubeAPIParameters(ctx context.Context) error {

return nil
}

func (s *Service) ownerRef() []metav1.OwnerReference {
c := s.scope.ClusterObj()
c.GetObjectKind().GroupVersionKind().GroupVersion().String()
return []metav1.OwnerReference{
metav1.OwnerReference{
APIVersion: c.GetObjectKind().GroupVersionKind().GroupVersion().String(),
Kind: c.GetObjectKind().GroupVersionKind().Kind,
Name: s.scope.Name(),
UID: c.GetUID(),
Controller: ptr.To(true),
BlockOwnerDeletion: ptr.To(true),
},
}
}

0 comments on commit 659e0e7

Please sign in to comment.