Skip to content
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

Don't error when attempting to trigger schedules for inactive projects #5649

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
12 changes: 12 additions & 0 deletions flyteadmin/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,3 +202,15 @@
adminError, ok := err.(FlyteAdminError)
return ok && adminError.Code() == codes.NotFound
}

func NewInactiveProjectError(ctx context.Context, id string) FlyteAdminError {
errMsg := fmt.Sprintf("project [%s] is not active", id)
statusErr, transformationErr := NewFlyteAdminError(codes.InvalidArgument, errMsg).WithDetails(&admin.InactiveProject{
Id: id,
})
if transformationErr != nil {
logger.Errorf(ctx, "failed to wrap grpc status in type 'Error': %v", transformationErr)
return NewFlyteAdminErrorf(codes.InvalidArgument, errMsg)

Check warning on line 213 in flyteadmin/pkg/errors/errors.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/pkg/errors/errors.go#L212-L213

Added lines #L212 - L213 were not covered by tests
}
return statusErr
}
12 changes: 12 additions & 0 deletions flyteadmin/pkg/errors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,15 @@ func TestIsNotDoesNotExistError(t *testing.T) {
func TestIsNotDoesNotExistErrorBecauseOfNoneAdminError(t *testing.T) {
assert.False(t, IsDoesNotExistError(errors.New("foo")))
}

func TestNewInactiveProjectError(t *testing.T) {
err := NewInactiveProjectError(context.TODO(), identifier.GetProject())
statusErr, ok := status.FromError(err)

assert.True(t, ok)

details, ok := statusErr.Details()[0].(*admin.InactiveProject)

assert.True(t, ok)
assert.Equal(t, identifier.GetProject(), details.Id)
}
3 changes: 1 addition & 2 deletions flyteadmin/pkg/manager/impl/validation/project_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ func ValidateProjectAndDomain(
projectID, domainID, err)
}
if *project.State != int32(admin.Project_ACTIVE) {
return errors.NewFlyteAdminErrorf(codes.InvalidArgument,
"project [%s] is not active", projectID)
return errors.NewInactiveProjectError(ctx, projectID)
}
var validDomain bool
domains := config.GetDomainsConfig()
Expand Down
19 changes: 19 additions & 0 deletions flyteadmin/scheduler/executor/executor_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@
},
func() error {
_, execErr := w.adminServiceClient.CreateExecution(context.Background(), executionRequest)
if isInactiveProjectError(execErr) {
logger.Debugf(ctx, "project %+v is inactive, ignoring schedule create failure for %+v", s.Project, s)
return nil

Check warning on line 119 in flyteadmin/scheduler/executor/executor_impl.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/scheduler/executor/executor_impl.go#L118-L119

Added lines #L118 - L119 were not covered by tests
}
return execErr
},
)
Expand Down Expand Up @@ -144,3 +148,18 @@
"count of successful attempts to fire execution for a schedules"),
}
}

func isInactiveProjectError(err error) bool {
statusErr, ok := status.FromError(err)
if !ok {
return false

Check warning on line 155 in flyteadmin/scheduler/executor/executor_impl.go

View check run for this annotation

Codecov / codecov/patch

flyteadmin/scheduler/executor/executor_impl.go#L155

Added line #L155 was not covered by tests
}
if len(statusErr.Details()) > 0 {
for _, detail := range statusErr.Details() {
if _, ok := detail.(*admin.InactiveProject); ok {
return true
}
}
}
return false
}
12 changes: 12 additions & 0 deletions flyteadmin/scheduler/executor/executor_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/flyteorg/flyte/flyteadmin/pkg/errors"
"github.com/flyteorg/flyte/flyteadmin/scheduler/repositories/models"
Expand Down Expand Up @@ -98,3 +99,14 @@ func TestExecutorInactiveSchedule(t *testing.T) {
err := executor.Execute(context.Background(), time.Now(), schedule)
assert.Nil(t, err)
}

func TestIsInactiveProjectError(t *testing.T) {
statusErr := status.New(codes.InvalidArgument, "foo")
var transformationErr error
statusErr, transformationErr = statusErr.WithDetails(&admin.InactiveProject{
Id: "project",
})
assert.NoError(t, transformationErr)

assert.True(t, isInactiveProjectError(statusErr.Err()))
}
50 changes: 50 additions & 0 deletions flyteidl/gen/pb-es/flyteidl/admin/project_pb.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

114 changes: 95 additions & 19 deletions flyteidl/gen/pb-go/flyteidl/admin/project.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 58 additions & 0 deletions flyteidl/gen/pb-js/flyteidl.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading