Skip to content

Commit

Permalink
Merge pull request #656 from whitebear009/event-type
Browse files Browse the repository at this point in the history
change event type when meet error
  • Loading branch information
qmhu authored Dec 16, 2022
2 parents 357c2ff + 3d78d10 commit ea3976c
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion docs/code-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ klog.ErrorDepth(5, fmt.Errorf("failed to get ehpa %s: %v", klog.KObj(ehpa), err)
- consider failure paths and success paths
- event do not need the object key
```go
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetSubstitute", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetSubstitute", err.Error())
```

### comment
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/ehpa/effective_hpa_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (c *EffectiveHPAController) Reconcile(ctx context.Context, req ctrl.Request

scale, mapping, err := utils.GetScale(ctx, c.RestMapper, c.ScaleClient, ehpa.Namespace, ehpa.Spec.ScaleTargetRef)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetScale", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetScale", err.Error())
klog.Errorf("Failed to get scale, ehpa %s", klog.KObj(ehpa))
setCondition(newStatus, autoscalingapi.Ready, metav1.ConditionFalse, "FailedGetScale", "Failed to get scale")
c.UpdateStatus(ctx, ehpa, newStatus)
Expand Down Expand Up @@ -132,7 +132,7 @@ func (c *EffectiveHPAController) Reconcile(ctx context.Context, req ctrl.Request
scale.Spec.Replicas = *ehpa.Spec.SpecificReplicas
updatedScale, err := c.ScaleClient.Scales(scale.Namespace).Update(ctx, mapping.Resource.GroupResource(), scale, metav1.UpdateOptions{})
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedManualScale", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedManualScale", err.Error())
msg := fmt.Sprintf("Failed to manual scale target to specific replicas, ehpa %s replicas %d", klog.KObj(ehpa), *ehpa.Spec.SpecificReplicas)
klog.Error(err, msg)
setCondition(newStatus, autoscalingapi.Ready, metav1.ConditionFalse, "FailedScale", msg)
Expand All @@ -156,7 +156,7 @@ func (c *EffectiveHPAController) UpdateStatus(ctx context.Context, ehpa *autosca
ehpa.Status = *newStatus
err := c.Status().Update(ctx, ehpa)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedUpdateStatus", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedUpdateStatus", err.Error())
klog.Errorf("Failed to update status, ehpa %s error %v", klog.KObj(ehpa), err)
return
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/ehpa/hpa.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (c *EffectiveHPAController) ReconcileHPA(ctx context.Context, ehpa *autosca
if errors.IsNotFound(err) {
return c.CreateHPA(ctx, ehpa, substitute, tsp)
} else {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetHPA", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetHPA", err.Error())
klog.Errorf("Failed to get HPA, ehpa %s error %v", klog.KObj(ehpa), err)
return nil, err
}
Expand Down Expand Up @@ -62,14 +62,14 @@ func (c *EffectiveHPAController) GetHPA(ctx context.Context, ehpa *autoscalingap
func (c *EffectiveHPAController) CreateHPA(ctx context.Context, ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler, substitute *autoscalingapi.Substitute, tsp *predictionapi.TimeSeriesPrediction) (*autoscalingv2.HorizontalPodAutoscaler, error) {
hpa, err := c.NewHPAObject(ctx, ehpa, substitute, tsp)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreateHPAObject", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreateHPAObject", err.Error())
klog.Errorf("Failed to create object, HorizontalPodAutoscaler %s error %v", klog.KObj(hpa), err)
return nil, err
}

err = c.Client.Create(ctx, hpa)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreateHPA", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreateHPA", err.Error())
klog.Errorf("Failed to create HorizontalPodAutoscaler %s, error %v", klog.KObj(hpa), err)
return nil, err
}
Expand Down Expand Up @@ -140,7 +140,7 @@ func (c *EffectiveHPAController) UpdateHPAIfNeed(ctx context.Context, ehpa *auto
var needUpdate bool
hpa, err := c.NewHPAObject(ctx, ehpa, substitute, tsp)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreateHPAObject", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreateHPAObject", err.Error())
klog.Errorf("Failed to create object, HorizontalPodAutoscaler %s error %v", klog.KObj(hpa), err)
return nil, err
}
Expand All @@ -163,7 +163,7 @@ func (c *EffectiveHPAController) UpdateHPAIfNeed(ctx context.Context, ehpa *auto
if needUpdate {
err := c.Update(ctx, hpaExist)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedUpdateHPA", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedUpdateHPA", err.Error())
klog.Errorf("Failed to update HorizontalPodAutoscaler %s error %v", klog.KObj(hpaExist), err)
return nil, err
}
Expand Down
10 changes: 5 additions & 5 deletions pkg/controller/ehpa/predict.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (c *EffectiveHPAController) ReconcilePredication(ctx context.Context, ehpa
if errors.IsNotFound(err) {
return c.CreatePrediction(ctx, ehpa)
} else {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetPrediction", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetPrediction", err.Error())
klog.Errorf("Failed to get TimeSeriesPrediction, ehpa %s error %v", klog.KObj(ehpa), err)
return nil, err
}
Expand Down Expand Up @@ -60,14 +60,14 @@ func (c *EffectiveHPAController) GetPredication(ctx context.Context, ehpa *autos
func (c *EffectiveHPAController) CreatePrediction(ctx context.Context, ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler) (*predictionapi.TimeSeriesPrediction, error) {
prediction, err := c.NewPredictionObject(ehpa)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreatePredictionObject", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreatePredictionObject", err.Error())
klog.Errorf("Failed to create object, TimeSeriesPrediction %s error %v", klog.KObj(prediction), err)
return nil, err
}

