<pre><code>import (
    &quot;context&quot;
    &quot;fmt&quot;

    infinimeshv1beta1 &quot;github.com/infinimesh/operator/pkg/apis/infinimesh/v1beta1&quot;
    v1beta1 &quot;k8s.io/api/batch/v1beta1&quot;
    corev1 &quot;k8s.io/api/core/v1&quot;
    &quot;k8s.io/apimachinery/pkg/api/errors&quot;
    metav1 &quot;k8s.io/apimachinery/pkg/apis/meta/v1&quot;
    &quot;k8s.io/apimachinery/pkg/types&quot;
    &quot;sigs.k8s.io/controller-runtime/pkg/controller/controllerutil&quot;
    &quot;sigs.k8s.io/controller-runtime/pkg/reconcile&quot;
)

func (r *ReconcilePlatform) reconcileResetRootAccount(request reconcile.Request, instance *infinimeshv1beta1.Platform) error {
    log := logger.WithName(&quot;Reset Root Account Pwd&quot;)
    job := &amp;v1beta1.CronJob{
        ObjectMeta: metav1.ObjectMeta{
            Name: &quot;example&quot;,
        },
        Spec: v1beta1.CronJobSpec{
            Schedule:          &quot;* * * * *&quot;,
            ConcurrencyPolicy: v1beta1.ForbidConcurrent,
            JobTemplate: v1beta1.JobTemplate{
                Spec: v1beta1.JobTemplateSpec{
                    Template: corev1.PodTemplateSpec{
                        Spec: corev1.PodSpec{
                            RestartPolicy: &quot;Never&quot;,
                            Containers: []corev1.Container{
                                {
                                    Name:  &quot;cli&quot;,
                                    Image: &quot;busybox&quot;,
                                    Command: []string{
                                        &quot;/bin/bash&quot;,
                                        &quot;-c&quot;,
                                        &quot;echo 1&quot;,
                                    },
                                    ImagePullPolicy: &quot;Always&quot;,
                                },
                            },
                        },
                    },
                },
            },
        },
    }
</code></pre>
<p>I am getting error here</p>
<pre><code>JobTemplate: v1beta1.JobTemplate{
                Spec: v1beta1.JobTemplateSpec{
                    Template: corev1.PodTemplateSpec{

</code></pre>
<p>as might be I am not defining it in the right way. Please guide me the right way to create a cronjob in Go. You can also write your own way of writing cronjobs in golang as I want to automate the cronjob in the kubernetes operator as when I restart the platform, cronjob will create automatically.</p>

ayesha kaleem
<p>A cronjob wraps a job which wraps a pod.So you need to put the <code>PodTemplateSpec</code> inside a <code>JobSpec</code> inside the <code>CronJobSpec</code>.</p>
<pre><code>    cronjob := &amp;v1beta1.CronJob{
        ObjectMeta: metav1.ObjectMeta{
            Name:      &quot;demo-cronjob&quot;,
            Namespace: &quot;gitlab&quot;,
        },
        Spec: v1beta1.CronJobSpec{
            Schedule:          &quot;* * * * *&quot;,
            ConcurrencyPolicy: v1beta1.ForbidConcurrent,
            JobTemplate: v1beta1.JobTemplateSpec{
                Spec: batchv1.JobSpec{
                    Template: v1.PodTemplateSpec{
                        Spec: v1.PodSpec{
                          ...
                        },
                    },
                },
            },
        },
    }
</code></pre>
