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

fix: podTransitionRule webhook #132

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions pkg/controllers/podtransitionrule/processor/rules/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@

res, err := w.polling(taskId)

w.recordTime(taskId, res.Message)
w.recordTime(taskId, res.Message, false)

if err != nil {
newWebhookState.ItemStatus = appendStatus(newWebhookState.ItemStatus, pods, func(po string) bool {
Expand Down Expand Up @@ -304,37 +304,41 @@

// First request
selfTraceId, res, err := w.query(effectiveSubjects)
taskId := getTaskId(res)
klog.Infof(
"do podtransitionrule webhook [%s], pods: %v, taskId: %s, traceId: %s, resp: %s",
w.key(),
effectiveSubjects.List(),
taskId,
selfTraceId,
utils.DumpJSON(res),
)
if err != nil {
for eft := range effectiveSubjects {
rejectedPods[eft] = fmt.Sprintf(
"fail to do webhook [%s], %v, traceId %s, taskId %s",
"fail to request webhook [%s], %v, traceId %s",

Check warning on line 310 in pkg/controllers/podtransitionrule/processor/rules/webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/podtransitionrule/processor/rules/webhook.go#L310

Added line #L310 was not covered by tests
w.key(),
err,
selfTraceId,
taskId,
)
}
klog.Errorf(
"fail to request podtransitionrule webhook [%s], pods: %v, traceId: %s, resp: %s",
w.key(),
effectiveSubjects.List(),
selfTraceId,
utils.DumpJSON(res),
)

Check warning on line 322 in pkg/controllers/podtransitionrule/processor/rules/webhook.go

View check run for this annotation

Codecov / codecov/patch

pkg/controllers/podtransitionrule/processor/rules/webhook.go#L316-L322

Added lines #L316 - L322 were not covered by tests
return &FilterResult{
Passed: checked,
Rejected: rejectedPods,
Err: err,
RuleState: &appsv1alpha1.RuleState{Name: w.RuleName, WebhookStatus: newWebhookState},
}
}

taskId := getTaskId(res)
klog.Infof(
"request podtransitionrule webhook [%s], pods: %v, taskId: %s, traceId: %s, resp: %s",
w.key(),
effectiveSubjects.List(),
taskId,
selfTraceId,
utils.DumpJSON(res),
)
if taskId != "" {
w.recordTime(taskId, res.Message)
w.recordTime(taskId, res.Message, true)
}

localFinished := sets.NewString(res.FinishedNames...)

if !res.Success {
Expand Down Expand Up @@ -403,17 +407,19 @@
return states
}

func (w *Webhook) recordTime(taskId, msg string) {
func (w *Webhook) recordTime(taskId, msg string, isFirst bool) {
timeNow := time.Now()
newRecord := &appsv1alpha1.TaskInfo{
TaskId: taskId,
BeginTime: &metav1.Time{Time: timeNow},
LastTime: &metav1.Time{Time: timeNow},
Message: msg,
}
tm := w.getTaskInfo(taskId)
if tm != nil && tm.BeginTime != nil {
newRecord.BeginTime = tm.BeginTime.DeepCopy()
if !isFirst {
tm := w.getTaskInfo(taskId)
if tm != nil && tm.BeginTime != nil {
newRecord.BeginTime = tm.BeginTime.DeepCopy()
}
}
w.taskInfo[taskId] = newRecord
}
Expand Down Expand Up @@ -527,7 +533,7 @@
}

func getTaskId(resp *appsv1alpha1.WebhookResponse) string {
if resp.Async || resp.Poll {
if resp != nil && (resp.Async || resp.Poll) {
if resp.TaskId != "" {
return resp.TaskId
}
Expand Down
Loading