-
Notifications
You must be signed in to change notification settings - Fork 444
/
status.go
66 lines (53 loc) · 1.92 KB
/
status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package statusutils
import (
"github.com/solo-io/gloo/projects/gloo/api/external/solo/ratelimit"
ratelimitpkg "github.com/solo-io/gloo/projects/gloo/pkg/api/external/solo/ratelimit"
"github.com/solo-io/solo-kit/pkg/api/v1/resources"
"github.com/solo-io/solo-kit/pkg/api/v1/resources/core"
"github.com/solo-io/solo-kit/pkg/utils/statusutils"
)
func GetStatusReporterNamespaceOrDefault(defaultNamespace string) string {
namespace, err := statusutils.GetStatusReporterNamespaceFromEnv()
if err == nil {
return namespace
}
return defaultNamespace
}
func GetStatusClientFromEnvOrDefault(defaultNamespace string) resources.StatusClient {
statusReporterNamespace := GetStatusReporterNamespaceOrDefault(defaultNamespace)
return GetStatusClientForNamespace(statusReporterNamespace)
}
func GetStatusClientForNamespace(namespace string) resources.StatusClient {
return &HybridStatusClient{
namespacedStatusClient: statusutils.NewNamespacedStatusesClient(namespace),
}
}
var _ resources.StatusClient = &HybridStatusClient{}
// The HybridStatusClient is used while some resources support namespaced statuses
// and others (RateLimitConfig) do not
type HybridStatusClient struct {
namespacedStatusClient *statusutils.NamespacedStatusesClient
}
func (h *HybridStatusClient) GetStatus(resource resources.InputResource) *core.Status {
if h.shouldUseDeprecatedStatus(resource) {
return resource.GetStatus()
}
return h.namespacedStatusClient.GetStatus(resource)
}
func (h *HybridStatusClient) SetStatus(resource resources.InputResource, status *core.Status) {
if h.shouldUseDeprecatedStatus(resource) {
resource.SetStatus(status)
return
}
h.namespacedStatusClient.SetStatus(resource, status)
}
func (h *HybridStatusClient) shouldUseDeprecatedStatus(resource resources.InputResource) bool {
switch resource.(type) {
case *ratelimit.RateLimitConfig:
return true
case *ratelimitpkg.RateLimitConfig:
return true
default:
return false
}
}