Skip to content

treat fatal errors as actually fatal #12842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 8, 2017
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
9 changes: 6 additions & 3 deletions pkg/build/controller/config_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ type ConfigControllerFatalError struct {
}

// Error returns the error string for this fatal error
func (e ConfigControllerFatalError) Error() string {
func (e *ConfigControllerFatalError) Error() string {
return fmt.Sprintf("fatal error processing BuildConfig: %s", e.Reason)
}

// IsFatal returns true if err is a fatal error
func IsFatal(err error) bool {
_, isFatal := err.(ConfigControllerFatalError)
_, isFatal := err.(*ConfigControllerFatalError)
return isFatal
}

Expand Down Expand Up @@ -73,7 +73,10 @@ func (c *BuildConfigController) HandleBuildConfig(bc *buildapi.BuildConfig) erro
if kerrors.IsConflict(err) {
instantiateErr = fmt.Errorf("unable to instantiate Build for BuildConfig %s/%s due to a conflicting update: %v", bc.Namespace, bc.Name, err)
utilruntime.HandleError(instantiateErr)
} else if buildgenerator.IsFatal(err) || kerrors.IsNotFound(err) || kerrors.IsBadRequest(err) {
} else if buildgenerator.IsFatal(err) || kerrors.IsNotFound(err) || kerrors.IsBadRequest(err) || kerrors.IsForbidden(err) {
instantiateErr = fmt.Errorf("gave up on Build for BuildConfig %s/%s due to fatal error: %v", bc.Namespace, bc.Name, err)
utilruntime.HandleError(instantiateErr)
c.Recorder.Event(bc, kapi.EventTypeWarning, "BuildConfigInstantiateFailed", instantiateErr.Error())
return &ConfigControllerFatalError{err.Error()}
} else {
instantiateErr = fmt.Errorf("error instantiating Build from BuildConfig %s/%s: %v", bc.Namespace, bc.Name, err)
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func (bc *BuildController) nextBuildPhase(build *buildapi.Build) error {
build.Status.Reason = buildapi.StatusReasonCannotCreateBuildPodSpec
build.Status.Message = buildapi.StatusMessageCannotCreateBuildPodSpec
if strategy.IsFatal(err) {
return strategy.FatalError(fmt.Sprintf("failed to create a build pod spec for build %s/%s: %v", build.Namespace, build.Name, err))
return &strategy.FatalError{fmt.Sprintf("failed to create a build pod spec for build %s/%s: %v", build.Namespace, build.Name, err)}
}
return fmt.Errorf("failed to create a build pod spec for build %s/%s: %v", build.Namespace, build.Name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/build/controller/strategy/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (bs *CustomBuildStrategy) CreateBuildPod(build *buildapi.Build) (*kapi.Pod,
if len(strategy.BuildAPIVersion) != 0 {
gv, err := unversioned.ParseGroupVersion(strategy.BuildAPIVersion)
if err != nil {
return nil, FatalError(fmt.Sprintf("failed to parse buildAPIVersion specified in custom build strategy (%q): %v", strategy.BuildAPIVersion, err))
return nil, &FatalError{fmt.Sprintf("failed to parse buildAPIVersion specified in custom build strategy (%q): %v", strategy.BuildAPIVersion, err)}
}
codec = kapi.Codecs.LegacyCodec(gv)
}
Expand Down
11 changes: 7 additions & 4 deletions pkg/build/controller/strategy/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ const (
var whitelistEnvVarNames = []string{"BUILD_LOGLEVEL", "GIT_SSL_NO_VERIFY"}

// FatalError is an error which can't be retried.
type FatalError string
type FatalError struct {
// Reason the fatal error occurred
Reason string
}

// Error implements the error interface.
func (e FatalError) Error() string {
return string(e)
func (e *FatalError) Error() string {
return fmt.Sprintf("fatal error: %s", e.Reason)
}

// IsFatal returns true if the error is fatal
func IsFatal(err error) bool {
_, isFatal := err.(FatalError)
_, isFatal := err.(*FatalError)
return isFatal
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/build/generator/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ type GeneratorFatalError struct {
}

// Error returns the error string for this fatal error
func (e GeneratorFatalError) Error() string {
func (e *GeneratorFatalError) Error() string {
return fmt.Sprintf("fatal error generating Build from BuildConfig: %s", e.Reason)
}

// IsFatal returns true if err is a fatal error
func IsFatal(err error) bool {
_, isFatal := err.(GeneratorFatalError)
_, isFatal := err.(*GeneratorFatalError)
return isFatal
}

Expand Down