Reconciler Implementation and Design
- Update the and initialize the
Status
conditions (as defined insamplesource_lifecycle.go
andsamplesource_types.go
)
- Create/reconcile the Receive Adapter (detailed below)
- If successful, update the
Status
andMarkDeployed
src.Status.PropagateDeploymentAvailability(ra)
- Create/reconcile the
SinkBinding
for the Receive Adapter targeting theSink
(detailed below) - MarkSink with the result
src.Status.MarkSink(sb.Status.SinkURI)
- Return a new reconciler event stating that the process is done
return pkgreconciler.NewEvent(corev1.EventTypeNormal, "SampleSourceReconciled", "SampleSource reconciled: \"%s/%s\"", namespace, name)
As part of the source reconciliation, we have to create and deploy (and update if necessary) the underlying receive adapter.
Assemble the ReceiveAdapterArgs
ra, err := r.KubeClientSet.AppsV1().Deployments(namespace).Get(expected.Name, metav1.GetOptions{})
- Otherwise, create the deployment
ra, err = r.KubeClientSet.AppsV1().Deployments(namespace).Create(expected)
- Check if the expected vs existing spec is different, and update the deployment if required
} else if r.podSpecImageSync(expected.Spec.Template.Spec, ra.Spec.Template.Spec) {
ra.Spec.Template.Spec = expected.Spec.Template.Spec
if ra, err = r.KubeClientSet.AppsV1().Deployments(namespace).Update(ra); err != nil {
return ra, err
}
- If updated, record the event
Instead of directly giving the details of the sink to the receive adapter, use a SinkBinding
to bind the receive adapter with the sink.
- Create a
Reference
for the receive adapter deployment. This deployment will be ‘s source:
APIVersion: appsv1.SchemeGroupVersion.String(),
Kind: "Deployment",
Namespace: ra.Namespace,
Name: ra.Name,
}
- Fetch the existing
SinkBinding
namespace := owner.GetObjectMeta().GetNamespace()
sb, err := r.EventingClientSet.SourcesV1alpha2().SinkBindings(namespace).Get(expected.Name, metav1.GetOptions{})
- If it doesn’t exist, create it
sb, err = r.EventingClientSet.SourcesV1alpha2().SinkBindings(namespace).Create(expected)
- Check if the expected vs existing spec is different, and update the
SinkBinding
if required
- If updated, record the event