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

[Backend] Patch default bucket name and project ID #2938

Merged
merged 21 commits into from
Jan 31, 2020
24 changes: 24 additions & 0 deletions backend/src/apiserver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ import (
"google.golang.org/grpc/reflection"
)

const (
HasDefaultBucketEnvVar = "HASDEFAULTBUCKET"
numerology marked this conversation as resolved.
Show resolved Hide resolved
ProjectIDEnvVar = "PROJECTID"
DefaultBucketNameEnvVar = "BUCKETNAME"
)

var (
rpcPortFlag = flag.String("rpcPortFlag", ":8887", "RPC Port")
httpPortFlag = flag.String("httpPortFlag", ":8888", "Http Proxy Port")
Expand Down Expand Up @@ -189,6 +195,24 @@ func loadSamples(resourceManager *resource.ResourceManager) error {
if configErr != nil {
return fmt.Errorf("Failed to decompress the file %s. Error: %v", config.Name, configErr)
}
// Patch the default bucket name read from ConfigMap
if common.GetBoolConfigWithDefault(HasDefaultBucketEnvVar, false) {
defaultBucket := common.GetStringConfig(DefaultBucketNameEnvVar)
projectId := common.GetStringConfig(ProjectIDEnvVar)
patchMap := map[string]string{
"<your-gcs-bucket>": defaultBucket,
numerology marked this conversation as resolved.
Show resolved Hide resolved
"<your-project-id>": projectId,
}
if config.Name == "[Sample] ML - XGBoost - Training with Confusion Matrix" {
numerology marked this conversation as resolved.
Show resolved Hide resolved
pipelineFile, err := server.PatchPipelineDefaultParameter(pipelineFile, patchMap)
}
if config.Name == "[Sample] Unified DSL - Taxi Tip Prediction Model Trainer" {
numerology marked this conversation as resolved.
Show resolved Hide resolved
pipelineFile, err := server.PatchPipelineDefaultParameter(pipelineFile, patchMap)
}
if err != nil {
return fmt.Errorf("Failed to patch default value to %s. Error: %v", config.Name, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If patching fails, will APIserver keep restarting?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it does. Do you recommend swallow the error? IMO patching should work unless user configured something in the wrong way. Thanks!

}
}
_, configErr = resourceManager.CreatePipeline(config.Name, config.Description, pipelineFile)
if configErr != nil {
// Log the error but not fail. The API Server pod can restart and it could potentially cause name collision.
Expand Down
12 changes: 12 additions & 0 deletions backend/src/apiserver/server/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,18 @@ func ReadPipelineFile(fileName string, fileReader io.Reader, maxFileLength int)
return processedFile, nil
}

// Mutate default values of specified pipeline file.
// Args:
// file: pipeline file in bytes.
// toPatch: mapping from the old value to its new value.
func PatchPipelineDefaultParameter(file []byte, toPatch map[string]string) ([]byte, error) {
pipelineRawString := string(file)
for key, value := range toPatch {
strings.Replace(pipelineRawString, key, value)
}
return []byte(pipelineRawString), nil
}

func printParameters(params []*api.Parameter) string {
var s strings.Builder
for _, p := range params {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,21 @@ spec:
spec:
containers:
- env:
- name: HASDEFAULTBUCKET
valueFrom:
configMapKeyRef:
name: {{ .Value.gcpDefaultConfigName}}
key: "has_default_bucket"
- name: BUCKETNAME
valueFrom:
configMapKeyRef:
name: {{ .Value.gcpDefaultConfigName}}
key: "bucket_name"
- name: PROJECTID
valueFrom:
configMapKeyRef:
name: {{ .Value.gcpDefaultConfigName}}
key: "project_id"
- name: POD_NAMESPACE
valueFrom:
fieldRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ images:

gcpSecretName: "user-gcp-sa"
serviceAccountCredential: ""
gcpDefaultConfigName: "gcp-default-config"

managedstorage:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# Path of pipeline root, should be a GCS path.
pipeline_root = os.path.join(
'gs://your-bucket', 'tfx_taxi_simple', kfp.dsl.RUN_ID_PLACEHOLDER
'gs://<your-gcs-bucket>', 'tfx_taxi_simple', kfp.dsl.RUN_ID_PLACEHOLDER
)


Expand Down
4 changes: 2 additions & 2 deletions samples/core/xgboost_training_cm/xgboost_training_cm.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ def dataproc_predict_op(
description='A trainer that does end-to-end distributed training for XGBoost models.'
)
def xgb_train_pipeline(
output='gs://your-gcs-bucket',
project='your-gcp-project',
output='gs://<your-gcs-bucket>',
project='<your-project-id>',
cluster_name='xgb-%s' % dsl.RUN_ID_PLACEHOLDER,
region='us-central1',
train_data='gs://ml-pipeline-playground/sfpd/train.csv',
Expand Down