[go: nahoru, domu]

Skip to content
This repository has been archived by the owner on Nov 16, 2023. It is now read-only.

Enrich PodSpecError to early fail Pod #52

Merged
merged 1 commit into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Enrich PodSpecError to early fail Pod
  • Loading branch information
yqwang-ms committed Jan 16, 2020
commit 624002bf73197e437b1e47fdef554f22e171e32c
6 changes: 3 additions & 3 deletions pkg/apis/frameworkcontroller/v1/completion.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const (
CompletionCodeConfigMapCreationTimeout CompletionCode = -110
CompletionCodePodCreationTimeout CompletionCode = -111
// -2XX: Permanent Error
CompletionCodePodSpecInvalid CompletionCode = -200
CompletionCodePodSpecPermanentError CompletionCode = -200
CompletionCodeStopFrameworkRequested CompletionCode = -210
CompletionCodeFrameworkAttemptCompletion CompletionCode = -220
// -3XX: Unknown Error
Expand Down Expand Up @@ -163,8 +163,8 @@ func initCompletionCodeInfos() {
[]CompletionTypeAttribute{CompletionTypeAttributeTransient}},
},
{
Code: CompletionCodePodSpecInvalid.Ptr(),
Phrase: "PodSpecInvalid",
Code: CompletionCodePodSpecPermanentError.Ptr(),
Phrase: "PodSpecPermanentError",
Type: CompletionType{CompletionTypeNameFailed,
[]CompletionTypeAttribute{CompletionTypeAttributePermanent}},
},
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/frameworkcontroller/v1/funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,7 @@ func (rp RetryPolicySpec) ShouldRetry(
ct := cs.Type

// 0. Built-in Always-on RetryPolicy
if cs.Code == CompletionCodePodSpecInvalid ||
cs.Code == CompletionCodeStopFrameworkRequested ||
if cs.Code == CompletionCodeStopFrameworkRequested ||
cs.Code == CompletionCodeFrameworkAttemptCompletion {
return RetryDecision{false, true, 0, fmt.Sprintf(
"CompletionCode is %v, %v", cs.Code, cs.Phrase)}
Expand Down
3 changes: 1 addition & 2 deletions pkg/apis/frameworkcontroller/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ const (
// complete a single Task in the TaskRole.
//
// Usage:
// If the Pod Spec is invalid or
// the ExecutionType is ExecutionStop or
// If the ExecutionType is ExecutionStop or
// the Task's FrameworkAttempt is completing,
// will not retry.
//
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ func (c *FrameworkController) createConfigMap(

remoteCM, createErr := c.kClient.CoreV1().ConfigMaps(f.Namespace).Create(cm)
if createErr != nil {
if apiErrors.IsConflict(createErr) {
if apiErrors.IsAlreadyExists(createErr) {
// Best effort to judge if conflict with a not controlled object.
localCM, getErr := c.cmLister.ConfigMaps(f.Namespace).Get(cm.Name)
if getErr == nil && !meta.IsControlledBy(localCM, f) {
Expand Down Expand Up @@ -1431,9 +1431,9 @@ func (c *FrameworkController) syncTaskState(
pod, err = c.createPod(f, cm, taskRoleName, taskIndex)
if err != nil {
apiErr := errorWrap.Cause(err)
if apiErrors.IsInvalid(apiErr) {
if internal.IsPodSpecPermanentError(apiErr) {
// Should be Framework Error instead of Platform Transient Error.
diag := fmt.Sprintf("%v", apiErr)
diag := fmt.Sprintf("Failed to create Pod: %v", common.ToJson(apiErr))
klog.Info(logPfx + diag)

// Ensure pod is deleted in remote to avoid managed pod leak after
Expand All @@ -1444,7 +1444,7 @@ func (c *FrameworkController) syncTaskState(
}

c.completeTaskAttempt(f, taskRoleName, taskIndex, true,
ci.CompletionCodePodSpecInvalid.
ci.CompletionCodePodSpecPermanentError.
NewTaskAttemptCompletionStatus(diag, nil))
return nil
} else {
Expand Down Expand Up @@ -1702,7 +1702,7 @@ func (c *FrameworkController) createPod(

remotePod, createErr := c.kClient.CoreV1().Pods(f.Namespace).Create(pod)
if createErr != nil {
if apiErrors.IsConflict(createErr) {
if apiErrors.IsAlreadyExists(createErr) {
// Best effort to judge if conflict with a not controlled object.
localPod, getErr := c.podLister.Pods(f.Namespace).Get(pod.Name)
if getErr == nil && !meta.IsControlledBy(localPod, cm) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/internal/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"k8s.io/client-go/tools/cache"
"k8s.io/klog"
"reflect"
"strings"
"time"
)

Expand Down Expand Up @@ -221,3 +222,11 @@ func GetPodDeletionStartTime(pod *core.Pod) *meta.Time {
}
return common.PtrTime(meta.NewTime(pod.DeletionTimestamp.Add(-gracePeriod)))
}

func IsPodSpecPermanentError(apiErr error) bool {
return apiErrors.IsBadRequest(apiErr) ||
apiErrors.IsInvalid(apiErr) ||
apiErrors.IsRequestEntityTooLargeError(apiErr) ||
(apiErrors.IsForbidden(apiErr) &&
!strings.Contains(apiErr.Error(), "exceeded quota"))
}