Check the availability of docker image and schedule job if image is unavailable
@@ -403,7 +403,44 @@ func (r *ReconcileAPI) Reconcile(request reconcile.Request) (reconcile.Result, e
log.Info("Successfully created secret")
}
+ analyticsEnabledBool, _ := strconv.ParseBool(analyticsEnabled)
+ dep := createMgwDeployment(instance, imageName, controlConf, analyticsEnabledBool, r)
+ depFound := &appsv1.Deployment{}
+ deperr := r.client.Get(context.TODO(), types.NamespacedName{Name: dep.Name, Namespace: dep.Namespace}, depFound)
+
+ svc := createMgwLBService(instance, userNameSpace)
+ svcFound := &corev1.Service{}
+ svcErr := r.client.Get(context.TODO(), types.NamespacedName{Name: svc.Name, Namespace: svc.Namespace}, svcFound)
+
//Schedule Kaniko pod
+ if imageExist {
+ if deperr != nil && errors.IsNotFound(deperr) {
+ reqLogger.Info("Creating a new Dep", "Dep.Namespace", dep.Namespace, "Dep.Name", dep.Name)
+ deperr = r.client.Create(context.TODO(), dep)
+ if deperr != nil {
+ return reconcile.Result{}, deperr
+ }
+ // deployment created successfully - go to create service
+ } else if deperr != nil {
+ return reconcile.Result{}, deperr
+ }
+
+ if svcErr != nil && errors.IsNotFound(svcErr) {
+ reqLogger.Info("Creating a new Service", "SVC.Namespace", svc.Namespace, "SVC.Name", svc.Name)
+ svcErr = r.client.Create(context.TODO(), svc)
+ if svcErr != nil {
+ return reconcile.Result{}, svcErr
+ }
+ //Service created successfully - don't requeue
+ return reconcile.Result{}, nil
+ } else if svcErr != nil {
+ return reconcile.Result{}, svcErr
+ }
+ // if service already exsits
+ reqLogger.Info("Skip reconcile: Service already exists", "SVC.Namespace",
+ svcFound.Namespace, "SVC.Name", svcFound.Name)
+ return reconcile.Result{}, nil
+ } else {
job := scheduleKanikoJob(instance, imageName, controlConf, jobVolumeMount, jobVolume)
if err := controllerutil.SetControllerReference(instance, job, r.scheme); err != nil {
return reconcile.Result{}, err
@@ -421,15 +458,6 @@ func (r *ReconcileAPI) Reconcile(request reconcile.Request) (reconcile.Result, e
return reconcile.Result{}, jobErr
}
- analyticsEnabledBool, _ := strconv.ParseBool(analyticsEnabled)
- dep := createMgwDeployment(instance, imageName, controlConf, analyticsEnabledBool, r)
- depFound := &appsv1.Deployment{}
- deperr := r.client.Get(context.TODO(), types.NamespacedName{Name: dep.Name, Namespace: dep.Namespace}, depFound)
-
- svc := createMgwLBService(instance, userNameSpace)
- svcFound := &corev1.Service{}
- svcErr := r.client.Get(context.TODO(), types.NamespacedName{Name: svc.Name, Namespace: svc.Namespace}, svcFound)
-
// if kaniko job is succeeded, create the deployment
if kubeJob.Status.Succeeded > 0 {
reqLogger.Info("Job completed successfully", "Job.Namespace", job.Namespace, "Job.Name", job.Name)
@@ -463,9 +491,7 @@ func (r *ReconcileAPI) Reconcile(request reconcile.Request) (reconcile.Result, e
reqLogger.Info("Job is still not completed.", "Job.Status", job.Status)
return reconcile.Result{}, deperr
}
- // Job already exists - don't requeue
- reqLogger.Info("Skip reconcile: Job already exists", "Job.Namespace", job.Namespace, "Job.Name", job.Name)
- return reconcile.Result{}, jobErr
+ }
}
// gets the data from analytics secret
