Reconciler Implementation and Design
Update the and initialize the
Status
conditions as defined insamplesource_lifecycle.go
andsamplesource_types.go
:Follow the later Reconcile/Create the Receive Adapter procedure.
If successful, update the
Status
andMarkDeployed
:src.Status.PropagateDeploymentAvailability(ra)
Follow the later procedure for the receive adapter targeting the sink.
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)
Verify the specified kubernetes resources are valid, and update the Status
accordingly
Assemble the ReceiveAdapterArgs
NB The exact arguments may change based on functional requirements Create the underlying deployment from the arguments provided, matching pod templates, labels, owner references, etc as needed to fill out the deployment Example: pkg/reconciler/sample/resources/receive_adapter.go
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
}
Instead of directly giving the details of the sink to the receive adapter, use a SinkBinding
to bind the receive adapter with the sink.
Steps here are almost the same with the Deployment
reconciliation mentioned earlier, but it is for another resource, SinkBinding
.
Create a
Reference
for the receive adapter deployment. This deployment will beSinkBinding
‘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-