Skip to content

Commit

Permalink
convert to case-switch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ryan Tay committed Sep 10, 2024
1 parent 57ab64e commit 03f0998
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions admiral/pkg/controller/admiral/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,10 @@ func checkIfResourceVersionHasIncreased(ctxLogger *logrus.Entry, ctx context.Con
}

func shouldRetry(ctxLogger *logrus.Entry, ctx context.Context, obj interface{}, delegator Delegator) bool {
var (
latestObjMeta metav1.Object
latestOk bool
)
objMeta, ok := obj.(metav1.Object)
if ok {
if reflect.ValueOf(objMeta).IsNil() || reflect.ValueOf(delegator).IsNil() {
Expand All @@ -465,9 +469,12 @@ func shouldRetry(ctxLogger *logrus.Entry, ctx context.Context, obj interface{},
ctxLogger.Errorf("task=shouldRetry message=unable to fetch latest object from cache, obj received=%+v", objMeta)
return true
}
latestObjMeta, latestOk := objFromCache.(metav1.Object)
if servicesSlice, servicesSliceOk := objFromCache.([]*v1.Service); servicesSliceOk {
switch objFromCache.(type) {
case []*v1.Service:
servicesSlice, _ := objFromCache.([]*v1.Service)
latestObjMeta, latestOk = getMatchingServiceFromServiceSlice(objMeta, servicesSlice)
default:
latestObjMeta, latestOk = objFromCache.(metav1.Object)
}
if !latestOk || reflect.ValueOf(latestObjMeta).IsNil() {
ctxLogger.Errorf("task=shouldRetry message=unable to cast latest object from cache to metav1 object, obj is of type %+v,obj received=%+v", reflect.TypeOf(objFromCache), objMeta)
Expand Down

0 comments on commit 03f0998

Please sign in to comment.