Fix: optimize workflow debug cmd (#4638)

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>

Signed-off-by: FogDong <dongtianxin.tx@alibaba-inc.com>
This commit is contained in:
Tianxin Dong
2022-08-23 15:32:50 +08:00
committed by GitHub
parent 5a241078b7
commit 1e87f455e8
2 changed files with 15 additions and 9 deletions

View File

@@ -118,13 +118,20 @@ func (d *debugOpts) debugApplication(ctx context.Context, c common.Args, app *v1
}
// debug workflow steps
rawValue, err := d.getDebugRawValue(ctx, cli, pd, app)
rawValue, data, err := d.getDebugRawValue(ctx, cli, pd, app)
if err != nil {
if data != "" {
ioStreams.Info(color.RedString("%s%s", emojiFail, err.Error()))
ioStreams.Info(color.GreenString("Original Data in Debug:\n"), data)
return nil
}
return err
}
if err := d.handleCueSteps(rawValue, ioStreams); err != nil {
return err
ioStreams.Info(color.RedString("%s%s", emojiFail, err.Error()))
ioStreams.Info(color.GreenString("Original Data in Debug:\n"), data)
return nil
}
} else {
// dry run components
@@ -252,20 +259,20 @@ func unwrapStepName(step string) string {
return step
}
func (d *debugOpts) getDebugRawValue(ctx context.Context, cli client.Client, pd *packages.PackageDiscover, app *v1beta1.Application) (*value.Value, error) {
func (d *debugOpts) getDebugRawValue(ctx context.Context, cli client.Client, pd *packages.PackageDiscover, app *v1beta1.Application) (*value.Value, string, error) {
debugCM := &corev1.ConfigMap{}
if err := cli.Get(ctx, client.ObjectKey{Name: debug.GenerateContextName(app.Name, d.step), Namespace: app.Namespace}, debugCM); err != nil {
return nil, fmt.Errorf("failed to get debug configmap, please make sure your application have the debug policy, you can add the debug policy by using `vela up -f <app.yaml> --debug`: %w", err)
return nil, "", fmt.Errorf("failed to get debug configmap, please make sure your application have the debug policy, you can add the debug policy by using `vela up -f <app.yaml> --debug`: %w", err)
}
if debugCM.Data == nil || debugCM.Data["debug"] == "" {
return nil, fmt.Errorf("debug configmap is empty")
return nil, "", fmt.Errorf("debug configmap is empty")
}
v, err := value.NewValue(debugCM.Data["debug"], pd, "")
if err != nil {
return nil, fmt.Errorf("failed to parse debug configmap: %w", err)
return nil, debugCM.Data["debug"], fmt.Errorf("failed to parse debug configmap: %w", err)
}
return v, nil
return v, debugCM.Data["debug"], nil
}
func (d *debugOpts) handleCueSteps(v *value.Value, ioStreams cmdutil.IOStreams) error {

View File

@@ -93,8 +93,7 @@ func TestDebugApplicationWithWorkflow(t *testing.T) {
"debug": "error",
},
},
step: "test-wf1",
expectedErr: "failed to parse debug configmap",
step: "test-wf1",
},
"success": {
app: &v1beta1.Application{