Skip to content

fix panic when k8s_event.GetEventRecorder() is nil #1264

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

Merged
merged 9 commits into from
Dec 19, 2023
Merged
Changes from 3 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
34 changes: 17 additions & 17 deletions helper/envconfig/aliyunlog_operation_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,13 @@ func (o *operationWrapper) makesureProjectExist(config *AliyunLogConfigSpec, pro
logstore = config.Logstore
}
annotations := GetAnnotationByObject(config, project, logstore, "", configName, false)
if err != nil {
if k8s_event.GetEventRecorder() != nil {
if k8s_event.GetEventRecorder() != nil {
if err != nil {
customErr := CustomErrorFromSlsSDKError(err)
k8s_event.GetEventRecorder().SendErrorEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), GetAnnotationByError(annotations, customErr), k8s_event.CreateProject, "", fmt.Sprintf("create project failed, error: %s", err.Error()))
} else {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.CreateProject, "create project success")
}
} else if k8s_event.GetEventRecorder() != nil {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.CreateProject, "create project success")
}
return err
}
Expand Down Expand Up @@ -667,13 +667,11 @@ func (o *operationWrapper) updateConfigInner(config *AliyunLogConfigSpec) error
}

annotations := GetAnnotationByObject(config, project, logstore, "", config.LogtailConfig.ConfigName, true)
if err != nil {
if k8s_event.GetEventRecorder() != nil {
if k8s_event.GetEventRecorder() != nil {
if err != nil {
customErr := CustomErrorFromSlsSDKError(err)
k8s_event.GetEventRecorder().SendErrorEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), GetAnnotationByError(annotations, customErr), k8s_event.UpdateConfig, "", fmt.Sprintf("update config failed, error: %s", err.Error()))
}
} else {
if k8s_event.GetEventRecorder() != nil {
} else {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.UpdateConfig, "update config success")
}
}
Expand Down Expand Up @@ -706,13 +704,13 @@ func (o *operationWrapper) updateConfigInner(config *AliyunLogConfigSpec) error
}
}
annotations := GetAnnotationByObject(config, project, logstore, "", config.LogtailConfig.ConfigName, true)
if err != nil {
if k8s_event.GetEventRecorder() != nil {
if k8s_event.GetEventRecorder() != nil {
if err != nil {
customErr := CustomErrorFromSlsSDKError(err)
k8s_event.GetEventRecorder().SendErrorEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), GetAnnotationByError(annotations, customErr), k8s_event.UpdateConfig, "", fmt.Sprintf("update config failed, error: %s", err.Error()))
} else {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.UpdateConfig, "update config success")
}
} else if k8s_event.GetEventRecorder() != nil {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.UpdateConfig, "update config success")
}
}
if err != nil {
Expand All @@ -728,10 +726,12 @@ func (o *operationWrapper) updateConfigInner(config *AliyunLogConfigSpec) error
logtailConfigTags[SlsLogtailChannalKey] = SlsLogtailChannalEnv
err = o.TagLogtailConfig(project, config.LogtailConfig.ConfigName, logtailConfigTags)
annotations := GetAnnotationByObject(config, project, logstore, "", config.LogtailConfig.ConfigName, true)
if err != nil {
k8s_event.GetEventRecorder().SendErrorEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), GetAnnotationByError(annotations, CustomErrorFromSlsSDKError(err)), k8s_event.CreateTag, "", fmt.Sprintf("tag config %s error :%s", config.LogtailConfig.ConfigName, err.Error()))
} else {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.CreateTag, fmt.Sprintf("tag config %s success", config.LogtailConfig.ConfigName))
if k8s_event.GetEventRecorder() != nil {
if err != nil {
k8s_event.GetEventRecorder().SendErrorEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), GetAnnotationByError(annotations, CustomErrorFromSlsSDKError(err)), k8s_event.CreateTag, "", fmt.Sprintf("tag config %s error :%s", config.LogtailConfig.ConfigName, err.Error()))
} else {
k8s_event.GetEventRecorder().SendNormalEventWithAnnotation(k8s_event.GetEventRecorder().GetObject(), annotations, k8s_event.CreateTag, fmt.Sprintf("tag config %s success", config.LogtailConfig.ConfigName))
}
}

// check if config is in the machine group
Expand Down