K8s: Add resource type helper to avoid so many hardcoded names (#79344)

This commit is contained in:
Ryan McKinley
2023-12-11 22:03:48 +02:00
committed by GitHub
parent 5147bdeb4b
commit f69516bf47
11 changed files with 190 additions and 71 deletions
@@ -8,6 +8,7 @@ import (
"k8s.io/apiserver/pkg/endpoints/request"
"github.com/grafana/grafana/pkg/infra/appcontext"
"github.com/grafana/grafana/pkg/setting"
)
@@ -75,3 +76,16 @@ func ParseNamespace(ns string) (NamespaceInfo, error) {
}
return info, nil
}
func OrgIDForList(ctx context.Context) (int64, error) {
ns := request.NamespaceValue(ctx)
if ns == "" {
user, err := appcontext.User(ctx)
if user != nil {
return user.OrgID, err
}
return -1, err
}
info, err := ParseNamespace(ns)
return info.OrgID, err
}