-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(backend): let components add default values (#9591)
* let components add default values * address comments and add unit tests * address comments * backend test * backend test 2 * backend test 3 * backend test 4 * backend test 5 * backend test 6 * do not use python component in unit tests * shell command * shell command * shell command * does not delete tmp folder * change folder permission * update launcher image
- Loading branch information
Showing
5 changed files
with
300 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// Copyright 2023 The Kubeflow Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
package component | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/kubeflow/pipelines/api/v2alpha1/go/pipelinespec" | ||
"github.com/kubeflow/pipelines/backend/src/v2/metadata" | ||
"github.com/kubeflow/pipelines/backend/src/v2/objectstore" | ||
"github.com/stretchr/testify/assert" | ||
"gocloud.dev/blob" | ||
"google.golang.org/protobuf/types/known/structpb" | ||
"k8s.io/client-go/kubernetes/fake" | ||
) | ||
|
||
var addNumbersComponent = &pipelinespec.ComponentSpec{ | ||
Implementation: &pipelinespec.ComponentSpec_ExecutorLabel{ExecutorLabel: "add"}, | ||
InputDefinitions: &pipelinespec.ComponentInputsSpec{ | ||
Parameters: map[string]*pipelinespec.ComponentInputsSpec_ParameterSpec{ | ||
"a": {ParameterType: pipelinespec.ParameterType_NUMBER_INTEGER, DefaultValue: structpb.NewNumberValue(5)}, | ||
"b": {ParameterType: pipelinespec.ParameterType_NUMBER_INTEGER}, | ||
}, | ||
}, | ||
OutputDefinitions: &pipelinespec.ComponentOutputsSpec{ | ||
Parameters: map[string]*pipelinespec.ComponentOutputsSpec_ParameterSpec{ | ||
"Output": {ParameterType: pipelinespec.ParameterType_NUMBER_INTEGER}, | ||
}, | ||
}, | ||
} | ||
|
||
// Tests that launcher correctly executes the user component and successfully writes output parameters to file. | ||
func Test_executeV2_Parameters(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
executorInput *pipelinespec.ExecutorInput | ||
executorArgs []string | ||
wantErr bool | ||
}{ | ||
{ | ||
"happy pass", | ||
&pipelinespec.ExecutorInput{ | ||
Inputs: &pipelinespec.ExecutorInput_Inputs{ | ||
ParameterValues: map[string]*structpb.Value{"a": structpb.NewNumberValue(1), "b": structpb.NewNumberValue(2)}, | ||
}, | ||
}, | ||
[]string{"-c", "test {{$.inputs.parameters['a']}} -eq 1 || exit 1\ntest {{$.inputs.parameters['b']}} -eq 2 || exit 1"}, | ||
false, | ||
}, | ||
{ | ||
"use default value", | ||
&pipelinespec.ExecutorInput{ | ||
Inputs: &pipelinespec.ExecutorInput_Inputs{ | ||
ParameterValues: map[string]*structpb.Value{"b": structpb.NewNumberValue(2)}, | ||
}, | ||
}, | ||
[]string{"-c", "test {{$.inputs.parameters['a']}} -eq 5 || exit 1\ntest {{$.inputs.parameters['b']}} -eq 2 || exit 1"}, | ||
false, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
fakeKubernetesClientset := &fake.Clientset{} | ||
fakeMetadataClient := metadata.NewFakeClient() | ||
bucket, err := blob.OpenBucket(context.Background(), "gs://test-bucket") | ||
assert.Nil(t, err) | ||
bucketConfig, err := objectstore.ParseBucketConfig("gs://test-bucket/pipeline-root/") | ||
assert.Nil(t, err) | ||
_, _, err = executeV2(context.Background(), test.executorInput, addNumbersComponent, "sh", test.executorArgs, bucket, bucketConfig, fakeMetadataClient, "namespace", fakeKubernetesClientset) | ||
|
||
if test.wantErr { | ||
assert.NotNil(t, err) | ||
} else { | ||
assert.Nil(t, err) | ||
|
||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.