Skip to content

Commit

Permalink
improve performance of casting status type (istio#30204)
Browse files Browse the repository at this point in the history
* improve performance of casting status type

* convert status references to pointers
  • Loading branch information
therealmitchconnors authored Jan 20, 2021
1 parent 504383a commit 68d5c3f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions pilot/pkg/status/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package status

import (
"encoding/json"
"fmt"
"strconv"
"strings"
Expand Down Expand Up @@ -227,12 +226,11 @@ func (c *DistributionController) configDeleted(res config.Config) {
c.workers.Delete(*r)
}

func GetTypedStatus(in interface{}) (out v1alpha1.IstioStatus, err error) {
var statusBytes []byte
if statusBytes, err = json.Marshal(in); err == nil {
err = json.Unmarshal(statusBytes, &out)
func GetTypedStatus(in interface{}) (out *v1alpha1.IstioStatus, err error) {
if ret, ok := in.(*v1alpha1.IstioStatus); ok {
return ret, nil
}
return
return nil, fmt.Errorf("cannot cast %t: %v to IstioStatus", in, in)
}

func boolToConditionStatus(b bool) string {
Expand All @@ -259,11 +257,11 @@ func ReconcileStatuses(current *config.Config, desired Progress, generation int6
} else {
scope.Warn("Encountered unexpected status content. Overwriting status.")
}
currentStatus = v1alpha1.IstioStatus{
currentStatus = &v1alpha1.IstioStatus{
Conditions: []*v1alpha1.IstioCondition{&desiredCondition},
}
currentStatus.ObservedGeneration = generation
return true, &currentStatus
return true, currentStatus
}
var currentCondition *v1alpha1.IstioCondition
conditionIndex := -1
Expand All @@ -284,7 +282,7 @@ func ReconcileStatuses(current *config.Config, desired Progress, generation int6
currentStatus.Conditions = append(currentStatus.Conditions, &desiredCondition)
}
currentStatus.ObservedGeneration = generation
return needsReconcile, &currentStatus
return needsReconcile, currentStatus
}

type DistroReportHandler struct {
Expand Down
4 changes: 2 additions & 2 deletions pilot/pkg/status/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
"istio.io/istio/pkg/config"
)

var statusStillPropagating = v1alpha1.IstioStatus{
var statusStillPropagating = &v1alpha1.IstioStatus{
Conditions: []*v1alpha1.IstioCondition{
{
Type: "PassedValidation",
Expand Down Expand Up @@ -175,7 +175,7 @@ func Test_getTypedStatus(t *testing.T) {
tests := []struct {
name string
args args
wantOut v1alpha1.IstioStatus
wantOut *v1alpha1.IstioStatus
wantErr bool
}{
{
Expand Down

0 comments on commit 68d5c3f

Please sign in to comment.