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

[feature] libfaketime 支援相對時間 #22

Open
huli-ctw opened this issue Jun 10, 2024 · 1 comment
Open

[feature] libfaketime 支援相對時間 #22

huli-ctw opened this issue Jun 10, 2024 · 1 comment

Comments

@huli-ctw
Copy link

libfaketime 有支援相對時間的用法:https://github.com/wolfcw/libfaketime#:~:text=4d)%20Using%20offsets%20for%20relative%20dates

如 "-120" 或是 "+120" 等等

儘管在 yaml 中看似可以傳入相對時間,但是在 plugin 中都是轉成了絕對時間:https://github.com/CloudNativeGame/fake-time-injector/blob/main/plugins/faketime/faketime.go#L56

func calculateFakeTime(t string) (string, error) {
	if strings.Contains(t, ":") {
		t_, err := time.Parse("2006-01-02 15:04:05", t)
		if err != nil {
			return "", err
		}
		s := t_.UTC().String()
		return s, nil
	}
	// 解析时间间隔字符串为Duration类型
	duration, err := time.ParseDuration(t)
	if err != nil {
		return "", err
	}
	s := time.Now().UTC().Add(duration).String()
	return s, nil
}

而 libFakeTimePatches 是直接使用了這個絕對時間:https://github.com/CloudNativeGame/fake-time-injector/blob/main/plugins/faketime/faketime.go#L217

	Env := []apiv1.EnvVar{
		{Name: "LD_PRELOAD", Value: LibFakeTimePath},
		{Name: "FAKETIME", Value: fmt.Sprintf("@%s", fakeTime)},
	}

這造成了在 libfaketime 中無法使用相對時間來調整,希望能加上相關功能,能夠讓 FAKETIME 也支援如 "+120" 這類的語法,或至少在 annotation 的參數如果是數字的話,就直接使用這個數字,而不是用 calculateFakeTime 回傳新的 date time

@songkang7
Copy link
Contributor

@huli-ctw 已支持相对时间
#24

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants