Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- func (r *ReconcilePerconaXtraDBCluster) deploy(cr *api.PerconaXtraDBCluster) error {
- serverVersion := r.serverVersion
- if cr.Spec.Platform != nil {
- serverVersion.Platform = *cr.Spec.Platform
- }
- sfs := statefulset.NewNode(cr)
- nodeSet, err := pxc.StatefulSet(sfs, cr.Spec.PXC, cr, serverVersion)
- if err != nil {
- return err
- }
- err = setControllerReference(cr, nodeSet, r.scheme)
- if err != nil {
- return err
- }
- err = r.client.Create(context.TODO(), nodeSet)
- if err != nil && !errors.IsAlreadyExists(err) {
- return fmt.Errorf("create newStatefulSetNode: %v", err)
- }
- nodesService := pxc.NewServiceNodes(cr)
- err = setControllerReference(cr, nodesService, r.scheme)
- if err != nil {
- return err
- }
- err = r.client.Create(context.TODO(), nodesService)
- if err != nil && !errors.IsAlreadyExists(err) {
- return fmt.Errorf("create PXC Service: %v", err)
- }
- // PodDistributedBudget object for nodes
- if cr.Spec.PXC.PodDisruptionBudget != nil {
- pdbPXC := pxc.NewPodDistributedBudget(cr, cr.Spec.PXC.PodDisruptionBudget, "-nodes")
- err = r.client.Create(context.TODO(), pdbPXC)
- if err != nil && !errors.IsAlreadyExists(err) {
- return fmt.Errorf("create PodDisruptionBudget-PXC: %v", err)
- }
- // TODO! set reference to NodeSet
- err = setControllerReference2(nodeSet, pdbPXC, r.scheme)
- // err = setControllerReference2(sfs, pdbPXC, r.scheme)
- if err != nil {
- return err
- }
- }
- if cr.Spec.ProxySQL != nil && cr.Spec.ProxySQL.Enabled {
- proxySet, err := pxc.StatefulSet(statefulset.NewProxy(cr), cr.Spec.ProxySQL, cr, serverVersion)
- if err != nil {
- return fmt.Errorf("create ProxySQL Service: %v", err)
- }
- err = setControllerReference(cr, proxySet, r.scheme)
- if err != nil {
- return err
- }
- err = r.client.Create(context.TODO(), proxySet)
- if err != nil && !errors.IsAlreadyExists(err) {
- return fmt.Errorf("create newStatefulSetProxySQL: %v", err)
- }
- proxys := pxc.NewServiceProxySQL(cr)
- err = setControllerReference(cr, proxys, r.scheme)
- if err != nil {
- return err
- }
- err = r.client.Create(context.TODO(), proxys)
- if err != nil && !errors.IsAlreadyExists(err) {
- return fmt.Errorf("create PXC Service: %v", err)
- }
- }
- return nil
- }
- func setControllerReference(cr *api.PerconaXtraDBCluster, obj metav1.Object, scheme *runtime.Scheme) error {
- ownerRef, err := cr.OwnerRef(scheme)
- if err != nil {
- return err
- }
- obj.SetOwnerReferences(append(obj.GetOwnerReferences(), ownerRef))
- return nil
- }
- func setControllerReference2(sfs *appsv1.StatefulSet, obj metav1.Object, scheme *runtime.Scheme) error {
- ownerRef, err := pxc.StatefulSetOwnerRef(sfs, scheme)
- if err != nil {
- return err
- }
- obj.SetOwnerReferences(append(obj.GetOwnerReferences(), ownerRef))
- return nil
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement