package resource import ( "sync" "k8s.io/apimachinery/pkg/runtime/schema" ) //rancherTypes is a set of all types generated by rancher var ( rancherTypes = struct { sync.RWMutex m map[schema.GroupVersionResource]bool }{m: make(map[schema.GroupVersionResource]bool)} ) //Get returns a copy of the set of rancherTypes func Get() map[schema.GroupVersionResource]bool { rancherTypes.RLock() defer rancherTypes.RUnlock() targetMap := make(map[schema.GroupVersionResource]bool, len(rancherTypes.m)) for key, value := range rancherTypes.m { targetMap[key] = value } return targetMap } //Put adds an object to the set and panic on collision func Put(key schema.GroupVersionResource) { rancherTypes.Lock() defer rancherTypes.Unlock() _, exists := rancherTypes.m[key] if exists { //only used in an init function panic("key exists in rancherTypes") } rancherTypes.m[key] = true }