| 4176 | } |
| 4177 | |
| 4178 | func (woc *wfOperationCtx) createPDBResource(ctx context.Context) error { |
| 4179 | if woc.execWf.Spec.PodDisruptionBudget == nil { |
| 4180 | return nil |
| 4181 | } |
| 4182 | |
| 4183 | labels := map[string]string{common.LabelKeyWorkflow: woc.wf.Name} |
| 4184 | pdbSpec := *woc.execWf.Spec.PodDisruptionBudget |
| 4185 | if pdbSpec.Selector == nil { |
| 4186 | pdbSpec.Selector = &metav1.LabelSelector{ |
| 4187 | MatchLabels: labels, |
| 4188 | } |
| 4189 | } |
| 4190 | |
| 4191 | newPDB := policyv1.PodDisruptionBudget{ |
| 4192 | ObjectMeta: metav1.ObjectMeta{ |
| 4193 | Name: woc.wf.Name, |
| 4194 | Labels: labels, |
| 4195 | OwnerReferences: []metav1.OwnerReference{ |
| 4196 | *metav1.NewControllerRef(woc.wf, wfv1.SchemeGroupVersion.WithKind(workflow.WorkflowKind)), |
| 4197 | }, |
| 4198 | }, |
| 4199 | Spec: pdbSpec, |
| 4200 | } |
| 4201 | _, err := woc.controller.kubeclientset.PolicyV1().PodDisruptionBudgets(woc.wf.Namespace).Create(ctx, &newPDB, metav1.CreateOptions{}) |
| 4202 | if err != nil { |
| 4203 | if apierr.IsAlreadyExists(err) { |
| 4204 | woc.log.Info(ctx, "PDB resource already exists for workflow.") |
| 4205 | return nil |
| 4206 | } |
| 4207 | return err |
| 4208 | } |
| 4209 | woc.log.Info(ctx, "Created PDB resource for workflow.") |
| 4210 | woc.updated = true |
| 4211 | return nil |
| 4212 | } |
| 4213 | |
| 4214 | func (woc *wfOperationCtx) deletePDBResource(ctx context.Context) error { |
| 4215 | if woc.execWf.Spec.PodDisruptionBudget == nil { |