mirror of
https://github.com/rancher/types.git
synced 2025-09-01 05:09:10 +00:00
Bump vendor
This commit is contained in:
1
vendor/github.com/golang/groupcache/.gitignore
generated
vendored
Normal file
1
vendor/github.com/golang/groupcache/.gitignore
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*~
|
191
vendor/github.com/golang/groupcache/LICENSE
generated
vendored
Normal file
191
vendor/github.com/golang/groupcache/LICENSE
generated
vendored
Normal file
@@ -0,0 +1,191 @@
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction, and
|
||||
distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by the copyright
|
||||
owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all other entities
|
||||
that control, are controlled by, or are under common control with that entity.
|
||||
For the purposes of this definition, "control" means (i) the power, direct or
|
||||
indirect, to cause the direction or management of such entity, whether by
|
||||
contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity exercising
|
||||
permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications, including
|
||||
but not limited to software source code, documentation source, and configuration
|
||||
files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical transformation or
|
||||
translation of a Source form, including but not limited to compiled object code,
|
||||
generated documentation, and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or Object form, made
|
||||
available under the License, as indicated by a copyright notice that is included
|
||||
in or attached to the work (an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object form, that
|
||||
is based on (or derived from) the Work and for which the editorial revisions,
|
||||
annotations, elaborations, or other modifications represent, as a whole, an
|
||||
original work of authorship. For the purposes of this License, Derivative Works
|
||||
shall not include works that remain separable from, or merely link (or bind by
|
||||
name) to the interfaces of, the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including the original version
|
||||
of the Work and any modifications or additions to that Work or Derivative Works
|
||||
thereof, that is intentionally submitted to Licensor for inclusion in the Work
|
||||
by the copyright owner or by an individual or Legal Entity authorized to submit
|
||||
on behalf of the copyright owner. For the purposes of this definition,
|
||||
"submitted" means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems, and
|
||||
issue tracking systems that are managed by, or on behalf of, the Licensor for
|
||||
the purpose of discussing and improving the Work, but excluding communication
|
||||
that is conspicuously marked or otherwise designated in writing by the copyright
|
||||
owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf
|
||||
of whom a Contribution has been received by Licensor and subsequently
|
||||
incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the Work and such
|
||||
Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License.
|
||||
|
||||
Subject to the terms and conditions of this License, each Contributor hereby
|
||||
grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free,
|
||||
irrevocable (except as stated in this section) patent license to make, have
|
||||
made, use, offer to sell, sell, import, and otherwise transfer the Work, where
|
||||
such license applies only to those patent claims licensable by such Contributor
|
||||
that are necessarily infringed by their Contribution(s) alone or by combination
|
||||
of their Contribution(s) with the Work to which such Contribution(s) was
|
||||
submitted. If You institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work or a
|
||||
Contribution incorporated within the Work constitutes direct or contributory
|
||||
patent infringement, then any patent licenses granted to You under this License
|
||||
for that Work shall terminate as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution.
|
||||
|
||||
You may reproduce and distribute copies of the Work or Derivative Works thereof
|
||||
in any medium, with or without modifications, and in Source or Object form,
|
||||
provided that You meet the following conditions:
|
||||
|
||||
You must give any other recipients of the Work or Derivative Works a copy of
|
||||
this License; and
|
||||
You must cause any modified files to carry prominent notices stating that You
|
||||
changed the files; and
|
||||
You must retain, in the Source form of any Derivative Works that You distribute,
|
||||
all copyright, patent, trademark, and attribution notices from the Source form
|
||||
of the Work, excluding those notices that do not pertain to any part of the
|
||||
Derivative Works; and
|
||||
If the Work includes a "NOTICE" text file as part of its distribution, then any
|
||||
Derivative Works that You distribute must include a readable copy of the
|
||||
attribution notices contained within such NOTICE file, excluding those notices
|
||||
that do not pertain to any part of the Derivative Works, in at least one of the
|
||||
following places: within a NOTICE text file distributed as part of the
|
||||
Derivative Works; within the Source form or documentation, if provided along
|
||||
with the Derivative Works; or, within a display generated by the Derivative
|
||||
Works, if and wherever such third-party notices normally appear. The contents of
|
||||
the NOTICE file are for informational purposes only and do not modify the
|
||||
License. You may add Your own attribution notices within Derivative Works that
|
||||
You distribute, alongside or as an addendum to the NOTICE text from the Work,
|
||||
provided that such additional attribution notices cannot be construed as
|
||||
modifying the License.
|
||||
You may add Your own copyright statement to Your modifications and may provide
|
||||
additional or different license terms and conditions for use, reproduction, or
|
||||
distribution of Your modifications, or for any such Derivative Works as a whole,
|
||||
provided Your use, reproduction, and distribution of the Work otherwise complies
|
||||
with the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions.
|
||||
|
||||
Unless You explicitly state otherwise, any Contribution intentionally submitted
|
||||
for inclusion in the Work by You to the Licensor shall be under the terms and
|
||||
conditions of this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify the terms of
|
||||
any separate license agreement you may have executed with Licensor regarding
|
||||
such Contributions.
|
||||
|
||||
6. Trademarks.
|
||||
|
||||
This License does not grant permission to use the trade names, trademarks,
|
||||
service marks, or product names of the Licensor, except as required for
|
||||
reasonable and customary use in describing the origin of the Work and
|
||||
reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty.
|
||||
|
||||
Unless required by applicable law or agreed to in writing, Licensor provides the
|
||||
Work (and each Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied,
|
||||
including, without limitation, any warranties or conditions of TITLE,
|
||||
NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are
|
||||
solely responsible for determining the appropriateness of using or
|
||||
redistributing the Work and assume any risks associated with Your exercise of
|
||||
permissions under this License.
|
||||
|
||||
8. Limitation of Liability.
|
||||
|
||||
In no event and under no legal theory, whether in tort (including negligence),
|
||||
contract, or otherwise, unless required by applicable law (such as deliberate
|
||||
and grossly negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special, incidental,
|
||||
or consequential damages of any character arising as a result of this License or
|
||||
out of the use or inability to use the Work (including but not limited to
|
||||
damages for loss of goodwill, work stoppage, computer failure or malfunction, or
|
||||
any and all other commercial damages or losses), even if such Contributor has
|
||||
been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability.
|
||||
|
||||
While redistributing the Work or Derivative Works thereof, You may choose to
|
||||
offer, and charge a fee for, acceptance of support, warranty, indemnity, or
|
||||
other liability obligations and/or rights consistent with this License. However,
|
||||
in accepting such obligations, You may act only on Your own behalf and on Your
|
||||
sole responsibility, not on behalf of any other Contributor, and only if You
|
||||
agree to indemnify, defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason of your
|
||||
accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work
|
||||
|
||||
To apply the Apache License to your work, attach the following boilerplate
|
||||
notice, with the fields enclosed by brackets "[]" replaced with your own
|
||||
identifying information. (Don't include the brackets!) The text should be
|
||||
enclosed in the appropriate comment syntax for the file format. We also
|
||||
recommend that a file or class name and description of purpose be included on
|
||||
the same "printed page" as the copyright notice for easier identification within
|
||||
third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
73
vendor/github.com/golang/groupcache/README.md
generated
vendored
Normal file
73
vendor/github.com/golang/groupcache/README.md
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
# groupcache
|
||||
|
||||
## Summary
|
||||
|
||||
groupcache is a caching and cache-filling library, intended as a
|
||||
replacement for memcached in many cases.
|
||||
|
||||
For API docs and examples, see http://godoc.org/github.com/golang/groupcache
|
||||
|
||||
## Comparison to memcached
|
||||
|
||||
### **Like memcached**, groupcache:
|
||||
|
||||
* shards by key to select which peer is responsible for that key
|
||||
|
||||
### **Unlike memcached**, groupcache:
|
||||
|
||||
* does not require running a separate set of servers, thus massively
|
||||
reducing deployment/configuration pain. groupcache is a client
|
||||
library as well as a server. It connects to its own peers.
|
||||
|
||||
* comes with a cache filling mechanism. Whereas memcached just says
|
||||
"Sorry, cache miss", often resulting in a thundering herd of
|
||||
database (or whatever) loads from an unbounded number of clients
|
||||
(which has resulted in several fun outages), groupcache coordinates
|
||||
cache fills such that only one load in one process of an entire
|
||||
replicated set of processes populates the cache, then multiplexes
|
||||
the loaded value to all callers.
|
||||
|
||||
* does not support versioned values. If key "foo" is value "bar",
|
||||
key "foo" must always be "bar". There are neither cache expiration
|
||||
times, nor explicit cache evictions. Thus there is also no CAS,
|
||||
nor Increment/Decrement. This also means that groupcache....
|
||||
|
||||
* ... supports automatic mirroring of super-hot items to multiple
|
||||
processes. This prevents memcached hot spotting where a machine's
|
||||
CPU and/or NIC are overloaded by very popular keys/values.
|
||||
|
||||
* is currently only available for Go. It's very unlikely that I
|
||||
(bradfitz@) will port the code to any other language.
|
||||
|
||||
## Loading process
|
||||
|
||||
In a nutshell, a groupcache lookup of **Get("foo")** looks like:
|
||||
|
||||
(On machine #5 of a set of N machines running the same code)
|
||||
|
||||
1. Is the value of "foo" in local memory because it's super hot? If so, use it.
|
||||
|
||||
2. Is the value of "foo" in local memory because peer #5 (the current
|
||||
peer) is the owner of it? If so, use it.
|
||||
|
||||
3. Amongst all the peers in my set of N, am I the owner of the key
|
||||
"foo"? (e.g. does it consistent hash to 5?) If so, load it. If
|
||||
other callers come in, via the same process or via RPC requests
|
||||
from peers, they block waiting for the load to finish and get the
|
||||
same answer. If not, RPC to the peer that's the owner and get
|
||||
the answer. If the RPC fails, just load it locally (still with
|
||||
local dup suppression).
|
||||
|
||||
## Users
|
||||
|
||||
groupcache is in production use by dl.google.com (its original user),
|
||||
parts of Blogger, parts of Google Code, parts of Google Fiber, parts
|
||||
of Google production monitoring systems, etc.
|
||||
|
||||
## Presentations
|
||||
|
||||
See http://talks.golang.org/2013/oscon-dl.slide
|
||||
|
||||
## Help
|
||||
|
||||
Use the golang-nuts mailing list for any discussion or questions.
|
121
vendor/github.com/golang/groupcache/lru/lru.go
generated
vendored
Normal file
121
vendor/github.com/golang/groupcache/lru/lru.go
generated
vendored
Normal file
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
Copyright 2013 Google Inc.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// Package lru implements an LRU cache.
|
||||
package lru
|
||||
|
||||
import "container/list"
|
||||
|
||||
// Cache is an LRU cache. It is not safe for concurrent access.
|
||||
type Cache struct {
|
||||
// MaxEntries is the maximum number of cache entries before
|
||||
// an item is evicted. Zero means no limit.
|
||||
MaxEntries int
|
||||
|
||||
// OnEvicted optionally specificies a callback function to be
|
||||
// executed when an entry is purged from the cache.
|
||||
OnEvicted func(key Key, value interface{})
|
||||
|
||||
ll *list.List
|
||||
cache map[interface{}]*list.Element
|
||||
}
|
||||
|
||||
// A Key may be any value that is comparable. See http://golang.org/ref/spec#Comparison_operators
|
||||
type Key interface{}
|
||||
|
||||
type entry struct {
|
||||
key Key
|
||||
value interface{}
|
||||
}
|
||||
|
||||
// New creates a new Cache.
|
||||
// If maxEntries is zero, the cache has no limit and it's assumed
|
||||
// that eviction is done by the caller.
|
||||
func New(maxEntries int) *Cache {
|
||||
return &Cache{
|
||||
MaxEntries: maxEntries,
|
||||
ll: list.New(),
|
||||
cache: make(map[interface{}]*list.Element),
|
||||
}
|
||||
}
|
||||
|
||||
// Add adds a value to the cache.
|
||||
func (c *Cache) Add(key Key, value interface{}) {
|
||||
if c.cache == nil {
|
||||
c.cache = make(map[interface{}]*list.Element)
|
||||
c.ll = list.New()
|
||||
}
|
||||
if ee, ok := c.cache[key]; ok {
|
||||
c.ll.MoveToFront(ee)
|
||||
ee.Value.(*entry).value = value
|
||||
return
|
||||
}
|
||||
ele := c.ll.PushFront(&entry{key, value})
|
||||
c.cache[key] = ele
|
||||
if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries {
|
||||
c.RemoveOldest()
|
||||
}
|
||||
}
|
||||
|
||||
// Get looks up a key's value from the cache.
|
||||
func (c *Cache) Get(key Key) (value interface{}, ok bool) {
|
||||
if c.cache == nil {
|
||||
return
|
||||
}
|
||||
if ele, hit := c.cache[key]; hit {
|
||||
c.ll.MoveToFront(ele)
|
||||
return ele.Value.(*entry).value, true
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// Remove removes the provided key from the cache.
|
||||
func (c *Cache) Remove(key Key) {
|
||||
if c.cache == nil {
|
||||
return
|
||||
}
|
||||
if ele, hit := c.cache[key]; hit {
|
||||
c.removeElement(ele)
|
||||
}
|
||||
}
|
||||
|
||||
// RemoveOldest removes the oldest item from the cache.
|
||||
func (c *Cache) RemoveOldest() {
|
||||
if c.cache == nil {
|
||||
return
|
||||
}
|
||||
ele := c.ll.Back()
|
||||
if ele != nil {
|
||||
c.removeElement(ele)
|
||||
}
|
||||
}
|
||||
|
||||
func (c *Cache) removeElement(e *list.Element) {
|
||||
c.ll.Remove(e)
|
||||
kv := e.Value.(*entry)
|
||||
delete(c.cache, kv.key)
|
||||
if c.OnEvicted != nil {
|
||||
c.OnEvicted(kv.key, kv.value)
|
||||
}
|
||||
}
|
||||
|
||||
// Len returns the number of items in the cache.
|
||||
func (c *Cache) Len() int {
|
||||
if c.cache == nil {
|
||||
return 0
|
||||
}
|
||||
return c.ll.Len()
|
||||
}
|
22
vendor/github.com/rancher/norman/clientbase/object_client.go
generated
vendored
22
vendor/github.com/rancher/norman/clientbase/object_client.go
generated
vendored
@@ -6,6 +6,7 @@ import (
|
||||
"github.com/pkg/errors"
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
"k8s.io/apimachinery/pkg/watch"
|
||||
@@ -18,6 +19,17 @@ type ObjectFactory interface {
|
||||
List() runtime.Object
|
||||
}
|
||||
|
||||
type UnstructuredObjectFactory struct {
|
||||
}
|
||||
|
||||
func (u *UnstructuredObjectFactory) Object() runtime.Object {
|
||||
return &unstructured.Unstructured{}
|
||||
}
|
||||
|
||||
func (u *UnstructuredObjectFactory) List() runtime.Object {
|
||||
return &unstructured.UnstructuredList{}
|
||||
}
|
||||
|
||||
type ObjectClient struct {
|
||||
restClient rest.Interface
|
||||
resource *metav1.APIResource
|
||||
@@ -36,6 +48,16 @@ func NewObjectClient(namespace string, restClient rest.Interface, apiResource *m
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ObjectClient) UnstructuredClient() *ObjectClient {
|
||||
return &ObjectClient{
|
||||
restClient: p.restClient,
|
||||
resource: p.resource,
|
||||
gvk: p.gvk,
|
||||
ns: p.ns,
|
||||
Factory: &UnstructuredObjectFactory{},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *ObjectClient) getAPIPrefix() string {
|
||||
if p.gvk.Group == "" {
|
||||
return "api"
|
||||
|
149
vendor/github.com/rancher/norman/condition/condition.go
generated
vendored
Normal file
149
vendor/github.com/rancher/norman/condition/condition.go
generated
vendored
Normal file
@@ -0,0 +1,149 @@
|
||||
package condition
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/rancher/norman/controller"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
)
|
||||
|
||||
type Cond string
|
||||
|
||||
func (c Cond) True(obj runtime.Object) {
|
||||
setStatus(obj, string(c), "True")
|
||||
}
|
||||
|
||||
func (c Cond) IsTrue(obj runtime.Object) bool {
|
||||
return getStatus(obj, string(c)) == "True"
|
||||
}
|
||||
|
||||
func (c Cond) False(obj runtime.Object) {
|
||||
setStatus(obj, string(c), "False")
|
||||
}
|
||||
|
||||
func (c Cond) IsFalse(obj runtime.Object) bool {
|
||||
return getStatus(obj, string(c)) == "False"
|
||||
}
|
||||
|
||||
func (c Cond) Unknown(obj runtime.Object) {
|
||||
setStatus(obj, string(c), "Unknown")
|
||||
}
|
||||
|
||||
func (c Cond) IsUnknown(obj runtime.Object) bool {
|
||||
return getStatus(obj, string(c)) == "Unknown"
|
||||
}
|
||||
|
||||
func (c Cond) Reason(obj runtime.Object, reason string) {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
getFieldValue(cond, "Reason").SetString(reason)
|
||||
touchTS(cond)
|
||||
}
|
||||
|
||||
func (c Cond) GetReason(obj runtime.Object) string {
|
||||
cond := findOrCreateCond(obj, string(c))
|
||||
return getFieldValue(cond, "Reason").String()
|
||||
}
|
||||
|
||||
func (c Cond) Once(obj runtime.Object, f func() (runtime.Object, error)) (runtime.Object, error) {
|
||||
if c.IsFalse(obj) {
|
||||
return obj, &controller.ForgetError{
|
||||
Err: errors.New(c.GetReason(obj)),
|
||||
}
|
||||
}
|
||||
|
||||
if c.IsTrue(obj) {
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
c.Unknown(obj)
|
||||
newObj, err := f()
|
||||
if newObj != nil {
|
||||
obj = newObj
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
c.False(obj)
|
||||
c.Reason(obj, err.Error())
|
||||
return obj, err
|
||||
}
|
||||
c.True(obj)
|
||||
return obj, nil
|
||||
}
|
||||
|
||||
func (c Cond) Do(obj runtime.Object, f func() error) error {
|
||||
c.Unknown(obj)
|
||||
if err := f(); err != nil {
|
||||
c.False(obj)
|
||||
c.Reason(obj, err.Error())
|
||||
return err
|
||||
}
|
||||
c.True(obj)
|
||||
return nil
|
||||
}
|
||||
|
||||
func touchTS(value reflect.Value) {
|
||||
now := time.Now().Format(time.RFC3339)
|
||||
getFieldValue(value, "LastUpdateTime").SetString(now)
|
||||
}
|
||||
|
||||
func getStatus(obj interface{}, condName string) string {
|
||||
cond := findOrCreateCond(obj, condName)
|
||||
return getFieldValue(cond, "Status").String()
|
||||
}
|
||||
|
||||
func setStatus(obj interface{}, condName, status string) {
|
||||
cond := findOrCreateCond(obj, condName)
|
||||
getFieldValue(cond, "Status").SetString(status)
|
||||
touchTS(cond)
|
||||
}
|
||||
|
||||
func findOrCreateCond(obj interface{}, condName string) reflect.Value {
|
||||
condSlice := getValue(obj, "Status", "Conditions")
|
||||
cond := findCond(condSlice, condName)
|
||||
if cond != nil {
|
||||
return *cond
|
||||
}
|
||||
|
||||
newCond := reflect.New(condSlice.Type().Elem()).Elem()
|
||||
newCond.FieldByName("Type").SetString(condName)
|
||||
newCond.FieldByName("Status").SetString("Unknown")
|
||||
condSlice.Set(reflect.Append(condSlice, newCond))
|
||||
return newCond
|
||||
}
|
||||
|
||||
func findCond(val reflect.Value, name string) *reflect.Value {
|
||||
for i := 0; i < val.Len(); i++ {
|
||||
cond := val.Index(i)
|
||||
typeVal := getFieldValue(cond, "Type")
|
||||
if typeVal.String() == name {
|
||||
return &cond
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getValue(obj interface{}, name ...string) reflect.Value {
|
||||
v := reflect.ValueOf(obj)
|
||||
t := v.Type()
|
||||
if t.Kind() == reflect.Ptr {
|
||||
v = v.Elem()
|
||||
t = v.Type()
|
||||
}
|
||||
|
||||
field := v.FieldByName(name[0])
|
||||
if len(name) == 1 {
|
||||
return field
|
||||
}
|
||||
return getFieldValue(field, name[1:]...)
|
||||
}
|
||||
|
||||
func getFieldValue(v reflect.Value, name ...string) reflect.Value {
|
||||
field := v.FieldByName(name[0])
|
||||
if len(name) == 1 {
|
||||
return field
|
||||
}
|
||||
return getFieldValue(field, name[1:]...)
|
||||
}
|
9
vendor/github.com/rancher/norman/controller/error.go
generated
vendored
Normal file
9
vendor/github.com/rancher/norman/controller/error.go
generated
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
package controller
|
||||
|
||||
type ForgetError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (f *ForgetError) Error() string {
|
||||
return f.Err.Error()
|
||||
}
|
2
vendor/github.com/rancher/norman/controller/generic_controller.go
generated
vendored
2
vendor/github.com/rancher/norman/controller/generic_controller.go
generated
vendored
@@ -162,7 +162,7 @@ func (g *genericController) processNextWorkItem() bool {
|
||||
|
||||
// do your work on the key. This method will contains your "do stuff" logic
|
||||
err := g.syncHandler(key.(string))
|
||||
if err == nil {
|
||||
if _, ok := err.(*ForgetError); err == nil || ok {
|
||||
g.queue.Forget(key)
|
||||
return true
|
||||
}
|
||||
|
39
vendor/github.com/rancher/norman/event/logger.go
generated
vendored
Normal file
39
vendor/github.com/rancher/norman/event/logger.go
generated
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
package event
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/client-go/tools/record"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Info(obj runtime.Object, message string)
|
||||
Infof(obj runtime.Object, messagefmt string, args ...interface{})
|
||||
Error(obj runtime.Object, message string)
|
||||
Errorf(obj runtime.Object, messagefmt string, args ...interface{})
|
||||
}
|
||||
|
||||
type logger struct {
|
||||
recorder record.EventRecorder
|
||||
}
|
||||
|
||||
func (l *logger) Info(obj runtime.Object, message string) {
|
||||
l.recorder.Event(obj, "Normal", "Message", message)
|
||||
}
|
||||
|
||||
func (l *logger) Infof(obj runtime.Object, messagefmt string, args ...interface{}) {
|
||||
l.recorder.Eventf(obj, "Normal", "Message", messagefmt, args...)
|
||||
}
|
||||
|
||||
func (l *logger) Error(obj runtime.Object, message string) {
|
||||
l.recorder.Event(obj, "Warning", "Message", message)
|
||||
}
|
||||
|
||||
func (l *logger) Errorf(obj runtime.Object, messagefmt string, args ...interface{}) {
|
||||
l.recorder.Eventf(obj, "Warning", "Message", messagefmt, args...)
|
||||
}
|
||||
|
||||
func NewLogger(recorder record.EventRecorder) Logger {
|
||||
return &logger{
|
||||
recorder: recorder,
|
||||
}
|
||||
}
|
15
vendor/github.com/rancher/norman/generator/controller_template.go
generated
vendored
15
vendor/github.com/rancher/norman/generator/controller_template.go
generated
vendored
@@ -19,8 +19,8 @@ import (
|
||||
|
||||
var (
|
||||
{{.schema.CodeName}}GroupVersionKind = schema.GroupVersionKind{
|
||||
Version: "{{.schema.Version.Version}}",
|
||||
Group: "{{.schema.Version.Group}}",
|
||||
Version: Version,
|
||||
Group: GroupName,
|
||||
Kind: "{{.schema.CodeName}}",
|
||||
}
|
||||
{{.schema.CodeName}}Resource = metav1.APIResource{
|
||||
@@ -67,6 +67,8 @@ type {{.schema.CodeName}}Interface interface {
|
||||
Watch(opts metav1.ListOptions) (watch.Interface, error)
|
||||
DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error
|
||||
Controller() {{.schema.CodeName}}Controller
|
||||
AddSyncHandler(sync {{.schema.CodeName}}HandlerFunc)
|
||||
AddLifecycle(name string, lifecycle {{.schema.CodeName}}Lifecycle)
|
||||
}
|
||||
|
||||
type {{.schema.ID}}Lister struct {
|
||||
@@ -199,4 +201,13 @@ func (s *{{.schema.ID}}Client) Watch(opts metav1.ListOptions) (watch.Interface,
|
||||
func (s *{{.schema.ID}}Client) DeleteCollection(deleteOpts *metav1.DeleteOptions, listOpts metav1.ListOptions) error {
|
||||
return s.objectClient.DeleteCollection(deleteOpts, listOpts)
|
||||
}
|
||||
|
||||
func (s *{{.schema.ID}}Client) AddSyncHandler(sync {{.schema.CodeName}}HandlerFunc) {
|
||||
s.Controller().AddHandler(sync)
|
||||
}
|
||||
|
||||
func (s *{{.schema.ID}}Client) AddLifecycle(name string, lifecycle {{.schema.CodeName}}Lifecycle) {
|
||||
sync := New{{.schema.CodeName}}LifecycleAdapter(name, s, lifecycle)
|
||||
s.AddSyncHandler(sync)
|
||||
}
|
||||
`
|
||||
|
50
vendor/github.com/rancher/norman/generator/generator.go
generated
vendored
50
vendor/github.com/rancher/norman/generator/generator.go
generated
vendored
@@ -195,6 +195,38 @@ func generateController(external bool, outputDir string, schema *types.Schema, s
|
||||
})
|
||||
}
|
||||
|
||||
func generateScheme(external bool, outputDir string, version *types.APIVersion, schemas []*types.Schema) error {
|
||||
filePath := strings.ToLower("zz_generated_scheme.go")
|
||||
output, err := os.Create(path.Join(outputDir, filePath))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer output.Close()
|
||||
|
||||
typeTemplate, err := template.New("scheme.template").
|
||||
Funcs(funcs()).
|
||||
Parse(strings.Replace(schemeTemplate, "%BACK%", "`", -1))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
names := []string{}
|
||||
for _, schema := range schemas {
|
||||
if !external {
|
||||
names = append(names, schema.CodeName)
|
||||
}
|
||||
if schema.CanList() {
|
||||
names = append(names, schema.CodeName+"List")
|
||||
}
|
||||
}
|
||||
|
||||
return typeTemplate.Execute(output, map[string]interface{}{
|
||||
"version": version,
|
||||
"schemas": schemas,
|
||||
"names": names,
|
||||
})
|
||||
}
|
||||
|
||||
func generateK8sClient(outputDir string, version *types.APIVersion, schemas []*types.Schema) error {
|
||||
filePath := strings.ToLower("zz_generated_k8s_client.go")
|
||||
output, err := os.Create(path.Join(outputDir, filePath))
|
||||
@@ -270,6 +302,10 @@ func GenerateControllerForTypes(version *types.APIVersion, k8sOutputPackage stri
|
||||
return err
|
||||
}
|
||||
|
||||
if err := generateScheme(true, k8sDir, version, controllers); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return gofmt(baseDir, k8sOutputPackage)
|
||||
}
|
||||
|
||||
@@ -318,7 +354,13 @@ func Generate(schemas *types.Schemas, cattleOutputPackage, k8sOutputPackage stri
|
||||
return err
|
||||
}
|
||||
|
||||
generateK8sClient(k8sDir, &controllers[0].Version, controllers)
|
||||
if err := generateK8sClient(k8sDir, &controllers[0].Version, controllers); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := generateScheme(false, k8sDir, &controllers[0].Version, controllers); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if err := gofmt(baseDir, k8sOutputPackage); err != nil {
|
||||
@@ -382,9 +424,9 @@ func deepCopyGen(workDir, pkg string) error {
|
||||
HeaderText: []byte{},
|
||||
GeneratorFunc: func(c *generator.Context) []generator.Generator {
|
||||
return []generator.Generator{
|
||||
&noInitGenerator{
|
||||
generators.NewGenDeepCopy(arguments.OutputFileBaseName, pkg, nil, true, true),
|
||||
},
|
||||
//&noInitGenerator{
|
||||
generators.NewGenDeepCopy(arguments.OutputFileBaseName, pkg, nil, true, true),
|
||||
//},
|
||||
}
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *gengotypes.Type) bool {
|
||||
|
42
vendor/github.com/rancher/norman/generator/scheme_template.go
generated
vendored
Normal file
42
vendor/github.com/rancher/norman/generator/scheme_template.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package generator
|
||||
|
||||
var schemeTemplate = `package {{.version.Version}}
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
const (
|
||||
GroupName = "{{.version.Group}}"
|
||||
Version = "{{.version.Version}}"
|
||||
)
|
||||
|
||||
// SchemeGroupVersion is group version used to register these objects
|
||||
var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: Version}
|
||||
|
||||
// Kind takes an unqualified kind and returns a Group qualified GroupKind
|
||||
func Kind(kind string) schema.GroupKind {
|
||||
return SchemeGroupVersion.WithKind(kind).GroupKind()
|
||||
}
|
||||
|
||||
// Resource takes an unqualified resource and returns a Group qualified GroupResource
|
||||
func Resource(resource string) schema.GroupResource {
|
||||
return SchemeGroupVersion.WithResource(resource).GroupResource()
|
||||
}
|
||||
|
||||
var (
|
||||
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
|
||||
AddToScheme = SchemeBuilder.AddToScheme
|
||||
)
|
||||
|
||||
// Adds the list of known types to api.Scheme.
|
||||
func addKnownTypes(scheme *runtime.Scheme) error {
|
||||
// TODO this gets cleaned up when the types are fixed
|
||||
scheme.AddKnownTypes(SchemeGroupVersion,
|
||||
{{range .names}}
|
||||
&{{.}}{},{{end}}
|
||||
)
|
||||
return nil
|
||||
}
|
||||
`
|
59
vendor/github.com/rancher/norman/lifecycle/object.go
generated
vendored
59
vendor/github.com/rancher/norman/lifecycle/object.go
generated
vendored
@@ -51,7 +51,11 @@ func (o *objectLifecycleAdapter) sync(key string, obj runtime.Object) error {
|
||||
return err
|
||||
}
|
||||
|
||||
obj = obj.DeepCopyObject()
|
||||
if newObj, err := o.lifecycle.Updated(obj); err != nil {
|
||||
if newObj != nil {
|
||||
o.objectClient.Update(metadata.GetName(), newObj)
|
||||
}
|
||||
return err
|
||||
} else if newObj != nil {
|
||||
_, err = o.objectClient.Update(metadata.GetName(), newObj)
|
||||
@@ -72,29 +76,39 @@ func (o *objectLifecycleAdapter) finalize(metadata metav1.Object, obj runtime.Ob
|
||||
}
|
||||
|
||||
obj = obj.DeepCopyObject()
|
||||
if newObj, err := o.lifecycle.Finalize(obj); err != nil {
|
||||
if newObj != nil {
|
||||
o.objectClient.Update(metadata.GetName(), newObj)
|
||||
}
|
||||
return false, err
|
||||
} else if newObj != nil {
|
||||
obj = newObj
|
||||
}
|
||||
|
||||
if err := removeFinalizer(o.name, obj); err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
_, err := o.objectClient.Update(metadata.GetName(), obj)
|
||||
return false, err
|
||||
}
|
||||
|
||||
func removeFinalizer(name string, obj runtime.Object) error {
|
||||
metadata, err := meta.Accessor(obj)
|
||||
if err != nil {
|
||||
return false, err
|
||||
return err
|
||||
}
|
||||
|
||||
var finalizers []string
|
||||
for _, finalizer := range metadata.GetFinalizers() {
|
||||
if finalizer == o.name {
|
||||
if finalizer == name {
|
||||
continue
|
||||
}
|
||||
finalizers = append(finalizers, finalizer)
|
||||
}
|
||||
metadata.SetFinalizers(finalizers)
|
||||
|
||||
if newObj, err := o.lifecycle.Finalize(obj); err != nil {
|
||||
return false, err
|
||||
} else if newObj != nil {
|
||||
_, err = o.objectClient.Update(metadata.GetName(), newObj)
|
||||
} else {
|
||||
_, err = o.objectClient.Update(metadata.GetName(), obj)
|
||||
}
|
||||
|
||||
return false, err
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *objectLifecycleAdapter) createKey() string {
|
||||
@@ -104,28 +118,31 @@ func (o *objectLifecycleAdapter) createKey() string {
|
||||
func (o *objectLifecycleAdapter) create(metadata metav1.Object, obj runtime.Object) (bool, error) {
|
||||
initialized := o.createKey()
|
||||
|
||||
if metadata.GetLabels()[initialized] == "true" {
|
||||
if metadata.GetAnnotations()[initialized] == "true" {
|
||||
return true, nil
|
||||
}
|
||||
|
||||
obj = obj.DeepCopyObject()
|
||||
if newObj, err := o.lifecycle.Create(obj); err != nil {
|
||||
if newObj != nil {
|
||||
o.objectClient.Update(metadata.GetName(), newObj)
|
||||
}
|
||||
return false, err
|
||||
} else if newObj != nil {
|
||||
obj = newObj
|
||||
}
|
||||
|
||||
metadata, err := meta.Accessor(obj)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
if metadata.GetLabels() == nil {
|
||||
metadata.SetLabels(map[string]string{})
|
||||
if metadata.GetAnnotations() == nil {
|
||||
metadata.SetAnnotations(map[string]string{})
|
||||
}
|
||||
|
||||
metadata.SetFinalizers(append(metadata.GetFinalizers(), o.name))
|
||||
metadata.GetLabels()[initialized] = "true"
|
||||
if newObj, err := o.lifecycle.Create(obj); err != nil {
|
||||
return false, err
|
||||
} else if newObj != nil {
|
||||
_, err = o.objectClient.Update(metadata.GetName(), newObj)
|
||||
return false, err
|
||||
}
|
||||
metadata.GetAnnotations()[initialized] = "true"
|
||||
|
||||
_, err = o.objectClient.Update(metadata.GetName(), obj)
|
||||
return false, err
|
||||
|
206
vendor/github.com/rancher/norman/types/schemas.go
generated
vendored
206
vendor/github.com/rancher/norman/types/schemas.go
generated
vendored
@@ -5,6 +5,8 @@ import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"sync"
|
||||
|
||||
"github.com/rancher/norman/name"
|
||||
"github.com/rancher/norman/types/convert"
|
||||
"github.com/rancher/norman/types/definition"
|
||||
@@ -14,7 +16,9 @@ type SchemaCollection struct {
|
||||
Data []Schema
|
||||
}
|
||||
|
||||
type SchemaInitFunc func(*Schemas) *Schemas
|
||||
type SchemasInitFunc func(*Schemas) *Schemas
|
||||
|
||||
type SchemaHook func(*Schema)
|
||||
|
||||
type MappersFactory func() []Mapper
|
||||
|
||||
@@ -24,14 +28,17 @@ type BackReference struct {
|
||||
}
|
||||
|
||||
type Schemas struct {
|
||||
sync.Mutex
|
||||
schemasByPath map[string]map[string]*Schema
|
||||
schemasBySubContext map[string]*Schema
|
||||
mappers map[string]map[string][]Mapper
|
||||
references map[string][]BackReference
|
||||
embedded map[string]*Schema
|
||||
DefaultMappers MappersFactory
|
||||
DefaultPostMappers MappersFactory
|
||||
versions []APIVersion
|
||||
schemas []*Schema
|
||||
AddHook SchemaHook
|
||||
errors []error
|
||||
}
|
||||
|
||||
@@ -41,10 +48,11 @@ func NewSchemas() *Schemas {
|
||||
schemasBySubContext: map[string]*Schema{},
|
||||
mappers: map[string]map[string][]Mapper{},
|
||||
references: map[string][]BackReference{},
|
||||
embedded: map[string]*Schema{},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Schemas) Init(initFunc SchemaInitFunc) *Schemas {
|
||||
func (s *Schemas) Init(initFunc SchemasInitFunc) *Schemas {
|
||||
return initFunc(s)
|
||||
}
|
||||
|
||||
@@ -53,13 +61,11 @@ func (s *Schemas) Err() error {
|
||||
}
|
||||
|
||||
func (s *Schemas) SubContext(subContext string) *Schema {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.schemasBySubContext[subContext]
|
||||
}
|
||||
|
||||
func (s *Schemas) SubContextSchemas() map[string]*Schema {
|
||||
return s.schemasBySubContext
|
||||
}
|
||||
|
||||
func (s *Schemas) AddSchemas(schema *Schemas) *Schemas {
|
||||
for _, schema := range schema.Schemas() {
|
||||
s.AddSchema(*schema)
|
||||
@@ -67,27 +73,58 @@ func (s *Schemas) AddSchemas(schema *Schemas) *Schemas {
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Schemas) RemoveSchema(schema Schema) *Schemas {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.doRemoveSchema(schema)
|
||||
}
|
||||
|
||||
func (s *Schemas) doRemoveSchema(schema Schema) *Schemas {
|
||||
delete(s.schemasByPath[schema.Version.Path], schema.ID)
|
||||
|
||||
s.removeReferences(&schema)
|
||||
|
||||
delete(s.schemasBySubContext, schema.SubContext)
|
||||
|
||||
if schema.Embed {
|
||||
s.removeEmbed(&schema)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Schemas) removeReferences(schema *Schema) {
|
||||
fullType := convert.ToFullReference(schema.Version.Path, schema.ID)
|
||||
delete(s.references, fullType)
|
||||
|
||||
for name, values := range s.references {
|
||||
changed := false
|
||||
var modified []BackReference
|
||||
for _, value := range values {
|
||||
if value.Schema.ID == schema.ID && value.Schema.Version.Path == schema.Version.Path {
|
||||
changed = true
|
||||
continue
|
||||
}
|
||||
modified = append(modified, value)
|
||||
}
|
||||
|
||||
if changed {
|
||||
s.references[name] = modified
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Schemas) AddSchema(schema Schema) *Schemas {
|
||||
schema.Type = "/meta/schemas/schema"
|
||||
if schema.ID == "" {
|
||||
s.errors = append(s.errors, fmt.Errorf("ID is not set on schema: %v", schema))
|
||||
return s
|
||||
}
|
||||
if schema.Version.Path == "" || schema.Version.Version == "" {
|
||||
s.errors = append(s.errors, fmt.Errorf("version is not set on schema: %s", schema.ID))
|
||||
return s
|
||||
}
|
||||
if schema.PluralName == "" {
|
||||
schema.PluralName = name.GuessPluralName(schema.ID)
|
||||
}
|
||||
if schema.CodeName == "" {
|
||||
schema.CodeName = convert.Capitalize(schema.ID)
|
||||
}
|
||||
if schema.CodeNamePlural == "" {
|
||||
schema.CodeNamePlural = name.GuessPluralName(schema.CodeName)
|
||||
}
|
||||
if schema.BaseType == "" {
|
||||
schema.BaseType = schema.ID
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.doAddSchema(schema)
|
||||
}
|
||||
|
||||
func (s *Schemas) doAddSchema(schema Schema) *Schemas {
|
||||
s.setupDefaults(&schema)
|
||||
|
||||
if s.AddHook != nil {
|
||||
s.AddHook(&schema)
|
||||
}
|
||||
|
||||
schemas, ok := s.schemasByPath[schema.Version.Path]
|
||||
@@ -101,20 +138,8 @@ func (s *Schemas) AddSchema(schema Schema) *Schemas {
|
||||
schemas[schema.ID] = &schema
|
||||
s.schemas = append(s.schemas, &schema)
|
||||
|
||||
for name, field := range schema.ResourceFields {
|
||||
if !definition.IsReferenceType(field.Type) {
|
||||
continue
|
||||
}
|
||||
|
||||
refType := definition.SubType(field.Type)
|
||||
if !strings.HasPrefix(refType, "/") {
|
||||
refType = convert.ToFullReference(schema.Version.Path, refType)
|
||||
}
|
||||
|
||||
s.references[refType] = append(s.references[refType], BackReference{
|
||||
FieldName: name,
|
||||
Schema: &schema,
|
||||
})
|
||||
if !schema.Embed {
|
||||
s.addReferences(&schema)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,11 +147,100 @@ func (s *Schemas) AddSchema(schema Schema) *Schemas {
|
||||
s.schemasBySubContext[schema.SubContext] = &schema
|
||||
}
|
||||
|
||||
if schema.Embed {
|
||||
s.embed(&schema)
|
||||
}
|
||||
|
||||
return s
|
||||
}
|
||||
|
||||
func (s *Schemas) removeEmbed(schema *Schema) {
|
||||
target := s.doSchema(&schema.Version, schema.EmbedType, false)
|
||||
if target == nil {
|
||||
return
|
||||
}
|
||||
|
||||
newSchema := *target
|
||||
newSchema.ResourceFields = map[string]Field{}
|
||||
|
||||
for k, v := range target.ResourceFields {
|
||||
newSchema.ResourceFields[k] = v
|
||||
}
|
||||
|
||||
for k := range schema.ResourceFields {
|
||||
delete(newSchema.ResourceFields, k)
|
||||
}
|
||||
|
||||
s.doRemoveSchema(*target)
|
||||
s.doAddSchema(newSchema)
|
||||
}
|
||||
|
||||
func (s *Schemas) embed(schema *Schema) {
|
||||
target := s.doSchema(&schema.Version, schema.EmbedType, false)
|
||||
if target == nil {
|
||||
return
|
||||
}
|
||||
|
||||
newSchema := *target
|
||||
newSchema.ResourceFields = map[string]Field{}
|
||||
|
||||
for k, v := range target.ResourceFields {
|
||||
newSchema.ResourceFields[k] = v
|
||||
}
|
||||
for k, v := range schema.ResourceFields {
|
||||
newSchema.ResourceFields[k] = v
|
||||
}
|
||||
|
||||
s.doRemoveSchema(*target)
|
||||
s.doAddSchema(newSchema)
|
||||
}
|
||||
|
||||
func (s *Schemas) addReferences(schema *Schema) {
|
||||
for name, field := range schema.ResourceFields {
|
||||
if !definition.IsReferenceType(field.Type) {
|
||||
continue
|
||||
}
|
||||
|
||||
refType := definition.SubType(field.Type)
|
||||
if !strings.HasPrefix(refType, "/") {
|
||||
refType = convert.ToFullReference(schema.Version.Path, refType)
|
||||
}
|
||||
|
||||
s.references[refType] = append(s.references[refType], BackReference{
|
||||
FieldName: name,
|
||||
Schema: schema,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Schemas) setupDefaults(schema *Schema) {
|
||||
schema.Type = "/meta/schemas/schema"
|
||||
if schema.ID == "" {
|
||||
s.errors = append(s.errors, fmt.Errorf("ID is not set on schema: %v", schema))
|
||||
return
|
||||
}
|
||||
if schema.Version.Path == "" || schema.Version.Version == "" {
|
||||
s.errors = append(s.errors, fmt.Errorf("version is not set on schema: %s", schema.ID))
|
||||
return
|
||||
}
|
||||
if schema.PluralName == "" {
|
||||
schema.PluralName = name.GuessPluralName(schema.ID)
|
||||
}
|
||||
if schema.CodeName == "" {
|
||||
schema.CodeName = convert.Capitalize(schema.ID)
|
||||
}
|
||||
if schema.CodeNamePlural == "" {
|
||||
schema.CodeNamePlural = name.GuessPluralName(schema.CodeName)
|
||||
}
|
||||
if schema.BaseType == "" {
|
||||
schema.BaseType = schema.ID
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Schemas) References(schema *Schema) []BackReference {
|
||||
refType := convert.ToFullReference(schema.Version.Path, schema.ID)
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.references[refType]
|
||||
}
|
||||
|
||||
@@ -142,6 +256,8 @@ func (s *Schemas) AddMapper(version *APIVersion, schemaID string, mapper Mapper)
|
||||
}
|
||||
|
||||
func (s *Schemas) SchemasForVersion(version APIVersion) map[string]*Schema {
|
||||
s.Lock()
|
||||
defer s.Unlock()
|
||||
return s.schemasByPath[version.Path]
|
||||
}
|
||||
|
||||
@@ -182,6 +298,10 @@ func (s *Schemas) mapper(version *APIVersion, name string) []Mapper {
|
||||
}
|
||||
|
||||
func (s *Schemas) Schema(version *APIVersion, name string) *Schema {
|
||||
return s.doSchema(version, name, true)
|
||||
}
|
||||
|
||||
func (s *Schemas) doSchema(version *APIVersion, name string, lock bool) *Schema {
|
||||
var (
|
||||
path string
|
||||
)
|
||||
@@ -196,7 +316,13 @@ func (s *Schemas) Schema(version *APIVersion, name string) *Schema {
|
||||
path = "core"
|
||||
}
|
||||
|
||||
if lock {
|
||||
s.Lock()
|
||||
}
|
||||
schemas, ok := s.schemasByPath[path]
|
||||
if lock {
|
||||
s.Unlock()
|
||||
}
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
|
3
vendor/github.com/rancher/norman/types/server_types.go
generated
vendored
3
vendor/github.com/rancher/norman/types/server_types.go
generated
vendored
@@ -148,6 +148,7 @@ type URLBuilder interface {
|
||||
Sort(field string) string
|
||||
SetSubContext(subContext string)
|
||||
FilterLink(schema *Schema, fieldName string, value string) string
|
||||
Action(action string, resource *RawResource) string
|
||||
}
|
||||
|
||||
type Store interface {
|
||||
@@ -155,6 +156,6 @@ type Store interface {
|
||||
List(apiContext *APIContext, schema *Schema, opt QueryOptions) ([]map[string]interface{}, error)
|
||||
Create(apiContext *APIContext, schema *Schema, data map[string]interface{}) (map[string]interface{}, error)
|
||||
Update(apiContext *APIContext, schema *Schema, data map[string]interface{}, id string) (map[string]interface{}, error)
|
||||
Delete(apiContext *APIContext, schema *Schema, id string) error
|
||||
Delete(apiContext *APIContext, schema *Schema, id string) (map[string]interface{}, error)
|
||||
Watch(apiContext *APIContext, schema *Schema, opt QueryOptions) (chan map[string]interface{}, error)
|
||||
}
|
||||
|
2
vendor/github.com/rancher/norman/types/types.go
generated
vendored
2
vendor/github.com/rancher/norman/types/types.go
generated
vendored
@@ -79,6 +79,8 @@ type TypeScope string
|
||||
|
||||
type Schema struct {
|
||||
ID string `json:"id,omitempty"`
|
||||
Embed bool `json:"embed,omitempty"`
|
||||
EmbedType string `json:"embedType,omitempty"`
|
||||
CodeName string `json:"-"`
|
||||
CodeNamePlural string `json:"-"`
|
||||
PkgName string `json:"-"`
|
||||
|
Reference in New Issue
Block a user