github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/controllers/apis/uiresource/disable.go (about) 1 package uiresource 2 3 import ( 4 "github.com/tilt-dev/tilt/internal/controllers/apis/configmap" 5 "github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1" 6 ) 7 8 func DisableResourceStatus(getCM func(name string) (v1alpha1.ConfigMap, error), disableSources []v1alpha1.DisableSource) (v1alpha1.DisableResourceStatus, error) { 9 var result v1alpha1.DisableResourceStatus 10 if len(disableSources) == 0 { 11 result.State = v1alpha1.DisableStateEnabled 12 return result, nil 13 } 14 15 errorCount := 0 16 pendingCount := 0 17 for _, source := range disableSources { 18 19 dr, _, err := configmap.DisableStatus(getCM, &source) 20 if err != nil { 21 return v1alpha1.DisableResourceStatus{}, err 22 } 23 switch dr { 24 case v1alpha1.DisableStateEnabled: 25 result.EnabledCount += 1 26 case v1alpha1.DisableStateDisabled: 27 result.DisabledCount += 1 28 case v1alpha1.DisableStatePending: 29 pendingCount += 1 30 case v1alpha1.DisableStateError: 31 // TODO(matt) - there are arguments for incrementing any of the three fields in this case, or adding an ErrorCount field 32 // but none seem compelling. We could add an ErrorCount later, but that's just another case to handle downstream. 33 result.DisabledCount += 1 34 errorCount += 1 35 } 36 } 37 result.State = v1alpha1.DisableStatePending 38 39 if errorCount > 0 { 40 result.State = v1alpha1.DisableStateError 41 } else if pendingCount > 0 { 42 result.State = v1alpha1.DisableStatePending 43 } else if result.DisabledCount > 0 { 44 result.State = v1alpha1.DisableStateDisabled 45 } else if result.EnabledCount > 0 { 46 result.State = v1alpha1.DisableStateEnabled 47 } 48 result.Sources = disableSources 49 return result, nil 50 }