err = c.Client.Create(ctx, prediction)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreatePrediction", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreatePrediction", err.Error())
klog.Errorf("Failed to create TimeSeriesPrediction %s error %v", klog.KObj(prediction), err)
return nil, err
}
Expand All @@ -81,7 +81,7 @@ func (c *EffectiveHPAController) CreatePrediction(ctx context.Context, ehpa *aut
func (c *EffectiveHPAController) UpdatePredictionIfNeed(ctx context.Context, ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler, predictionExist *predictionapi.TimeSeriesPrediction) (*predictionapi.TimeSeriesPrediction, error) {
prediction, err := c.NewPredictionObject(ehpa)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreatePredictionObject", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreatePredictionObject", err.Error())
klog.Errorf("Failed to create object, TimeSeriesPrediction %s error %v", klog.KObj(prediction), err)
return nil, err
}
Expand All @@ -90,7 +90,7 @@ func (c *EffectiveHPAController) UpdatePredictionIfNeed(ctx context.Context, ehp
predictionExist.Spec = prediction.Spec
err := c.Update(ctx, predictionExist)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedUpdatePrediction", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedUpdatePrediction", err.Error())
klog.Errorf("Failed to update TimeSeriesPrediction %s", klog.KObj(predictionExist))
return nil, err
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/controller/ehpa/substitute.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (c *EffectiveHPAController) ReconcileSubstitute(ctx context.Context, ehpa *
if errors.IsNotFound(err) {
return c.CreateSubstitute(ctx, ehpa, scale)
} else {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetSubstitute", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetSubstitute", err.Error())
klog.Errorf("Failed to get Substitute, ehpa %s error %v", klog.KObj(ehpa), err)
return nil, err
}
Expand All @@ -42,14 +42,14 @@ func (c *EffectiveHPAController) ReconcileSubstitute(ctx context.Context, ehpa *
func (c *EffectiveHPAController) CreateSubstitute(ctx context.Context, ehpa *autoscalingapi.EffectiveHorizontalPodAutoscaler, scale *autoscalingapiv1.Scale) (*autoscalingapi.Substitute, error) {
substitute, err := c.NewSubstituteObject(ehpa, scale)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreateSubstituteObject", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreateSubstituteObject", err.Error())
klog.Errorf("Failed to create object, Substitute %s error %v", klog.KObj(substitute), err)
return nil, err
}

