Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
quzard committed Dec 15, 2023
1 parent e9ed0d0 commit 404317e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 27 deletions.
46 changes: 19 additions & 27 deletions helper/envconfig/aliyunlog_operation_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,11 @@ func (o *operationWrapper) makesureProjectExist(config *AliyunLogConfigSpec, pro
logstore = config.Logstore
}
annotations := GetAnnotationByObject(config, project, logstore, "", configName, false)
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")
}
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")
}
return err
}
Expand Down Expand Up @@ -667,13 +665,11 @@ func (o *operationWrapper) updateConfigInner(config *AliyunLogConfigSpec) error
}

annotations := GetAnnotationByObject(config, project, logstore, "", config.LogtailConfig.ConfigName, true)
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")
}
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 {
Expand Down Expand Up @@ -704,13 +700,11 @@ func (o *operationWrapper) updateConfigInner(config *AliyunLogConfigSpec) error
}
}
annotations := GetAnnotationByObject(config, project, logstore, "", config.LogtailConfig.ConfigName, true)
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")
}
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")
}
}
if err != nil {
Expand All @@ -726,12 +720,10 @@ 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 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))
}
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
6 changes: 6 additions & 0 deletions pkg/helper/eventrecorder/event_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ func (e *EventRecorder) SendErrorEvent(object runtime.Object, action Action, ala
}

func (e *EventRecorder) SendNormalEventWithAnnotation(object runtime.Object, annotations map[string]string, action Action, message string) {
if e == nil {
return
}
if message == "" {
message = "success"
}
Expand All @@ -112,6 +115,9 @@ func (e *EventRecorder) SendNormalEventWithAnnotation(object runtime.Object, ann
}

func (e *EventRecorder) SendErrorEventWithAnnotation(object runtime.Object, annotations map[string]string, action Action, alarm Alarm, message string) {
if e == nil {
return
}
if message == "" {
message = "failed"
}
Expand Down

0 comments on commit 404317e

Please sign in to comment.