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

feat: added namespace as cache scope #6342

Merged
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
11 changes: 11 additions & 0 deletions backend/src/apiserver/server/task_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/kubeflow/pipelines/backend/src/apiserver/model"
"github.com/kubeflow/pipelines/backend/src/apiserver/resource"
"github.com/kubeflow/pipelines/backend/src/common/util"
"strings"
)

type TaskServer struct {
Expand Down Expand Up @@ -40,6 +41,16 @@ func (s *TaskServer) validateCreateTaskRequest(request *api.CreateTaskRequest) e
if task.GetPipelineName() == "" {
return errMustSpecify("PipelineName")
}
if strings.HasPrefix(task.GetPipelineName(), "namespace/") {
s := strings.SplitN(task.GetPipelineName(), "/", 4)
if len(s) != 4 {
return util.NewInvalidInputError("invalid PipelineName for namespaced pipelines, need to follow 'namespace/${namespace}/pipeline/${pipelineName}': %s", task.GetPipelineName())
}
namespace := s[1]
if task.GetNamespace() != "" && namespace != task.GetNamespace() {
return util.NewInvalidInputError("the namespace %s extracted from pipelineName is not equal to the namespace %s in task", namespace, task.GetNamespace())
}
}
if task.GetRunId() == "" {
return errMustSpecify("RunId")
}
Expand Down
9 changes: 7 additions & 2 deletions v2/cacheutils/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func cacheDefaultEndpoint() string {
return defaultKfpApiEndpoint
}

func (c *Client) GetExecutionCache(fingerPrint, pipelineName string) (string, error) {
func (c *Client) GetExecutionCache(fingerPrint, pipelineName, namespace string) (string, error) {
fingerPrintPredicate := &api.Predicate{
Op: api.Predicate_EQUALS,
Key: "fingerprint",
Expand All @@ -155,7 +155,12 @@ func (c *Client) GetExecutionCache(fingerPrint, pipelineName string) (string, er
Key: "pipelineName",
Value: &api.Predicate_StringValue{StringValue: pipelineName},
}
filter := api.Filter{Predicates: []*api.Predicate{fingerPrintPredicate, pipelineNamePredicate}}
namespacePredicate := &api.Predicate{
Op: api.Predicate_EQUALS,
Key: "namespace",
Value: &api.Predicate_StringValue{StringValue: namespace},
}
filter := api.Filter{Predicates: []*api.Predicate{fingerPrintPredicate, pipelineNamePredicate, namespacePredicate}}

taskFilterJson, err := protojson.Marshal(&filter)
if err != nil {
Expand Down
13 changes: 12 additions & 1 deletion v2/component/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,16 @@ func (o *LauncherOptions) validate() error {
if empty(o.MLMDServerPort) {
return err("MLMDServerPort")
}
if strings.HasPrefix(o.PipelineName, "namespace/") {
s := strings.SplitN(o.PipelineName, "/", 4)
if len(s) != 4 {
return fmt.Errorf("invalid PipelineName options for namespaced pipelines, need to follow 'namespace/${namespace}/pipeline/${pipelineName}': %s", o.PipelineName)
}
namespace := s[1]
if namespace != o.Namespace {
return fmt.Errorf("the namespace %s extracted from pipelineName is not equal to the namespace %s in launcher options", namespace, o.Namespace)
}
}
return nil
}

Expand Down Expand Up @@ -230,7 +240,7 @@ func (l *Launcher) executeWithCacheEnabled(ctx context.Context, executorInput *p
return fmt.Errorf("failure while generating CacheKey: %w", err)
}
fingerPrint, err := cacheutils.GenerateFingerPrint(cacheKey)
cachedMLMDExecutionID, err := l.cacheClient.GetExecutionCache(fingerPrint, l.options.PipelineName)
cachedMLMDExecutionID, err := l.cacheClient.GetExecutionCache(fingerPrint, l.options.PipelineName, l.options.Namespace)
if err != nil {
return fmt.Errorf("failure while getting executionCache: %w", err)
}
Expand Down Expand Up @@ -399,6 +409,7 @@ func (l *Launcher) executeWithoutCacheHit(ctx context.Context, executorInput *pi
}
task := &api.Task{
PipelineName: l.options.PipelineName,
Namespace: l.options.Namespace,
RunId: l.options.RunID,
MlmdExecutionID: strconv.FormatInt(id, 10),
CreatedAt: &timestamp.Timestamp{Seconds: executedStartedTime},
Expand Down