err = c.Client.Create(ctx, substitute)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedCreateSubstitute", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedCreateSubstitute", err.Error())
klog.Errorf("Failed to create Substitute %s error %v", klog.KObj(substitute), err)
return nil, err
}
Expand Down Expand Up @@ -92,7 +92,7 @@ func (c *EffectiveHPAController) UpdateSubstituteIfNeed(ctx context.Context, ehp
substituteExist.Spec.SubstituteTargetRef = ehpa.Spec.ScaleTargetRef
err := c.Update(ctx, substituteExist)
if err != nil {
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedUpdateSubstitute", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedUpdateSubstitute", err.Error())
klog.Errorf("Failed to update Substitute %s, error %v", klog.KObj(substituteExist), err)
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/ehpa/substitute_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (c *SubstituteController) Reconcile(ctx context.Context, req ctrl.Request)

scale, _, err := utils.GetScale(ctx, c.RestMapper, c.ScaleClient, substitute.Namespace, substitute.Spec.SubstituteTargetRef)
if err != nil {
c.Recorder.Event(substitute, v1.EventTypeNormal, "FailedGetScale", err.Error())
c.Recorder.Event(substitute, v1.EventTypeWarning, "FailedGetScale", err.Error())
klog.Errorf("Failed to get scale, Substitute %s error %v", klog.KObj(substitute), err)
return ctrl.Result{}, err
}
Expand All @@ -63,7 +63,7 @@ func (c *SubstituteController) Reconcile(ctx context.Context, req ctrl.Request)

err := c.Update(ctx, substitute)
if err != nil {
c.Recorder.Event(substitute, v1.EventTypeNormal, "FailedUpdateSubstitute", err.Error())
c.Recorder.Event(substitute, v1.EventTypeWarning, "FailedUpdateSubstitute", err.Error())
klog.Errorf("Failed to update Substitute %s, error %v", klog.KObj(substitute), err)
return ctrl.Result{}, err
}
Expand All @@ -75,7 +75,7 @@ func (c *SubstituteController) Reconcile(ctx context.Context, req ctrl.Request)
substitute.Status = newStatus
err := c.Status().Update(ctx, substitute)
if err != nil {
c.Recorder.Event(substitute, v1.EventTypeNormal, "FailedUpdateStatus", err.Error())
c.Recorder.Event(substitute, v1.EventTypeWarning, "FailedUpdateStatus", err.Error())
klog.Errorf("Failed to update status, Substitute %s error %v", klog.KObj(substitute), err)
return ctrl.Result{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/evpa/effective_vpa_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func (c *EffectiveVPAController) UpdateStatus(ctx context.Context, evpa *autosca
evpa.Status = *newStatus
err := c.Status().Update(ctx, evpa)
if err != nil {
c.Recorder.Event(evpa, v1.EventTypeNormal, "FailedUpdateStatus", err.Error())
c.Recorder.Event(evpa, v1.EventTypeWarning, "FailedUpdateStatus", err.Error())
klog.Errorf("Failed to update status, evpa %s error %v", klog.KObj(evpa), err)
return
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/timeseriesprediction/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (tc *Controller) UpdateStatus(ctx context.Context, tsPrediction *prediction
tsPrediction.Status = *newStatus
err := tc.Client.Status().Update(ctx, tsPrediction)
if err != nil {
tc.Recorder.Event(tsPrediction, v1.EventTypeNormal, "FailedUpdateStatus", err.Error())
tc.Recorder.Event(tsPrediction, v1.EventTypeWarning, "FailedUpdateStatus", err.Error())
klog.Errorf("Failed to update status for %v", klog.KObj(tsPrediction))
return err
}
Expand Down
2 changes: 1 addition & 1 deletion site/content/en/docs/Contributing/code-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ klog.ErrorDepth(5, fmt.Errorf("failed to get ehpa %s: %v", klog.KObj(ehpa), err)
- consider failure paths and success paths
- event do not need the object key
```go
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetSubstitute", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetSubstitute", err.Error())
```

### comment
Expand Down
2 changes: 1 addition & 1 deletion site/content/zh/docs/Contributing/code-standards.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ klog.ErrorDepth(5, fmt.Errorf("failed to get ehpa %s: %v", klog.KObj(ehpa), err)
- consider failure paths and success paths
- event do not need the object key
```go
c.Recorder.Event(ehpa, v1.EventTypeNormal, "FailedGetSubstitute", err.Error())
c.Recorder.Event(ehpa, v1.EventTypeWarning, "FailedGetSubstitute", err.Error())
```

### comment
Expand Down

0 comments on commit ea3976c

Please sign in to comment.