forked from flyteorg/flyte
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Execution event cluster validation (flyteorg#307)
- Loading branch information
Katrina Rogan
authored
Jan 5, 2022
1 parent
59d33f0
commit 81ac07f
Showing
19 changed files
with
397 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/flyteorg/flyteadmin/pkg/common" | ||
"github.com/flyteorg/flyteadmin/pkg/errors" | ||
"github.com/flyteorg/flyteadmin/pkg/repositories" | ||
repoInterfaces "github.com/flyteorg/flyteadmin/pkg/repositories/interfaces" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/flyteorg/flytestdlib/logger" | ||
) | ||
|
||
// ValidateClusterForExecutionID validates that the execution denoted by executionId is recorded as executing on `cluster`. | ||
func ValidateClusterForExecutionID(ctx context.Context, db repositories.RepositoryInterface, executionID *core.WorkflowExecutionIdentifier, cluster string) error { | ||
workflowExecution, err := db.ExecutionRepo().Get(ctx, repoInterfaces.Identifier{ | ||
Project: executionID.Project, | ||
Domain: executionID.Domain, | ||
Name: executionID.Name, | ||
}) | ||
if err != nil { | ||
logger.Debugf(ctx, "Failed to find existing execution with id [%+v] with err: %v", executionID, err) | ||
return err | ||
} | ||
return ValidateCluster(ctx, workflowExecution.Cluster, cluster) | ||
} | ||
|
||
// ValidateClusterForExecution validates that the execution is recorded as executing on `cluster`. | ||
func ValidateCluster(ctx context.Context, recordedCluster, cluster string) error { | ||
// DefaultProducerID is used in older versions of propeller which hard code this producer id. | ||
// See https://github.com/flyteorg/flytepropeller/blob/eaf084934de5d630cd4c11aae15ecae780cc787e/pkg/controller/nodes/task/transformer.go#L114 | ||
if len(cluster) == 0 || cluster == common.DefaultProducerID { | ||
return nil | ||
} | ||
if recordedCluster != cluster { | ||
errorMsg := fmt.Sprintf("Cluster/producer from event [%s] does not match existing workflow execution cluster: [%s]", | ||
recordedCluster, cluster) | ||
return errors.NewIncompatibleClusterError(ctx, errorMsg, recordedCluster) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package validation | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/flyteorg/flyteadmin/pkg/common" | ||
"github.com/flyteorg/flyteadmin/pkg/errors" | ||
"github.com/flyteorg/flyteadmin/pkg/repositories/interfaces" | ||
repositoryMocks "github.com/flyteorg/flyteadmin/pkg/repositories/mocks" | ||
"github.com/flyteorg/flyteadmin/pkg/repositories/models" | ||
"github.com/flyteorg/flyteidl/gen/pb-go/flyteidl/core" | ||
"github.com/stretchr/testify/assert" | ||
"google.golang.org/grpc/codes" | ||
) | ||
|
||
var testCluster = "C1" | ||
|
||
var testExecID = &core.WorkflowExecutionIdentifier{ | ||
Project: "p", | ||
Domain: "d", | ||
Name: "n", | ||
} | ||
|
||
func TestValidateClusterForExecutionID(t *testing.T) { | ||
repository := repositoryMocks.NewMockRepository() | ||
repository.ExecutionRepo().(*repositoryMocks.MockExecutionRepo).SetGetCallback(func(ctx context.Context, input interfaces.Identifier) (models.Execution, error) { | ||
return models.Execution{ | ||
Cluster: testCluster, | ||
}, nil | ||
}) | ||
assert.NoError(t, ValidateClusterForExecutionID(context.TODO(), repository, testExecID, testCluster)) | ||
assert.NoError(t, ValidateClusterForExecutionID(context.TODO(), repository, testExecID, common.DefaultProducerID)) | ||
} | ||
|
||
func TestValidateCluster_Nonmatching(t *testing.T) { | ||
repository := repositoryMocks.NewMockRepository() | ||
repository.ExecutionRepo().(*repositoryMocks.MockExecutionRepo).SetGetCallback(func(ctx context.Context, input interfaces.Identifier) (models.Execution, error) { | ||
return models.Execution{ | ||
Cluster: "C2", | ||
}, nil | ||
}) | ||
err := ValidateClusterForExecutionID(context.TODO(), repository, testExecID, testCluster) | ||
assert.Equal(t, codes.FailedPrecondition, err.(errors.FlyteAdminError).Code()) | ||
} | ||
|
||
func TestValidateCluster_NoExecution(t *testing.T) { | ||
repository := repositoryMocks.NewMockRepository() | ||
expectedErr := errors.NewFlyteAdminError(codes.Internal, "foo") | ||
repository.ExecutionRepo().(*repositoryMocks.MockExecutionRepo).SetGetCallback(func(ctx context.Context, input interfaces.Identifier) (models.Execution, error) { | ||
return models.Execution{}, expectedErr | ||
}) | ||
err := ValidateClusterForExecutionID(context.TODO(), repository, testExecID, testCluster) | ||
assert.Equal(t, expectedErr, err) | ||
} |
Oops, something went wrong.