Skip to content

Commit

Permalink
fix(nimbus-k8tls): Remove ownerref from ns
Browse files Browse the repository at this point in the history
Signed-off-by: Anurag Rajawat <[email protected]>
  • Loading branch information
Anurag Rajawat committed Jun 25, 2024
1 parent 9f8fa93 commit 920965c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pkg/adapter/nimbus-k8tls/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

func main() {
ctrl.SetLogger(zap.New(zap.UseDevMode(true)))
ctrl.SetLogger(zap.New())
logger := ctrl.Log

ctx, cancelFunc := context.WithCancel(context.Background())
Expand Down
4 changes: 2 additions & 2 deletions pkg/adapter/nimbus-k8tls/manager/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func createOrUpdateCj(ctx context.Context, logger logr.Logger, cwnp v1alpha1.Clu
logger.Info("configured Kubernetes CronJob", "CronJob.Name", cronJob.Name, "CronJob.Namespace", cronJob.Namespace)
}

if err = adapterutil.UpdateCwnpStatus(ctx, k8sClient, "CronJob/"+cronJob.Name, cwnp.Name, false); err != nil {
if err = adapterutil.UpdateCwnpStatus(ctx, k8sClient, cronJob.Namespace+"/CronJob/"+cronJob.Name, cwnp.Name, false); err != nil {
logger.Error(err, "failed to update ClusterNimbusPolicy status")
}
}
Expand All @@ -67,7 +67,7 @@ func deleteCronJobs(ctx context.Context, logger logr.Logger, cwnpName string, cr
continue
}

if err := adapterutil.UpdateCwnpStatus(ctx, k8sClient, "CronJob/"+cronJob.Name, cwnpName, true); err != nil {
if err := adapterutil.UpdateCwnpStatus(ctx, k8sClient, cronJob.Namespace+"/CronJob/"+cronJob.Name, cwnpName, true); err != nil {
logger.Error(err, "failed to update ClusterNimbusPolicy status")
}
logger.Info("Dangling Kubernetes CronJob deleted", "CronJobJob.Name", cronJob.Name, "CronJob.Namespace", cronJob.Namespace)
Expand Down
8 changes: 6 additions & 2 deletions pkg/adapter/nimbus-k8tls/manager/k8tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,12 @@ func setupK8tlsEnv(ctx context.Context, cwnp v1alpha1.ClusterNimbusPolicy, schem
objs := []client.Object{ns, cm, sa, clusterRole, clusterRoleBinding}
for idx := range objs {
objToCreate := objs[idx]
if err := ctrl.SetControllerReference(&cwnp, objToCreate, scheme); err != nil {
return err

// Don't set owner ref on namespace.
if idx != 0 {
if err := ctrl.SetControllerReference(&cwnp, objToCreate, scheme); err != nil {
return err
}
}

var existingObj client.Object
Expand Down

0 comments on commit 920965c

Please sign in to comment.