Skip to content

Instantly share code, notes, and snippets.

@lordofthejars
Created December 24, 2018 08:20
func (r *ReconcileHello) Reconcile(request reconcile.Request) (reconcile.Result, error) {
reqLogger := log.WithValues("Request.Namespace", request.Namespace, "Request.Name", request.Name)
reqLogger.Info("Reconciling Hello")
// Fetch the Hello instance
instance := &hellov1alpha1.Hello{}
err := r.client.Get(context.TODO(), request.NamespacedName, instance)
...
// Define a new Pod object
pod := newPodForCR(instance)
// Set Hello instance as the owner and controller
if err := controllerutil.SetControllerReference(instance, pod, r.scheme); err != nil {
return reconcile.Result{}, err
}
...
}
func newPodForCR(cr *hellov1alpha1.Hello) *corev1.Pod {
labels := map[string]string{
"app": cr.Name,
}
return &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: cr.Name + "-pod",
Namespace: cr.Namespace,
Labels: labels,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "busybox",
Image: "busybox",
Command: []string{"sleep", "3600"},
},
},
},
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment