# TektonCD Operator Reconciler Refactoring v0.1
Motivation:
- at present all resources are re-applied again and again, and the logs are repeating lines of "creteing reosurce" , "updating etc". current logs are not useful/
- create check/conditions to mark stages in installation/upgrade lifecycle
- re-attempt only the part of the lifecycle that fails
Side effect:
- resources will not be reapplied over and over (effectively reseting user changes)
- change from current behavior
## sideNote:
check <conditio>=True
if false
perform operator logic (create/update resource)
if err
requeue
else
if no response from controllers/cluster needed (eg: pod creation)
continue
else
requeue
## Reconcile
if verison is different
reset all conditions
continue
if !CRDS_INSTALLED:
create CRDs {
filter through manifests, and install
}
if err
set phase = Error
return and requeue
else
set condition CRDS_INSTALLED=true
set phase = Installing Dependencies
requeue #as the api resoruces changed in etcd
if !CLUSTERSCOPED_DEPENDENCIES_INSTALLED:
create ClusterScoped Resources (namespace, ClusterRoles)
if err:
set phase = Error
requeue err
else
set CLUSTERSCOPED_DEPENDENCIES_INSTALLED = true
set phase = Installing Dependencies
requeue true #as the api resoruces changed in etcd
if !NAMESPACED_DEPENDENCIES_INSTALLED:
create Namespaced Resources (namespace, ClusterRoles)
if err:
set phase = Error
requeue err
else
set NAMESPACED_DEPENDENCIES_INSTALLED = true
set phase = Installing Webhooks
requeue true #as the api resoruces changed in etcd
if !WEBHOOK_READY
check webhook status
- check deployment is up
if false
create deployment
set phase = Installing Webhooks
requeue true
- svc has endpoints listed
if false
try to handle error
set phase = Error
requeue error
set WEBHOOK_READY=true
set phase = Installing Controller
requeue #as the api resoruces changed in etcd
if !CONTROLLER_READY
if !deployment pods not ready
create deployment
if err
set phase = error
requeue error
set phase = Installing Controller
requeue true #so that pods can come up
else
set phase = Validating
set CONTROLLER_READY = true
requeue true
if !PIPELINES_READY
validate installation {
#check tektoncd/pipelines and plumbing to see if there are additinal checks that can be perfromed as part of best practices
}
if !vadlid
set phase = error
requue error
else
set PIPELINE_READY = true
set phase = Ready
requeue nil #do not requeue
perform end to end validation
if not valid set respective condition to false
reconcile true
else
reconcile nil
---
## Finalizer
err = fetch TP CR instance
if err
if err == Not Found
return nil
return errr # requeue !!
run extensions Finzaliwer logic
<!-- Run uninstall logic-->
when there is a delete event on instance of TektonPipeline 'pipeline'
FinalizeKind will be called
### Finalizer logic
delete CRDs
enusre CRDs are removed (so that they are cascade finzalided and deleted)
delete webhooks and deployments
ensure webhooks and deployments are gone
delete all other resources
ensure everyis deleted
return nil (this is make knative/pkg remove finalizer and delete the instance of TektonPipeline)
## Status Design
kind: TektonPipelien
metadata:
name: pipeline
spec:
..
...
staus:
conditions:
- message:
tyepe: CRDS-INSTALLED
status: true/false
- message:
tyepe: DEPLOYMENTS-READY
status: true/false
- message:
tyepe: COMPOENT-READY
status: true/false
state: creating/creating-crds/wating-for-deployment/waiting-for-webhooks/deleting-CRDs/deleting-deployments/CRD-installation-error
# Naming Coditions and Phases
Phase:
- Unknown
- Installing CRDs
- Installing Dependencies
- Creating Deployments
- Validating
- Ready
- Error
Condition:
- status: "True"
type: CRDS_INSTALLED
- status: "True"
type: CLUSTERSCOPED_DEPENDENCIES_INSTALLED
- status: "True"
type: NAMESPACED_DEPENDENCIES_INSTALLED
- status: "True"
type: WEBHOOK_READY
- status: "True"
type: CONTROLLER_READY
- status: "True"
type: PIPELINES_READY
# Notes
- Read and parse release.yaml only once
- outside reconcile loop, during reconciler initialization
- TektonConfig shouldnot create TektonTriggers or TektonAddons CR until the TketonPipeline status is Ready
-
Discussions:
- add a finzlizer to all resources created by the operator so that they can be protected from manual deletion by a user. (note: if the operator controller is down the deletions should not block: may be add graceful termination to controller which will remove finalizers)
#scrapnotes
- events that trigger reconcile
- events on Tektonpipeline CRD instances
- events on Deployments