Skip to content

Commit

Permalink
Set cert suite pod's owner reference to be corresponding run CR (#44)
Browse files Browse the repository at this point in the history
The run CR is set as the owner of the cnf cert suite pod created when
reconcile function was triggered.
That so, if the CR is deleted, the pod will also be deleted.
  • Loading branch information
shirmoran authored Mar 18, 2024
1 parent 3dd7334 commit 97bcf66
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/controller/cnf-cert-job/cnfcertjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

"github.com/test-network-function/cnf-certsuite-operator/internal/controller/definitions"
)
Expand Down Expand Up @@ -244,6 +245,19 @@ func WithEnableDataCollection(enableDataCollection string) func(*corev1.Pod) err
}
}

func WithOwnerReference(ownerUID types.UID, ownerName, ownerKind, ownerAPIVersion string) func(*corev1.Pod) error {
return func(p *corev1.Pod) error {
ownerReference := &metav1.OwnerReference{
APIVersion: ownerAPIVersion,
Kind: ownerKind,
Name: ownerName,
UID: ownerUID,
}
p.ObjectMeta.OwnerReferences = []metav1.OwnerReference{*ownerReference}
return nil
}
}

func getSideCarAppContainer(p *corev1.Pod) *corev1.Container {
for i := range p.Spec.Containers {
if p.Spec.Containers[i].Name == definitions.CnfCertSuiteSidecarContainerName {
Expand Down
1 change: 1 addition & 0 deletions internal/controller/cnfcertificationsuiterun_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ func (r *CnfCertificationSuiteRunReconciler) Reconcile(ctx context.Context, req
cnfcertjob.WithPreflightSecret(runCR.Spec.PreflightSecretName),
cnfcertjob.WithSideCarApp(sideCarImage),
cnfcertjob.WithEnableDataCollection(strconv.FormatBool(runCR.Spec.EnableDataCollection)),
cnfcertjob.WithOwnerReference(runCR.UID, runCR.Name, runCR.Kind, runCR.APIVersion),
)
if err != nil {
logger.Errorf("Failed to create CNF Cert job pod spec: %w", err)
Expand Down

0 comments on commit 97bcf66

Please sign in to comment.