func DeployRunnerGroup()

in contrib/utils/utils.go [259:321]


func DeployRunnerGroup(ctx context.Context,
	kubeCfgPath, runnerImage, rgCfgFile string,
	runnerFlowControl, runnerGroupAffinity string) (*types.RunnerGroupsReport, error) {

	infoLogger := log.GetLogger(ctx).WithKeyValues("level", "info")
	warnLogger := log.GetLogger(ctx).WithKeyValues("level", "warn")

	kr := NewKperfRunner(kubeCfgPath, runnerImage)

	infoLogger.LogKV("msg", "deleting existing runner group")
	derr := kr.RGDelete(ctx, 0)
	if derr != nil {
		return nil, fmt.Errorf("failed to delete existing runner group: %w", derr)
	}

	infoLogger.LogKV("msg", "deploying runner group")
	rerr := kr.RGRun(ctx, 0, rgCfgFile, runnerFlowControl, runnerGroupAffinity)
	if rerr != nil {
		return nil, fmt.Errorf("failed to deploy runner group: %w", rerr)
	}

	infoLogger.LogKV("msg", "start to wait runner group")
	for {
		select {
		case <-ctx.Done():
			return nil, ctx.Err()
		default:
		}

		// NOTE: The result subcommand will hold the long connection
		// until runner-group's server replies. However, there is no
		// data transport before runners finish. If the apiserver
		// has been restarted, the proxy tunnel will be broken and
		// the client won't be notified. So, the client will hang forever.
		// Using 1 min as timeout is to ensure we can get result in time.
		data, err := kr.RGResult(ctx, 1*time.Minute)
		if err != nil {
			// FIXME(weifu): If the pod is not found, we should fast
			// return. However, it's hard to maintain error string
			// match. We should use specific commandline error code
			// or use package instead of binary call.
			if strings.Contains(err.Error(), `pods "runnergroup-server" not found`) {
				return nil, err
			}

			warnLogger.LogKV("msg", fmt.Errorf("failed to fetch runner group's result: %w", err))
			continue
		}

		infoLogger.LogKV("msg", "dump RunnerGroupsReport", "data", data)

		var rgResult types.RunnerGroupsReport
		if err = json.Unmarshal([]byte(data), &rgResult); err != nil {
			return nil, fmt.Errorf("failed to unmarshal into RunnerGroupsReport: %w", err)
		}

		infoLogger.LogKV("msg", "deleting runner group")
		if derr := kr.RGDelete(ctx, 0); derr != nil {
			warnLogger.LogKV("msg", "failed to delete runner group", "err", err)
		}
		return &rgResult, nil
	}
}