1
0
mirror of https://github.com/rancher/types.git synced 2025-06-30 07:21:49 +00:00

Update vendor

This commit is contained in:
Darren Shepherd 2018-07-13 13:36:36 -07:00
parent a21edd69e2
commit 463ed73f9f
58 changed files with 1144 additions and 223 deletions

View File

@ -2,9 +2,7 @@
github.com/rancher/types
k8s.io/kubernetes v1.10.5 transitive=true,staging=true
bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git
bitbucket.org/ww/goautoneg a547fc61f48d567d5b4ec6f8aee5573d8efce11d https://github.com/rancher/goautoneg.git
golang.org/x/sync fd80eb99c8f653c847d294a001bdf2a3a6f768f5
github.com/rancher/norman 57e8282a33f04091e30df7700bd328f3205c1189
github.com/rancher/norman c032c4611f2eec1652ef37d254f0e8ccf90c80aa

View File

@ -24,8 +24,7 @@ const (
)
var (
debug = false
dialer = &websocket.Dialer{}
Debug = false
)
type APIBaseClientInterface interface {
@ -90,7 +89,7 @@ func IsNotFound(err error) bool {
return apiError.StatusCode == http.StatusNotFound
}
func newAPIError(resp *http.Response, url string) *APIError {
func NewAPIError(resp *http.Response, url string) *APIError {
contents, err := ioutil.ReadAll(resp.Body)
var body string
if err != nil {
@ -177,7 +176,7 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
}
if opts.Timeout == 0 {
opts.Timeout = time.Second * 10
opts.Timeout = time.Minute
}
client.Timeout = opts.Timeout
@ -209,7 +208,6 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
if err != nil {
return result, err
}
req.Header.Add("Authorization", opts.getAuthHeader())
resp, err := client.Do(req)
@ -219,7 +217,7 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
defer resp.Body.Close()
if resp.StatusCode != 200 {
return result, newAPIError(resp, opts.URL)
return result, NewAPIError(resp, opts.URL)
}
schemasURLs := resp.Header.Get("X-API-Schemas")
@ -229,20 +227,23 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
if schemasURLs != opts.URL {
req, err = http.NewRequest("GET", schemasURLs, nil)
req.Header.Add("Authorization", opts.getAuthHeader())
if err != nil {
return result, err
}
req.Header.Add("Authorization", opts.getAuthHeader())
if Debug {
fmt.Println("GET " + req.URL.String())
}
resp, err = client.Do(req)
if err != nil {
return result, err
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
return result, newAPIError(resp, opts.URL)
return result, NewAPIError(resp, schemasURLs)
}
}
@ -252,6 +253,10 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
return result, err
}
if Debug {
fmt.Println("Response <= " + string(bytes))
}
err = json.Unmarshal(bytes, &schemas)
if err != nil {
return result, err
@ -265,9 +270,15 @@ func NewAPIClient(opts *ClientOpts) (APIBaseClient, error) {
result.Ops = &APIOperations{
Opts: opts,
Client: client,
Dialer: &websocket.Dialer{},
Types: result.Types,
}
ht, ok := client.Transport.(*http.Transport)
if ok {
result.Ops.Dialer.TLSClientConfig = ht.TLSClientConfig
}
return result, nil
}
@ -287,7 +298,7 @@ func (a *APIBaseClient) Websocket(url string, headers map[string][]string) (*web
httpHeaders.Add("Authorization", a.Opts.getAuthHeader())
}
return dialer.Dial(url, http.Header(httpHeaders))
return a.Ops.Dialer.Dial(url, http.Header(httpHeaders))
}
func (a *APIBaseClient) List(schemaType string, opts *types.ListOpts, respObject interface{}) error {
@ -341,8 +352,8 @@ func (a *APIBaseClient) Action(schemaType string, action string,
}
func init() {
debug = os.Getenv("RANCHER_CLIENT_DEBUG") == "true"
if debug {
Debug = os.Getenv("RANCHER_CLIENT_DEBUG") == "true"
if Debug {
fmt.Println("Rancher client debug on")
}
}

View File

@ -7,7 +7,10 @@ import (
"io"
"io/ioutil"
"net/http"
"net/url"
"regexp"
"github.com/gorilla/websocket"
"github.com/pkg/errors"
"github.com/rancher/norman/types"
)
@ -16,9 +19,10 @@ type APIOperations struct {
Opts *ClientOpts
Types map[string]types.Schema
Client *http.Client
Dialer *websocket.Dialer
}
func (a *APIOperations) setupRequest(req *http.Request) {
func (a *APIOperations) SetupRequest(req *http.Request) {
req.Header.Add("Authorization", a.Opts.getAuthHeader())
}
@ -28,18 +32,19 @@ func (a *APIOperations) DoDelete(url string) error {
return err
}
a.setupRequest(req)
a.SetupRequest(req)
resp, err := a.Client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
io.Copy(ioutil.Discard, resp.Body)
defer func() {
io.Copy(ioutil.Discard, resp.Body)
resp.Body.Close()
}()
if resp.StatusCode >= 300 {
return newAPIError(resp, url)
return NewAPIError(resp, url)
}
return nil
@ -54,7 +59,7 @@ func (a *APIOperations) DoGet(url string, opts *types.ListOpts, respObject inter
return err
}
if debug {
if Debug {
fmt.Println("GET " + url)
}
@ -63,7 +68,7 @@ func (a *APIOperations) DoGet(url string, opts *types.ListOpts, respObject inter
return err
}
a.setupRequest(req)
a.SetupRequest(req)
resp, err := a.Client.Do(req)
if err != nil {
@ -73,7 +78,7 @@ func (a *APIOperations) DoGet(url string, opts *types.ListOpts, respObject inter
defer resp.Body.Close()
if resp.StatusCode != 200 {
return newAPIError(resp, url)
return NewAPIError(resp, url)
}
byteContent, err := ioutil.ReadAll(resp.Body)
@ -81,7 +86,7 @@ func (a *APIOperations) DoGet(url string, opts *types.ListOpts, respObject inter
return err
}
if debug {
if Debug {
fmt.Println("Response <= " + string(byteContent))
}
@ -102,7 +107,12 @@ func (a *APIOperations) DoList(schemaType string, opts *types.ListOpts, respObje
return errors.New("Resource type [" + schemaType + "] is not listable")
}
return a.DoGet(a.Opts.URL+"/"+schemaType, opts, respObject)
collectionURL, ok := schema.Links["collection"]
if !ok {
return errors.New("Resource type [" + schemaType + "] does not have a collection URL")
}
return a.DoGet(collectionURL, opts, respObject)
}
func (a *APIOperations) DoNext(nextURL string, respObject interface{}) error {
@ -115,7 +125,7 @@ func (a *APIOperations) DoModify(method string, url string, createObj interface{
return err
}
if debug {
if Debug {
fmt.Println(method + " " + url)
fmt.Println("Request => " + string(bodyContent))
}
@ -125,7 +135,7 @@ func (a *APIOperations) DoModify(method string, url string, createObj interface{
return err
}
a.setupRequest(req)
a.SetupRequest(req)
req.Header.Set("Content-Type", "application/json")
resp, err := a.Client.Do(req)
@ -136,7 +146,7 @@ func (a *APIOperations) DoModify(method string, url string, createObj interface{
defer resp.Body.Close()
if resp.StatusCode >= 300 {
return newAPIError(resp, url)
return NewAPIError(resp, url)
}
byteContent, err := ioutil.ReadAll(resp.Body)
@ -145,7 +155,7 @@ func (a *APIOperations) DoModify(method string, url string, createObj interface{
}
if len(byteContent) > 0 {
if debug {
if Debug {
fmt.Println("Response <= " + string(byteContent))
}
return json.Unmarshal(byteContent, respObject)
@ -170,12 +180,27 @@ func (a *APIOperations) DoCreate(schemaType string, createObj interface{}, respO
return errors.New("Resource type [" + schemaType + "] is not creatable")
}
// using collection link to post doesn't help the resources under project or cluster, because they need a projectId or clusterId in the path
// for example, v3/projects/foo/apps, v3/cluster/bar/namespaces
return a.DoModify("POST", a.Opts.URL+"/"+schemaType, createObj, respObject)
var collectionURL string
collectionURL, ok = schema.Links[COLLECTION]
if !ok {
// return errors.New("Failed to find collection URL for [" + schemaType + "]")
// This is a hack to address https://github.com/rancher/cattle/issues/254
re := regexp.MustCompile("schemas.*")
collectionURL = re.ReplaceAllString(schema.Links[SELF], schema.PluralName)
}
return a.DoModify("POST", collectionURL, createObj, respObject)
}
func (a *APIOperations) DoReplace(schemaType string, existing *types.Resource, updates interface{}, respObject interface{}) error {
return a.doUpdate(schemaType, true, existing, updates, respObject)
}
func (a *APIOperations) DoUpdate(schemaType string, existing *types.Resource, updates interface{}, respObject interface{}) error {
return a.doUpdate(schemaType, false, existing, updates, respObject)
}
func (a *APIOperations) doUpdate(schemaType string, replace bool, existing *types.Resource, updates interface{}, respObject interface{}) error {
if existing == nil {
return errors.New("Existing object is nil")
}
@ -185,6 +210,17 @@ func (a *APIOperations) DoUpdate(schemaType string, existing *types.Resource, up
return fmt.Errorf("failed to find self URL of [%v]", existing)
}
if replace {
u, err := url.Parse(selfURL)
if err != nil {
return fmt.Errorf("failed to parse url %s: %v", selfURL, err)
}
q := u.Query()
q.Set("_replace", "true")
u.RawQuery = q.Encode()
selfURL = u.String()
}
if updates == nil {
updates = map[string]string{}
}
@ -285,7 +321,7 @@ func (a *APIOperations) doAction(
var input io.Reader
if debug {
if Debug {
fmt.Println("POST " + actionURL)
}
@ -294,7 +330,7 @@ func (a *APIOperations) doAction(
if err != nil {
return err
}
if debug {
if Debug {
fmt.Println("Request => " + string(bodyContent))
}
input = bytes.NewBuffer(bodyContent)
@ -305,7 +341,7 @@ func (a *APIOperations) doAction(
return err
}
a.setupRequest(req)
a.SetupRequest(req)
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Content-Length", "0")
@ -317,7 +353,7 @@ func (a *APIOperations) doAction(
defer resp.Body.Close()
if resp.StatusCode >= 300 {
return newAPIError(resp, actionURL)
return NewAPIError(resp, actionURL)
}
byteContent, err := ioutil.ReadAll(resp.Body)
@ -325,7 +361,7 @@ func (a *APIOperations) doAction(
return err
}
if debug {
if Debug {
fmt.Println("Response <= " + string(byteContent))
}

View File

@ -124,14 +124,14 @@ func (g *genericController) sync(ctx context.Context) error {
DeleteFunc: g.queueObject,
})
logrus.Infof("Syncing %s Controller", g.name)
logrus.Debugf("Syncing %s Controller", g.name)
go g.informer.Run(ctx.Done())
if !cache.WaitForCacheSync(ctx.Done(), g.informer.HasSynced) {
return fmt.Errorf("failed to sync controller %s", g.name)
}
logrus.Infof("Syncing %s Controller Done", g.name)
logrus.Debugf("Syncing %s Controller Done", g.name)
g.synced = true
return nil

View File

@ -25,7 +25,7 @@ type {{.schema.CodeName}} struct {
{{- end}}
}
{{- if .schema | hasGet }}
{{ if .schema | hasGet }}
type {{.schema.CodeName}}Collection struct {
types.Collection
Data []{{.schema.CodeName}} %BACK%json:"data,omitempty"%BACK%
@ -40,6 +40,7 @@ type {{.schema.CodeName}}Operations interface {
List(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error)
Create(opts *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error)
Update(existing *{{.schema.CodeName}}, updates interface{}) (*{{.schema.CodeName}}, error)
Replace(existing *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error)
ByID(id string) (*{{.schema.CodeName}}, error)
Delete(container *{{.schema.CodeName}}) error
{{range $key, $value := .resourceActions}}
@ -84,6 +85,12 @@ func (c *{{.schema.CodeName}}Client) Update(existing *{{.schema.CodeName}}, upda
return resp, err
}
func (c *{{.schema.CodeName}}Client) Replace(obj *{{.schema.CodeName}}) (*{{.schema.CodeName}}, error) {
resp := &{{.schema.CodeName}}{}
err := c.apiClient.Ops.DoReplace({{.schema.CodeName}}Type, &obj.Resource, obj, resp)
return resp, err
}
func (c *{{.schema.CodeName}}Client) List(opts *types.ListOpts) (*{{.schema.CodeName}}Collection, error) {
resp := &{{.schema.CodeName}}Collection{}
err := c.apiClient.Ops.DoList({{.schema.CodeName}}Type, opts, resp)

View File

@ -9,6 +9,7 @@ var (
PermissionDenied = ErrorCode{"PermissionDenied", 403}
NotFound = ErrorCode{"NotFound", 404}
MethodNotAllowed = ErrorCode{"MethodNotAllow", 405}
Conflict = ErrorCode{"Conflict", 409}
InvalidDateFormat = ErrorCode{"InvalidDateFormat", 422}
InvalidFormat = ErrorCode{"InvalidFormat", 422}

View File

@ -17,6 +17,7 @@ import (
"github.com/rancher/norman/types/values"
"github.com/sirupsen/logrus"
"k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
"k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
@ -121,14 +122,14 @@ func NewProxyStore(ctx context.Context, clientGetter ClientGetter, storageContex
}
}
func (p *Store) getUser(apiContext *types.APIContext) string {
func (s *Store) getUser(apiContext *types.APIContext) string {
return apiContext.Request.Header.Get(userAuthHeader)
}
func (p *Store) doAuthed(apiContext *types.APIContext, request *rest.Request) rest.Result {
func (s *Store) doAuthed(apiContext *types.APIContext, request *rest.Request) rest.Result {
start := time.Now()
defer func() {
logrus.Debug("GET: ", time.Now().Sub(start), p.resourcePlural)
logrus.Debug("GET: ", time.Now().Sub(start), s.resourcePlural)
}()
for _, header := range authHeaders {
@ -137,11 +138,11 @@ func (p *Store) doAuthed(apiContext *types.APIContext, request *rest.Request) re
return request.Do()
}
func (p *Store) k8sClient(apiContext *types.APIContext) (rest.Interface, error) {
return p.clientGetter.UnversionedClient(apiContext, p.storageContext)
func (s *Store) k8sClient(apiContext *types.APIContext) (rest.Interface, error) {
return s.clientGetter.UnversionedClient(apiContext, s.storageContext)
}
func (p *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
func (s *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
splitted := strings.Split(strings.TrimSpace(id), ":")
validID := false
namespaced := schema.Scope == types.NamespaceScope
@ -154,42 +155,42 @@ func (p *Store) ByID(apiContext *types.APIContext, schema *types.Schema, id stri
return nil, httperror.NewAPIError(httperror.NotFound, "failed to find resource by id")
}
_, result, err := p.byID(apiContext, schema, id)
_, result, err := s.byID(apiContext, schema, id)
return result, err
}
func (p *Store) byID(apiContext *types.APIContext, schema *types.Schema, id string) (string, map[string]interface{}, error) {
func (s *Store) byID(apiContext *types.APIContext, schema *types.Schema, id string) (string, map[string]interface{}, error) {
namespace, id := splitID(id)
k8sClient, err := p.k8sClient(apiContext)
k8sClient, err := s.k8sClient(apiContext)
if err != nil {
return "", nil, err
}
req := p.common(namespace, k8sClient.Get()).
req := s.common(namespace, k8sClient.Get()).
Name(id)
return p.singleResult(apiContext, schema, req)
return s.singleResult(apiContext, schema, req)
}
func (p *Store) Context() types.StorageContext {
return p.storageContext
func (s *Store) Context() types.StorageContext {
return s.storageContext
}
func (p *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
func (s *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) ([]map[string]interface{}, error) {
namespace := getNamespace(apiContext, opt)
k8sClient, err := p.k8sClient(apiContext)
k8sClient, err := s.k8sClient(apiContext)
if err != nil {
return nil, err
}
req := p.common(namespace, k8sClient.Get())
req := s.common(namespace, k8sClient.Get())
resultList := &unstructured.UnstructuredList{}
start := time.Now()
err = req.Do().Into(resultList)
logrus.Debug("LIST: ", time.Now().Sub(start), p.resourcePlural)
logrus.Debug("LIST: ", time.Now().Sub(start), s.resourcePlural)
if err != nil {
return nil, err
}
@ -197,27 +198,27 @@ func (p *Store) List(apiContext *types.APIContext, schema *types.Schema, opt *ty
var result []map[string]interface{}
for _, obj := range resultList.Items {
result = append(result, p.fromInternal(schema, obj.Object))
result = append(result, s.fromInternal(apiContext, schema, obj.Object))
}
return apiContext.AccessControl.FilterList(apiContext, schema, result, p.authContext), nil
return apiContext.AccessControl.FilterList(apiContext, schema, result, s.authContext), nil
}
func (p *Store) Watch(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) (chan map[string]interface{}, error) {
c, err := p.shareWatch(apiContext, schema, opt)
func (s *Store) Watch(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) (chan map[string]interface{}, error) {
c, err := s.shareWatch(apiContext, schema, opt)
if err != nil {
return nil, err
}
return convert.Chan(c, func(data map[string]interface{}) map[string]interface{} {
return apiContext.AccessControl.Filter(apiContext, schema, data, p.authContext)
return apiContext.AccessControl.Filter(apiContext, schema, data, s.authContext)
}), nil
}
func (p *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) (chan map[string]interface{}, error) {
func (s *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, opt *types.QueryOptions) (chan map[string]interface{}, error) {
namespace := getNamespace(apiContext, opt)
k8sClient, err := p.k8sClient(apiContext)
k8sClient, err := s.k8sClient(apiContext)
if err != nil {
return nil, err
}
@ -227,7 +228,7 @@ func (p *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op
}
timeout := int64(60 * 60)
req := p.common(namespace, k8sClient.Get())
req := s.common(namespace, k8sClient.Get())
req.VersionedParams(&metav1.ListOptions{
Watch: true,
TimeoutSeconds: &timeout,
@ -253,7 +254,7 @@ func (p *Store) realWatch(apiContext *types.APIContext, schema *types.Schema, op
go func() {
for event := range watcher.ResultChan() {
data := event.Object.(*unstructured.Unstructured)
p.fromInternal(schema, data.Object)
s.fromInternal(apiContext, schema, data.Object)
if event.Type == watch.Deleted && data.Object != nil {
data.Object[".removed"] = true
}
@ -285,16 +286,22 @@ func getNamespace(apiContext *types.APIContext, opt *types.QueryOptions) string
if condition.Field == "namespaceId" && condition.Value != "" {
return condition.Value
}
if condition.Field == "namespace" && condition.Value != "" {
return condition.Value
}
}
return ""
}
func (p *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
namespace, _ := data["namespaceId"].(string)
p.toInternal(schema.Mapper, data)
func (s *Store) Create(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) (map[string]interface{}, error) {
if err := s.toInternal(schema.Mapper, data); err != nil {
return nil, err
}
values.PutValue(data, p.getUser(apiContext), "metadata", "annotations", "field.cattle.io/creatorId")
namespace, _ := values.GetValueN(data, "metadata", "namespace").(string)
values.PutValue(data, s.getUser(apiContext), "metadata", "annotations", "field.cattle.io/creatorId")
name, _ := values.GetValueN(data, "metadata", "name").(string)
if name == "" {
@ -304,67 +311,84 @@ func (p *Store) Create(apiContext *types.APIContext, schema *types.Schema, data
}
}
k8sClient, err := p.k8sClient(apiContext)
k8sClient, err := s.k8sClient(apiContext)
if err != nil {
return nil, err
}
req := p.common(namespace, k8sClient.Post()).
req := s.common(namespace, k8sClient.Post()).
Body(&unstructured.Unstructured{
Object: data,
})
_, result, err := p.singleResult(apiContext, schema, req)
_, result, err := s.singleResult(apiContext, schema, req)
return result, err
}
func (p *Store) toInternal(mapper types.Mapper, data map[string]interface{}) {
func (s *Store) toInternal(mapper types.Mapper, data map[string]interface{}) error {
if mapper != nil {
mapper.ToInternal(data)
if err := mapper.ToInternal(data); err != nil {
return err
}
}
if p.group == "" {
data["apiVersion"] = p.version
if s.group == "" {
data["apiVersion"] = s.version
} else {
data["apiVersion"] = p.group + "/" + p.version
data["apiVersion"] = s.group + "/" + s.version
}
data["kind"] = p.kind
data["kind"] = s.kind
return nil
}
func (p *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
k8sClient, err := p.k8sClient(apiContext)
func (s *Store) Update(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}, id string) (map[string]interface{}, error) {
var (
result map[string]interface{}
err error
)
k8sClient, err := s.k8sClient(apiContext)
if err != nil {
return nil, err
}
namespace, id := splitID(id)
req := p.common(namespace, k8sClient.Get()).
Name(id)
resourceVersion, existing, err := p.singleResultRaw(apiContext, schema, req)
if err != nil {
return data, nil
if err := s.toInternal(schema.Mapper, data); err != nil {
return nil, err
}
p.toInternal(schema.Mapper, data)
existing = merge.APIUpdateMerge(schema.InternalSchema, apiContext.Schemas, existing, data, apiContext.Query.Get("_replace") == "true")
for i := 0; i < 5; i++ {
req := s.common(namespace, k8sClient.Get()).
Name(id)
values.PutValue(existing, resourceVersion, "metadata", "resourceVersion")
values.PutValue(existing, namespace, "metadata", "namespace")
values.PutValue(existing, id, "metadata", "name")
resourceVersion, existing, rawErr := s.singleResultRaw(apiContext, schema, req)
if rawErr != nil {
return nil, rawErr
}
req = p.common(namespace, k8sClient.Put()).
Body(&unstructured.Unstructured{
Object: existing,
}).
Name(id)
existing = merge.APIUpdateMerge(schema.InternalSchema, apiContext.Schemas, existing, data, apiContext.Option("replace") == "true")
values.PutValue(existing, resourceVersion, "metadata", "resourceVersion")
values.PutValue(existing, namespace, "metadata", "namespace")
values.PutValue(existing, id, "metadata", "name")
req = s.common(namespace, k8sClient.Put()).
Body(&unstructured.Unstructured{
Object: existing,
}).
Name(id)
_, result, err = s.singleResult(apiContext, schema, req)
if errors.IsConflict(err) {
continue
}
}
_, result, err := p.singleResult(apiContext, schema, req)
return result, err
}
func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
k8sClient, err := p.k8sClient(apiContext)
func (s *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id string) (map[string]interface{}, error) {
k8sClient, err := s.k8sClient(apiContext)
if err != nil {
return nil, err
}
@ -372,36 +396,36 @@ func (p *Store) Delete(apiContext *types.APIContext, schema *types.Schema, id st
namespace, name := splitID(id)
prop := metav1.DeletePropagationForeground
req := p.common(namespace, k8sClient.Delete()).
req := s.common(namespace, k8sClient.Delete()).
Body(&metav1.DeleteOptions{
PropagationPolicy: &prop,
}).
Name(name)
err = p.doAuthed(apiContext, req).Error()
err = s.doAuthed(apiContext, req).Error()
if err != nil {
return nil, err
}
obj, err := p.ByID(apiContext, schema, id)
obj, err := s.ByID(apiContext, schema, id)
if err != nil {
return nil, nil
}
return obj, nil
}
func (p *Store) singleResult(apiContext *types.APIContext, schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) {
version, data, err := p.singleResultRaw(apiContext, schema, req)
func (s *Store) singleResult(apiContext *types.APIContext, schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) {
version, data, err := s.singleResultRaw(apiContext, schema, req)
if err != nil {
return "", nil, err
}
p.fromInternal(schema, data)
s.fromInternal(apiContext, schema, data)
return version, data, nil
}
func (p *Store) singleResultRaw(apiContext *types.APIContext, schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) {
func (s *Store) singleResultRaw(apiContext *types.APIContext, schema *types.Schema, req *rest.Request) (string, map[string]interface{}, error) {
result := &unstructured.Unstructured{}
err := p.doAuthed(apiContext, req).Into(result)
err := s.doAuthed(apiContext, req).Into(result)
if err != nil {
return "", nil, err
}
@ -420,14 +444,14 @@ func splitID(id string) (string, string) {
return namespace, id
}
func (p *Store) common(namespace string, req *rest.Request) *rest.Request {
prefix := append([]string{}, p.prefix...)
if p.group != "" {
prefix = append(prefix, p.group)
func (s *Store) common(namespace string, req *rest.Request) *rest.Request {
prefix := append([]string{}, s.prefix...)
if s.group != "" {
prefix = append(prefix, s.group)
}
prefix = append(prefix, p.version)
prefix = append(prefix, s.version)
req.Prefix(prefix...).
Resource(p.resourcePlural)
Resource(s.resourcePlural)
if namespace != "" {
req.Namespace(namespace)
@ -436,7 +460,10 @@ func (p *Store) common(namespace string, req *rest.Request) *rest.Request {
return req
}
func (p *Store) fromInternal(schema *types.Schema, data map[string]interface{}) map[string]interface{} {
func (s *Store) fromInternal(apiContext *types.APIContext, schema *types.Schema, data map[string]interface{}) map[string]interface{} {
if apiContext.Option("export") == "true" {
delete(data, "status")
}
if schema.Mapper != nil {
schema.Mapper.FromInternal(data)
}

View File

@ -133,7 +133,7 @@ func LowerTitle(input string) string {
return string(runes)
}
func IsEmpty(v interface{}) bool {
func IsAPIObjectEmpty(v interface{}) bool {
if v == nil || v == "" || v == 0 || v == false {
return true
}
@ -211,3 +211,40 @@ func EncodeToMap(obj interface{}) (map[string]interface{}, error) {
dec.UseNumber()
return result, dec.Decode(&result)
}
func ToJSONKey(str string) string {
parts := strings.Split(str, "_")
for i := 1; i < len(parts); i++ {
parts[i] = strings.Title(parts[i])
}
return strings.Join(parts, "")
}
func ToYAMLKey(str string) string {
var result []rune
cap := false
for i, r := range []rune(str) {
if i == 0 {
if unicode.IsUpper(r) {
cap = true
}
result = append(result, unicode.ToLower(r))
continue
}
if unicode.IsUpper(r) {
if cap {
result = append(result, unicode.ToLower(r))
} else {
result = append(result, '_', unicode.ToLower(r))
}
} else {
cap = false
result = append(result, r)
}
}
return string(result)
}

View File

@ -5,37 +5,17 @@ import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/definition"
)
func APIUpdateMerge(schema *types.Schema, schemas *types.Schemas, dest, src map[string]interface{}, replace bool) map[string]interface{} {
result := map[string]interface{}{}
if replace {
if status, ok := dest["status"]; ok {
result["status"] = status
}
if metadata, ok := dest["metadata"]; ok {
result["metadata"] = metadata
}
} else {
result = copyMap(dest)
result := mergeMaps(schema, schemas, replace, dest, src)
if s, ok := dest["status"]; ok {
result["status"] = s
}
for k, v := range src {
if k == "metadata" {
result["metadata"] = mergeMetadata(convert.ToMapInterface(dest["metadata"]), convert.ToMapInterface(v))
continue
} else if k == "status" {
continue
}
existing, ok := dest[k]
if ok && !replace {
result[k] = merge(k, schema, schemas, existing, v)
} else {
result[k] = v
}
if m, ok := dest["metadata"]; ok {
result["metadata"] = mergeMetadata(convert.ToMapInterface(m), convert.ToMapInterface(src["metadata"]))
}
return result
}
@ -93,7 +73,7 @@ func mergeMetadata(dest map[string]interface{}, src map[string]interface{}) map[
return result
}
func merge(field string, schema *types.Schema, schemas *types.Schemas, dest, src interface{}) interface{} {
func merge(field string, schema *types.Schema, schemas *types.Schemas, replace bool, dest, src interface{}) interface{} {
if isMap(field, schema) {
return src
}
@ -101,7 +81,7 @@ func merge(field string, schema *types.Schema, schemas *types.Schemas, dest, src
sm, smOk := src.(map[string]interface{})
dm, dmOk := dest.(map[string]interface{})
if smOk && dmOk {
return mergeMaps(getSchema(field, schema, schemas), schemas, dm, sm)
return mergeMaps(getSchema(field, schema, schemas), schemas, replace, dm, sm)
}
return src
}
@ -122,13 +102,13 @@ func isMap(field string, schema *types.Schema) bool {
return false
}
f := schema.ResourceFields[field]
return strings.HasPrefix(f.Type, "map[")
return definition.IsMapType(f.Type)
}
func mergeMaps(schema *types.Schema, schemas *types.Schemas, dest map[string]interface{}, src map[string]interface{}) interface{} {
result := copyMap(dest)
func mergeMaps(schema *types.Schema, schemas *types.Schemas, replace bool, dest map[string]interface{}, src map[string]interface{}) map[string]interface{} {
result := copyMapReplace(schema, dest, replace)
for k, v := range src {
result[k] = merge(k, schema, schemas, dest[k], v)
result[k] = merge(k, schema, schemas, replace, dest[k], v)
}
return result
}
@ -140,3 +120,17 @@ func copyMap(src map[string]interface{}) map[string]interface{} {
}
return result
}
func copyMapReplace(schema *types.Schema, src map[string]interface{}, replace bool) map[string]interface{} {
result := map[string]interface{}{}
for k, v := range src {
if replace {
f := schema.ResourceFields[k]
if f.Update {
continue
}
}
result[k] = v
}
return result
}

View File

@ -3,10 +3,15 @@ package types
import (
"encoding/json"
"io"
"regexp"
"github.com/ghodss/yaml"
)
var (
commenter = regexp.MustCompile("(?m)^( *)zzz#\\((.*)\\)\\((.*)\\)([a-z]+.*):(.*)")
)
func JSONEncoder(writer io.Writer, v interface{}) error {
return json.NewEncoder(writer).Encode(v)
}
@ -20,6 +25,8 @@ func YAMLEncoder(writer io.Writer, v interface{}) error {
if err != nil {
return err
}
//buf = commenter.ReplaceAll(buf, []byte("${1}# ${2}type: ${3}\n${1}# ${4}:${5}"))
buf = commenter.ReplaceAll(buf, []byte("${1}# ${4}:${5}"))
_, err = writer.Write(buf)
return err
}

View File

@ -5,11 +5,12 @@ import (
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/definition"
"github.com/rancher/norman/types/values"
)
type Mapper interface {
FromInternal(data map[string]interface{})
ToInternal(data map[string]interface{})
ToInternal(data map[string]interface{}) error
ModifySchema(schema *Schema, schemas *Schemas) error
}
@ -21,10 +22,12 @@ func (m Mappers) FromInternal(data map[string]interface{}) {
}
}
func (m Mappers) ToInternal(data map[string]interface{}) {
func (m Mappers) ToInternal(data map[string]interface{}) error {
var errors []error
for i := len(m) - 1; i >= 0; i-- {
m[i].ToInternal(data)
errors = append(errors, m[i].ToInternal(data))
}
return NewErrors(errors...)
}
func (m Mappers) ModifySchema(schema *Schema, schemas *Schemas) error {
@ -42,9 +45,13 @@ type typeMapper struct {
typeName string
subSchemas map[string]*Schema
subArraySchemas map[string]*Schema
subMapSchemas map[string]*Schema
}
func (t *typeMapper) FromInternal(data map[string]interface{}) {
name, _ := values.GetValueN(data, "metadata", "name").(string)
namespace, _ := values.GetValueN(data, "metadata", "namespace").(string)
for fieldName, schema := range t.subSchemas {
if schema.Mapper == nil {
continue
@ -53,6 +60,17 @@ func (t *typeMapper) FromInternal(data map[string]interface{}) {
schema.Mapper.FromInternal(fieldData)
}
for fieldName, schema := range t.subMapSchemas {
if schema.Mapper == nil {
continue
}
datas, _ := data[fieldName].(map[string]interface{})
for _, fieldData := range datas {
mapFieldData, _ := fieldData.(map[string]interface{})
schema.Mapper.FromInternal(mapFieldData)
}
}
for fieldName, schema := range t.subArraySchemas {
if schema.Mapper == nil {
continue
@ -64,16 +82,13 @@ func (t *typeMapper) FromInternal(data map[string]interface{}) {
}
}
Mappers(t.Mappers).FromInternal(data)
if _, ok := data["type"]; !ok && data != nil {
data["type"] = t.typeName
}
if data != nil && t.root {
name, _ := data["name"].(string)
namespace, _ := data["namespaceId"].(string)
Mappers(t.Mappers).FromInternal(data)
if data != nil && t.root {
if _, ok := data["id"]; ok {
if namespace != "" {
id, _ := data["id"].(string)
@ -91,8 +106,9 @@ func (t *typeMapper) FromInternal(data map[string]interface{}) {
}
}
func (t *typeMapper) ToInternal(data map[string]interface{}) {
Mappers(t.Mappers).ToInternal(data)
func (t *typeMapper) ToInternal(data map[string]interface{}) error {
errors := Errors{}
errors.Add(Mappers(t.Mappers).ToInternal(data))
for fieldName, schema := range t.subArraySchemas {
if schema.Mapper == nil {
@ -100,7 +116,17 @@ func (t *typeMapper) ToInternal(data map[string]interface{}) {
}
datas, _ := data[fieldName].([]interface{})
for _, fieldData := range datas {
schema.Mapper.ToInternal(convert.ToMapInterface(fieldData))
errors.Add(schema.Mapper.ToInternal(convert.ToMapInterface(fieldData)))
}
}
for fieldName, schema := range t.subMapSchemas {
if schema.Mapper == nil {
continue
}
datas, _ := data[fieldName].(map[string]interface{})
for _, fieldData := range datas {
errors.Add(schema.Mapper.ToInternal(convert.ToMapInterface(fieldData)))
}
}
@ -109,13 +135,16 @@ func (t *typeMapper) ToInternal(data map[string]interface{}) {
continue
}
fieldData, _ := data[fieldName].(map[string]interface{})
schema.Mapper.ToInternal(fieldData)
errors.Add(schema.Mapper.ToInternal(fieldData))
}
return errors.Err()
}
func (t *typeMapper) ModifySchema(schema *Schema, schemas *Schemas) error {
t.subSchemas = map[string]*Schema{}
t.subArraySchemas = map[string]*Schema{}
t.subMapSchemas = map[string]*Schema{}
t.typeName = fmt.Sprintf("%s/schemas/%s", schema.Version.Path, schema.ID)
mapperSchema := schema
@ -128,6 +157,9 @@ func (t *typeMapper) ModifySchema(schema *Schema, schemas *Schemas) error {
if definition.IsArrayType(fieldType) {
fieldType = definition.SubType(fieldType)
targetMap = t.subArraySchemas
} else if definition.IsMapType(fieldType) {
fieldType = definition.SubType(fieldType)
targetMap = t.subMapSchemas
}
schema := schemas.Schema(&schema.Version, fieldType)

View File

@ -7,18 +7,23 @@ import (
)
type Access struct {
Fields map[string]string
Fields map[string]string
Optional bool
}
func (e Access) FromInternal(data map[string]interface{}) {
}
func (e Access) ToInternal(data map[string]interface{}) {
func (e Access) ToInternal(data map[string]interface{}) error {
return nil
}
func (e Access) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
for name, access := range e.Fields {
if err := ValidateField(name, schema); err != nil {
if e.Optional {
continue
}
return err
}

View File

@ -36,7 +36,7 @@ func (e AnnotationField) FromInternal(data map[string]interface{}) {
}
}
func (e AnnotationField) ToInternal(data map[string]interface{}) {
func (e AnnotationField) ToInternal(data map[string]interface{}) error {
v, ok := data[e.Field]
if ok {
if e.Object || e.List {
@ -47,6 +47,7 @@ func (e AnnotationField) ToInternal(data map[string]interface{}) {
values.PutValue(data, convert.ToString(v), "annotations", "field.cattle.io/"+e.Field)
}
values.RemoveValue(data, e.Field)
return nil
}
func (e AnnotationField) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -0,0 +1,35 @@
package mapper
import (
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
)
type APIGroup struct {
apiVersion string
kind string
}
func (a *APIGroup) FromInternal(data map[string]interface{}) {
}
func (a *APIGroup) ToInternal(data map[string]interface{}) error {
_, ok := data["apiVersion"]
if !ok && data != nil {
data["apiVersion"] = a.apiVersion
}
_, ok = data["kind"]
if !ok && data != nil {
data["kind"] = a.kind
}
return nil
}
func (a *APIGroup) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
a.apiVersion = schema.Version.Group + "/" + schema.Version.Version
a.kind = convert.Capitalize(schema.ID)
return nil
}

View File

@ -31,16 +31,18 @@ func (m Base64) FromInternal(data map[string]interface{}) {
}
}
func (m Base64) ToInternal(data map[string]interface{}) {
func (m Base64) ToInternal(data map[string]interface{}) error {
if v, ok := values.RemoveValue(data, strings.Split(m.Field, m.getSep())...); ok {
str := convert.ToString(v)
if str == "" {
return
return nil
}
newData := base64.StdEncoding.EncodeToString([]byte(str))
values.PutValue(data, newData, strings.Split(m.Field, m.getSep())...)
}
return nil
}
func (m Base64) ModifySchema(s *types.Schema, schemas *types.Schemas) error {

View File

@ -20,10 +20,12 @@ func (b *BatchMove) FromInternal(data map[string]interface{}) {
}
}
func (b *BatchMove) ToInternal(data map[string]interface{}) {
func (b *BatchMove) ToInternal(data map[string]interface{}) error {
errors := types.Errors{}
for i := len(b.moves) - 1; i >= 0; i-- {
b.moves[i].ToInternal(data)
errors.Add(b.moves[i].ToInternal(data))
}
return errors.Err()
}
func (b *BatchMove) ModifySchema(s *types.Schema, schemas *types.Schemas) error {

View File

@ -12,7 +12,8 @@ type ChangeType struct {
func (c ChangeType) FromInternal(data map[string]interface{}) {
}
func (c ChangeType) ToInternal(data map[string]interface{}) {
func (c ChangeType) ToInternal(data map[string]interface{}) error {
return nil
}
func (c ChangeType) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -16,10 +16,11 @@ func (m Condition) FromInternal(data map[string]interface{}) {
}
}
func (m Condition) ToInternal(data map[string]interface{}) {
func (m Condition) ToInternal(data map[string]interface{}) error {
if data[m.Field] == m.Value {
m.Mapper.ToInternal(data)
return m.Mapper.ToInternal(data)
}
return nil
}
func (m Condition) ModifySchema(s *types.Schema, schemas *types.Schemas) error {

View File

@ -20,15 +20,17 @@ func (c Copy) FromInternal(data map[string]interface{}) {
}
}
func (c Copy) ToInternal(data map[string]interface{}) {
func (c Copy) ToInternal(data map[string]interface{}) error {
if data == nil {
return
return nil
}
t, tok := data[c.To]
_, fok := data[c.From]
if tok && !fok {
data[c.From] = t
}
return nil
}
func (c Copy) ModifySchema(s *types.Schema, schemas *types.Schemas) error {

View File

@ -20,8 +20,8 @@ func (d DisplayName) FromInternal(data map[string]interface{}) {
displayNameMappers.FromInternal(data)
}
func (d DisplayName) ToInternal(data map[string]interface{}) {
displayNameMappers.ToInternal(data)
func (d DisplayName) ToInternal(data map[string]interface{}) error {
return displayNameMappers.ToInternal(data)
}
func (d DisplayName) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -15,7 +15,8 @@ func (d Drop) FromInternal(data map[string]interface{}) {
delete(data, d.Field)
}
func (d Drop) ToInternal(data map[string]interface{}) {
func (d Drop) ToInternal(data map[string]interface{}) error {
return nil
}
func (d Drop) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -26,9 +26,9 @@ func (e *Embed) FromInternal(data map[string]interface{}) {
delete(data, e.Field)
}
func (e *Embed) ToInternal(data map[string]interface{}) {
func (e *Embed) ToInternal(data map[string]interface{}) error {
if data == nil {
return
return nil
}
sub := map[string]interface{}{}
@ -43,9 +43,10 @@ func (e *Embed) ToInternal(data map[string]interface{}) {
if e.EmptyValueOk {
data[e.Field] = nil
}
return
return nil
}
data[e.Field] = sub
return nil
}
func (e *Embed) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
@ -62,6 +63,9 @@ func (e *Embed) ModifySchema(schema *types.Schema, schemas *types.Schemas) error
embeddedSchemaID := schema.ResourceFields[e.Field].Type
embeddedSchema := schemas.Schema(&schema.Version, embeddedSchemaID)
if embeddedSchema == nil {
if e.Optional {
return nil
}
return fmt.Errorf("failed to find schema %s for embedding", embeddedSchemaID)
}

View File

@ -12,7 +12,8 @@ type Enum struct {
func (e Enum) FromInternal(data map[string]interface{}) {
}
func (e Enum) ToInternal(data map[string]interface{}) {
func (e Enum) ToInternal(data map[string]interface{}) error {
return nil
}
func (e Enum) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -27,12 +27,13 @@ func (m JSONEncode) FromInternal(data map[string]interface{}) {
}
}
func (m JSONEncode) ToInternal(data map[string]interface{}) {
func (m JSONEncode) ToInternal(data map[string]interface{}) error {
if v, ok := values.RemoveValue(data, strings.Split(m.Field, m.getSep())...); ok && v != nil {
if bytes, err := json.Marshal(v); err == nil {
values.PutValue(data, string(bytes), strings.Split(m.Field, m.getSep())...)
}
}
return nil
}
func (m JSONEncode) getSep() string {

View File

@ -16,11 +16,12 @@ func (e LabelField) FromInternal(data map[string]interface{}) {
}
}
func (e LabelField) ToInternal(data map[string]interface{}) {
func (e LabelField) ToInternal(data map[string]interface{}) error {
v, ok := data[e.Field]
if ok {
values.PutValue(data, v, "labels", "field.cattle.io/"+e.Field)
}
return nil
}
func (e LabelField) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -8,7 +8,7 @@ func NewMetadataMapper() types.Mapper {
return types.Mappers{
ChangeType{Field: "name", Type: "dnsLabel"},
Drop{Field: "generateName"},
Move{From: "uid", To: "uuid"},
Move{From: "uid", To: "uuid", CodeName: "UUID"},
Drop{Field: "resourceVersion"},
Drop{Field: "generation"},
Move{From: "creationTimestamp", To: "created"},

View File

@ -12,9 +12,9 @@ import (
)
type Move struct {
From, To string
DestDefined bool
NoDeleteFromField bool
From, To, CodeName string
DestDefined bool
NoDeleteFromField bool
}
func (m Move) FromInternal(data map[string]interface{}) {
@ -23,10 +23,11 @@ func (m Move) FromInternal(data map[string]interface{}) {
}
}
func (m Move) ToInternal(data map[string]interface{}) {
func (m Move) ToInternal(data map[string]interface{}) error {
if v, ok := values.RemoveValue(data, strings.Split(m.To, "/")...); ok {
values.PutValue(data, v, strings.Split(m.From, "/")...)
}
return nil
}
func (m Move) ModifySchema(s *types.Schema, schemas *types.Schemas) error {
@ -52,7 +53,11 @@ func (m Move) ModifySchema(s *types.Schema, schemas *types.Schemas) error {
}
if !m.DestDefined {
fromField.CodeName = convert.Capitalize(toFieldName)
if m.CodeName == "" {
fromField.CodeName = convert.Capitalize(toFieldName)
} else {
fromField.CodeName = m.CodeName
}
toSchema.ResourceFields[toFieldName] = fromField
}

View File

@ -11,6 +11,7 @@ type Object struct {
func NewObject(mappers ...types.Mapper) Object {
return Object{
Mappers: append([]types.Mapper{
&APIGroup{},
&Embed{Field: "metadata"},
&Embed{Field: "spec", Optional: true},
&ReadOnly{Field: "status", Optional: true, SubFields: true},

View File

@ -13,7 +13,8 @@ type ReadOnly struct {
func (r ReadOnly) FromInternal(data map[string]interface{}) {
}
func (r ReadOnly) ToInternal(data map[string]interface{}) {
func (r ReadOnly) ToInternal(data map[string]interface{}) error {
return nil
}
func (r ReadOnly) readOnly(field types.Field, schema *types.Schema, schemas *types.Schemas) types.Field {

View File

@ -4,6 +4,7 @@ import (
"strings"
"github.com/rancher/norman/types"
"github.com/rancher/norman/types/convert"
"github.com/rancher/norman/types/definition"
)
@ -17,10 +18,11 @@ func (r *RenameReference) FromInternal(data map[string]interface{}) {
}
}
func (r *RenameReference) ToInternal(data map[string]interface{}) {
func (r *RenameReference) ToInternal(data map[string]interface{}) error {
if r.mapper != nil {
r.mapper.ToInternal(data)
return r.mapper.ToInternal(data)
}
return nil
}
func (r *RenameReference) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {
@ -28,7 +30,8 @@ func (r *RenameReference) ModifySchema(schema *types.Schema, schemas *types.Sche
for name, field := range schema.ResourceFields {
if definition.IsReferenceType(field.Type) && strings.HasSuffix(name, "Name") {
newName := strings.TrimSuffix(name, "Name") + "Id"
move := Move{From: name, To: newName}
newCodeName := convert.Capitalize(strings.TrimSuffix(name, "Name") + "ID")
move := Move{From: name, To: newName, CodeName: newCodeName}
if err := move.ModifySchema(schema, schemas); err != nil {
return err
}
@ -36,7 +39,8 @@ func (r *RenameReference) ModifySchema(schema *types.Schema, schemas *types.Sche
mappers = append(mappers, move)
} else if definition.IsArrayType(field.Type) && definition.IsReferenceType(definition.SubType(field.Type)) && strings.HasSuffix(name, "Names") {
newName := strings.TrimSuffix(name, "Names") + "Ids"
move := Move{From: name, To: newName}
newCodeName := convert.Capitalize(strings.TrimSuffix(name, "Names") + "IDs")
move := Move{From: name, To: newName, CodeName: newCodeName}
if err := move.ModifySchema(schema, schemas); err != nil {
return err
}

View File

@ -11,7 +11,8 @@ type Required struct {
func (e Required) FromInternal(data map[string]interface{}) {
}
func (e Required) ToInternal(data map[string]interface{}) {
func (e Required) ToInternal(data map[string]interface{}) error {
return nil
}
func (e Required) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

31
vendor/github.com/rancher/norman/types/mapper/root.go generated vendored Normal file
View File

@ -0,0 +1,31 @@
package mapper
import (
"github.com/rancher/norman/types"
)
type Root struct {
enabled bool
Mapper types.Mapper
}
func (m *Root) FromInternal(data map[string]interface{}) {
if m.enabled {
m.Mapper.FromInternal(data)
}
}
func (m *Root) ToInternal(data map[string]interface{}) error {
if m.enabled {
return m.Mapper.ToInternal(data)
}
return nil
}
func (m *Root) ModifySchema(s *types.Schema, schemas *types.Schemas) error {
if s.CanList(nil) == nil {
m.enabled = true
return m.Mapper.ModifySchema(s, schemas)
}
return nil
}

View File

@ -17,10 +17,11 @@ func (s *Scope) FromInternal(data map[string]interface{}) {
}
}
func (s *Scope) ToInternal(data map[string]interface{}) {
func (s *Scope) ToInternal(data map[string]interface{}) error {
if s.run {
types.Mappers(s.Mappers).ToInternal(data)
return types.Mappers(s.Mappers).ToInternal(data)
}
return nil
}
func (s *Scope) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -39,10 +39,10 @@ func (s SetValue) getTo() string {
return s.To
}
func (s SetValue) ToInternal(data map[string]interface{}) {
func (s SetValue) ToInternal(data map[string]interface{}) error {
v, ok := values.GetValue(data, strings.Split(s.getTo(), "/")...)
if !ok {
return
return nil
}
if s.IfEq == nil {
@ -50,6 +50,8 @@ func (s SetValue) ToInternal(data map[string]interface{}) {
} else if v == s.Value {
values.PutValue(data, s.IfEq, strings.Split(s.Field, "/")...)
}
return nil
}
func (s SetValue) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -26,7 +26,8 @@ func (s SliceMerge) FromInternal(data map[string]interface{}) {
}
}
func (s SliceMerge) ToInternal(data map[string]interface{}) {
func (s SliceMerge) ToInternal(data map[string]interface{}) error {
return nil
}
func (s SliceMerge) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -29,7 +29,7 @@ func (s SliceToMap) FromInternal(data map[string]interface{}) {
}
}
func (s SliceToMap) ToInternal(data map[string]interface{}) {
func (s SliceToMap) ToInternal(data map[string]interface{}) error {
datas, _ := data[s.Field].(map[string]interface{})
var result []interface{}
@ -46,6 +46,8 @@ func (s SliceToMap) ToInternal(data map[string]interface{}) {
} else if datas != nil {
data[s.Field] = result
}
return nil
}
func (s SliceToMap) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -23,7 +23,7 @@ func (u *UnionEmbed) FromInternal(data map[string]interface{}) {
}
}
func (u *UnionEmbed) ToInternal(data map[string]interface{}) {
func (u *UnionEmbed) ToInternal(data map[string]interface{}) error {
outer:
for _, mapper := range u.Fields {
if len(mapper.CheckFields) == 0 {
@ -32,15 +32,16 @@ outer:
for _, check := range mapper.CheckFields {
v, ok := data[check]
if !ok || convert.IsEmpty(v) {
if !ok || convert.IsAPIObjectEmpty(v) {
continue outer
}
}
embed := u.embeds[mapper.FieldName]
embed.ToInternal(data)
return
return embed.ToInternal(data)
}
return nil
}
func (u *UnionEmbed) ModifySchema(schema *types.Schema, schemas *types.Schemas) error {

View File

@ -18,10 +18,12 @@ func (m UntypedMove) FromInternal(data map[string]interface{}) {
}
}
func (m UntypedMove) ToInternal(data map[string]interface{}) {
func (m UntypedMove) ToInternal(data map[string]interface{}) error {
if v, ok := values.RemoveValue(data, strings.Split(m.To, m.getSep())...); ok {
values.PutValue(data, v, strings.Split(m.From, m.getSep())...)
}
return nil
}
func (m UntypedMove) getSep() string {

View File

@ -99,6 +99,8 @@ func (s *Schemas) setupFilters(schema *Schema) {
switch field.Type {
case "enum":
mods = []ModifierType{ModifierEQ, ModifierNE, ModifierIn, ModifierNotIn}
case "date":
fallthrough
case "dnsLabel":
fallthrough
case "hostname":

View File

@ -343,7 +343,28 @@ type MultiErrors struct {
Errors []error
}
func NewErrors(errors ...error) error {
type Errors struct {
errors []error
}
func (e *Errors) Add(err error) {
if err != nil {
e.errors = append(e.errors, err)
}
}
func (e *Errors) Err() error {
return NewErrors(e.errors...)
}
func NewErrors(inErrors ...error) error {
var errors []error
for _, err := range inErrors {
if err != nil {
errors = append(errors, err)
}
}
if len(errors) == 0 {
return nil
} else if len(errors) == 1 {

View File

@ -12,13 +12,14 @@ type ValuesMap struct {
}
type RawResource struct {
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Schema *Schema `json:"-" yaml:"-"`
Links map[string]string `json:"links" yaml:"links"`
Actions map[string]string `json:"actions" yaml:"actions"`
Values map[string]interface{} `json:",inline"`
ActionLinks bool `json:"-"`
ID string `json:"id,omitempty" yaml:"id,omitempty"`
Type string `json:"type,omitempty" yaml:"type,omitempty"`
Schema *Schema `json:"-" yaml:"-"`
Links map[string]string `json:"links,omitempty" yaml:"links,omitempty"`
Actions map[string]string `json:"actions,omitempty" yaml:"actions,omitempty"`
Values map[string]interface{} `json:",inline" yaml:",inline"`
ActionLinks bool `json:"-" yaml:"-"`
DropReadOnly bool `json:"-" yaml:"-"`
}
func (r *RawResource) AddAction(apiContext *APIContext, name string) {
@ -26,23 +27,38 @@ func (r *RawResource) AddAction(apiContext *APIContext, name string) {
}
func (r *RawResource) MarshalJSON() ([]byte, error) {
return json.Marshal(r.ToMap())
}
func (r *RawResource) ToMap() map[string]interface{} {
data := map[string]interface{}{}
for k, v := range r.Values {
data[k] = v
}
if r.ID != "" {
if r.ID != "" && !r.DropReadOnly {
data["id"] = r.ID
}
data["type"] = r.Type
data["baseType"] = r.Schema.BaseType
data["links"] = r.Links
if r.ActionLinks {
data["actionLinks"] = r.Actions
} else {
data["actions"] = r.Actions
if r.Type != "" && !r.DropReadOnly {
data["type"] = r.Type
}
return json.Marshal(data)
if r.Schema.BaseType != "" && !r.DropReadOnly {
data["baseType"] = r.Schema.BaseType
}
if len(r.Links) > 0 && !r.DropReadOnly {
data["links"] = r.Links
}
if len(r.Actions) > 0 && !r.DropReadOnly {
if r.ActionLinks {
data["actionLinks"] = r.Actions
} else {
data["actions"] = r.Actions
}
}
return data
}
type ActionHandler func(actionName string, action *Action, request *APIContext) error
@ -53,6 +69,8 @@ type QueryFilter func(opts *QueryOptions, schema *Schema, data []map[string]inte
type Validator func(request *APIContext, schema *Schema, data map[string]interface{}) error
type InputFormatter func(request *APIContext, schema *Schema, data map[string]interface{}, create bool) error
type Formatter func(request *APIContext, resource *RawResource)
type CollectionFormatter func(request *APIContext, collection *GenericCollection)
@ -124,6 +142,10 @@ func GetAPIContext(ctx context.Context) *APIContext {
return apiContext
}
func (r *APIContext) Option(key string) string {
return r.Query.Get("_" + key)
}
func (r *APIContext) WriteResponse(code int, obj interface{}) {
r.ResponseWriter.Write(r, code, obj)
}

View File

@ -8,3 +8,15 @@ func ContainsString(slice []string, item string) bool {
}
return false
}
func StringsEqual(left, right []string) bool {
if len(left) != len(right) {
return false
}
for i := 0; i < len(left); i++ {
if left[i] != right[i] {
return false
}
}
return true
}

View File

@ -111,6 +111,7 @@ type Schema struct {
CreateHandler RequestHandler `json:"-"`
DeleteHandler RequestHandler `json:"-"`
UpdateHandler RequestHandler `json:"-"`
InputFormatter InputFormatter `json:"-"`
Formatter Formatter `json:"-"`
CollectionFormatter CollectionFormatter `json:"-"`
ErrorHandler ErrorHandler `json:"-"`

44
vendor/k8s.io/api/admissionregistration/v1beta1/BUILD generated vendored Normal file
View File

@ -0,0 +1,44 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
],
importpath = "k8s.io/api/admissionregistration/v1beta1",
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)
filegroup(
name = "go_default_library_protos",
srcs = ["generated.proto"],
visibility = ["//visibility:public"],
)

43
vendor/k8s.io/api/apps/v1/BUILD generated vendored Normal file
View File

@ -0,0 +1,43 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
],
importpath = "k8s.io/api/apps/v1",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/intstr:go_default_library",
],
)
filegroup(
name = "go_default_library_protos",
srcs = ["generated.proto"],
visibility = ["//visibility:public"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

42
vendor/k8s.io/api/events/v1beta1/BUILD generated vendored Normal file
View File

@ -0,0 +1,42 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
filegroup(
name = "go_default_library_protos",
srcs = ["generated.proto"],
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
],
importpath = "k8s.io/api/events/v1beta1",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/k8s.io/api/core/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

42
vendor/k8s.io/api/storage/v1alpha1/BUILD generated vendored Normal file
View File

@ -0,0 +1,42 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
filegroup(
name = "go_default_library_protos",
srcs = ["generated.proto"],
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
],
importpath = "k8s.io/api/storage/v1alpha1",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/github.com/gogo/protobuf/sortkeys:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

45
vendor/k8s.io/apimachinery/pkg/apis/meta/v1beta1/BUILD generated vendored Normal file
View File

@ -0,0 +1,45 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
filegroup(
name = "go_default_library_protos",
srcs = ["generated.proto"],
visibility = ["//visibility:public"],
)
go_library(
name = "go_default_library",
srcs = [
"conversion.go",
"deepcopy.go",
"doc.go",
"generated.pb.go",
"register.go",
"types.go",
"types_swagger_doc_generated.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
importpath = "k8s.io/apimachinery/pkg/apis/meta/v1beta1",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/gogo/protobuf/proto:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,40 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"admissionregistration_client.go",
"doc.go",
"generated_expansion.go",
"mutatingwebhookconfiguration.go",
"validatingwebhookconfiguration.go",
],
importpath = "k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1",
visibility = ["//visibility:public"],
deps = [
"//vendor/k8s.io/api/admissionregistration/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/kubernetes/typed/admissionregistration/v1beta1/fake:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

43
vendor/k8s.io/client-go/kubernetes/typed/apps/v1/BUILD generated vendored Normal file
View File

@ -0,0 +1,43 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"apps_client.go",
"controllerrevision.go",
"daemonset.go",
"deployment.go",
"doc.go",
"generated_expansion.go",
"replicaset.go",
"statefulset.go",
],
importpath = "k8s.io/client-go/kubernetes/typed/apps/v1",
visibility = ["//visibility:public"],
deps = [
"//vendor/k8s.io/api/apps/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/kubernetes/typed/apps/v1/fake:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,39 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"event.go",
"events_client.go",
"generated_expansion.go",
],
importpath = "k8s.io/client-go/kubernetes/typed/events/v1beta1",
visibility = ["//visibility:public"],
deps = [
"//vendor/k8s.io/api/events/v1beta1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/kubernetes/typed/events/v1beta1/fake:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,39 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"generated_expansion.go",
"storage_client.go",
"volumeattachment.go",
],
importpath = "k8s.io/client-go/kubernetes/typed/storage/v1alpha1",
visibility = ["//visibility:public"],
deps = [
"//vendor/k8s.io/api/storage/v1alpha1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/types:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/watch:go_default_library",
"//vendor/k8s.io/client-go/kubernetes/scheme:go_default_library",
"//vendor/k8s.io/client-go/rest:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/kubernetes/typed/storage/v1alpha1/fake:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,36 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"register.go",
"types.go",
"zz_generated.deepcopy.go",
],
importpath = "k8s.io/client-go/pkg/apis/clientauthentication",
visibility = ["//visibility:public"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/pkg/apis/clientauthentication/install:all-srcs",
"//staging/src/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1:all-srcs",
],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

View File

@ -0,0 +1,39 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = [
"doc.go",
"register.go",
"types.go",
"zz_generated.conversion.go",
"zz_generated.deepcopy.go",
"zz_generated.defaults.go",
],
importpath = "k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1",
deps = [
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/conversion:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/clientauthentication:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)

38
vendor/k8s.io/client-go/plugin/pkg/client/auth/BUILD generated vendored Normal file
View File

@ -0,0 +1,38 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
)
go_library(
name = "go_default_library",
srcs = ["plugins.go"],
importpath = "k8s.io/client-go/plugin/pkg/client/auth",
deps = [
"//vendor/k8s.io/client-go/plugin/pkg/client/auth/azure:go_default_library",
"//vendor/k8s.io/client-go/plugin/pkg/client/auth/gcp:go_default_library",
"//vendor/k8s.io/client-go/plugin/pkg/client/auth/oidc:go_default_library",
"//vendor/k8s.io/client-go/plugin/pkg/client/auth/openstack:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [
":package-srcs",
"//staging/src/k8s.io/client-go/plugin/pkg/client/auth/azure:all-srcs",
"//staging/src/k8s.io/client-go/plugin/pkg/client/auth/exec:all-srcs",
"//staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp:all-srcs",
"//staging/src/k8s.io/client-go/plugin/pkg/client/auth/oidc:all-srcs",
"//staging/src/k8s.io/client-go/plugin/pkg/client/auth/openstack:all-srcs",
],
tags = ["automanaged"],
)

View File

@ -0,0 +1,44 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["exec.go"],
importpath = "k8s.io/client-go/plugin/pkg/client/auth/exec",
visibility = ["//visibility:public"],
deps = [
"//vendor/github.com/golang/glog:go_default_library",
"//vendor/golang.org/x/crypto/ssh/terminal:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/serializer:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/clientauthentication:go_default_library",
"//vendor/k8s.io/client-go/pkg/apis/clientauthentication/v1alpha1:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["exec_test.go"],
data = glob(["testdata/**"]),
embed = [":go_default_library"],
deps = [
"//vendor/k8s.io/client-go/pkg/apis/clientauthentication:go_default_library",
"//vendor/k8s.io/client-go/tools/clientcmd/api:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

29
vendor/k8s.io/client-go/util/buffer/BUILD generated vendored Normal file
View File

@ -0,0 +1,29 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
go_library(
name = "go_default_library",
srcs = ["ring_growing.go"],
importpath = "k8s.io/client-go/util/buffer",
visibility = ["//visibility:public"],
)
go_test(
name = "go_default_test",
srcs = ["ring_growing_test.go"],
embed = [":go_default_library"],
deps = ["//vendor/github.com/stretchr/testify/assert:go_default_library"],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
visibility = ["//visibility:public"],
)

41
vendor/k8s.io/client-go/util/retry/BUILD generated vendored Normal file
View File

@ -0,0 +1,41 @@
package(default_visibility = ["//visibility:public"])
load(
"@io_bazel_rules_go//go:def.bzl",
"go_library",
"go_test",
)
go_library(
name = "go_default_library",
srcs = ["util.go"],
importpath = "k8s.io/client-go/util/retry",
deps = [
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
)
go_test(
name = "go_default_test",
srcs = ["util_test.go"],
embed = [":go_default_library"],
deps = [
"//vendor/k8s.io/apimachinery/pkg/api/errors:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/runtime/schema:go_default_library",
"//vendor/k8s.io/apimachinery/pkg/util/wait:go_default_library",
],
)
filegroup(
name = "package-srcs",
srcs = glob(["**"]),
tags = ["automanaged"],
visibility = ["//visibility:private"],
)
filegroup(
name = "all-srcs",
srcs = [":package-srcs"],
tags = ["automanaged"],
)