Commit 24876cee authored by Ioannis Plakas's avatar Ioannis Plakas

minor fixes

parent 2f47e8cb
......@@ -6,8 +6,8 @@ to the Kubernetes Cluster and reconciling in order to match the desired
state described in `Spec` to the observed state (`Status`).
## Objective
The purpose of this controller is to create the a number of pods that will
run a command.Both the pods and the command will be provided in CRD.
The purpose of this controller is to create the number of pods that will
run a command. Both the pods and the command will be provided in CRD.
## Prerequesties
......@@ -35,12 +35,13 @@ kubectl get crds
make manifests
make install
```
The created resource is retrieved `kubectl get crd`
The created resource is retrieved: `kubectl get crd`
![Image of new crds](images/crd.png?raw=true)
---------------------------------------------------------
4. The generated CRD is fully described in yaml format in `config/crd/bases/ubi.ubitech.eu_pgouvs.yaml` which is generated by the corresponding go type
(pgouv_types.go)
```go
// PgouvSpec defines the desired state of Pgouv
......@@ -134,19 +135,19 @@ Pods need to get deleted.
pod := spawn.NewPodForCR(instance)
//Set owner for the pod before initiate it
if err = controllerutil.SetControllerReference(instance, pod, r.Scheme); err != nil {
return reconcile.Result{}, err
return reconcile.Result{}, err
}
err = r.Create(context, pod)
if err != nil {
if errors.IsNotFound(err) {
return reconcile.Result{}, nil
}
return reconcile.Result{}, err
if errors.IsNotFound(err) {
return reconcile.Result{}, nil
}
return reconcile.Result{}, err
}
instance.Status.AliveRelplicas++
err = r.Status().Update(context, instance)
if err != nil {
return ctrl.Result{}, err
return ctrl.Result{}, err
}
logger.Info("Pod created")
return reconcile.Result{}, err
......@@ -157,31 +158,26 @@ Or when we need to delete Pods
else if diff < 0 {
logger.Info("need to delete a pod")
podlist := &corev1.PodList{}
//lbs := map[string]string{
// "app": instance.Name,
// }
//labelSelector := labels.SelectorFromSet(lbs)
// lsopt := &client.ListOption{LabelSelector: labelSelector, Namespace: instance.name}
err := r.List(context, podlist, client.InNamespace(req.Namespace), client.MatchingLabels{"app": instance.Name})
if err != nil {
if errors.IsNotFound(err) {
return reconcile.Result{}, nil
}
return reconcile.Result{}, err
if errors.IsNotFound(err) {
return reconcile.Result{}, nil
}
return reconcile.Result{}, err
}
logger.Info("Deleted Pod")
instance.Status.AliveRelplicas--
logger.Info("Update deteted status")
err = r.Status().Update(context, instance)
if err != nil {
return ctrl.Result{}, err
}
if err != nil {
return ctrl.Result{}, err
}
err = r.Delete(context, &podlist.Items[0])
if err != nil {
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
}
if err != nil {
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
}
```
-------------------------------------------------------
9. The Reconcile function needs to have a Manger (possibly managing other controllers/reconcilers)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment