Skip to content

Commit

Permalink
ignore handled pod
Browse files Browse the repository at this point in the history
  • Loading branch information
Luke-Smartnews committed May 15, 2024
1 parent 8bbc3ee commit bb9def0
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/controllers/provisioning/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,29 @@ func (p *Provisioner) Validate(ctx context.Context, pod *v1.Pod) error {
validateNodeSelector(pod),
validateAffinity(pod),
p.volumeTopology.ValidatePersistentVolumeClaims(ctx, pod),
p.isPodHandled(ctx, pod),
)
}

func (p *Provisioner) isPodHandled(ctx context.Context, pod *v1.Pod) (err error) {
var events v1.EventList
filter := client.MatchingFields{
"metadata.namespace": pod.Namespace,
"involvedObject.kind": "Pod",
"involvedObject.name": pod.Name,
"reason": "HandledByKarpenter",
}
if err := p.kubeClient.List(ctx, &events, filter); err == nil {
for _, event := range events.Items {
// ignore the pod if it's already handled in 3 minute
if !time.Now().Add(3 * time.Minute).After(event.LastTimestamp.Time) {
return fmt.Errorf("pod is handled")
}
}
}
return nil
}

// validateKarpenterManagedLabelCanExist provides a more clear error message in the event of scheduling a pod that specifically doesn't
// want to run on a Karpenter node (e.g. a Karpenter controller replica).
func validateKarpenterManagedLabelCanExist(p *v1.Pod) error {
Expand Down

0 comments on commit bb9def0

Please sign in to comment.