using Operator-SDK to develop K8s operator. Requirement is to listen to CR and perform actions like create secrets and configmaps then update the workload(Deployment/DaemonSet/StatefulSet) by mounting the secret and configmaps. Until CR is reconciled workload should be in pending state.
To achieve this, In the CRD spec, embed k8s Deployment, StatefulSet or DaemonSet objects. Once pre-processing is done and adjusted the workload, the apply the workload to cluster.
type Foo struct{
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`
Spec FooSpec `json:"spec,omitempty"`
Status FooStatus `json:"status,omitempty"`
}
type FooSpec struc{
Template <Deployment|DaemonSet|StatefulSet> `json:"template,omitempty"`
}
Above is the template sample. In this Template
can be of deployment or statefulSet or DaemonSet.
How to define such a CRD spec using operator-sdk in golang?
How to cast the Template
, in reconciliation loop, to the actual object(Deployment/DaemonSet/StatefulSet)?