MCPcopy
hub / github.com/derailed/k9s / NewGVR

Function NewGVR

internal/client/gvr.go:58–84  ·  view source on GitHub ↗

NewGVR builds a new gvr from a group, version, resource.

(s string)

Source from the content-addressed store, hash-verified

56
57// NewGVR builds a new gvr from a group, version, resource.
58func NewGVR(s string) *GVR {
59 raw := s
60 tokens := strings.Split(s, ":")
61 var g, v, r, sr string
62 if len(tokens) == 2 {
63 raw, sr = tokens[0], tokens[1]
64 }
65 tokens = strings.Split(raw, "/")
66 switch len(tokens) {
67 case 3:
68 g, v, r = tokens[0], tokens[1], tokens[2]
69 case 2:
70 v, r = tokens[0], tokens[1]
71 case 1:
72 r = tokens[0]
73 default:
74 slog.Error("GVR init failed!", slogs.Error, fmt.Errorf("can't parse GVR %q", s))
75 }
76
77 gvr := GVR{raw: s, g: g, v: v, r: r, sr: sr}
78 if cgvr := gvrsCache.get(gvr.String()); cgvr != nil {
79 return cgvr
80 }
81 gvrsCache.add(&gvr)
82
83 return &gvr
84}
85
86func (g *GVR) IsAlias() bool {
87 return !g.IsK8sRes()

Callers 15

TestGVRFunction · 0.92
TestAsGVFunction · 0.92
TestNewGVRFunction · 0.92
TestGVRAsResourceNameFunction · 0.92
TestToRFunction · 0.92
TestToGFunction · 0.92
TestToVFunction · 0.92
TestToStringFunction · 0.92
TestLogFullBufferFunction · 0.92
TestLogFilterFunction · 0.92
TestLogStartStopFunction · 0.92
TestLogClearFunction · 0.92

Calls 4

StringMethod · 0.95
getMethod · 0.80
ErrorMethod · 0.45
addMethod · 0.45

Tested by 15

TestGVRFunction · 0.74
TestAsGVFunction · 0.74
TestNewGVRFunction · 0.74
TestGVRAsResourceNameFunction · 0.74
TestToRFunction · 0.74
TestToGFunction · 0.74
TestToVFunction · 0.74
TestToStringFunction · 0.74
TestLogFullBufferFunction · 0.74
TestLogFilterFunction · 0.74
TestLogStartStopFunction · 0.74
TestLogClearFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…