1
0
mirror of https://github.com/rancher/steve.git synced 2025-09-17 07:48:52 +00:00
This commit is contained in:
Darren Shepherd
2020-07-24 01:42:00 -07:00
parent f403507ea9
commit a3fbe499d1
13 changed files with 195 additions and 264 deletions

View File

@@ -23,6 +23,7 @@ type Factory interface {
ByGVR(gvr schema.GroupVersionResource) string
ByGVK(gvr schema.GroupVersionKind) string
OnChange(ctx context.Context, cb func())
AddTemplate(template ...Template)
}
type Collection struct {
@@ -210,17 +211,19 @@ func (c *Collection) ByGVK(gvk schema.GroupVersionKind) string {
return c.byGVK[gvk]
}
func (c *Collection) AddTemplate(template *Template) {
func (c *Collection) AddTemplate(templates ...Template) {
c.lock.RLock()
defer c.lock.RUnlock()
if template.Kind != "" {
c.templates[template.Group+"/"+template.Kind] = template
}
if template.ID != "" {
c.templates[template.ID] = template
}
if template.Kind == "" && template.Group == "" && template.ID == "" {
c.templates[""] = template
for i, template := range templates {
if template.Kind != "" {
c.templates[template.Group+"/"+template.Kind] = &templates[i]
}
if template.ID != "" {
c.templates[template.ID] = &templates[i]
}
if template.Kind == "" && template.Group == "" && template.ID == "" {
c.templates[""] = &templates[i]
}
}
}