mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 19:49:46 +00:00
Vendor all tools for generating code and config
This commit is contained in:
parent
b6052216c7
commit
e4c7302e7c
89 changed files with 9330 additions and 93 deletions
.travis.ymlMakefilego.modgo.summodules.txt
pkg/client/versioned
scripts
vendor
github.com
brancz/gojsontoyaml
fatih/color
jsonnet-bundler/jsonnet-bundler
mattn
go-colorable
.travis.ymlLICENSEREADME.mdcolorable_appengine.gocolorable_others.gocolorable_windows.gononcolorable.go
go-isatty
stretchr/testify
k8s.io/code-generator
cmd
client-gen
OWNERSREADME.md
args
generators
client_generator.go
main.gofake
fake_client_generator.gogenerator_fake_for_clientset.gogenerator_fake_for_group.gogenerator_fake_for_type.go
generator_for_clientset.gogenerator_for_expansion.gogenerator_for_group.gogenerator_for_type.goscheme
util
path
types
informer-gen
args
generators
factory.gofactoryinterface.gogeneric.gogroupinterface.goinformer.gopackages.gotags.gotypes.goversioninterface.go
main.golister-gen
pkg/namer
|
@ -2,7 +2,7 @@ sudo: required
|
|||
dist: xenial
|
||||
language: go
|
||||
go:
|
||||
- "1.11.x"
|
||||
- "1.12.x"
|
||||
go_import_path: github.com/coreos/prometheus-operator
|
||||
env:
|
||||
- GO111MODULE=on
|
||||
|
|
19
Makefile
19
Makefile
|
@ -15,13 +15,6 @@ EMBEDMD_BINARY:=$(FIRST_GOPATH)/bin/embedmd
|
|||
|
||||
TYPES_V1_TARGET:=pkg/apis/monitoring/v1/types.go
|
||||
|
||||
# Unfortunately kube-openapi doesn't seem to be properly tagged yet as the other generator binary.
|
||||
# Starting with https://github.com/kubernetes/kube-openapi/commit/07437455b254b00a4deb3b420e790b2215450487
|
||||
# type object declarations are added which break prometheus operator.
|
||||
#
|
||||
# TODO(sur): bump this to a proper release branch once upstream resolved this.
|
||||
K8S_OPENAPI_GEN_VERSION:=b3a7cee44a305be0a69e1b9ac03018307287e1b0
|
||||
|
||||
K8S_GEN_VERSION:=release-1.14
|
||||
K8S_GEN_BINARIES:=deepcopy-gen informer-gen lister-gen client-gen
|
||||
K8S_GEN_ARGS:=--go-header-file $(FIRST_GOPATH)/src/$(GO_PKG)/.header --v=1 --logtostderr
|
||||
|
@ -247,15 +240,11 @@ define _K8S_GEN_VAR_TARGET_
|
|||
$(shell echo $(1) | tr '[:lower:]' '[:upper:]' | tr '-' '_')_BINARY:=$(FIRST_GOPATH)/bin/$(1)
|
||||
|
||||
$(FIRST_GOPATH)/bin/$(1):
|
||||
# go get -u -d k8s.io/code-generator/cmd/$(1)
|
||||
# cd $(FIRST_GOPATH)/src/k8s.io/code-generator; git checkout $(K8S_GEN_VERSION)
|
||||
go install k8s.io/code-generator/cmd/$(1)
|
||||
|
||||
endef
|
||||
|
||||
$(OPENAPI_GEN_BINARY):
|
||||
# go get -u -d k8s.io/kube-openapi/cmd/openapi-gen
|
||||
# cd $(FIRST_GOPATH)/src/k8s.io/kube-openapi; git checkout $(K8S_OPENAPI_GEN_VERSION)
|
||||
go install k8s.io/kube-openapi/cmd/openapi-gen
|
||||
|
||||
$(foreach binary,$(K8S_GEN_BINARIES),$(eval $(call _K8S_GEN_VAR_TARGET_,$(binary))))
|
||||
|
@ -264,13 +253,13 @@ $(EMBEDMD_BINARY):
|
|||
@go get github.com/campoy/embedmd
|
||||
|
||||
$(JB_BINARY):
|
||||
go get -u github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
|
||||
@go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
|
||||
|
||||
$(PO_CRDGEN_BINARY): cmd/po-crdgen/main.go $(OPENAPI_TARGET)
|
||||
go install $(GO_PKG)/cmd/po-crdgen
|
||||
@go install $(GO_PKG)/cmd/po-crdgen
|
||||
|
||||
$(PO_DOCGEN_BINARY): $(shell find cmd/po-docgen -type f) $(TYPES_V1_TARGET)
|
||||
go install $(GO_PKG)/cmd/po-docgen
|
||||
@go install $(GO_PKG)/cmd/po-docgen
|
||||
|
||||
$(GOJSONTOYAML_BINARY):
|
||||
go get -u github.com/brancz/gojsontoyaml
|
||||
@go install github.com/brancz/gojsontoyaml
|
||||
|
|
13
go.mod
13
go.mod
|
@ -3,11 +3,10 @@ module github.com/coreos/prometheus-operator
|
|||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc // indirect
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf // indirect
|
||||
github.com/ant31/crd-validation v0.0.0-20180702145049-30f8a35d0ac2
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 // indirect
|
||||
github.com/blang/semver v3.5.1+incompatible
|
||||
github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d
|
||||
github.com/campoy/embedmd v1.0.0
|
||||
github.com/cespare/xxhash v1.1.0 // indirect
|
||||
github.com/emicklei/go-restful v2.6.0+incompatible // indirect
|
||||
|
@ -33,7 +32,7 @@ require (
|
|||
github.com/imdario/mergo v0.3.5 // indirect
|
||||
github.com/improbable-eng/thanos v0.3.2
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 // indirect
|
||||
github.com/kisielk/errcheck v1.2.0 // indirect
|
||||
github.com/jsonnet-bundler/jsonnet-bundler v0.1.0
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 // indirect
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
|
||||
|
@ -51,13 +50,9 @@ require (
|
|||
github.com/prometheus/common v0.0.0-20181218105931-67670fe90761 // indirect
|
||||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a // indirect
|
||||
github.com/prometheus/tsdb v0.2.0 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001 // indirect
|
||||
github.com/spf13/pflag v1.0.3 // indirect
|
||||
github.com/stretchr/testify v1.2.2
|
||||
github.com/stretchr/testify v1.3.0
|
||||
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d // indirect
|
||||
golang.org/x/exp v0.0.0-20190424083841-8c7d1c524af6 // indirect
|
||||
golang.org/x/image v0.0.0-20190424155947-59b11bec70c7 // indirect
|
||||
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6 // indirect
|
||||
golang.org/x/net v0.0.0-20190424112056-4829fb13d2c6 // indirect
|
||||
golang.org/x/oauth2 v0.0.0-20190402181905-9f3314589c9a // indirect
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58
|
||||
|
@ -65,14 +60,12 @@ require (
|
|||
golang.org/x/text v0.3.1 // indirect
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 // indirect
|
||||
gonum.org/v1/gonum v0.0.0-20190424212039-2a1643c79af2 // indirect
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
gopkg.in/fsnotify.v1 v1.4.7 // indirect
|
||||
gopkg.in/inf.v0 v0.9.0 // indirect
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2
|
||||
|
||||
k8s.io/api v0.0.0-20190313235455-40a48860b5ab
|
||||
k8s.io/apiextensions-apiserver v0.0.0-20190315093550-53c4693659ed
|
||||
k8s.io/apimachinery v0.0.0-20190313205120-d7deff9243b1
|
||||
|
|
51
go.sum
51
go.sum
|
@ -1,5 +1,4 @@
|
|||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
|
||||
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
|
||||
github.com/PuerkitoBio/purell v1.1.0 h1:rmGxhojJlM0tuKtfdvliR84CFHljx9ag64t2xmVkjK4=
|
||||
|
@ -16,16 +15,21 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973 h1:xJ4a3vCFaGF/jqvzLM
|
|||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
|
||||
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
|
||||
github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d h1:DMb8SuAL9+demT8equqMMzD8C/uxqWmj4cgV7ufrpQo=
|
||||
github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d/go.mod h1:IyUJYN1gvWjtLF5ZuygmxbnsAyP3aJS6cHzIuZY50B0=
|
||||
github.com/campoy/embedmd v1.0.0 h1:V4kI2qTJJLf4J29RzI/MAt2c3Bl4dQSYPuflzwFH2hY=
|
||||
github.com/campoy/embedmd v1.0.0/go.mod h1:oxyr9RCiSXg0M3VJ3ks0UGfp98BpSSGr0kpiX3MzVl8=
|
||||
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
|
||||
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/emicklei/go-restful v2.6.0+incompatible h1:luAX89wpjId5gV+GJV11MFD56GpAJTG2eUqCeDDgB98=
|
||||
github.com/emicklei/go-restful v2.6.0+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.1.0+incompatible h1:K1MDoo4AZ4wU0GIU/fPmtZg7VpzLjCxu+UwBD1FvwOc=
|
||||
github.com/evanphx/json-patch v4.1.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
|
||||
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
|
||||
github.com/fortytw2/leaktest v1.2.0 h1:cj6GCiwJDH7l3tMHLjZDo0QqPtrXJiWSI9JgpeQKw+Q=
|
||||
github.com/fortytw2/leaktest v1.2.0/go.mod h1:jDsjWgpAGjm2CA7WthBh/CdZYEPF31XHquHwclZch5g=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
|
@ -52,7 +56,6 @@ github.com/go-openapi/swag v0.17.2 h1:K/ycE/XTUDFltNHSO32cGRUhrVGJD64o8WgAIZNyc3
|
|||
github.com/go-openapi/swag v0.17.2/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
||||
github.com/go-stack/stack v1.8.0 h1:5SgMzNM5HxrEjV0ww2lTmX6E2Izsfxas4+YHWRs3Lsk=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gogo/protobuf v0.0.0-20171007142547-342cbe0a0415/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/golang/groupcache v0.0.0-20180924190550-6f2cf27854a4 h1:6UVLWz0fIIrv0UVj6t0A7cL48n8IyAdLVQqAYzEfsKI=
|
||||
|
@ -75,8 +78,9 @@ github.com/improbable-eng/thanos v0.3.2 h1:iZfU7exq+RD5Lnb8n3Eh9MNYoRLeyeGO/85Av
|
|||
github.com/improbable-eng/thanos v0.3.2/go.mod h1:GZewVGILKuJVPNRn7L4Zw+7X96qzFOwj63b22xYGXBE=
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3 h1:/UewZcckqhvnnS0C6r3Sher2hSEbVmM6Ogpcjen08+Y=
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/jsonnet-bundler/jsonnet-bundler v0.1.0 h1:T/HtHFr+mYCRULrH1x/RnoB0prIs0rMkolJhFMXNC9A=
|
||||
github.com/jsonnet-bundler/jsonnet-bundler v0.1.0/go.mod h1:YKsSFc9VFhhLITkJS3X2PrRqWG9u2Jq99udTdDjQLfM=
|
||||
github.com/kisielk/errcheck v1.1.0/go.mod h1:EZBBE59ingxPouuu3KfxchcWSUPOHkagtvWXihfKN4Q=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515 h1:T+h1c/A9Gawja4Y9mFVWj2vyii2bbUNDw3kt9VxK2EY=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
|
@ -89,6 +93,10 @@ github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348 h1:MtvEpTB6LX3v
|
|||
github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348/go.mod h1:B69LEHPfb2qLo0BaaOLcbitczOKLWTsrBG9LczfCD4k=
|
||||
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329 h1:2gxZ0XQIU/5z3Z3bUBu+FXuk2pFbkN6tcwi/pjyaDic=
|
||||
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
|
||||
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
|
||||
github.com/mattn/go-isatty v0.0.6 h1:SrwhHcpV4nWrMGdNcC2kXpMfcBVYGDuTArqyhocJgvA=
|
||||
github.com/mattn/go-isatty v0.0.6/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1 h1:4hp9jkHxhMHkqkrB3Ix0jegS5sx/RkqARlsWZ6pIwiU=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452 h1:hOY53G+kBFhbYFpRVxHl5eS7laP6B1+Cq+Z9Dry1iMU=
|
||||
|
@ -105,6 +113,7 @@ github.com/onsi/ginkgo v1.6.0 h1:Ix8l273rp3QzYgXSR+c8d1fTG7UPgYkOSELPhiY/YGw=
|
|||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.1 h1:PZSj/UFNaVp3KxrzHOcS7oyuWA7LoOY/77yCTEFu21U=
|
||||
github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
|
@ -119,26 +128,18 @@ github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a h1:9a8MnZMP0X2nL
|
|||
github.com/prometheus/procfs v0.0.0-20181204211112-1dc9a6cbc91a/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/tsdb v0.2.0 h1:27z98vFd/gPew17nmKEbLn37exGCwc2F5EyrgScg6bk=
|
||||
github.com/prometheus/tsdb v0.2.0/go.mod h1:lFf/o1J2a31WmWQbxYXfY1azJK5Xp5D8hwKMnVMBTGU=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20190321074620-2f0d2b0e0001/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 h1:qLC7fQah7D6K1B0ujays3HV9gkFtllcxhzImRR7ArPQ=
|
||||
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72/go.mod h1:JwIasOWyU6f++ZhiEuf87xNszmSA2myDM2Kzu9HwQUA=
|
||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d h1:adrbvkTDn9rGnXg2IJDKozEpXXLZN89pdIA+Syt4/u0=
|
||||
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/exp v0.0.0-20190125153040-c74c464bbbf2/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20190312203227-4b39c73a6495/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/exp v0.0.0-20190424083841-8c7d1c524af6/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8=
|
||||
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/image v0.0.0-20190424155947-59b11bec70c7/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
|
||||
golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE=
|
||||
golang.org/x/mobile v0.0.0-20190415191353-3e0bab5405d6/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181005035420-146acd28ed58/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
|
@ -153,10 +154,9 @@ golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJ
|
|||
golang.org/x/sync v0.0.0-20190423024810-112230192c58 h1:8gQV6CLnAEikrhgkHFbMAEhagSSnXWGV915qUMm9mrU=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190310054646-10058d7d4faa/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190425045458-9f0b1ff7b46a h1:8cVTj31lbQ2I9z63Y1LjjHVKGisLuXDt12kKR0+r89w=
|
||||
golang.org/x/sys v0.0.0-20190425045458-9f0b1ff7b46a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190425145619-16072639606e h1:4ktJgTV34+N3qOZUc5fAaG3Pb11qzMm3PkAoTAgUZ2I=
|
||||
golang.org/x/sys v0.0.0-20190425145619-16072639606e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
|
@ -166,16 +166,8 @@ golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 h1:+DCIGbF/swA92ohVg0//6X2I
|
|||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190206041539-40960b6deb8e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262 h1:qsl9y/CJx34tuA7QCPNp86JNJe4spst6Ff8MjvPUdPg=
|
||||
golang.org/x/tools v0.0.0-20190425150028-36563e24a262/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
gonum.org/v1/gonum v0.0.0-20190331200053-3d26580ed485/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
|
||||
gonum.org/v1/gonum v0.0.0-20190424212039-2a1643c79af2/go.mod h1:2ltnJ7xHfj0zHS40VVPYEAAMTa3ZGguvHGBSJeRWqE0=
|
||||
gonum.org/v1/netlib v0.0.0-20190313105609-8cb42192e0e0/go.mod h1:wa6Ws7BG/ESfp6dHfk7C6KdzKA7wR7u/rKwOGE66zvw=
|
||||
gonum.org/v1/netlib v0.0.0-20190331212654-76723241ea4e/go.mod h1:kS+toOQn6AQKjmKJ7gzohV1XkqsFehRA2FbsbkopSuQ=
|
||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
|
||||
|
@ -189,6 +181,7 @@ gopkg.in/inf.v0 v0.9.0 h1:3zYtXIO92bvsdS3ggAdA8Gb4Azj0YU+TVY1uGYNFA8o=
|
|||
gopkg.in/inf.v0 v0.9.0/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.1.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
|
@ -202,9 +195,6 @@ k8s.io/client-go v11.0.0+incompatible h1:LBbX2+lOwY9flffWlJM7f1Ct8V2SRNiMRDFeiwn
|
|||
k8s.io/client-go v11.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
|
||||
k8s.io/code-generator v0.0.0-20190311093542-50b561225d70 h1:lgPp615xLHxN84RBd+viA/oHzJfI0miFYFH4T9wpPQ4=
|
||||
k8s.io/code-generator v0.0.0-20190311093542-50b561225d70/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
|
||||
k8s.io/code-generator v0.0.0-20190419212335-ff26e7842f9d h1:QY1FeareEgkYrWnF2D2XxZFlF0k5Ir4uE8YjD1kHi94=
|
||||
k8s.io/code-generator v0.0.0-20190419212335-ff26e7842f9d/go.mod h1:rVrFWfTVftGH7bb972nWC6N4QkJ4LU7FOXu8GH2UkJo=
|
||||
k8s.io/gengo v0.0.0-20190116091435-f8a0810f38af/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a h1:QoHVuRquf80YZ+/bovwxoMO3Q/A3nt3yTgS0/0nejuk=
|
||||
k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.3.0 h1:0VPpR+sizsiivjIfIAQH/rl8tan6jvWkS7lU+0di3lE=
|
||||
|
@ -213,10 +203,5 @@ k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30 h1:TRb4wNWoBVrH9plmkp2q86
|
|||
k8s.io/kube-openapi v0.0.0-20190228160746-b3a7cee44a30/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
|
||||
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7 h1:8r+l4bNWjRlsFYlQJnKJ2p7s1YQPj4XyXiJVqDHRx7c=
|
||||
k8s.io/utils v0.0.0-20190308190857-21c4ce38f2a7/go.mod h1:8k8uAuAQ0rXslZKaEWd0c3oVhZz7sSzSiPnVZayjIX0=
|
||||
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
|
||||
modernc.org/golex v1.0.0/go.mod h1:b/QX9oBD/LhixY6NDh+IdGv17hgB+51fET1i2kPSmvk=
|
||||
modernc.org/mathutil v1.0.0/go.mod h1:wU0vUrJsVWBZ4P6e7xtFJEhFSNsfRLJ8H458uRjg03k=
|
||||
modernc.org/strutil v1.0.0/go.mod h1:lstksw84oURvj9y3tn8lGvRxyRC1S2+g5uuIzNfIOBs=
|
||||
modernc.org/xc v1.0.0/go.mod h1:mRNCo0bvLjGhHO9WsyuKVU4q0ceiDDDoEeWDJHrNx8I=
|
||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
|
|
@ -39,7 +39,7 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
|||
}
|
||||
}
|
||||
|
||||
cs := &Clientset{tracker: o}
|
||||
cs := &Clientset{}
|
||||
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
|
||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
||||
|
@ -61,17 +61,12 @@ func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
|||
type Clientset struct {
|
||||
testing.Fake
|
||||
discovery *fakediscovery.FakeDiscovery
|
||||
tracker testing.ObjectTracker
|
||||
}
|
||||
|
||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
||||
return c.discovery
|
||||
}
|
||||
|
||||
func (c *Clientset) Tracker() testing.ObjectTracker {
|
||||
return c.tracker
|
||||
}
|
||||
|
||||
var _ clientset.Interface = &Clientset{}
|
||||
|
||||
// MonitoringV1 retrieves the MonitoringV1Client
|
||||
|
|
|
@ -19,6 +19,7 @@ package v1
|
|||
import (
|
||||
v1 "github.com/coreos/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
"github.com/coreos/prometheus-operator/pkg/client/versioned/scheme"
|
||||
serializer "k8s.io/apimachinery/pkg/runtime/serializer"
|
||||
rest "k8s.io/client-go/rest"
|
||||
)
|
||||
|
||||
|
@ -83,7 +84,7 @@ func setConfigDefaults(config *rest.Config) error {
|
|||
gv := v1.SchemeGroupVersion
|
||||
config.GroupVersion = &gv
|
||||
config.APIPath = "/apis"
|
||||
config.NegotiatedSerializer = scheme.Codecs.WithoutConversion()
|
||||
config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs}
|
||||
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = rest.DefaultKubernetesUserAgent()
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
// Copyright 2018 The prometheus-operator Authors
|
||||
//
|
||||
// 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.
|
||||
|
||||
//+build tools
|
||||
|
||||
// Package tools tracks dependencies for tools that are required to generate the protobuf code.
|
||||
|
@ -5,7 +19,12 @@
|
|||
package tools
|
||||
|
||||
import (
|
||||
_ "github.com/brancz/gojsontoyaml"
|
||||
_ "github.com/campoy/embedmd"
|
||||
_ "github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb"
|
||||
_ "k8s.io/code-generator/cmd/client-gen"
|
||||
_ "k8s.io/code-generator/cmd/deepcopy-gen"
|
||||
_ "k8s.io/code-generator/cmd/informer-gen"
|
||||
_ "k8s.io/code-generator/cmd/lister-gen"
|
||||
_ "k8s.io/kube-openapi/cmd/openapi-gen"
|
||||
)
|
||||
|
|
14
vendor/github.com/brancz/gojsontoyaml/.gitignore
generated
vendored
Normal file
14
vendor/github.com/brancz/gojsontoyaml/.gitignore
generated
vendored
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Binaries for programs and plugins
|
||||
*.exe
|
||||
*.dll
|
||||
*.so
|
||||
*.dylib
|
||||
|
||||
# Test binary, build with `go test -c`
|
||||
*.test
|
||||
|
||||
# Output of the go coverage tool, specifically when used with LiteIDE
|
||||
*.out
|
||||
|
||||
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
|
||||
.glide/
|
21
vendor/github.com/brancz/gojsontoyaml/Gopkg.lock
generated
vendored
Normal file
21
vendor/github.com/brancz/gojsontoyaml/Gopkg.lock
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/ghodss/yaml"
|
||||
packages = ["."]
|
||||
revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
name = "gopkg.in/yaml.v2"
|
||||
packages = ["."]
|
||||
revision = "7f97868eec74b32b0982dd158a51a446d1da7eb5"
|
||||
version = "v2.1.1"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "714ea508b74c96cca7230568cb19bac8cb14719312298add5ffedd390410353e"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
25
vendor/github.com/brancz/gojsontoyaml/Gopkg.toml
generated
vendored
Normal file
25
vendor/github.com/brancz/gojsontoyaml/Gopkg.toml
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/ghodss/yaml"
|
||||
version = "1.0.0"
|
21
vendor/github.com/brancz/gojsontoyaml/LICENSE
generated
vendored
Normal file
21
vendor/github.com/brancz/gojsontoyaml/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2018 Frederic Branczyk
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
26
vendor/github.com/brancz/gojsontoyaml/README.md
generated
vendored
Normal file
26
vendor/github.com/brancz/gojsontoyaml/README.md
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
# gojsontoyaml
|
||||
|
||||
This is a small tool written in go to convert json to yaml reading from STDIN and writing to STDOUT. The heavy lifting is actually done by [ghodss/yaml](https://github.com/ghodss/yaml) and [gopkg.in/yaml.v2](http://gopkg.in/yaml.v2).
|
||||
|
||||
## Install
|
||||
|
||||
To install simply
|
||||
|
||||
```
|
||||
go get github.com/brancz/gojsontoyaml
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
Simply pipe a json string into `gojsontoyaml` and it will print the converted yaml string to STDOUT.
|
||||
|
||||
```
|
||||
$ echo '{"test":"test string with\\nmultiple lines"}' | gojsontoyaml
|
||||
test: |-
|
||||
test string with
|
||||
multiple lines
|
||||
```
|
||||
|
||||
## Motivation
|
||||
|
||||
You may ask yourself why this was developed. The answer is simple, when I wrote this there was no simple to use binary for this purpose that supported yaml multiline strings. All alternatives out there that I tried kept line breaks in the string rather than making use of the yaml multiline strings.
|
8
vendor/github.com/brancz/gojsontoyaml/go.mod
generated
vendored
Normal file
8
vendor/github.com/brancz/gojsontoyaml/go.mod
generated
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
module github.com/brancz/gojsontoyaml
|
||||
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/ghodss/yaml v1.0.0
|
||||
gopkg.in/yaml.v2 v2.1.1
|
||||
)
|
5
vendor/github.com/brancz/gojsontoyaml/go.sum
generated
vendored
Normal file
5
vendor/github.com/brancz/gojsontoyaml/go.sum
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.1.1 h1:fxK3tv8mQPVEgxu/S2LJ040LyqiajHt+syP0CdDS/Sc=
|
||||
gopkg.in/yaml.v2 v2.1.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
43
vendor/github.com/brancz/gojsontoyaml/main.go
generated
vendored
Normal file
43
vendor/github.com/brancz/gojsontoyaml/main.go
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
)
|
||||
|
||||
func main() {
|
||||
yamltojson := flag.Bool("yamltojson", false, "Convert yaml to json instead of the default json to yaml.")
|
||||
flag.Parse()
|
||||
|
||||
fi, err := os.Stdin.Stat()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
if fi.Mode()&os.ModeNamedPipe == 0 {
|
||||
log.Fatal("no data to read from stdin")
|
||||
}
|
||||
|
||||
inBytes, err := ioutil.ReadAll(os.Stdin)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
var outBytes []byte
|
||||
if *yamltojson {
|
||||
outBytes, err = yaml.YAMLToJSON(inBytes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
} else {
|
||||
outBytes, err = yaml.JSONToYAML(inBytes)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
os.Stdout.Write(outBytes)
|
||||
}
|
5
vendor/github.com/fatih/color/.travis.yml
generated
vendored
Normal file
5
vendor/github.com/fatih/color/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.8.x
|
||||
- tip
|
||||
|
27
vendor/github.com/fatih/color/Gopkg.lock
generated
vendored
Normal file
27
vendor/github.com/fatih/color/Gopkg.lock
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-colorable"
|
||||
packages = ["."]
|
||||
revision = "167de6bfdfba052fa6b2d3664c8f5272e23c9072"
|
||||
version = "v0.0.9"
|
||||
|
||||
[[projects]]
|
||||
name = "github.com/mattn/go-isatty"
|
||||
packages = ["."]
|
||||
revision = "0360b2af4f38e8d38c7fce2a9f4e702702d73a39"
|
||||
version = "v0.0.3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
name = "golang.org/x/sys"
|
||||
packages = ["unix"]
|
||||
revision = "37707fdb30a5b38865cfb95e5aab41707daec7fd"
|
||||
|
||||
[solve-meta]
|
||||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
inputs-digest = "e8a50671c3cb93ea935bf210b1cd20702876b9d9226129be581ef646d1565cdc"
|
||||
solver-name = "gps-cdcl"
|
||||
solver-version = 1
|
30
vendor/github.com/fatih/color/Gopkg.toml
generated
vendored
Normal file
30
vendor/github.com/fatih/color/Gopkg.toml
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
|
||||
# Gopkg.toml example
|
||||
#
|
||||
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
|
||||
# for detailed Gopkg.toml documentation.
|
||||
#
|
||||
# required = ["github.com/user/thing/cmd/thing"]
|
||||
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project"
|
||||
# version = "1.0.0"
|
||||
#
|
||||
# [[constraint]]
|
||||
# name = "github.com/user/project2"
|
||||
# branch = "dev"
|
||||
# source = "github.com/myfork/project2"
|
||||
#
|
||||
# [[override]]
|
||||
# name = "github.com/x/y"
|
||||
# version = "2.4.0"
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/mattn/go-colorable"
|
||||
version = "0.0.9"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/mattn/go-isatty"
|
||||
version = "0.0.3"
|
20
vendor/github.com/fatih/color/LICENSE.md
generated
vendored
Normal file
20
vendor/github.com/fatih/color/LICENSE.md
generated
vendored
Normal file
|
@ -0,0 +1,20 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 Fatih Arslan
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
179
vendor/github.com/fatih/color/README.md
generated
vendored
Normal file
179
vendor/github.com/fatih/color/README.md
generated
vendored
Normal file
|
@ -0,0 +1,179 @@
|
|||
# Color [](https://godoc.org/github.com/fatih/color) [](https://travis-ci.org/fatih/color)
|
||||
|
||||
|
||||
|
||||
Color lets you use colorized outputs in terms of [ANSI Escape
|
||||
Codes](http://en.wikipedia.org/wiki/ANSI_escape_code#Colors) in Go (Golang). It
|
||||
has support for Windows too! The API can be used in several ways, pick one that
|
||||
suits you.
|
||||
|
||||
|
||||

|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```bash
|
||||
go get github.com/fatih/color
|
||||
```
|
||||
|
||||
Note that the `vendor` folder is here for stability. Remove the folder if you
|
||||
already have the dependencies in your GOPATH.
|
||||
|
||||
## Examples
|
||||
|
||||
### Standard colors
|
||||
|
||||
```go
|
||||
// Print with default helper functions
|
||||
color.Cyan("Prints text in cyan.")
|
||||
|
||||
// A newline will be appended automatically
|
||||
color.Blue("Prints %s in blue.", "text")
|
||||
|
||||
// These are using the default foreground colors
|
||||
color.Red("We have red")
|
||||
color.Magenta("And many others ..")
|
||||
|
||||
```
|
||||
|
||||
### Mix and reuse colors
|
||||
|
||||
```go
|
||||
// Create a new color object
|
||||
c := color.New(color.FgCyan).Add(color.Underline)
|
||||
c.Println("Prints cyan text with an underline.")
|
||||
|
||||
// Or just add them to New()
|
||||
d := color.New(color.FgCyan, color.Bold)
|
||||
d.Printf("This prints bold cyan %s\n", "too!.")
|
||||
|
||||
// Mix up foreground and background colors, create new mixes!
|
||||
red := color.New(color.FgRed)
|
||||
|
||||
boldRed := red.Add(color.Bold)
|
||||
boldRed.Println("This will print text in bold red.")
|
||||
|
||||
whiteBackground := red.Add(color.BgWhite)
|
||||
whiteBackground.Println("Red text with white background.")
|
||||
```
|
||||
|
||||
### Use your own output (io.Writer)
|
||||
|
||||
```go
|
||||
// Use your own io.Writer output
|
||||
color.New(color.FgBlue).Fprintln(myWriter, "blue color!")
|
||||
|
||||
blue := color.New(color.FgBlue)
|
||||
blue.Fprint(writer, "This will print text in blue.")
|
||||
```
|
||||
|
||||
### Custom print functions (PrintFunc)
|
||||
|
||||
```go
|
||||
// Create a custom print function for convenience
|
||||
red := color.New(color.FgRed).PrintfFunc()
|
||||
red("Warning")
|
||||
red("Error: %s", err)
|
||||
|
||||
// Mix up multiple attributes
|
||||
notice := color.New(color.Bold, color.FgGreen).PrintlnFunc()
|
||||
notice("Don't forget this...")
|
||||
```
|
||||
|
||||
### Custom fprint functions (FprintFunc)
|
||||
|
||||
```go
|
||||
blue := color.New(FgBlue).FprintfFunc()
|
||||
blue(myWriter, "important notice: %s", stars)
|
||||
|
||||
// Mix up with multiple attributes
|
||||
success := color.New(color.Bold, color.FgGreen).FprintlnFunc()
|
||||
success(myWriter, "Don't forget this...")
|
||||
```
|
||||
|
||||
### Insert into noncolor strings (SprintFunc)
|
||||
|
||||
```go
|
||||
// Create SprintXxx functions to mix strings with other non-colorized strings:
|
||||
yellow := color.New(color.FgYellow).SprintFunc()
|
||||
red := color.New(color.FgRed).SprintFunc()
|
||||
fmt.Printf("This is a %s and this is %s.\n", yellow("warning"), red("error"))
|
||||
|
||||
info := color.New(color.FgWhite, color.BgGreen).SprintFunc()
|
||||
fmt.Printf("This %s rocks!\n", info("package"))
|
||||
|
||||
// Use helper functions
|
||||
fmt.Println("This", color.RedString("warning"), "should be not neglected.")
|
||||
fmt.Printf("%v %v\n", color.GreenString("Info:"), "an important message.")
|
||||
|
||||
// Windows supported too! Just don't forget to change the output to color.Output
|
||||
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS"))
|
||||
```
|
||||
|
||||
### Plug into existing code
|
||||
|
||||
```go
|
||||
// Use handy standard colors
|
||||
color.Set(color.FgYellow)
|
||||
|
||||
fmt.Println("Existing text will now be in yellow")
|
||||
fmt.Printf("This one %s\n", "too")
|
||||
|
||||
color.Unset() // Don't forget to unset
|
||||
|
||||
// You can mix up parameters
|
||||
color.Set(color.FgMagenta, color.Bold)
|
||||
defer color.Unset() // Use it in your function
|
||||
|
||||
fmt.Println("All text will now be bold magenta.")
|
||||
```
|
||||
|
||||
### Disable/Enable color
|
||||
|
||||
There might be a case where you want to explicitly disable/enable color output. the
|
||||
`go-isatty` package will automatically disable color output for non-tty output streams
|
||||
(for example if the output were piped directly to `less`)
|
||||
|
||||
`Color` has support to disable/enable colors both globally and for single color
|
||||
definitions. For example suppose you have a CLI app and a `--no-color` bool flag. You
|
||||
can easily disable the color output with:
|
||||
|
||||
```go
|
||||
|
||||
var flagNoColor = flag.Bool("no-color", false, "Disable color output")
|
||||
|
||||
if *flagNoColor {
|
||||
color.NoColor = true // disables colorized output
|
||||
}
|
||||
```
|
||||
|
||||
It also has support for single color definitions (local). You can
|
||||
disable/enable color output on the fly:
|
||||
|
||||
```go
|
||||
c := color.New(color.FgCyan)
|
||||
c.Println("Prints cyan text")
|
||||
|
||||
c.DisableColor()
|
||||
c.Println("This is printed without any color")
|
||||
|
||||
c.EnableColor()
|
||||
c.Println("This prints again cyan...")
|
||||
```
|
||||
|
||||
## Todo
|
||||
|
||||
* Save/Return previous values
|
||||
* Evaluate fmt.Formatter interface
|
||||
|
||||
|
||||
## Credits
|
||||
|
||||
* [Fatih Arslan](https://github.com/fatih)
|
||||
* Windows support via @mattn: [colorable](https://github.com/mattn/go-colorable)
|
||||
|
||||
## License
|
||||
|
||||
The MIT License (MIT) - see [`LICENSE.md`](https://github.com/fatih/color/blob/master/LICENSE.md) for more details
|
||||
|
603
vendor/github.com/fatih/color/color.go
generated
vendored
Normal file
603
vendor/github.com/fatih/color/color.go
generated
vendored
Normal file
|
@ -0,0 +1,603 @@
|
|||
package color
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/mattn/go-colorable"
|
||||
"github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
var (
|
||||
// NoColor defines if the output is colorized or not. It's dynamically set to
|
||||
// false or true based on the stdout's file descriptor referring to a terminal
|
||||
// or not. This is a global option and affects all colors. For more control
|
||||
// over each color block use the methods DisableColor() individually.
|
||||
NoColor = os.Getenv("TERM") == "dumb" ||
|
||||
(!isatty.IsTerminal(os.Stdout.Fd()) && !isatty.IsCygwinTerminal(os.Stdout.Fd()))
|
||||
|
||||
// Output defines the standard output of the print functions. By default
|
||||
// os.Stdout is used.
|
||||
Output = colorable.NewColorableStdout()
|
||||
|
||||
// Error defines a color supporting writer for os.Stderr.
|
||||
Error = colorable.NewColorableStderr()
|
||||
|
||||
// colorsCache is used to reduce the count of created Color objects and
|
||||
// allows to reuse already created objects with required Attribute.
|
||||
colorsCache = make(map[Attribute]*Color)
|
||||
colorsCacheMu sync.Mutex // protects colorsCache
|
||||
)
|
||||
|
||||
// Color defines a custom color object which is defined by SGR parameters.
|
||||
type Color struct {
|
||||
params []Attribute
|
||||
noColor *bool
|
||||
}
|
||||
|
||||
// Attribute defines a single SGR Code
|
||||
type Attribute int
|
||||
|
||||
const escape = "\x1b"
|
||||
|
||||
// Base attributes
|
||||
const (
|
||||
Reset Attribute = iota
|
||||
Bold
|
||||
Faint
|
||||
Italic
|
||||
Underline
|
||||
BlinkSlow
|
||||
BlinkRapid
|
||||
ReverseVideo
|
||||
Concealed
|
||||
CrossedOut
|
||||
)
|
||||
|
||||
// Foreground text colors
|
||||
const (
|
||||
FgBlack Attribute = iota + 30
|
||||
FgRed
|
||||
FgGreen
|
||||
FgYellow
|
||||
FgBlue
|
||||
FgMagenta
|
||||
FgCyan
|
||||
FgWhite
|
||||
)
|
||||
|
||||
// Foreground Hi-Intensity text colors
|
||||
const (
|
||||
FgHiBlack Attribute = iota + 90
|
||||
FgHiRed
|
||||
FgHiGreen
|
||||
FgHiYellow
|
||||
FgHiBlue
|
||||
FgHiMagenta
|
||||
FgHiCyan
|
||||
FgHiWhite
|
||||
)
|
||||
|
||||
// Background text colors
|
||||
const (
|
||||
BgBlack Attribute = iota + 40
|
||||
BgRed
|
||||
BgGreen
|
||||
BgYellow
|
||||
BgBlue
|
||||
BgMagenta
|
||||
BgCyan
|
||||
BgWhite
|
||||
)
|
||||
|
||||
// Background Hi-Intensity text colors
|
||||
const (
|
||||
BgHiBlack Attribute = iota + 100
|
||||
BgHiRed
|
||||
BgHiGreen
|
||||
BgHiYellow
|
||||
BgHiBlue
|
||||
BgHiMagenta
|
||||
BgHiCyan
|
||||
BgHiWhite
|
||||
)
|
||||
|
||||
// New returns a newly created color object.
|
||||
func New(value ...Attribute) *Color {
|
||||
c := &Color{params: make([]Attribute, 0)}
|
||||
c.Add(value...)
|
||||
return c
|
||||
}
|
||||
|
||||
// Set sets the given parameters immediately. It will change the color of
|
||||
// output with the given SGR parameters until color.Unset() is called.
|
||||
func Set(p ...Attribute) *Color {
|
||||
c := New(p...)
|
||||
c.Set()
|
||||
return c
|
||||
}
|
||||
|
||||
// Unset resets all escape attributes and clears the output. Usually should
|
||||
// be called after Set().
|
||||
func Unset() {
|
||||
if NoColor {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(Output, "%s[%dm", escape, Reset)
|
||||
}
|
||||
|
||||
// Set sets the SGR sequence.
|
||||
func (c *Color) Set() *Color {
|
||||
if c.isNoColorSet() {
|
||||
return c
|
||||
}
|
||||
|
||||
fmt.Fprintf(Output, c.format())
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Color) unset() {
|
||||
if c.isNoColorSet() {
|
||||
return
|
||||
}
|
||||
|
||||
Unset()
|
||||
}
|
||||
|
||||
func (c *Color) setWriter(w io.Writer) *Color {
|
||||
if c.isNoColorSet() {
|
||||
return c
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, c.format())
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Color) unsetWriter(w io.Writer) {
|
||||
if c.isNoColorSet() {
|
||||
return
|
||||
}
|
||||
|
||||
if NoColor {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%s[%dm", escape, Reset)
|
||||
}
|
||||
|
||||
// Add is used to chain SGR parameters. Use as many as parameters to combine
|
||||
// and create custom color objects. Example: Add(color.FgRed, color.Underline).
|
||||
func (c *Color) Add(value ...Attribute) *Color {
|
||||
c.params = append(c.params, value...)
|
||||
return c
|
||||
}
|
||||
|
||||
func (c *Color) prepend(value Attribute) {
|
||||
c.params = append(c.params, 0)
|
||||
copy(c.params[1:], c.params[0:])
|
||||
c.params[0] = value
|
||||
}
|
||||
|
||||
// Fprint formats using the default formats for its operands and writes to w.
|
||||
// Spaces are added between operands when neither is a string.
|
||||
// It returns the number of bytes written and any write error encountered.
|
||||
// On Windows, users should wrap w with colorable.NewColorable() if w is of
|
||||
// type *os.File.
|
||||
func (c *Color) Fprint(w io.Writer, a ...interface{}) (n int, err error) {
|
||||
c.setWriter(w)
|
||||
defer c.unsetWriter(w)
|
||||
|
||||
return fmt.Fprint(w, a...)
|
||||
}
|
||||
|
||||
// Print formats using the default formats for its operands and writes to
|
||||
// standard output. Spaces are added between operands when neither is a
|
||||
// string. It returns the number of bytes written and any write error
|
||||
// encountered. This is the standard fmt.Print() method wrapped with the given
|
||||
// color.
|
||||
func (c *Color) Print(a ...interface{}) (n int, err error) {
|
||||
c.Set()
|
||||
defer c.unset()
|
||||
|
||||
return fmt.Fprint(Output, a...)
|
||||
}
|
||||
|
||||
// Fprintf formats according to a format specifier and writes to w.
|
||||
// It returns the number of bytes written and any write error encountered.
|
||||
// On Windows, users should wrap w with colorable.NewColorable() if w is of
|
||||
// type *os.File.
|
||||
func (c *Color) Fprintf(w io.Writer, format string, a ...interface{}) (n int, err error) {
|
||||
c.setWriter(w)
|
||||
defer c.unsetWriter(w)
|
||||
|
||||
return fmt.Fprintf(w, format, a...)
|
||||
}
|
||||
|
||||
// Printf formats according to a format specifier and writes to standard output.
|
||||
// It returns the number of bytes written and any write error encountered.
|
||||
// This is the standard fmt.Printf() method wrapped with the given color.
|
||||
func (c *Color) Printf(format string, a ...interface{}) (n int, err error) {
|
||||
c.Set()
|
||||
defer c.unset()
|
||||
|
||||
return fmt.Fprintf(Output, format, a...)
|
||||
}
|
||||
|
||||
// Fprintln formats using the default formats for its operands and writes to w.
|
||||
// Spaces are always added between operands and a newline is appended.
|
||||
// On Windows, users should wrap w with colorable.NewColorable() if w is of
|
||||
// type *os.File.
|
||||
func (c *Color) Fprintln(w io.Writer, a ...interface{}) (n int, err error) {
|
||||
c.setWriter(w)
|
||||
defer c.unsetWriter(w)
|
||||
|
||||
return fmt.Fprintln(w, a...)
|
||||
}
|
||||
|
||||
// Println formats using the default formats for its operands and writes to
|
||||
// standard output. Spaces are always added between operands and a newline is
|
||||
// appended. It returns the number of bytes written and any write error
|
||||
// encountered. This is the standard fmt.Print() method wrapped with the given
|
||||
// color.
|
||||
func (c *Color) Println(a ...interface{}) (n int, err error) {
|
||||
c.Set()
|
||||
defer c.unset()
|
||||
|
||||
return fmt.Fprintln(Output, a...)
|
||||
}
|
||||
|
||||
// Sprint is just like Print, but returns a string instead of printing it.
|
||||
func (c *Color) Sprint(a ...interface{}) string {
|
||||
return c.wrap(fmt.Sprint(a...))
|
||||
}
|
||||
|
||||
// Sprintln is just like Println, but returns a string instead of printing it.
|
||||
func (c *Color) Sprintln(a ...interface{}) string {
|
||||
return c.wrap(fmt.Sprintln(a...))
|
||||
}
|
||||
|
||||
// Sprintf is just like Printf, but returns a string instead of printing it.
|
||||
func (c *Color) Sprintf(format string, a ...interface{}) string {
|
||||
return c.wrap(fmt.Sprintf(format, a...))
|
||||
}
|
||||
|
||||
// FprintFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Fprint().
|
||||
func (c *Color) FprintFunc() func(w io.Writer, a ...interface{}) {
|
||||
return func(w io.Writer, a ...interface{}) {
|
||||
c.Fprint(w, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Print().
|
||||
func (c *Color) PrintFunc() func(a ...interface{}) {
|
||||
return func(a ...interface{}) {
|
||||
c.Print(a...)
|
||||
}
|
||||
}
|
||||
|
||||
// FprintfFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Fprintf().
|
||||
func (c *Color) FprintfFunc() func(w io.Writer, format string, a ...interface{}) {
|
||||
return func(w io.Writer, format string, a ...interface{}) {
|
||||
c.Fprintf(w, format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintfFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Printf().
|
||||
func (c *Color) PrintfFunc() func(format string, a ...interface{}) {
|
||||
return func(format string, a ...interface{}) {
|
||||
c.Printf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// FprintlnFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Fprintln().
|
||||
func (c *Color) FprintlnFunc() func(w io.Writer, a ...interface{}) {
|
||||
return func(w io.Writer, a ...interface{}) {
|
||||
c.Fprintln(w, a...)
|
||||
}
|
||||
}
|
||||
|
||||
// PrintlnFunc returns a new function that prints the passed arguments as
|
||||
// colorized with color.Println().
|
||||
func (c *Color) PrintlnFunc() func(a ...interface{}) {
|
||||
return func(a ...interface{}) {
|
||||
c.Println(a...)
|
||||
}
|
||||
}
|
||||
|
||||
// SprintFunc returns a new function that returns colorized strings for the
|
||||
// given arguments with fmt.Sprint(). Useful to put into or mix into other
|
||||
// string. Windows users should use this in conjunction with color.Output, example:
|
||||
//
|
||||
// put := New(FgYellow).SprintFunc()
|
||||
// fmt.Fprintf(color.Output, "This is a %s", put("warning"))
|
||||
func (c *Color) SprintFunc() func(a ...interface{}) string {
|
||||
return func(a ...interface{}) string {
|
||||
return c.wrap(fmt.Sprint(a...))
|
||||
}
|
||||
}
|
||||
|
||||
// SprintfFunc returns a new function that returns colorized strings for the
|
||||
// given arguments with fmt.Sprintf(). Useful to put into or mix into other
|
||||
// string. Windows users should use this in conjunction with color.Output.
|
||||
func (c *Color) SprintfFunc() func(format string, a ...interface{}) string {
|
||||
return func(format string, a ...interface{}) string {
|
||||
return c.wrap(fmt.Sprintf(format, a...))
|
||||
}
|
||||
}
|
||||
|
||||
// SprintlnFunc returns a new function that returns colorized strings for the
|
||||
// given arguments with fmt.Sprintln(). Useful to put into or mix into other
|
||||
// string. Windows users should use this in conjunction with color.Output.
|
||||
func (c *Color) SprintlnFunc() func(a ...interface{}) string {
|
||||
return func(a ...interface{}) string {
|
||||
return c.wrap(fmt.Sprintln(a...))
|
||||
}
|
||||
}
|
||||
|
||||
// sequence returns a formatted SGR sequence to be plugged into a "\x1b[...m"
|
||||
// an example output might be: "1;36" -> bold cyan
|
||||
func (c *Color) sequence() string {
|
||||
format := make([]string, len(c.params))
|
||||
for i, v := range c.params {
|
||||
format[i] = strconv.Itoa(int(v))
|
||||
}
|
||||
|
||||
return strings.Join(format, ";")
|
||||
}
|
||||
|
||||
// wrap wraps the s string with the colors attributes. The string is ready to
|
||||
// be printed.
|
||||
func (c *Color) wrap(s string) string {
|
||||
if c.isNoColorSet() {
|
||||
return s
|
||||
}
|
||||
|
||||
return c.format() + s + c.unformat()
|
||||
}
|
||||
|
||||
func (c *Color) format() string {
|
||||
return fmt.Sprintf("%s[%sm", escape, c.sequence())
|
||||
}
|
||||
|
||||
func (c *Color) unformat() string {
|
||||
return fmt.Sprintf("%s[%dm", escape, Reset)
|
||||
}
|
||||
|
||||
// DisableColor disables the color output. Useful to not change any existing
|
||||
// code and still being able to output. Can be used for flags like
|
||||
// "--no-color". To enable back use EnableColor() method.
|
||||
func (c *Color) DisableColor() {
|
||||
c.noColor = boolPtr(true)
|
||||
}
|
||||
|
||||
// EnableColor enables the color output. Use it in conjunction with
|
||||
// DisableColor(). Otherwise this method has no side effects.
|
||||
func (c *Color) EnableColor() {
|
||||
c.noColor = boolPtr(false)
|
||||
}
|
||||
|
||||
func (c *Color) isNoColorSet() bool {
|
||||
// check first if we have user setted action
|
||||
if c.noColor != nil {
|
||||
return *c.noColor
|
||||
}
|
||||
|
||||
// if not return the global option, which is disabled by default
|
||||
return NoColor
|
||||
}
|
||||
|
||||
// Equals returns a boolean value indicating whether two colors are equal.
|
||||
func (c *Color) Equals(c2 *Color) bool {
|
||||
if len(c.params) != len(c2.params) {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, attr := range c.params {
|
||||
if !c2.attrExists(attr) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
func (c *Color) attrExists(a Attribute) bool {
|
||||
for _, attr := range c.params {
|
||||
if attr == a {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
func boolPtr(v bool) *bool {
|
||||
return &v
|
||||
}
|
||||
|
||||
func getCachedColor(p Attribute) *Color {
|
||||
colorsCacheMu.Lock()
|
||||
defer colorsCacheMu.Unlock()
|
||||
|
||||
c, ok := colorsCache[p]
|
||||
if !ok {
|
||||
c = New(p)
|
||||
colorsCache[p] = c
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
func colorPrint(format string, p Attribute, a ...interface{}) {
|
||||
c := getCachedColor(p)
|
||||
|
||||
if !strings.HasSuffix(format, "\n") {
|
||||
format += "\n"
|
||||
}
|
||||
|
||||
if len(a) == 0 {
|
||||
c.Print(format)
|
||||
} else {
|
||||
c.Printf(format, a...)
|
||||
}
|
||||
}
|
||||
|
||||
func colorString(format string, p Attribute, a ...interface{}) string {
|
||||
c := getCachedColor(p)
|
||||
|
||||
if len(a) == 0 {
|
||||
return c.SprintFunc()(format)
|
||||
}
|
||||
|
||||
return c.SprintfFunc()(format, a...)
|
||||
}
|
||||
|
||||
// Black is a convenient helper function to print with black foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Black(format string, a ...interface{}) { colorPrint(format, FgBlack, a...) }
|
||||
|
||||
// Red is a convenient helper function to print with red foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Red(format string, a ...interface{}) { colorPrint(format, FgRed, a...) }
|
||||
|
||||
// Green is a convenient helper function to print with green foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Green(format string, a ...interface{}) { colorPrint(format, FgGreen, a...) }
|
||||
|
||||
// Yellow is a convenient helper function to print with yellow foreground.
|
||||
// A newline is appended to format by default.
|
||||
func Yellow(format string, a ...interface{}) { colorPrint(format, FgYellow, a...) }
|
||||
|
||||
// Blue is a convenient helper function to print with blue foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Blue(format string, a ...interface{}) { colorPrint(format, FgBlue, a...) }
|
||||
|
||||
// Magenta is a convenient helper function to print with magenta foreground.
|
||||
// A newline is appended to format by default.
|
||||
func Magenta(format string, a ...interface{}) { colorPrint(format, FgMagenta, a...) }
|
||||
|
||||
// Cyan is a convenient helper function to print with cyan foreground. A
|
||||
// newline is appended to format by default.
|
||||
func Cyan(format string, a ...interface{}) { colorPrint(format, FgCyan, a...) }
|
||||
|
||||
// White is a convenient helper function to print with white foreground. A
|
||||
// newline is appended to format by default.
|
||||
func White(format string, a ...interface{}) { colorPrint(format, FgWhite, a...) }
|
||||
|
||||
// BlackString is a convenient helper function to return a string with black
|
||||
// foreground.
|
||||
func BlackString(format string, a ...interface{}) string { return colorString(format, FgBlack, a...) }
|
||||
|
||||
// RedString is a convenient helper function to return a string with red
|
||||
// foreground.
|
||||
func RedString(format string, a ...interface{}) string { return colorString(format, FgRed, a...) }
|
||||
|
||||
// GreenString is a convenient helper function to return a string with green
|
||||
// foreground.
|
||||
func GreenString(format string, a ...interface{}) string { return colorString(format, FgGreen, a...) }
|
||||
|
||||
// YellowString is a convenient helper function to return a string with yellow
|
||||
// foreground.
|
||||
func YellowString(format string, a ...interface{}) string { return colorString(format, FgYellow, a...) }
|
||||
|
||||
// BlueString is a convenient helper function to return a string with blue
|
||||
// foreground.
|
||||
func BlueString(format string, a ...interface{}) string { return colorString(format, FgBlue, a...) }
|
||||
|
||||
// MagentaString is a convenient helper function to return a string with magenta
|
||||
// foreground.
|
||||
func MagentaString(format string, a ...interface{}) string {
|
||||
return colorString(format, FgMagenta, a...)
|
||||
}
|
||||
|
||||
// CyanString is a convenient helper function to return a string with cyan
|
||||
// foreground.
|
||||
func CyanString(format string, a ...interface{}) string { return colorString(format, FgCyan, a...) }
|
||||
|
||||
// WhiteString is a convenient helper function to return a string with white
|
||||
// foreground.
|
||||
func WhiteString(format string, a ...interface{}) string { return colorString(format, FgWhite, a...) }
|
||||
|
||||
// HiBlack is a convenient helper function to print with hi-intensity black foreground. A
|
||||
// newline is appended to format by default.
|
||||
func HiBlack(format string, a ...interface{}) { colorPrint(format, FgHiBlack, a...) }
|
||||
|
||||
// HiRed is a convenient helper function to print with hi-intensity red foreground. A
|
||||
// newline is appended to format by default.
|
||||
func HiRed(format string, a ...interface{}) { colorPrint(format, FgHiRed, a...) }
|
||||
|
||||
// HiGreen is a convenient helper function to print with hi-intensity green foreground. A
|
||||
// newline is appended to format by default.
|
||||
func HiGreen(format string, a ...interface{}) { colorPrint(format, FgHiGreen, a...) }
|
||||
|
||||
// HiYellow is a convenient helper function to print with hi-intensity yellow foreground.
|
||||
// A newline is appended to format by default.
|
||||
func HiYellow(format string, a ...interface{}) { colorPrint(format, FgHiYellow, a...) }
|
||||
|
||||
// HiBlue is a convenient helper function to print with hi-intensity blue foreground. A
|
||||
// newline is appended to format by default.
|
||||
func HiBlue(format string, a ...interface{}) { colorPrint(format, FgHiBlue, a...) }
|
||||
|
||||
// HiMagenta is a convenient helper function to print with hi-intensity magenta foreground.
|
||||
// A newline is appended to format by default.
|
||||
func HiMagenta(format string, a ...interface{}) { colorPrint(format, FgHiMagenta, a...) }
|
||||
|
||||
// HiCyan is a convenient helper function to print with hi-intensity cyan foreground. A
|
||||
// newline is appended to format by default.
|
||||
func HiCyan(format string, a ...interface{}) { colorPrint(format, FgHiCyan, a...) }
|
||||
|
||||
// HiWhite is a convenient helper function to print with hi-intensity white foreground. A
|
||||
// newline is appended to format by default.
|
||||
func HiWhite(format string, a ...interface{}) { colorPrint(format, FgHiWhite, a...) }
|
||||
|
||||
// HiBlackString is a convenient helper function to return a string with hi-intensity black
|
||||
// foreground.
|
||||
func HiBlackString(format string, a ...interface{}) string {
|
||||
return colorString(format, FgHiBlack, a...)
|
||||
}
|
||||
|
||||
// HiRedString is a convenient helper function to return a string with hi-intensity red
|
||||
// foreground.
|
||||
func HiRedString(format string, a ...interface{}) string { return colorString(format, FgHiRed, a...) }
|
||||
|
||||
// HiGreenString is a convenient helper function to return a string with hi-intensity green
|
||||
// foreground.
|
||||
func HiGreenString(format string, a ...interface{}) string {
|
||||
return colorString(format, FgHiGreen, a...)
|
||||
}
|
||||
|
||||
// HiYellowString is a convenient helper function to return a string with hi-intensity yellow
|
||||
// foreground.
|
||||
func HiYellowString(format string, a ...interface{}) string {
|
||||
return colorString(format, FgHiYellow, a...)
|
||||
}
|
||||
|
||||
// HiBlueString is a convenient helper function to return a string with hi-intensity blue
|
||||
// foreground.
|
||||
func HiBlueString(format string, a ...interface{}) string { return colorString(format, FgHiBlue, a...) }
|
||||
|
||||
// HiMagentaString is a convenient helper function to return a string with hi-intensity magenta
|
||||
// foreground.
|
||||
func HiMagentaString(format string, a ...interface{}) string {
|
||||
return colorString(format, FgHiMagenta, a...)
|
||||
}
|
||||
|
||||
// HiCyanString is a convenient helper function to return a string with hi-intensity cyan
|
||||
// foreground.
|
||||
func HiCyanString(format string, a ...interface{}) string { return colorString(format, FgHiCyan, a...) }
|
||||
|
||||
// HiWhiteString is a convenient helper function to return a string with hi-intensity white
|
||||
// foreground.
|
||||
func HiWhiteString(format string, a ...interface{}) string {
|
||||
return colorString(format, FgHiWhite, a...)
|
||||
}
|
133
vendor/github.com/fatih/color/doc.go
generated
vendored
Normal file
133
vendor/github.com/fatih/color/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*
|
||||
Package color is an ANSI color package to output colorized or SGR defined
|
||||
output to the standard output. The API can be used in several way, pick one
|
||||
that suits you.
|
||||
|
||||
Use simple and default helper functions with predefined foreground colors:
|
||||
|
||||
color.Cyan("Prints text in cyan.")
|
||||
|
||||
// a newline will be appended automatically
|
||||
color.Blue("Prints %s in blue.", "text")
|
||||
|
||||
// More default foreground colors..
|
||||
color.Red("We have red")
|
||||
color.Yellow("Yellow color too!")
|
||||
color.Magenta("And many others ..")
|
||||
|
||||
// Hi-intensity colors
|
||||
color.HiGreen("Bright green color.")
|
||||
color.HiBlack("Bright black means gray..")
|
||||
color.HiWhite("Shiny white color!")
|
||||
|
||||
However there are times where custom color mixes are required. Below are some
|
||||
examples to create custom color objects and use the print functions of each
|
||||
separate color object.
|
||||
|
||||
// Create a new color object
|
||||
c := color.New(color.FgCyan).Add(color.Underline)
|
||||
c.Println("Prints cyan text with an underline.")
|
||||
|
||||
// Or just add them to New()
|
||||
d := color.New(color.FgCyan, color.Bold)
|
||||
d.Printf("This prints bold cyan %s\n", "too!.")
|
||||
|
||||
|
||||
// Mix up foreground and background colors, create new mixes!
|
||||
red := color.New(color.FgRed)
|
||||
|
||||
boldRed := red.Add(color.Bold)
|
||||
boldRed.Println("This will print text in bold red.")
|
||||
|
||||
whiteBackground := red.Add(color.BgWhite)
|
||||
whiteBackground.Println("Red text with White background.")
|
||||
|
||||
// Use your own io.Writer output
|
||||
color.New(color.FgBlue).Fprintln(myWriter, "blue color!")
|
||||
|
||||
blue := color.New(color.FgBlue)
|
||||
blue.Fprint(myWriter, "This will print text in blue.")
|
||||
|
||||
You can create PrintXxx functions to simplify even more:
|
||||
|
||||
// Create a custom print function for convenient
|
||||
red := color.New(color.FgRed).PrintfFunc()
|
||||
red("warning")
|
||||
red("error: %s", err)
|
||||
|
||||
// Mix up multiple attributes
|
||||
notice := color.New(color.Bold, color.FgGreen).PrintlnFunc()
|
||||
notice("don't forget this...")
|
||||
|
||||
You can also FprintXxx functions to pass your own io.Writer:
|
||||
|
||||
blue := color.New(FgBlue).FprintfFunc()
|
||||
blue(myWriter, "important notice: %s", stars)
|
||||
|
||||
// Mix up with multiple attributes
|
||||
success := color.New(color.Bold, color.FgGreen).FprintlnFunc()
|
||||
success(myWriter, don't forget this...")
|
||||
|
||||
|
||||
Or create SprintXxx functions to mix strings with other non-colorized strings:
|
||||
|
||||
yellow := New(FgYellow).SprintFunc()
|
||||
red := New(FgRed).SprintFunc()
|
||||
|
||||
fmt.Printf("this is a %s and this is %s.\n", yellow("warning"), red("error"))
|
||||
|
||||
info := New(FgWhite, BgGreen).SprintFunc()
|
||||
fmt.Printf("this %s rocks!\n", info("package"))
|
||||
|
||||
Windows support is enabled by default. All Print functions work as intended.
|
||||
However only for color.SprintXXX functions, user should use fmt.FprintXXX and
|
||||
set the output to color.Output:
|
||||
|
||||
fmt.Fprintf(color.Output, "Windows support: %s", color.GreenString("PASS"))
|
||||
|
||||
info := New(FgWhite, BgGreen).SprintFunc()
|
||||
fmt.Fprintf(color.Output, "this %s rocks!\n", info("package"))
|
||||
|
||||
Using with existing code is possible. Just use the Set() method to set the
|
||||
standard output to the given parameters. That way a rewrite of an existing
|
||||
code is not required.
|
||||
|
||||
// Use handy standard colors.
|
||||
color.Set(color.FgYellow)
|
||||
|
||||
fmt.Println("Existing text will be now in Yellow")
|
||||
fmt.Printf("This one %s\n", "too")
|
||||
|
||||
color.Unset() // don't forget to unset
|
||||
|
||||
// You can mix up parameters
|
||||
color.Set(color.FgMagenta, color.Bold)
|
||||
defer color.Unset() // use it in your function
|
||||
|
||||
fmt.Println("All text will be now bold magenta.")
|
||||
|
||||
There might be a case where you want to disable color output (for example to
|
||||
pipe the standard output of your app to somewhere else). `Color` has support to
|
||||
disable colors both globally and for single color definition. For example
|
||||
suppose you have a CLI app and a `--no-color` bool flag. You can easily disable
|
||||
the color output with:
|
||||
|
||||
var flagNoColor = flag.Bool("no-color", false, "Disable color output")
|
||||
|
||||
if *flagNoColor {
|
||||
color.NoColor = true // disables colorized output
|
||||
}
|
||||
|
||||
It also has support for single color definitions (local). You can
|
||||
disable/enable color output on the fly:
|
||||
|
||||
c := color.New(color.FgCyan)
|
||||
c.Println("Prints cyan text")
|
||||
|
||||
c.DisableColor()
|
||||
c.Println("This is printed without any color")
|
||||
|
||||
c.EnableColor()
|
||||
c.Println("This prints again cyan...")
|
||||
*/
|
||||
package color
|
201
vendor/github.com/jsonnet-bundler/jsonnet-bundler/LICENSE
generated
vendored
Normal file
201
vendor/github.com/jsonnet-bundler/jsonnet-bundler/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,201 @@
|
|||
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:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) 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
|
||||
|
||||
(d) 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 2018 jsonnet-bundler authors
|
||||
|
||||
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.
|
370
vendor/github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb/main.go
generated
vendored
Normal file
370
vendor/github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb/main.go
generated
vendored
Normal file
|
@ -0,0 +1,370 @@
|
|||
/*
|
||||
Copyright 2018 jsonnet-bundler authors All rights reserved.
|
||||
|
||||
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 main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/url"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/pkg"
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
|
||||
"github.com/pkg/errors"
|
||||
"gopkg.in/alecthomas/kingpin.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
installActionName = "install"
|
||||
updateActionName = "update"
|
||||
initActionName = "init"
|
||||
basePath = ".jsonnetpkg"
|
||||
srcDirName = "src"
|
||||
)
|
||||
|
||||
var (
|
||||
availableSubcommands = []string{
|
||||
initActionName,
|
||||
installActionName,
|
||||
}
|
||||
gitSSHRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git")
|
||||
gitSSHWithVersionRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git@(.*)")
|
||||
gitSSHWithPathRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git/(.*)")
|
||||
gitSSHWithPathAndVersionRegex = regexp.MustCompile("git\\+ssh://git@([^:]+):([^/]+)/([^/]+).git/(.*)@(.*)")
|
||||
|
||||
githubSlugRegex = regexp.MustCompile("github.com/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)")
|
||||
githubSlugWithVersionRegex = regexp.MustCompile("github.com/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)@(.*)")
|
||||
githubSlugWithPathRegex = regexp.MustCompile("github.com/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/(.*)")
|
||||
githubSlugWithPathAndVersionRegex = regexp.MustCompile("github.com/([-_a-zA-Z0-9]+)/([-_a-zA-Z0-9]+)/(.*)@(.*)")
|
||||
)
|
||||
|
||||
func main() {
|
||||
os.Exit(Main())
|
||||
}
|
||||
|
||||
func Main() int {
|
||||
cfg := struct {
|
||||
JsonnetHome string
|
||||
}{}
|
||||
|
||||
a := kingpin.New(filepath.Base(os.Args[0]), "A jsonnet package manager")
|
||||
a.HelpFlag.Short('h')
|
||||
|
||||
a.Flag("jsonnetpkg-home", "The directory used to cache packages in.").
|
||||
Default("vendor").StringVar(&cfg.JsonnetHome)
|
||||
|
||||
initCmd := a.Command(initActionName, "Initialize a new empty jsonnetfile")
|
||||
|
||||
installCmd := a.Command(installActionName, "Install all dependencies or install specific ones")
|
||||
installCmdURLs := installCmd.Arg("packages", "URLs to package to install").URLList()
|
||||
|
||||
updateCmd := a.Command(updateActionName, "Update all dependencies.")
|
||||
|
||||
command, err := a.Parse(os.Args[1:])
|
||||
if err != nil {
|
||||
fmt.Fprintln(os.Stderr, errors.Wrapf(err, "Error parsing commandline arguments"))
|
||||
a.Usage(os.Args[1:])
|
||||
return 2
|
||||
}
|
||||
|
||||
switch command {
|
||||
case initCmd.FullCommand():
|
||||
return initCommand()
|
||||
case installCmd.FullCommand():
|
||||
return installCommand(cfg.JsonnetHome, *installCmdURLs...)
|
||||
case updateCmd.FullCommand():
|
||||
return updateCommand(cfg.JsonnetHome)
|
||||
default:
|
||||
installCommand(cfg.JsonnetHome)
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func initCommand() int {
|
||||
exists, err := pkg.FileExists(pkg.JsonnetFile)
|
||||
if err != nil {
|
||||
kingpin.Errorf("Failed to check for jsonnetfile.json: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if exists {
|
||||
kingpin.Errorf("jsonnetfile.json already exists")
|
||||
return 1
|
||||
}
|
||||
|
||||
if err := ioutil.WriteFile(pkg.JsonnetFile, []byte("{}\n"), 0644); err != nil {
|
||||
kingpin.Errorf("Failed to write new jsonnetfile.json: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func parseDepedency(urlString string) *spec.Dependency {
|
||||
if spec := parseGitSSHDependency(urlString); spec != nil {
|
||||
return spec
|
||||
}
|
||||
|
||||
if spec := parseGithubDependency(urlString); spec != nil {
|
||||
return spec
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseGitSSHDependency(urlString string) *spec.Dependency {
|
||||
if !gitSSHRegex.MatchString(urlString) {
|
||||
return nil
|
||||
}
|
||||
|
||||
subdir := ""
|
||||
host := ""
|
||||
org := ""
|
||||
repo := ""
|
||||
version := "master"
|
||||
|
||||
if gitSSHWithPathAndVersionRegex.MatchString(urlString) {
|
||||
matches := gitSSHWithPathAndVersionRegex.FindStringSubmatch(urlString)
|
||||
host = matches[1]
|
||||
org = matches[2]
|
||||
repo = matches[3]
|
||||
subdir = matches[4]
|
||||
version = matches[5]
|
||||
} else if gitSSHWithPathRegex.MatchString(urlString) {
|
||||
matches := gitSSHWithPathRegex.FindStringSubmatch(urlString)
|
||||
host = matches[1]
|
||||
org = matches[2]
|
||||
repo = matches[3]
|
||||
subdir = matches[4]
|
||||
} else if gitSSHWithVersionRegex.MatchString(urlString) {
|
||||
matches := gitSSHWithVersionRegex.FindStringSubmatch(urlString)
|
||||
host = matches[1]
|
||||
org = matches[2]
|
||||
repo = matches[3]
|
||||
version = matches[4]
|
||||
} else {
|
||||
matches := gitSSHRegex.FindStringSubmatch(urlString)
|
||||
host = matches[1]
|
||||
org = matches[2]
|
||||
repo = matches[3]
|
||||
}
|
||||
|
||||
return &spec.Dependency{
|
||||
Name: repo,
|
||||
Source: spec.Source{
|
||||
GitSource: &spec.GitSource{
|
||||
Remote: fmt.Sprintf("git@%s:%s/%s", host, org, repo),
|
||||
Subdir: subdir,
|
||||
},
|
||||
},
|
||||
Version: version,
|
||||
}
|
||||
}
|
||||
|
||||
func parseGithubDependency(urlString string) *spec.Dependency {
|
||||
if !githubSlugRegex.MatchString(urlString) {
|
||||
return nil
|
||||
}
|
||||
|
||||
name := ""
|
||||
user := ""
|
||||
repo := ""
|
||||
subdir := ""
|
||||
version := "master"
|
||||
|
||||
if githubSlugWithPathRegex.MatchString(urlString) {
|
||||
if githubSlugWithPathAndVersionRegex.MatchString(urlString) {
|
||||
matches := githubSlugWithPathAndVersionRegex.FindStringSubmatch(urlString)
|
||||
user = matches[1]
|
||||
repo = matches[2]
|
||||
subdir = matches[3]
|
||||
version = matches[4]
|
||||
name = path.Base(subdir)
|
||||
} else {
|
||||
matches := githubSlugWithPathRegex.FindStringSubmatch(urlString)
|
||||
user = matches[1]
|
||||
repo = matches[2]
|
||||
subdir = matches[3]
|
||||
name = path.Base(subdir)
|
||||
}
|
||||
} else {
|
||||
if githubSlugWithVersionRegex.MatchString(urlString) {
|
||||
matches := githubSlugWithVersionRegex.FindStringSubmatch(urlString)
|
||||
user = matches[1]
|
||||
repo = matches[2]
|
||||
name = repo
|
||||
version = matches[3]
|
||||
} else {
|
||||
matches := githubSlugRegex.FindStringSubmatch(urlString)
|
||||
user = matches[1]
|
||||
repo = matches[2]
|
||||
name = repo
|
||||
}
|
||||
}
|
||||
|
||||
return &spec.Dependency{
|
||||
Name: name,
|
||||
Source: spec.Source{
|
||||
GitSource: &spec.GitSource{
|
||||
Remote: fmt.Sprintf("https://github.com/%s/%s", user, repo),
|
||||
Subdir: subdir,
|
||||
},
|
||||
},
|
||||
Version: version,
|
||||
}
|
||||
}
|
||||
|
||||
func installCommand(jsonnetHome string, urls ...*url.URL) int {
|
||||
workdir := "."
|
||||
|
||||
jsonnetfile, isLock, err := pkg.ChooseJsonnetFile(workdir)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to choose jsonnetfile: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
m, err := pkg.LoadJsonnetfile(jsonnetfile)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to load jsonnetfile: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
if len(urls) > 0 {
|
||||
for _, url := range urls {
|
||||
// install package specified in command
|
||||
// $ jsonnetpkg install ksonnet git@github.com:ksonnet/ksonnet-lib
|
||||
// $ jsonnetpkg install grafonnet git@github.com:grafana/grafonnet-lib grafonnet
|
||||
// $ jsonnetpkg install github.com/grafana/grafonnet-lib/grafonnet
|
||||
//
|
||||
// github.com/(slug)/(dir)
|
||||
|
||||
urlString := url.String()
|
||||
newDep := parseDepedency(urlString)
|
||||
if newDep == nil {
|
||||
kingpin.Errorf("ignoring unrecognized url: %s", url)
|
||||
continue
|
||||
}
|
||||
|
||||
oldDeps := m.Dependencies
|
||||
newDeps := []spec.Dependency{}
|
||||
oldDepReplaced := false
|
||||
for _, d := range oldDeps {
|
||||
if d.Name == newDep.Name {
|
||||
newDeps = append(newDeps, *newDep)
|
||||
oldDepReplaced = true
|
||||
} else {
|
||||
newDeps = append(newDeps, d)
|
||||
}
|
||||
}
|
||||
|
||||
if !oldDepReplaced {
|
||||
newDeps = append(newDeps, *newDep)
|
||||
}
|
||||
|
||||
m.Dependencies = newDeps
|
||||
}
|
||||
}
|
||||
|
||||
srcPath := filepath.Join(jsonnetHome)
|
||||
err = os.MkdirAll(srcPath, os.ModePerm)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to create jsonnet home path: %v", err)
|
||||
return 3
|
||||
}
|
||||
|
||||
lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile, m, jsonnetHome)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to install: %v", err)
|
||||
return 3
|
||||
}
|
||||
|
||||
// If installing from lock file there is no need to write any files back.
|
||||
if !isLock {
|
||||
b, err := json.MarshalIndent(m, "", " ")
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to encode jsonnet file: %v", err)
|
||||
return 3
|
||||
}
|
||||
b = append(b, []byte("\n")...)
|
||||
|
||||
err = ioutil.WriteFile(pkg.JsonnetFile, b, 0644)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to write jsonnet file: %v", err)
|
||||
return 3
|
||||
}
|
||||
|
||||
b, err = json.MarshalIndent(lock, "", " ")
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to encode jsonnet file: %v", err)
|
||||
return 3
|
||||
}
|
||||
b = append(b, []byte("\n")...)
|
||||
|
||||
err = ioutil.WriteFile(pkg.JsonnetLockFile, b, 0644)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to write lock file: %v", err)
|
||||
return 3
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
func updateCommand(jsonnetHome string, urls ...*url.URL) int {
|
||||
jsonnetfile := pkg.JsonnetFile
|
||||
|
||||
m, err := pkg.LoadJsonnetfile(jsonnetfile)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to load jsonnetfile: %v", err)
|
||||
return 1
|
||||
}
|
||||
|
||||
err = os.MkdirAll(jsonnetHome, os.ModePerm)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to create jsonnet home path: %v", err)
|
||||
return 3
|
||||
}
|
||||
|
||||
// When updating, the lockfile is explicitly ignored.
|
||||
isLock := false
|
||||
lock, err := pkg.Install(context.TODO(), isLock, jsonnetfile, m, jsonnetHome)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to install: %v", err)
|
||||
return 3
|
||||
}
|
||||
|
||||
b, err := json.MarshalIndent(lock, "", " ")
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to encode jsonnet file: %v", err)
|
||||
return 3
|
||||
}
|
||||
b = append(b, []byte("\n")...)
|
||||
|
||||
err = ioutil.WriteFile(pkg.JsonnetLockFile, b, 0644)
|
||||
if err != nil {
|
||||
kingpin.Fatalf("failed to write lock file: %v", err)
|
||||
return 3
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
75
vendor/github.com/jsonnet-bundler/jsonnet-bundler/pkg/git.go
generated
vendored
Normal file
75
vendor/github.com/jsonnet-bundler/jsonnet-bundler/pkg/git.go
generated
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// 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 pkg
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"strings"
|
||||
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
|
||||
)
|
||||
|
||||
type GitPackage struct {
|
||||
Source *spec.GitSource
|
||||
}
|
||||
|
||||
func NewGitPackage(source *spec.GitSource) Interface {
|
||||
return &GitPackage{
|
||||
Source: source,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *GitPackage) Install(ctx context.Context, dir, version string) (lockVersion string, err error) {
|
||||
cmd := exec.CommandContext(ctx, "git", "clone", p.Source.Remote, dir)
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
cmd = exec.CommandContext(ctx, "git", "checkout", version)
|
||||
cmd.Stdin = os.Stdin
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
cmd.Dir = dir
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
b := bytes.NewBuffer(nil)
|
||||
cmd = exec.CommandContext(ctx, "git", "rev-parse", "HEAD")
|
||||
cmd.Stdout = b
|
||||
cmd.Dir = dir
|
||||
err = cmd.Run()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
commitHash := strings.TrimSpace(b.String())
|
||||
|
||||
err = os.RemoveAll(path.Join(dir, ".git"))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return commitHash, nil
|
||||
}
|
23
vendor/github.com/jsonnet-bundler/jsonnet-bundler/pkg/interface.go
generated
vendored
Normal file
23
vendor/github.com/jsonnet-bundler/jsonnet-bundler/pkg/interface.go
generated
vendored
Normal file
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// 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 pkg
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
type Interface interface {
|
||||
Install(ctx context.Context, dir, version string) (lockVersion string, err error)
|
||||
}
|
203
vendor/github.com/jsonnet-bundler/jsonnet-bundler/pkg/packages.go
generated
vendored
Normal file
203
vendor/github.com/jsonnet-bundler/jsonnet-bundler/pkg/packages.go
generated
vendored
Normal file
|
@ -0,0 +1,203 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// 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 pkg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/fatih/color"
|
||||
"github.com/jsonnet-bundler/jsonnet-bundler/spec"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
JsonnetFile = "jsonnetfile.json"
|
||||
JsonnetLockFile = "jsonnetfile.lock.json"
|
||||
VersionMismatch = errors.New("multiple colliding versions specified")
|
||||
)
|
||||
|
||||
func Install(ctx context.Context, isLock bool, dependencySourceIdentifier string, m spec.JsonnetFile, dir string) (lock *spec.JsonnetFile, err error) {
|
||||
lock = &spec.JsonnetFile{}
|
||||
for _, dep := range m.Dependencies {
|
||||
tmp := filepath.Join(dir, ".tmp")
|
||||
err = os.MkdirAll(tmp, os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create general tmp dir")
|
||||
}
|
||||
tmpDir, err := ioutil.TempDir(tmp, fmt.Sprintf("jsonnetpkg-%s-%s", dep.Name, dep.Version))
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create tmp dir")
|
||||
}
|
||||
defer os.RemoveAll(tmpDir)
|
||||
|
||||
subdir := ""
|
||||
var p Interface
|
||||
if dep.Source.GitSource != nil {
|
||||
p = NewGitPackage(dep.Source.GitSource)
|
||||
subdir = dep.Source.GitSource.Subdir
|
||||
}
|
||||
|
||||
lockVersion, err := p.Install(ctx, tmpDir, dep.Version)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to install package")
|
||||
}
|
||||
|
||||
color.Green(">>> Installed %s version %s\n", dep.Name, dep.Version)
|
||||
|
||||
destPath := path.Join(dir, dep.Name)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to find destination path for package")
|
||||
}
|
||||
|
||||
err = os.MkdirAll(path.Dir(destPath), os.ModePerm)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to create parent path")
|
||||
}
|
||||
|
||||
err = os.RemoveAll(destPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to clean previous destination path")
|
||||
}
|
||||
err = os.Rename(path.Join(tmpDir, subdir), destPath)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to move package")
|
||||
}
|
||||
|
||||
lock.Dependencies, err = insertDependency(lock.Dependencies, spec.Dependency{
|
||||
Name: dep.Name,
|
||||
Source: dep.Source,
|
||||
Version: lockVersion,
|
||||
DepSource: dependencySourceIdentifier,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to insert dependency to lock dependencies")
|
||||
}
|
||||
|
||||
// If dependencies are being installed from a lock file, the transitive
|
||||
// dependencies are not questioned, the locked dependencies are just
|
||||
// installed.
|
||||
if isLock {
|
||||
continue
|
||||
}
|
||||
|
||||
filepath, isLock, err := ChooseJsonnetFile(destPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
depsDeps, err := LoadJsonnetfile(filepath)
|
||||
// It is ok for depedencies not to have a JsonnetFile, it just means
|
||||
// they do not have transitive dependencies of their own.
|
||||
if err != nil && !os.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
depsInstalledByDependency, err := Install(ctx, isLock, filepath, depsDeps, dir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, d := range depsInstalledByDependency.Dependencies {
|
||||
lock.Dependencies, err = insertDependency(lock.Dependencies, d)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "failed to insert dependency to lock dependencies")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return lock, nil
|
||||
}
|
||||
|
||||
func insertDependency(deps []spec.Dependency, newDep spec.Dependency) ([]spec.Dependency, error) {
|
||||
if len(deps) == 0 {
|
||||
return []spec.Dependency{newDep}, nil
|
||||
}
|
||||
|
||||
res := []spec.Dependency{}
|
||||
newDepPreviouslyPresent := false
|
||||
for _, d := range deps {
|
||||
if d.Name == newDep.Name {
|
||||
if d.Version != newDep.Version {
|
||||
return nil, fmt.Errorf("multiple colliding versions specified for %s: %s (from %s) and %s (from %s)", d.Name, d.Version, d.DepSource, newDep.Version, newDep.DepSource)
|
||||
}
|
||||
res = append(res, d)
|
||||
newDepPreviouslyPresent = true
|
||||
} else {
|
||||
res = append(res, d)
|
||||
}
|
||||
}
|
||||
if !newDepPreviouslyPresent {
|
||||
res = append(res, newDep)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func FileExists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func ChooseJsonnetFile(dir string) (string, bool, error) {
|
||||
lockfile := path.Join(dir, JsonnetLockFile)
|
||||
jsonnetfile := path.Join(dir, JsonnetFile)
|
||||
filename := lockfile
|
||||
isLock := true
|
||||
|
||||
lockExists, err := FileExists(filepath.Join(dir, JsonnetLockFile))
|
||||
if err != nil {
|
||||
return "", false, err
|
||||
}
|
||||
|
||||
if !lockExists {
|
||||
filename = jsonnetfile
|
||||
isLock = false
|
||||
}
|
||||
|
||||
return filename, isLock, err
|
||||
}
|
||||
|
||||
func LoadJsonnetfile(filepath string) (spec.JsonnetFile, error) {
|
||||
m := spec.JsonnetFile{}
|
||||
|
||||
if _, err := os.Stat(filepath); err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
||||
f, err := os.Open(filepath)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
err = json.NewDecoder(f).Decode(&m)
|
||||
if err != nil {
|
||||
return m, err
|
||||
}
|
||||
|
||||
return m, nil
|
||||
}
|
35
vendor/github.com/jsonnet-bundler/jsonnet-bundler/spec/spec.go
generated
vendored
Normal file
35
vendor/github.com/jsonnet-bundler/jsonnet-bundler/spec/spec.go
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
// Copyright 2018 jsonnet-bundler authors
|
||||
//
|
||||
// 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 spec
|
||||
|
||||
type JsonnetFile struct {
|
||||
Dependencies []Dependency `json:"dependencies"`
|
||||
}
|
||||
|
||||
type Source struct {
|
||||
GitSource *GitSource `json:"git"`
|
||||
}
|
||||
|
||||
type GitSource struct {
|
||||
Remote string `json:"remote"`
|
||||
Subdir string `json:"subdir"`
|
||||
}
|
||||
|
||||
type Dependency struct {
|
||||
Name string `json:"name"`
|
||||
Source Source `json:"source"`
|
||||
Version string `json:"version"`
|
||||
DepSource string `json:"-"`
|
||||
}
|
9
vendor/github.com/mattn/go-colorable/.travis.yml
generated
vendored
Normal file
9
vendor/github.com/mattn/go-colorable/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
language: go
|
||||
go:
|
||||
- tip
|
||||
|
||||
before_install:
|
||||
- go get github.com/mattn/goveralls
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
script:
|
||||
- $HOME/gopath/bin/goveralls -repotoken xnXqRGwgW3SXIguzxf90ZSK1GPYZPaGrw
|
21
vendor/github.com/mattn/go-colorable/LICENSE
generated
vendored
Normal file
21
vendor/github.com/mattn/go-colorable/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Yasuhiro Matsumoto
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
48
vendor/github.com/mattn/go-colorable/README.md
generated
vendored
Normal file
48
vendor/github.com/mattn/go-colorable/README.md
generated
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
# go-colorable
|
||||
|
||||
[](http://godoc.org/github.com/mattn/go-colorable)
|
||||
[](https://travis-ci.org/mattn/go-colorable)
|
||||
[](https://coveralls.io/github/mattn/go-colorable?branch=master)
|
||||
[](https://goreportcard.com/report/mattn/go-colorable)
|
||||
|
||||
Colorable writer for windows.
|
||||
|
||||
For example, most of logger packages doesn't show colors on windows. (I know we can do it with ansicon. But I don't want.)
|
||||
This package is possible to handle escape sequence for ansi color on windows.
|
||||
|
||||
## Too Bad!
|
||||
|
||||

|
||||
|
||||
|
||||
## So Good!
|
||||
|
||||

|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
|
||||
logrus.SetOutput(colorable.NewColorableStdout())
|
||||
|
||||
logrus.Info("succeeded")
|
||||
logrus.Warn("not correct")
|
||||
logrus.Error("something error")
|
||||
logrus.Fatal("panic")
|
||||
```
|
||||
|
||||
You can compile above code on non-windows OSs.
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ go get github.com/mattn/go-colorable
|
||||
```
|
||||
|
||||
# License
|
||||
|
||||
MIT
|
||||
|
||||
# Author
|
||||
|
||||
Yasuhiro Matsumoto (a.k.a mattn)
|
29
vendor/github.com/mattn/go-colorable/colorable_appengine.go
generated
vendored
Normal file
29
vendor/github.com/mattn/go-colorable/colorable_appengine.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
// +build appengine
|
||||
|
||||
package colorable
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
_ "github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
// NewColorable return new instance of Writer which handle escape sequence.
|
||||
func NewColorable(file *os.File) io.Writer {
|
||||
if file == nil {
|
||||
panic("nil passed instead of *os.File to NewColorable()")
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
// NewColorableStdout return new instance of Writer which handle escape sequence for stdout.
|
||||
func NewColorableStdout() io.Writer {
|
||||
return os.Stdout
|
||||
}
|
||||
|
||||
// NewColorableStderr return new instance of Writer which handle escape sequence for stderr.
|
||||
func NewColorableStderr() io.Writer {
|
||||
return os.Stderr
|
||||
}
|
30
vendor/github.com/mattn/go-colorable/colorable_others.go
generated
vendored
Normal file
30
vendor/github.com/mattn/go-colorable/colorable_others.go
generated
vendored
Normal file
|
@ -0,0 +1,30 @@
|
|||
// +build !windows
|
||||
// +build !appengine
|
||||
|
||||
package colorable
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
|
||||
_ "github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
// NewColorable return new instance of Writer which handle escape sequence.
|
||||
func NewColorable(file *os.File) io.Writer {
|
||||
if file == nil {
|
||||
panic("nil passed instead of *os.File to NewColorable()")
|
||||
}
|
||||
|
||||
return file
|
||||
}
|
||||
|
||||
// NewColorableStdout return new instance of Writer which handle escape sequence for stdout.
|
||||
func NewColorableStdout() io.Writer {
|
||||
return os.Stdout
|
||||
}
|
||||
|
||||
// NewColorableStderr return new instance of Writer which handle escape sequence for stderr.
|
||||
func NewColorableStderr() io.Writer {
|
||||
return os.Stderr
|
||||
}
|
884
vendor/github.com/mattn/go-colorable/colorable_windows.go
generated
vendored
Normal file
884
vendor/github.com/mattn/go-colorable/colorable_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,884 @@
|
|||
// +build windows
|
||||
// +build !appengine
|
||||
|
||||
package colorable
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"github.com/mattn/go-isatty"
|
||||
)
|
||||
|
||||
const (
|
||||
foregroundBlue = 0x1
|
||||
foregroundGreen = 0x2
|
||||
foregroundRed = 0x4
|
||||
foregroundIntensity = 0x8
|
||||
foregroundMask = (foregroundRed | foregroundBlue | foregroundGreen | foregroundIntensity)
|
||||
backgroundBlue = 0x10
|
||||
backgroundGreen = 0x20
|
||||
backgroundRed = 0x40
|
||||
backgroundIntensity = 0x80
|
||||
backgroundMask = (backgroundRed | backgroundBlue | backgroundGreen | backgroundIntensity)
|
||||
)
|
||||
|
||||
type wchar uint16
|
||||
type short int16
|
||||
type dword uint32
|
||||
type word uint16
|
||||
|
||||
type coord struct {
|
||||
x short
|
||||
y short
|
||||
}
|
||||
|
||||
type smallRect struct {
|
||||
left short
|
||||
top short
|
||||
right short
|
||||
bottom short
|
||||
}
|
||||
|
||||
type consoleScreenBufferInfo struct {
|
||||
size coord
|
||||
cursorPosition coord
|
||||
attributes word
|
||||
window smallRect
|
||||
maximumWindowSize coord
|
||||
}
|
||||
|
||||
type consoleCursorInfo struct {
|
||||
size dword
|
||||
visible int32
|
||||
}
|
||||
|
||||
var (
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
procGetConsoleScreenBufferInfo = kernel32.NewProc("GetConsoleScreenBufferInfo")
|
||||
procSetConsoleTextAttribute = kernel32.NewProc("SetConsoleTextAttribute")
|
||||
procSetConsoleCursorPosition = kernel32.NewProc("SetConsoleCursorPosition")
|
||||
procFillConsoleOutputCharacter = kernel32.NewProc("FillConsoleOutputCharacterW")
|
||||
procFillConsoleOutputAttribute = kernel32.NewProc("FillConsoleOutputAttribute")
|
||||
procGetConsoleCursorInfo = kernel32.NewProc("GetConsoleCursorInfo")
|
||||
procSetConsoleCursorInfo = kernel32.NewProc("SetConsoleCursorInfo")
|
||||
procSetConsoleTitle = kernel32.NewProc("SetConsoleTitleW")
|
||||
)
|
||||
|
||||
// Writer provide colorable Writer to the console
|
||||
type Writer struct {
|
||||
out io.Writer
|
||||
handle syscall.Handle
|
||||
oldattr word
|
||||
oldpos coord
|
||||
}
|
||||
|
||||
// NewColorable return new instance of Writer which handle escape sequence from File.
|
||||
func NewColorable(file *os.File) io.Writer {
|
||||
if file == nil {
|
||||
panic("nil passed instead of *os.File to NewColorable()")
|
||||
}
|
||||
|
||||
if isatty.IsTerminal(file.Fd()) {
|
||||
var csbi consoleScreenBufferInfo
|
||||
handle := syscall.Handle(file.Fd())
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
return &Writer{out: file, handle: handle, oldattr: csbi.attributes, oldpos: coord{0, 0}}
|
||||
}
|
||||
return file
|
||||
}
|
||||
|
||||
// NewColorableStdout return new instance of Writer which handle escape sequence for stdout.
|
||||
func NewColorableStdout() io.Writer {
|
||||
return NewColorable(os.Stdout)
|
||||
}
|
||||
|
||||
// NewColorableStderr return new instance of Writer which handle escape sequence for stderr.
|
||||
func NewColorableStderr() io.Writer {
|
||||
return NewColorable(os.Stderr)
|
||||
}
|
||||
|
||||
var color256 = map[int]int{
|
||||
0: 0x000000,
|
||||
1: 0x800000,
|
||||
2: 0x008000,
|
||||
3: 0x808000,
|
||||
4: 0x000080,
|
||||
5: 0x800080,
|
||||
6: 0x008080,
|
||||
7: 0xc0c0c0,
|
||||
8: 0x808080,
|
||||
9: 0xff0000,
|
||||
10: 0x00ff00,
|
||||
11: 0xffff00,
|
||||
12: 0x0000ff,
|
||||
13: 0xff00ff,
|
||||
14: 0x00ffff,
|
||||
15: 0xffffff,
|
||||
16: 0x000000,
|
||||
17: 0x00005f,
|
||||
18: 0x000087,
|
||||
19: 0x0000af,
|
||||
20: 0x0000d7,
|
||||
21: 0x0000ff,
|
||||
22: 0x005f00,
|
||||
23: 0x005f5f,
|
||||
24: 0x005f87,
|
||||
25: 0x005faf,
|
||||
26: 0x005fd7,
|
||||
27: 0x005fff,
|
||||
28: 0x008700,
|
||||
29: 0x00875f,
|
||||
30: 0x008787,
|
||||
31: 0x0087af,
|
||||
32: 0x0087d7,
|
||||
33: 0x0087ff,
|
||||
34: 0x00af00,
|
||||
35: 0x00af5f,
|
||||
36: 0x00af87,
|
||||
37: 0x00afaf,
|
||||
38: 0x00afd7,
|
||||
39: 0x00afff,
|
||||
40: 0x00d700,
|
||||
41: 0x00d75f,
|
||||
42: 0x00d787,
|
||||
43: 0x00d7af,
|
||||
44: 0x00d7d7,
|
||||
45: 0x00d7ff,
|
||||
46: 0x00ff00,
|
||||
47: 0x00ff5f,
|
||||
48: 0x00ff87,
|
||||
49: 0x00ffaf,
|
||||
50: 0x00ffd7,
|
||||
51: 0x00ffff,
|
||||
52: 0x5f0000,
|
||||
53: 0x5f005f,
|
||||
54: 0x5f0087,
|
||||
55: 0x5f00af,
|
||||
56: 0x5f00d7,
|
||||
57: 0x5f00ff,
|
||||
58: 0x5f5f00,
|
||||
59: 0x5f5f5f,
|
||||
60: 0x5f5f87,
|
||||
61: 0x5f5faf,
|
||||
62: 0x5f5fd7,
|
||||
63: 0x5f5fff,
|
||||
64: 0x5f8700,
|
||||
65: 0x5f875f,
|
||||
66: 0x5f8787,
|
||||
67: 0x5f87af,
|
||||
68: 0x5f87d7,
|
||||
69: 0x5f87ff,
|
||||
70: 0x5faf00,
|
||||
71: 0x5faf5f,
|
||||
72: 0x5faf87,
|
||||
73: 0x5fafaf,
|
||||
74: 0x5fafd7,
|
||||
75: 0x5fafff,
|
||||
76: 0x5fd700,
|
||||
77: 0x5fd75f,
|
||||
78: 0x5fd787,
|
||||
79: 0x5fd7af,
|
||||
80: 0x5fd7d7,
|
||||
81: 0x5fd7ff,
|
||||
82: 0x5fff00,
|
||||
83: 0x5fff5f,
|
||||
84: 0x5fff87,
|
||||
85: 0x5fffaf,
|
||||
86: 0x5fffd7,
|
||||
87: 0x5fffff,
|
||||
88: 0x870000,
|
||||
89: 0x87005f,
|
||||
90: 0x870087,
|
||||
91: 0x8700af,
|
||||
92: 0x8700d7,
|
||||
93: 0x8700ff,
|
||||
94: 0x875f00,
|
||||
95: 0x875f5f,
|
||||
96: 0x875f87,
|
||||
97: 0x875faf,
|
||||
98: 0x875fd7,
|
||||
99: 0x875fff,
|
||||
100: 0x878700,
|
||||
101: 0x87875f,
|
||||
102: 0x878787,
|
||||
103: 0x8787af,
|
||||
104: 0x8787d7,
|
||||
105: 0x8787ff,
|
||||
106: 0x87af00,
|
||||
107: 0x87af5f,
|
||||
108: 0x87af87,
|
||||
109: 0x87afaf,
|
||||
110: 0x87afd7,
|
||||
111: 0x87afff,
|
||||
112: 0x87d700,
|
||||
113: 0x87d75f,
|
||||
114: 0x87d787,
|
||||
115: 0x87d7af,
|
||||
116: 0x87d7d7,
|
||||
117: 0x87d7ff,
|
||||
118: 0x87ff00,
|
||||
119: 0x87ff5f,
|
||||
120: 0x87ff87,
|
||||
121: 0x87ffaf,
|
||||
122: 0x87ffd7,
|
||||
123: 0x87ffff,
|
||||
124: 0xaf0000,
|
||||
125: 0xaf005f,
|
||||
126: 0xaf0087,
|
||||
127: 0xaf00af,
|
||||
128: 0xaf00d7,
|
||||
129: 0xaf00ff,
|
||||
130: 0xaf5f00,
|
||||
131: 0xaf5f5f,
|
||||
132: 0xaf5f87,
|
||||
133: 0xaf5faf,
|
||||
134: 0xaf5fd7,
|
||||
135: 0xaf5fff,
|
||||
136: 0xaf8700,
|
||||
137: 0xaf875f,
|
||||
138: 0xaf8787,
|
||||
139: 0xaf87af,
|
||||
140: 0xaf87d7,
|
||||
141: 0xaf87ff,
|
||||
142: 0xafaf00,
|
||||
143: 0xafaf5f,
|
||||
144: 0xafaf87,
|
||||
145: 0xafafaf,
|
||||
146: 0xafafd7,
|
||||
147: 0xafafff,
|
||||
148: 0xafd700,
|
||||
149: 0xafd75f,
|
||||
150: 0xafd787,
|
||||
151: 0xafd7af,
|
||||
152: 0xafd7d7,
|
||||
153: 0xafd7ff,
|
||||
154: 0xafff00,
|
||||
155: 0xafff5f,
|
||||
156: 0xafff87,
|
||||
157: 0xafffaf,
|
||||
158: 0xafffd7,
|
||||
159: 0xafffff,
|
||||
160: 0xd70000,
|
||||
161: 0xd7005f,
|
||||
162: 0xd70087,
|
||||
163: 0xd700af,
|
||||
164: 0xd700d7,
|
||||
165: 0xd700ff,
|
||||
166: 0xd75f00,
|
||||
167: 0xd75f5f,
|
||||
168: 0xd75f87,
|
||||
169: 0xd75faf,
|
||||
170: 0xd75fd7,
|
||||
171: 0xd75fff,
|
||||
172: 0xd78700,
|
||||
173: 0xd7875f,
|
||||
174: 0xd78787,
|
||||
175: 0xd787af,
|
||||
176: 0xd787d7,
|
||||
177: 0xd787ff,
|
||||
178: 0xd7af00,
|
||||
179: 0xd7af5f,
|
||||
180: 0xd7af87,
|
||||
181: 0xd7afaf,
|
||||
182: 0xd7afd7,
|
||||
183: 0xd7afff,
|
||||
184: 0xd7d700,
|
||||
185: 0xd7d75f,
|
||||
186: 0xd7d787,
|
||||
187: 0xd7d7af,
|
||||
188: 0xd7d7d7,
|
||||
189: 0xd7d7ff,
|
||||
190: 0xd7ff00,
|
||||
191: 0xd7ff5f,
|
||||
192: 0xd7ff87,
|
||||
193: 0xd7ffaf,
|
||||
194: 0xd7ffd7,
|
||||
195: 0xd7ffff,
|
||||
196: 0xff0000,
|
||||
197: 0xff005f,
|
||||
198: 0xff0087,
|
||||
199: 0xff00af,
|
||||
200: 0xff00d7,
|
||||
201: 0xff00ff,
|
||||
202: 0xff5f00,
|
||||
203: 0xff5f5f,
|
||||
204: 0xff5f87,
|
||||
205: 0xff5faf,
|
||||
206: 0xff5fd7,
|
||||
207: 0xff5fff,
|
||||
208: 0xff8700,
|
||||
209: 0xff875f,
|
||||
210: 0xff8787,
|
||||
211: 0xff87af,
|
||||
212: 0xff87d7,
|
||||
213: 0xff87ff,
|
||||
214: 0xffaf00,
|
||||
215: 0xffaf5f,
|
||||
216: 0xffaf87,
|
||||
217: 0xffafaf,
|
||||
218: 0xffafd7,
|
||||
219: 0xffafff,
|
||||
220: 0xffd700,
|
||||
221: 0xffd75f,
|
||||
222: 0xffd787,
|
||||
223: 0xffd7af,
|
||||
224: 0xffd7d7,
|
||||
225: 0xffd7ff,
|
||||
226: 0xffff00,
|
||||
227: 0xffff5f,
|
||||
228: 0xffff87,
|
||||
229: 0xffffaf,
|
||||
230: 0xffffd7,
|
||||
231: 0xffffff,
|
||||
232: 0x080808,
|
||||
233: 0x121212,
|
||||
234: 0x1c1c1c,
|
||||
235: 0x262626,
|
||||
236: 0x303030,
|
||||
237: 0x3a3a3a,
|
||||
238: 0x444444,
|
||||
239: 0x4e4e4e,
|
||||
240: 0x585858,
|
||||
241: 0x626262,
|
||||
242: 0x6c6c6c,
|
||||
243: 0x767676,
|
||||
244: 0x808080,
|
||||
245: 0x8a8a8a,
|
||||
246: 0x949494,
|
||||
247: 0x9e9e9e,
|
||||
248: 0xa8a8a8,
|
||||
249: 0xb2b2b2,
|
||||
250: 0xbcbcbc,
|
||||
251: 0xc6c6c6,
|
||||
252: 0xd0d0d0,
|
||||
253: 0xdadada,
|
||||
254: 0xe4e4e4,
|
||||
255: 0xeeeeee,
|
||||
}
|
||||
|
||||
// `\033]0;TITLESTR\007`
|
||||
func doTitleSequence(er *bytes.Reader) error {
|
||||
var c byte
|
||||
var err error
|
||||
|
||||
c, err = er.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c != '0' && c != '2' {
|
||||
return nil
|
||||
}
|
||||
c, err = er.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c != ';' {
|
||||
return nil
|
||||
}
|
||||
title := make([]byte, 0, 80)
|
||||
for {
|
||||
c, err = er.ReadByte()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if c == 0x07 || c == '\n' {
|
||||
break
|
||||
}
|
||||
title = append(title, c)
|
||||
}
|
||||
if len(title) > 0 {
|
||||
title8, err := syscall.UTF16PtrFromString(string(title))
|
||||
if err == nil {
|
||||
procSetConsoleTitle.Call(uintptr(unsafe.Pointer(title8)))
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Write write data on console
|
||||
func (w *Writer) Write(data []byte) (n int, err error) {
|
||||
var csbi consoleScreenBufferInfo
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
|
||||
er := bytes.NewReader(data)
|
||||
var bw [1]byte
|
||||
loop:
|
||||
for {
|
||||
c1, err := er.ReadByte()
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
if c1 != 0x1b {
|
||||
bw[0] = c1
|
||||
w.out.Write(bw[:])
|
||||
continue
|
||||
}
|
||||
c2, err := er.ReadByte()
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
|
||||
if c2 == ']' {
|
||||
if err := doTitleSequence(er); err != nil {
|
||||
break loop
|
||||
}
|
||||
continue
|
||||
}
|
||||
if c2 != 0x5b {
|
||||
continue
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
var m byte
|
||||
for {
|
||||
c, err := er.ReadByte()
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
||||
m = c
|
||||
break
|
||||
}
|
||||
buf.Write([]byte(string(c)))
|
||||
}
|
||||
|
||||
switch m {
|
||||
case 'A':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.y -= short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'B':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.y += short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'C':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x += short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'D':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x -= short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'E':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x = 0
|
||||
csbi.cursorPosition.y += short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'F':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x = 0
|
||||
csbi.cursorPosition.y -= short(n)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'G':
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
csbi.cursorPosition.x = short(n - 1)
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'H', 'f':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
if buf.Len() > 0 {
|
||||
token := strings.Split(buf.String(), ";")
|
||||
switch len(token) {
|
||||
case 1:
|
||||
n1, err := strconv.Atoi(token[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
csbi.cursorPosition.y = short(n1 - 1)
|
||||
case 2:
|
||||
n1, err := strconv.Atoi(token[0])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
n2, err := strconv.Atoi(token[1])
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
csbi.cursorPosition.x = short(n2 - 1)
|
||||
csbi.cursorPosition.y = short(n1 - 1)
|
||||
}
|
||||
} else {
|
||||
csbi.cursorPosition.y = 0
|
||||
}
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&csbi.cursorPosition)))
|
||||
case 'J':
|
||||
n := 0
|
||||
if buf.Len() > 0 {
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
var count, written dword
|
||||
var cursor coord
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
switch n {
|
||||
case 0:
|
||||
cursor = coord{x: csbi.cursorPosition.x, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
|
||||
case 1:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.window.top-csbi.cursorPosition.y)*csbi.size.x)
|
||||
case 2:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x + (csbi.size.y-csbi.cursorPosition.y)*csbi.size.x)
|
||||
}
|
||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
case 'K':
|
||||
n := 0
|
||||
if buf.Len() > 0 {
|
||||
n, err = strconv.Atoi(buf.String())
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
var cursor coord
|
||||
var count, written dword
|
||||
switch n {
|
||||
case 0:
|
||||
cursor = coord{x: csbi.cursorPosition.x + 1, y: csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x - 1)
|
||||
case 1:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x - csbi.cursorPosition.x)
|
||||
case 2:
|
||||
cursor = coord{x: csbi.window.left, y: csbi.window.top + csbi.cursorPosition.y}
|
||||
count = dword(csbi.size.x)
|
||||
}
|
||||
procFillConsoleOutputCharacter.Call(uintptr(w.handle), uintptr(' '), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
procFillConsoleOutputAttribute.Call(uintptr(w.handle), uintptr(csbi.attributes), uintptr(count), *(*uintptr)(unsafe.Pointer(&cursor)), uintptr(unsafe.Pointer(&written)))
|
||||
case 'm':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
attr := csbi.attributes
|
||||
cs := buf.String()
|
||||
if cs == "" {
|
||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(w.oldattr))
|
||||
continue
|
||||
}
|
||||
token := strings.Split(cs, ";")
|
||||
for i := 0; i < len(token); i++ {
|
||||
ns := token[i]
|
||||
if n, err = strconv.Atoi(ns); err == nil {
|
||||
switch {
|
||||
case n == 0 || n == 100:
|
||||
attr = w.oldattr
|
||||
case 1 <= n && n <= 5:
|
||||
attr |= foregroundIntensity
|
||||
case n == 7:
|
||||
attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
|
||||
case n == 22 || n == 25:
|
||||
attr |= foregroundIntensity
|
||||
case n == 27:
|
||||
attr = ((attr & foregroundMask) << 4) | ((attr & backgroundMask) >> 4)
|
||||
case 30 <= n && n <= 37:
|
||||
attr &= backgroundMask
|
||||
if (n-30)&1 != 0 {
|
||||
attr |= foregroundRed
|
||||
}
|
||||
if (n-30)&2 != 0 {
|
||||
attr |= foregroundGreen
|
||||
}
|
||||
if (n-30)&4 != 0 {
|
||||
attr |= foregroundBlue
|
||||
}
|
||||
case n == 38: // set foreground color.
|
||||
if i < len(token)-2 && (token[i+1] == "5" || token[i+1] == "05") {
|
||||
if n256, err := strconv.Atoi(token[i+2]); err == nil {
|
||||
if n256foreAttr == nil {
|
||||
n256setup()
|
||||
}
|
||||
attr &= backgroundMask
|
||||
attr |= n256foreAttr[n256]
|
||||
i += 2
|
||||
}
|
||||
} else {
|
||||
attr = attr & (w.oldattr & backgroundMask)
|
||||
}
|
||||
case n == 39: // reset foreground color.
|
||||
attr &= backgroundMask
|
||||
attr |= w.oldattr & foregroundMask
|
||||
case 40 <= n && n <= 47:
|
||||
attr &= foregroundMask
|
||||
if (n-40)&1 != 0 {
|
||||
attr |= backgroundRed
|
||||
}
|
||||
if (n-40)&2 != 0 {
|
||||
attr |= backgroundGreen
|
||||
}
|
||||
if (n-40)&4 != 0 {
|
||||
attr |= backgroundBlue
|
||||
}
|
||||
case n == 48: // set background color.
|
||||
if i < len(token)-2 && token[i+1] == "5" {
|
||||
if n256, err := strconv.Atoi(token[i+2]); err == nil {
|
||||
if n256backAttr == nil {
|
||||
n256setup()
|
||||
}
|
||||
attr &= foregroundMask
|
||||
attr |= n256backAttr[n256]
|
||||
i += 2
|
||||
}
|
||||
} else {
|
||||
attr = attr & (w.oldattr & foregroundMask)
|
||||
}
|
||||
case n == 49: // reset foreground color.
|
||||
attr &= foregroundMask
|
||||
attr |= w.oldattr & backgroundMask
|
||||
case 90 <= n && n <= 97:
|
||||
attr = (attr & backgroundMask)
|
||||
attr |= foregroundIntensity
|
||||
if (n-90)&1 != 0 {
|
||||
attr |= foregroundRed
|
||||
}
|
||||
if (n-90)&2 != 0 {
|
||||
attr |= foregroundGreen
|
||||
}
|
||||
if (n-90)&4 != 0 {
|
||||
attr |= foregroundBlue
|
||||
}
|
||||
case 100 <= n && n <= 107:
|
||||
attr = (attr & foregroundMask)
|
||||
attr |= backgroundIntensity
|
||||
if (n-100)&1 != 0 {
|
||||
attr |= backgroundRed
|
||||
}
|
||||
if (n-100)&2 != 0 {
|
||||
attr |= backgroundGreen
|
||||
}
|
||||
if (n-100)&4 != 0 {
|
||||
attr |= backgroundBlue
|
||||
}
|
||||
}
|
||||
procSetConsoleTextAttribute.Call(uintptr(w.handle), uintptr(attr))
|
||||
}
|
||||
}
|
||||
case 'h':
|
||||
var ci consoleCursorInfo
|
||||
cs := buf.String()
|
||||
if cs == "5>" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 0
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
} else if cs == "?25" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 1
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
}
|
||||
case 'l':
|
||||
var ci consoleCursorInfo
|
||||
cs := buf.String()
|
||||
if cs == "5>" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 1
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
} else if cs == "?25" {
|
||||
procGetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
ci.visible = 0
|
||||
procSetConsoleCursorInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&ci)))
|
||||
}
|
||||
case 's':
|
||||
procGetConsoleScreenBufferInfo.Call(uintptr(w.handle), uintptr(unsafe.Pointer(&csbi)))
|
||||
w.oldpos = csbi.cursorPosition
|
||||
case 'u':
|
||||
procSetConsoleCursorPosition.Call(uintptr(w.handle), *(*uintptr)(unsafe.Pointer(&w.oldpos)))
|
||||
}
|
||||
}
|
||||
|
||||
return len(data), nil
|
||||
}
|
||||
|
||||
type consoleColor struct {
|
||||
rgb int
|
||||
red bool
|
||||
green bool
|
||||
blue bool
|
||||
intensity bool
|
||||
}
|
||||
|
||||
func (c consoleColor) foregroundAttr() (attr word) {
|
||||
if c.red {
|
||||
attr |= foregroundRed
|
||||
}
|
||||
if c.green {
|
||||
attr |= foregroundGreen
|
||||
}
|
||||
if c.blue {
|
||||
attr |= foregroundBlue
|
||||
}
|
||||
if c.intensity {
|
||||
attr |= foregroundIntensity
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (c consoleColor) backgroundAttr() (attr word) {
|
||||
if c.red {
|
||||
attr |= backgroundRed
|
||||
}
|
||||
if c.green {
|
||||
attr |= backgroundGreen
|
||||
}
|
||||
if c.blue {
|
||||
attr |= backgroundBlue
|
||||
}
|
||||
if c.intensity {
|
||||
attr |= backgroundIntensity
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
var color16 = []consoleColor{
|
||||
{0x000000, false, false, false, false},
|
||||
{0x000080, false, false, true, false},
|
||||
{0x008000, false, true, false, false},
|
||||
{0x008080, false, true, true, false},
|
||||
{0x800000, true, false, false, false},
|
||||
{0x800080, true, false, true, false},
|
||||
{0x808000, true, true, false, false},
|
||||
{0xc0c0c0, true, true, true, false},
|
||||
{0x808080, false, false, false, true},
|
||||
{0x0000ff, false, false, true, true},
|
||||
{0x00ff00, false, true, false, true},
|
||||
{0x00ffff, false, true, true, true},
|
||||
{0xff0000, true, false, false, true},
|
||||
{0xff00ff, true, false, true, true},
|
||||
{0xffff00, true, true, false, true},
|
||||
{0xffffff, true, true, true, true},
|
||||
}
|
||||
|
||||
type hsv struct {
|
||||
h, s, v float32
|
||||
}
|
||||
|
||||
func (a hsv) dist(b hsv) float32 {
|
||||
dh := a.h - b.h
|
||||
switch {
|
||||
case dh > 0.5:
|
||||
dh = 1 - dh
|
||||
case dh < -0.5:
|
||||
dh = -1 - dh
|
||||
}
|
||||
ds := a.s - b.s
|
||||
dv := a.v - b.v
|
||||
return float32(math.Sqrt(float64(dh*dh + ds*ds + dv*dv)))
|
||||
}
|
||||
|
||||
func toHSV(rgb int) hsv {
|
||||
r, g, b := float32((rgb&0xFF0000)>>16)/256.0,
|
||||
float32((rgb&0x00FF00)>>8)/256.0,
|
||||
float32(rgb&0x0000FF)/256.0
|
||||
min, max := minmax3f(r, g, b)
|
||||
h := max - min
|
||||
if h > 0 {
|
||||
if max == r {
|
||||
h = (g - b) / h
|
||||
if h < 0 {
|
||||
h += 6
|
||||
}
|
||||
} else if max == g {
|
||||
h = 2 + (b-r)/h
|
||||
} else {
|
||||
h = 4 + (r-g)/h
|
||||
}
|
||||
}
|
||||
h /= 6.0
|
||||
s := max - min
|
||||
if max != 0 {
|
||||
s /= max
|
||||
}
|
||||
v := max
|
||||
return hsv{h: h, s: s, v: v}
|
||||
}
|
||||
|
||||
type hsvTable []hsv
|
||||
|
||||
func toHSVTable(rgbTable []consoleColor) hsvTable {
|
||||
t := make(hsvTable, len(rgbTable))
|
||||
for i, c := range rgbTable {
|
||||
t[i] = toHSV(c.rgb)
|
||||
}
|
||||
return t
|
||||
}
|
||||
|
||||
func (t hsvTable) find(rgb int) consoleColor {
|
||||
hsv := toHSV(rgb)
|
||||
n := 7
|
||||
l := float32(5.0)
|
||||
for i, p := range t {
|
||||
d := hsv.dist(p)
|
||||
if d < l {
|
||||
l, n = d, i
|
||||
}
|
||||
}
|
||||
return color16[n]
|
||||
}
|
||||
|
||||
func minmax3f(a, b, c float32) (min, max float32) {
|
||||
if a < b {
|
||||
if b < c {
|
||||
return a, c
|
||||
} else if a < c {
|
||||
return a, b
|
||||
} else {
|
||||
return c, b
|
||||
}
|
||||
} else {
|
||||
if a < c {
|
||||
return b, c
|
||||
} else if b < c {
|
||||
return b, a
|
||||
} else {
|
||||
return c, a
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var n256foreAttr []word
|
||||
var n256backAttr []word
|
||||
|
||||
func n256setup() {
|
||||
n256foreAttr = make([]word, 256)
|
||||
n256backAttr = make([]word, 256)
|
||||
t := toHSVTable(color16)
|
||||
for i, rgb := range color256 {
|
||||
c := t.find(rgb)
|
||||
n256foreAttr[i] = c.foregroundAttr()
|
||||
n256backAttr[i] = c.backgroundAttr()
|
||||
}
|
||||
}
|
55
vendor/github.com/mattn/go-colorable/noncolorable.go
generated
vendored
Normal file
55
vendor/github.com/mattn/go-colorable/noncolorable.go
generated
vendored
Normal file
|
@ -0,0 +1,55 @@
|
|||
package colorable
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
)
|
||||
|
||||
// NonColorable hold writer but remove escape sequence.
|
||||
type NonColorable struct {
|
||||
out io.Writer
|
||||
}
|
||||
|
||||
// NewNonColorable return new instance of Writer which remove escape sequence from Writer.
|
||||
func NewNonColorable(w io.Writer) io.Writer {
|
||||
return &NonColorable{out: w}
|
||||
}
|
||||
|
||||
// Write write data on console
|
||||
func (w *NonColorable) Write(data []byte) (n int, err error) {
|
||||
er := bytes.NewReader(data)
|
||||
var bw [1]byte
|
||||
loop:
|
||||
for {
|
||||
c1, err := er.ReadByte()
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
if c1 != 0x1b {
|
||||
bw[0] = c1
|
||||
w.out.Write(bw[:])
|
||||
continue
|
||||
}
|
||||
c2, err := er.ReadByte()
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
if c2 != 0x5b {
|
||||
continue
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
for {
|
||||
c, err := er.ReadByte()
|
||||
if err != nil {
|
||||
break loop
|
||||
}
|
||||
if ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z') || c == '@' {
|
||||
break
|
||||
}
|
||||
buf.Write([]byte(string(c)))
|
||||
}
|
||||
}
|
||||
|
||||
return len(data), nil
|
||||
}
|
13
vendor/github.com/mattn/go-isatty/.travis.yml
generated
vendored
Normal file
13
vendor/github.com/mattn/go-isatty/.travis.yml
generated
vendored
Normal file
|
@ -0,0 +1,13 @@
|
|||
language: go
|
||||
go:
|
||||
- tip
|
||||
|
||||
os:
|
||||
- linux
|
||||
- osx
|
||||
|
||||
before_install:
|
||||
- go get github.com/mattn/goveralls
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
script:
|
||||
- $HOME/gopath/bin/goveralls -repotoken 3gHdORO5k5ziZcWMBxnd9LrMZaJs8m9x5
|
9
vendor/github.com/mattn/go-isatty/LICENSE
generated
vendored
Normal file
9
vendor/github.com/mattn/go-isatty/LICENSE
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
Copyright (c) Yasuhiro MATSUMOTO <mattn.jp@gmail.com>
|
||||
|
||||
MIT License (Expat)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
50
vendor/github.com/mattn/go-isatty/README.md
generated
vendored
Normal file
50
vendor/github.com/mattn/go-isatty/README.md
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
# go-isatty
|
||||
|
||||
[](http://godoc.org/github.com/mattn/go-isatty)
|
||||
[](https://travis-ci.org/mattn/go-isatty)
|
||||
[](https://coveralls.io/github/mattn/go-isatty?branch=master)
|
||||
[](https://goreportcard.com/report/mattn/go-isatty)
|
||||
|
||||
isatty for golang
|
||||
|
||||
## Usage
|
||||
|
||||
```go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/mattn/go-isatty"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if isatty.IsTerminal(os.Stdout.Fd()) {
|
||||
fmt.Println("Is Terminal")
|
||||
} else if isatty.IsCygwinTerminal(os.Stdout.Fd()) {
|
||||
fmt.Println("Is Cygwin/MSYS2 Terminal")
|
||||
} else {
|
||||
fmt.Println("Is Not Terminal")
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```
|
||||
$ go get github.com/mattn/go-isatty
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Author
|
||||
|
||||
Yasuhiro Matsumoto (a.k.a mattn)
|
||||
|
||||
## Thanks
|
||||
|
||||
* k-takata: base idea for IsCygwinTerminal
|
||||
|
||||
https://github.com/k-takata/go-iscygpty
|
2
vendor/github.com/mattn/go-isatty/doc.go
generated
vendored
Normal file
2
vendor/github.com/mattn/go-isatty/doc.go
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
// Package isatty implements interface to isatty
|
||||
package isatty
|
3
vendor/github.com/mattn/go-isatty/go.mod
generated
vendored
Normal file
3
vendor/github.com/mattn/go-isatty/go.mod
generated
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
module github.com/mattn/go-isatty
|
||||
|
||||
require golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223
|
2
vendor/github.com/mattn/go-isatty/go.sum
generated
vendored
Normal file
2
vendor/github.com/mattn/go-isatty/go.sum
generated
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223 h1:DH4skfRX4EBpamg7iV4ZlCpblAHI6s6TDM39bFZumv8=
|
||||
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
17
vendor/github.com/mattn/go-isatty/isatty_android.go
generated
vendored
Normal file
17
vendor/github.com/mattn/go-isatty/isatty_android.go
generated
vendored
Normal file
|
@ -0,0 +1,17 @@
|
|||
// +build android
|
||||
|
||||
package isatty
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const ioctlReadTermios = syscall.TCGETS
|
||||
|
||||
// IsTerminal return true if the file descriptor is terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
var termios syscall.Termios
|
||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
||||
return err == 0
|
||||
}
|
24
vendor/github.com/mattn/go-isatty/isatty_bsd.go
generated
vendored
Normal file
24
vendor/github.com/mattn/go-isatty/isatty_bsd.go
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
// +build darwin freebsd openbsd netbsd dragonfly
|
||||
// +build !appengine
|
||||
|
||||
package isatty
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const ioctlReadTermios = syscall.TIOCGETA
|
||||
|
||||
// IsTerminal return true if the file descriptor is terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
var termios syscall.Termios
|
||||
_, _, err := syscall.Syscall6(syscall.SYS_IOCTL, fd, ioctlReadTermios, uintptr(unsafe.Pointer(&termios)), 0, 0, 0)
|
||||
return err == 0
|
||||
}
|
||||
|
||||
// IsCygwinTerminal return true if the file descriptor is a cygwin or msys2
|
||||
// terminal. This is also always false on this environment.
|
||||
func IsCygwinTerminal(fd uintptr) bool {
|
||||
return false
|
||||
}
|
19
vendor/github.com/mattn/go-isatty/isatty_linux.go
generated
vendored
Normal file
19
vendor/github.com/mattn/go-isatty/isatty_linux.go
generated
vendored
Normal file
|
@ -0,0 +1,19 @@
|
|||
// +build linux
|
||||
// +build !appengine
|
||||
// +build !android
|
||||
|
||||
package isatty
|
||||
|
||||
import "golang.org/x/sys/unix"
|
||||
|
||||
// IsTerminal return true if the file descriptor is terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
_, err := unix.IoctlGetTermios(int(fd), unix.TCGETS)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// IsCygwinTerminal return true if the file descriptor is a cygwin or msys2
|
||||
// terminal. This is also always false on this environment.
|
||||
func IsCygwinTerminal(fd uintptr) bool {
|
||||
return false
|
||||
}
|
15
vendor/github.com/mattn/go-isatty/isatty_others.go
generated
vendored
Normal file
15
vendor/github.com/mattn/go-isatty/isatty_others.go
generated
vendored
Normal file
|
@ -0,0 +1,15 @@
|
|||
// +build appengine js
|
||||
|
||||
package isatty
|
||||
|
||||
// IsTerminal returns true if the file descriptor is terminal which
|
||||
// is always false on js and appengine classic which is a sandboxed PaaS.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// IsCygwinTerminal() return true if the file descriptor is a cygwin or msys2
|
||||
// terminal. This is also always false on this environment.
|
||||
func IsCygwinTerminal(fd uintptr) bool {
|
||||
return false
|
||||
}
|
22
vendor/github.com/mattn/go-isatty/isatty_solaris.go
generated
vendored
Normal file
22
vendor/github.com/mattn/go-isatty/isatty_solaris.go
generated
vendored
Normal file
|
@ -0,0 +1,22 @@
|
|||
// +build solaris
|
||||
// +build !appengine
|
||||
|
||||
package isatty
|
||||
|
||||
import (
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
||||
// IsTerminal returns true if the given file descriptor is a terminal.
|
||||
// see: http://src.illumos.org/source/xref/illumos-gate/usr/src/lib/libbc/libc/gen/common/isatty.c
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
var termio unix.Termio
|
||||
err := unix.IoctlSetTermio(int(fd), unix.TCGETA, &termio)
|
||||
return err == nil
|
||||
}
|
||||
|
||||
// IsCygwinTerminal return true if the file descriptor is a cygwin or msys2
|
||||
// terminal. This is also always false on this environment.
|
||||
func IsCygwinTerminal(fd uintptr) bool {
|
||||
return false
|
||||
}
|
94
vendor/github.com/mattn/go-isatty/isatty_windows.go
generated
vendored
Normal file
94
vendor/github.com/mattn/go-isatty/isatty_windows.go
generated
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
// +build windows
|
||||
// +build !appengine
|
||||
|
||||
package isatty
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"syscall"
|
||||
"unicode/utf16"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
const (
|
||||
fileNameInfo uintptr = 2
|
||||
fileTypePipe = 3
|
||||
)
|
||||
|
||||
var (
|
||||
kernel32 = syscall.NewLazyDLL("kernel32.dll")
|
||||
procGetConsoleMode = kernel32.NewProc("GetConsoleMode")
|
||||
procGetFileInformationByHandleEx = kernel32.NewProc("GetFileInformationByHandleEx")
|
||||
procGetFileType = kernel32.NewProc("GetFileType")
|
||||
)
|
||||
|
||||
func init() {
|
||||
// Check if GetFileInformationByHandleEx is available.
|
||||
if procGetFileInformationByHandleEx.Find() != nil {
|
||||
procGetFileInformationByHandleEx = nil
|
||||
}
|
||||
}
|
||||
|
||||
// IsTerminal return true if the file descriptor is terminal.
|
||||
func IsTerminal(fd uintptr) bool {
|
||||
var st uint32
|
||||
r, _, e := syscall.Syscall(procGetConsoleMode.Addr(), 2, fd, uintptr(unsafe.Pointer(&st)), 0)
|
||||
return r != 0 && e == 0
|
||||
}
|
||||
|
||||
// Check pipe name is used for cygwin/msys2 pty.
|
||||
// Cygwin/MSYS2 PTY has a name like:
|
||||
// \{cygwin,msys}-XXXXXXXXXXXXXXXX-ptyN-{from,to}-master
|
||||
func isCygwinPipeName(name string) bool {
|
||||
token := strings.Split(name, "-")
|
||||
if len(token) < 5 {
|
||||
return false
|
||||
}
|
||||
|
||||
if token[0] != `\msys` && token[0] != `\cygwin` {
|
||||
return false
|
||||
}
|
||||
|
||||
if token[1] == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
if !strings.HasPrefix(token[2], "pty") {
|
||||
return false
|
||||
}
|
||||
|
||||
if token[3] != `from` && token[3] != `to` {
|
||||
return false
|
||||
}
|
||||
|
||||
if token[4] != "master" {
|
||||
return false
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
// IsCygwinTerminal() return true if the file descriptor is a cygwin or msys2
|
||||
// terminal.
|
||||
func IsCygwinTerminal(fd uintptr) bool {
|
||||
if procGetFileInformationByHandleEx == nil {
|
||||
return false
|
||||
}
|
||||
|
||||
// Cygwin/msys's pty is a pipe.
|
||||
ft, _, e := syscall.Syscall(procGetFileType.Addr(), 1, fd, 0, 0)
|
||||
if ft != fileTypePipe || e != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
var buf [2 + syscall.MAX_PATH]uint16
|
||||
r, _, e := syscall.Syscall6(procGetFileInformationByHandleEx.Addr(),
|
||||
4, fd, fileNameInfo, uintptr(unsafe.Pointer(&buf)),
|
||||
uintptr(len(buf)*2), 0, 0)
|
||||
if r == 0 || e != 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
l := *(*uint32)(unsafe.Pointer(&buf))
|
||||
return isCygwinPipeName(string(utf16.Decode(buf[2 : 2+l/2])))
|
||||
}
|
35
vendor/github.com/stretchr/testify/LICENSE
generated
vendored
35
vendor/github.com/stretchr/testify/LICENSE
generated
vendored
|
@ -1,22 +1,21 @@
|
|||
Copyright (c) 2012 - 2013 Mat Ryer and Tyler Bunnell
|
||||
MIT License
|
||||
|
||||
Please consider promoting this project if you find it useful.
|
||||
Copyright (c) 2012-2018 Mat Ryer and Tyler Bunnell
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without restriction,
|
||||
including without limitation the rights to use, copy, modify, merge,
|
||||
publish, distribute, sublicense, and/or sell copies of the Software,
|
||||
and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included
|
||||
in all copies or substantial portions of the Software.
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
||||
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
|
||||
OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
|
||||
OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
|
32
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
32
vendor/github.com/stretchr/testify/assert/assertions.go
generated
vendored
|
@ -39,7 +39,7 @@ type ValueAssertionFunc func(TestingT, interface{}, ...interface{}) bool
|
|||
// for table driven tests.
|
||||
type BoolAssertionFunc func(TestingT, bool, ...interface{}) bool
|
||||
|
||||
// ValuesAssertionFunc is a common function prototype when validating an error value. Can be useful
|
||||
// ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful
|
||||
// for table driven tests.
|
||||
type ErrorAssertionFunc func(TestingT, error, ...interface{}) bool
|
||||
|
||||
|
@ -179,7 +179,11 @@ func messageFromMsgAndArgs(msgAndArgs ...interface{}) string {
|
|||
return ""
|
||||
}
|
||||
if len(msgAndArgs) == 1 {
|
||||
return msgAndArgs[0].(string)
|
||||
msg := msgAndArgs[0]
|
||||
if msgAsStr, ok := msg.(string); ok {
|
||||
return msgAsStr
|
||||
}
|
||||
return fmt.Sprintf("%+v", msg)
|
||||
}
|
||||
if len(msgAndArgs) > 1 {
|
||||
return fmt.Sprintf(msgAndArgs[0].(string), msgAndArgs[1:]...)
|
||||
|
@ -415,6 +419,17 @@ func NotNil(t TestingT, object interface{}, msgAndArgs ...interface{}) bool {
|
|||
return Fail(t, "Expected value not to be nil.", msgAndArgs...)
|
||||
}
|
||||
|
||||
// containsKind checks if a specified kind in the slice of kinds.
|
||||
func containsKind(kinds []reflect.Kind, kind reflect.Kind) bool {
|
||||
for i := 0; i < len(kinds); i++ {
|
||||
if kind == kinds[i] {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// isNil checks if a specified object is nil or not, without Failing.
|
||||
func isNil(object interface{}) bool {
|
||||
if object == nil {
|
||||
|
@ -423,7 +438,14 @@ func isNil(object interface{}) bool {
|
|||
|
||||
value := reflect.ValueOf(object)
|
||||
kind := value.Kind()
|
||||
if kind >= reflect.Chan && kind <= reflect.Slice && value.IsNil() {
|
||||
isNilableKind := containsKind(
|
||||
[]reflect.Kind{
|
||||
reflect.Chan, reflect.Func,
|
||||
reflect.Interface, reflect.Map,
|
||||
reflect.Ptr, reflect.Slice},
|
||||
kind)
|
||||
|
||||
if isNilableKind && value.IsNil() {
|
||||
return true
|
||||
}
|
||||
|
||||
|
@ -1327,7 +1349,7 @@ func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) {
|
|||
}
|
||||
|
||||
// diff returns a diff of both values as long as both are of the same type and
|
||||
// are a struct, map, slice or array. Otherwise it returns an empty string.
|
||||
// are a struct, map, slice, array or string. Otherwise it returns an empty string.
|
||||
func diff(expected interface{}, actual interface{}) string {
|
||||
if expected == nil || actual == nil {
|
||||
return ""
|
||||
|
@ -1345,7 +1367,7 @@ func diff(expected interface{}, actual interface{}) string {
|
|||
}
|
||||
|
||||
var e, a string
|
||||
if ek != reflect.String {
|
||||
if et != reflect.TypeOf("") {
|
||||
e = spewConfig.Sdump(expected)
|
||||
a = spewConfig.Sdump(actual)
|
||||
} else {
|
||||
|
|
2
vendor/github.com/stretchr/testify/require/requirements.go
generated
vendored
2
vendor/github.com/stretchr/testify/require/requirements.go
generated
vendored
|
@ -22,7 +22,7 @@ type ValueAssertionFunc func(TestingT, interface{}, ...interface{})
|
|||
// for table driven tests.
|
||||
type BoolAssertionFunc func(TestingT, bool, ...interface{})
|
||||
|
||||
// ValuesAssertionFunc is a common function prototype when validating an error value. Can be useful
|
||||
// ErrorAssertionFunc is a common function prototype when validating an error value. Can be useful
|
||||
// for table driven tests.
|
||||
type ErrorAssertionFunc func(TestingT, error, ...interface{})
|
||||
|
||||
|
|
10
vendor/k8s.io/code-generator/cmd/client-gen/OWNERS
generated
vendored
Normal file
10
vendor/k8s.io/code-generator/cmd/client-gen/OWNERS
generated
vendored
Normal file
|
@ -0,0 +1,10 @@
|
|||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
approvers:
|
||||
- lavalamp
|
||||
- wojtek-t
|
||||
- caesarxuchao
|
||||
reviewers:
|
||||
- lavalamp
|
||||
- wojtek-t
|
||||
- caesarxuchao
|
4
vendor/k8s.io/code-generator/cmd/client-gen/README.md
generated
vendored
Normal file
4
vendor/k8s.io/code-generator/cmd/client-gen/README.md
generated
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
See [generating-clientset.md](https://git.k8s.io/community/contributors/devel/sig-api-machinery/generating-clientset.md)
|
||||
|
||||
|
||||
[]()
|
120
vendor/k8s.io/code-generator/cmd/client-gen/args/args.go
generated
vendored
Normal file
120
vendor/k8s.io/code-generator/cmd/client-gen/args/args.go
generated
vendored
Normal file
|
@ -0,0 +1,120 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 args
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/types"
|
||||
codegenutil "k8s.io/code-generator/pkg/util"
|
||||
)
|
||||
|
||||
var DefaultInputDirs = []string{}
|
||||
|
||||
// ClientGenArgs is a wrapper for arguments to client-gen.
|
||||
type CustomArgs struct {
|
||||
// A sorted list of group versions to generate. For each of them the package path is found
|
||||
// in GroupVersionToInputPath.
|
||||
Groups []types.GroupVersions
|
||||
|
||||
// Overrides for which types should be included in the client.
|
||||
IncludedTypesOverrides map[types.GroupVersion][]string
|
||||
|
||||
// ClientsetName is the name of the clientset to be generated. It's
|
||||
// populated from command-line arguments.
|
||||
ClientsetName string
|
||||
// ClientsetAPIPath is the default API HTTP path for generated clients.
|
||||
ClientsetAPIPath string
|
||||
// ClientsetOnly determines if we should generate the clients for groups and
|
||||
// types along with the clientset. It's populated from command-line
|
||||
// arguments.
|
||||
ClientsetOnly bool
|
||||
// FakeClient determines if client-gen generates the fake clients.
|
||||
FakeClient bool
|
||||
}
|
||||
|
||||
func NewDefaults() (*args.GeneratorArgs, *CustomArgs) {
|
||||
genericArgs := args.Default().WithoutDefaultFlagParsing()
|
||||
customArgs := &CustomArgs{
|
||||
ClientsetName: "internalclientset",
|
||||
ClientsetAPIPath: "/apis",
|
||||
ClientsetOnly: false,
|
||||
FakeClient: true,
|
||||
}
|
||||
genericArgs.CustomArgs = customArgs
|
||||
genericArgs.InputDirs = DefaultInputDirs
|
||||
|
||||
if pkg := codegenutil.CurrentPackage(); len(pkg) != 0 {
|
||||
genericArgs.OutputPackagePath = path.Join(pkg, "pkg/client/clientset")
|
||||
}
|
||||
|
||||
return genericArgs, customArgs
|
||||
}
|
||||
|
||||
func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet, inputBase string) {
|
||||
gvsBuilder := NewGroupVersionsBuilder(&ca.Groups)
|
||||
pflag.Var(NewGVPackagesValue(gvsBuilder, nil), "input", "group/versions that client-gen will generate clients for. At most one version per group is allowed. Specified in the format \"group1/version1,group2/version2...\".")
|
||||
pflag.Var(NewGVTypesValue(&ca.IncludedTypesOverrides, []string{}), "included-types-overrides", "list of group/version/type for which client should be generated. By default, client is generated for all types which have genclient in types.go. This overrides that. For each groupVersion in this list, only the types mentioned here will be included. The default check of genclient will be used for other group versions.")
|
||||
pflag.Var(NewInputBasePathValue(gvsBuilder, inputBase), "input-base", "base path to look for the api group.")
|
||||
pflag.StringVarP(&ca.ClientsetName, "clientset-name", "n", ca.ClientsetName, "the name of the generated clientset package.")
|
||||
pflag.StringVarP(&ca.ClientsetAPIPath, "clientset-api-path", "", ca.ClientsetAPIPath, "the value of default API HTTP path, starting with / and without trailing /.")
|
||||
pflag.BoolVar(&ca.ClientsetOnly, "clientset-only", ca.ClientsetOnly, "when set, client-gen only generates the clientset shell, without generating the individual typed clients")
|
||||
pflag.BoolVar(&ca.FakeClient, "fake-clientset", ca.FakeClient, "when set, client-gen will generate the fake clientset that can be used in tests")
|
||||
|
||||
// support old flags
|
||||
fs.SetNormalizeFunc(mapFlagName("clientset-path", "output-package", fs.GetNormalizeFunc()))
|
||||
}
|
||||
|
||||
func Validate(genericArgs *args.GeneratorArgs) error {
|
||||
customArgs := genericArgs.CustomArgs.(*CustomArgs)
|
||||
|
||||
if len(genericArgs.OutputPackagePath) == 0 {
|
||||
return fmt.Errorf("output package cannot be empty")
|
||||
}
|
||||
if len(customArgs.ClientsetName) == 0 {
|
||||
return fmt.Errorf("clientset name cannot be empty")
|
||||
}
|
||||
if len(customArgs.ClientsetAPIPath) == 0 {
|
||||
return fmt.Errorf("clientset API path cannot be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GroupVersionPackages returns a map from GroupVersion to the package with the types.go.
|
||||
func (ca *CustomArgs) GroupVersionPackages() map[types.GroupVersion]string {
|
||||
res := map[types.GroupVersion]string{}
|
||||
for _, pkg := range ca.Groups {
|
||||
for _, v := range pkg.Versions {
|
||||
res[types.GroupVersion{Group: pkg.Group, Version: v.Version}] = v.Package
|
||||
}
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func mapFlagName(from, to string, old func(fs *pflag.FlagSet, name string) pflag.NormalizedName) func(fs *pflag.FlagSet, name string) pflag.NormalizedName {
|
||||
return func(fs *pflag.FlagSet, name string) pflag.NormalizedName {
|
||||
if name == from {
|
||||
name = to
|
||||
}
|
||||
return old(fs, name)
|
||||
}
|
||||
}
|
183
vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages.go
generated
vendored
Normal file
183
vendor/k8s.io/code-generator/cmd/client-gen/args/gvpackages.go
generated
vendored
Normal file
|
@ -0,0 +1,183 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 args
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/csv"
|
||||
"flag"
|
||||
"path"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/types"
|
||||
)
|
||||
|
||||
type inputBasePathValue struct {
|
||||
builder *groupVersionsBuilder
|
||||
}
|
||||
|
||||
var _ flag.Value = &inputBasePathValue{}
|
||||
|
||||
func NewInputBasePathValue(builder *groupVersionsBuilder, def string) *inputBasePathValue {
|
||||
v := &inputBasePathValue{
|
||||
builder: builder,
|
||||
}
|
||||
v.Set(def)
|
||||
return v
|
||||
}
|
||||
|
||||
func (s *inputBasePathValue) Set(val string) error {
|
||||
s.builder.importBasePath = val
|
||||
return s.builder.update()
|
||||
}
|
||||
|
||||
func (s *inputBasePathValue) Type() string {
|
||||
return "string"
|
||||
}
|
||||
|
||||
func (s *inputBasePathValue) String() string {
|
||||
return s.builder.importBasePath
|
||||
}
|
||||
|
||||
type gvPackagesValue struct {
|
||||
builder *groupVersionsBuilder
|
||||
groups []string
|
||||
changed bool
|
||||
}
|
||||
|
||||
func NewGVPackagesValue(builder *groupVersionsBuilder, def []string) *gvPackagesValue {
|
||||
gvp := new(gvPackagesValue)
|
||||
gvp.builder = builder
|
||||
if def != nil {
|
||||
if err := gvp.set(def); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return gvp
|
||||
}
|
||||
|
||||
var _ flag.Value = &gvPackagesValue{}
|
||||
|
||||
func (s *gvPackagesValue) set(vs []string) error {
|
||||
if s.changed {
|
||||
s.groups = append(s.groups, vs...)
|
||||
} else {
|
||||
s.groups = append([]string(nil), vs...)
|
||||
}
|
||||
|
||||
s.builder.groups = s.groups
|
||||
return s.builder.update()
|
||||
}
|
||||
|
||||
func (s *gvPackagesValue) Set(val string) error {
|
||||
vs, err := readAsCSV(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.set(vs); err != nil {
|
||||
return err
|
||||
}
|
||||
s.changed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *gvPackagesValue) Type() string {
|
||||
return "stringSlice"
|
||||
}
|
||||
|
||||
func (s *gvPackagesValue) String() string {
|
||||
str, _ := writeAsCSV(s.groups)
|
||||
return "[" + str + "]"
|
||||
}
|
||||
|
||||
type groupVersionsBuilder struct {
|
||||
value *[]types.GroupVersions
|
||||
groups []string
|
||||
importBasePath string
|
||||
}
|
||||
|
||||
func NewGroupVersionsBuilder(groups *[]types.GroupVersions) *groupVersionsBuilder {
|
||||
return &groupVersionsBuilder{
|
||||
value: groups,
|
||||
}
|
||||
}
|
||||
|
||||
func (p *groupVersionsBuilder) update() error {
|
||||
var seenGroups = make(map[types.Group]*types.GroupVersions)
|
||||
for _, v := range p.groups {
|
||||
pth, gvString := parsePathGroupVersion(v)
|
||||
gv, err := types.ToGroupVersion(gvString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
versionPkg := types.PackageVersion{Package: path.Join(p.importBasePath, pth, gv.Group.NonEmpty(), gv.Version.String()), Version: gv.Version}
|
||||
if group, ok := seenGroups[gv.Group]; ok {
|
||||
seenGroups[gv.Group].Versions = append(group.Versions, versionPkg)
|
||||
} else {
|
||||
seenGroups[gv.Group] = &types.GroupVersions{
|
||||
PackageName: gv.Group.NonEmpty(),
|
||||
Group: gv.Group,
|
||||
Versions: []types.PackageVersion{versionPkg},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var groupNames []string
|
||||
for groupName := range seenGroups {
|
||||
groupNames = append(groupNames, groupName.String())
|
||||
}
|
||||
sort.Strings(groupNames)
|
||||
*p.value = []types.GroupVersions{}
|
||||
for _, groupName := range groupNames {
|
||||
*p.value = append(*p.value, *seenGroups[types.Group(groupName)])
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parsePathGroupVersion(pgvString string) (gvPath string, gvString string) {
|
||||
subs := strings.Split(pgvString, "/")
|
||||
length := len(subs)
|
||||
switch length {
|
||||
case 0, 1, 2:
|
||||
return "", pgvString
|
||||
default:
|
||||
return strings.Join(subs[:length-2], "/"), strings.Join(subs[length-2:], "/")
|
||||
}
|
||||
}
|
||||
|
||||
func readAsCSV(val string) ([]string, error) {
|
||||
if val == "" {
|
||||
return []string{}, nil
|
||||
}
|
||||
stringReader := strings.NewReader(val)
|
||||
csvReader := csv.NewReader(stringReader)
|
||||
return csvReader.Read()
|
||||
}
|
||||
|
||||
func writeAsCSV(vals []string) (string, error) {
|
||||
b := &bytes.Buffer{}
|
||||
w := csv.NewWriter(b)
|
||||
err := w.Write(vals)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
w.Flush()
|
||||
return strings.TrimSuffix(b.String(), "\n"), nil
|
||||
}
|
110
vendor/k8s.io/code-generator/cmd/client-gen/args/gvtype.go
generated
vendored
Normal file
110
vendor/k8s.io/code-generator/cmd/client-gen/args/gvtype.go
generated
vendored
Normal file
|
@ -0,0 +1,110 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 args
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/types"
|
||||
)
|
||||
|
||||
type gvTypeValue struct {
|
||||
gvToTypes *map[types.GroupVersion][]string
|
||||
changed bool
|
||||
}
|
||||
|
||||
func NewGVTypesValue(gvToTypes *map[types.GroupVersion][]string, def []string) *gvTypeValue {
|
||||
gvt := new(gvTypeValue)
|
||||
gvt.gvToTypes = gvToTypes
|
||||
if def != nil {
|
||||
if err := gvt.set(def); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
return gvt
|
||||
}
|
||||
|
||||
var _ flag.Value = &gvTypeValue{}
|
||||
|
||||
func (s *gvTypeValue) set(vs []string) error {
|
||||
if !s.changed {
|
||||
*s.gvToTypes = map[types.GroupVersion][]string{}
|
||||
}
|
||||
|
||||
for _, input := range vs {
|
||||
gvString, typeStr, err := parseGroupVersionType(input)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
gv, err := types.ToGroupVersion(gvString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
types, ok := (*s.gvToTypes)[gv]
|
||||
if !ok {
|
||||
types = []string{}
|
||||
}
|
||||
types = append(types, typeStr)
|
||||
(*s.gvToTypes)[gv] = types
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *gvTypeValue) Set(val string) error {
|
||||
vs, err := readAsCSV(val)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.set(vs); err != nil {
|
||||
return err
|
||||
}
|
||||
s.changed = true
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *gvTypeValue) Type() string {
|
||||
return "stringSlice"
|
||||
}
|
||||
|
||||
func (s *gvTypeValue) String() string {
|
||||
strs := make([]string, 0, len(*s.gvToTypes))
|
||||
for gv, ts := range *s.gvToTypes {
|
||||
for _, t := range ts {
|
||||
strs = append(strs, gv.Group.String()+"/"+gv.Version.String()+"/"+t)
|
||||
}
|
||||
}
|
||||
str, _ := writeAsCSV(strs)
|
||||
return "[" + str + "]"
|
||||
}
|
||||
|
||||
func parseGroupVersionType(gvtString string) (gvString string, typeStr string, err error) {
|
||||
invalidFormatErr := fmt.Errorf("invalid value: %s, should be of the form group/version/type", gvtString)
|
||||
subs := strings.Split(gvtString, "/")
|
||||
length := len(subs)
|
||||
switch length {
|
||||
case 2:
|
||||
// gvtString of the form group/type, e.g. api/Service,extensions/ReplicaSet
|
||||
return subs[0] + "/", subs[1], nil
|
||||
case 3:
|
||||
return strings.Join(subs[:length-1], "/"), subs[length-1], nil
|
||||
default:
|
||||
return "", "", invalidFormatErr
|
||||
}
|
||||
}
|
403
vendor/k8s.io/code-generator/cmd/client-gen/generators/client_generator.go
generated
vendored
Normal file
403
vendor/k8s.io/code-generator/cmd/client-gen/generators/client_generator.go
generated
vendored
Normal file
|
@ -0,0 +1,403 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 generators has the generators for the client-gen utility.
|
||||
package generators
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
clientgenargs "k8s.io/code-generator/cmd/client-gen/args"
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/fake"
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/scheme"
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
"k8s.io/code-generator/cmd/client-gen/path"
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
codegennamer "k8s.io/code-generator/pkg/namer"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// NameSystems returns the name system used by the generators in this package.
|
||||
func NameSystems() namer.NameSystems {
|
||||
pluralExceptions := map[string]string{
|
||||
"Endpoints": "Endpoints",
|
||||
}
|
||||
lowercaseNamer := namer.NewAllLowercasePluralNamer(pluralExceptions)
|
||||
|
||||
publicNamer := &ExceptionNamer{
|
||||
Exceptions: map[string]string{
|
||||
// these exceptions are used to deconflict the generated code
|
||||
// you can put your fully qualified package like
|
||||
// to generate a name that doesn't conflict with your group.
|
||||
// "k8s.io/apis/events/v1beta1.Event": "EventResource"
|
||||
},
|
||||
KeyFunc: func(t *types.Type) string {
|
||||
return t.Name.Package + "." + t.Name.Name
|
||||
},
|
||||
Delegate: namer.NewPublicNamer(0),
|
||||
}
|
||||
privateNamer := &ExceptionNamer{
|
||||
Exceptions: map[string]string{
|
||||
// these exceptions are used to deconflict the generated code
|
||||
// you can put your fully qualified package like
|
||||
// to generate a name that doesn't conflict with your group.
|
||||
// "k8s.io/apis/events/v1beta1.Event": "eventResource"
|
||||
},
|
||||
KeyFunc: func(t *types.Type) string {
|
||||
return t.Name.Package + "." + t.Name.Name
|
||||
},
|
||||
Delegate: namer.NewPrivateNamer(0),
|
||||
}
|
||||
publicPluralNamer := &ExceptionNamer{
|
||||
Exceptions: map[string]string{
|
||||
// these exceptions are used to deconflict the generated code
|
||||
// you can put your fully qualified package like
|
||||
// to generate a name that doesn't conflict with your group.
|
||||
// "k8s.io/apis/events/v1beta1.Event": "EventResource"
|
||||
},
|
||||
KeyFunc: func(t *types.Type) string {
|
||||
return t.Name.Package + "." + t.Name.Name
|
||||
},
|
||||
Delegate: namer.NewPublicPluralNamer(pluralExceptions),
|
||||
}
|
||||
privatePluralNamer := &ExceptionNamer{
|
||||
Exceptions: map[string]string{
|
||||
// you can put your fully qualified package like
|
||||
// to generate a name that doesn't conflict with your group.
|
||||
// "k8s.io/apis/events/v1beta1.Event": "eventResource"
|
||||
// these exceptions are used to deconflict the generated code
|
||||
"k8s.io/apis/events/v1beta1.Event": "eventResources",
|
||||
"k8s.io/kubernetes/pkg/apis/events.Event": "eventResources",
|
||||
},
|
||||
KeyFunc: func(t *types.Type) string {
|
||||
return t.Name.Package + "." + t.Name.Name
|
||||
},
|
||||
Delegate: namer.NewPrivatePluralNamer(pluralExceptions),
|
||||
}
|
||||
|
||||
return namer.NameSystems{
|
||||
"singularKind": namer.NewPublicNamer(0),
|
||||
"public": publicNamer,
|
||||
"private": privateNamer,
|
||||
"raw": namer.NewRawNamer("", nil),
|
||||
"publicPlural": publicPluralNamer,
|
||||
"privatePlural": privatePluralNamer,
|
||||
"allLowercasePlural": lowercaseNamer,
|
||||
"resource": codegennamer.NewTagOverrideNamer("resourceName", lowercaseNamer),
|
||||
}
|
||||
}
|
||||
|
||||
// ExceptionNamer allows you specify exceptional cases with exact names. This allows you to have control
|
||||
// for handling various conflicts, like group and resource names for instance.
|
||||
type ExceptionNamer struct {
|
||||
Exceptions map[string]string
|
||||
KeyFunc func(*types.Type) string
|
||||
|
||||
Delegate namer.Namer
|
||||
}
|
||||
|
||||
// Name provides the requested name for a type.
|
||||
func (n *ExceptionNamer) Name(t *types.Type) string {
|
||||
key := n.KeyFunc(t)
|
||||
if exception, ok := n.Exceptions[key]; ok {
|
||||
return exception
|
||||
}
|
||||
return n.Delegate.Name(t)
|
||||
}
|
||||
|
||||
// DefaultNameSystem returns the default name system for ordering the types to be
|
||||
// processed by the generators in this package.
|
||||
func DefaultNameSystem() string {
|
||||
return "public"
|
||||
}
|
||||
|
||||
func packageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetPackage string, groupPackageName string, groupGoName string, apiPath string, srcTreePath string, inputPackage string, boilerplate []byte) generator.Package {
|
||||
groupVersionClientPackage := filepath.Join(clientsetPackage, "typed", strings.ToLower(groupPackageName), strings.ToLower(gv.Version.NonEmpty()))
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: strings.ToLower(gv.Version.NonEmpty()),
|
||||
PackagePath: groupVersionClientPackage,
|
||||
HeaderText: boilerplate,
|
||||
PackageDocumentation: []byte(
|
||||
`// This package has the automatically generated typed clients.
|
||||
`),
|
||||
// GeneratorFunc returns a list of generators. Each generator makes a
|
||||
// single file.
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = []generator.Generator{
|
||||
// Always generate a "doc.go" file.
|
||||
generator.DefaultGen{OptionalName: "doc"},
|
||||
}
|
||||
// Since we want a file per type that we generate a client for, we
|
||||
// have to provide a function for this.
|
||||
for _, t := range typeList {
|
||||
generators = append(generators, &genClientForType{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: strings.ToLower(c.Namers["private"].Name(t)),
|
||||
},
|
||||
outputPackage: groupVersionClientPackage,
|
||||
clientsetPackage: clientsetPackage,
|
||||
group: gv.Group.NonEmpty(),
|
||||
version: gv.Version.String(),
|
||||
groupGoName: groupGoName,
|
||||
typeToMatch: t,
|
||||
imports: generator.NewImportTracker(),
|
||||
})
|
||||
}
|
||||
|
||||
generators = append(generators, &genGroup{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: groupPackageName + "_client",
|
||||
},
|
||||
outputPackage: groupVersionClientPackage,
|
||||
inputPackage: inputPackage,
|
||||
clientsetPackage: clientsetPackage,
|
||||
group: gv.Group.NonEmpty(),
|
||||
version: gv.Version.String(),
|
||||
groupGoName: groupGoName,
|
||||
apiPath: apiPath,
|
||||
types: typeList,
|
||||
imports: generator.NewImportTracker(),
|
||||
})
|
||||
|
||||
expansionFileName := "generated_expansion"
|
||||
generators = append(generators, &genExpansion{
|
||||
groupPackagePath: filepath.Join(srcTreePath, groupVersionClientPackage),
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: expansionFileName,
|
||||
},
|
||||
types: typeList,
|
||||
})
|
||||
|
||||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func packageForClientset(customArgs *clientgenargs.CustomArgs, clientsetPackage string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Package {
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: customArgs.ClientsetName,
|
||||
PackagePath: clientsetPackage,
|
||||
HeaderText: boilerplate,
|
||||
PackageDocumentation: []byte(
|
||||
`// This package has the automatically generated clientset.
|
||||
`),
|
||||
// GeneratorFunc returns a list of generators. Each generator generates a
|
||||
// single file.
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = []generator.Generator{
|
||||
// Always generate a "doc.go" file.
|
||||
generator.DefaultGen{OptionalName: "doc"},
|
||||
|
||||
&genClientset{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "clientset",
|
||||
},
|
||||
groups: customArgs.Groups,
|
||||
groupGoNames: groupGoNames,
|
||||
clientsetPackage: clientsetPackage,
|
||||
outputPackage: customArgs.ClientsetName,
|
||||
imports: generator.NewImportTracker(),
|
||||
},
|
||||
}
|
||||
return generators
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func packageForScheme(customArgs *clientgenargs.CustomArgs, clientsetPackage string, srcTreePath string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Package {
|
||||
schemePackage := filepath.Join(clientsetPackage, "scheme")
|
||||
|
||||
// create runtime.Registry for internal client because it has to know about group versions
|
||||
internalClient := false
|
||||
NextGroup:
|
||||
for _, group := range customArgs.Groups {
|
||||
for _, v := range group.Versions {
|
||||
if v.String() == "" {
|
||||
internalClient = true
|
||||
break NextGroup
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: "scheme",
|
||||
PackagePath: schemePackage,
|
||||
HeaderText: boilerplate,
|
||||
PackageDocumentation: []byte(
|
||||
`// This package contains the scheme of the automatically generated clientset.
|
||||
`),
|
||||
// GeneratorFunc returns a list of generators. Each generator generates a
|
||||
// single file.
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = []generator.Generator{
|
||||
// Always generate a "doc.go" file.
|
||||
generator.DefaultGen{OptionalName: "doc"},
|
||||
|
||||
&scheme.GenScheme{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "register",
|
||||
},
|
||||
InputPackages: customArgs.GroupVersionPackages(),
|
||||
OutputPackage: schemePackage,
|
||||
OutputPath: filepath.Join(srcTreePath, schemePackage),
|
||||
Groups: customArgs.Groups,
|
||||
GroupGoNames: groupGoNames,
|
||||
ImportTracker: generator.NewImportTracker(),
|
||||
CreateRegistry: internalClient,
|
||||
},
|
||||
}
|
||||
return generators
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// applyGroupOverrides applies group name overrides to each package, if applicable. If there is a
|
||||
// comment of the form "// +groupName=somegroup" or "// +groupName=somegroup.foo.bar.io", use the
|
||||
// first field (somegroup) as the name of the group in Go code, e.g. as the func name in a clientset.
|
||||
//
|
||||
// If the first field of the groupName is not unique within the clientset, use "// +groupName=unique
|
||||
func applyGroupOverrides(universe types.Universe, customArgs *clientgenargs.CustomArgs) {
|
||||
// Create a map from "old GV" to "new GV" so we know what changes we need to make.
|
||||
changes := make(map[clientgentypes.GroupVersion]clientgentypes.GroupVersion)
|
||||
for gv, inputDir := range customArgs.GroupVersionPackages() {
|
||||
p := universe.Package(inputDir)
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
|
||||
newGV := clientgentypes.GroupVersion{
|
||||
Group: clientgentypes.Group(override[0]),
|
||||
Version: gv.Version,
|
||||
}
|
||||
changes[gv] = newGV
|
||||
}
|
||||
}
|
||||
|
||||
// Modify customArgs.Groups based on the groupName overrides.
|
||||
newGroups := make([]clientgentypes.GroupVersions, 0, len(customArgs.Groups))
|
||||
for _, gvs := range customArgs.Groups {
|
||||
gv := clientgentypes.GroupVersion{
|
||||
Group: gvs.Group,
|
||||
Version: gvs.Versions[0].Version, // we only need a version, and the first will do
|
||||
}
|
||||
if newGV, ok := changes[gv]; ok {
|
||||
// There's an override, so use it.
|
||||
newGVS := clientgentypes.GroupVersions{
|
||||
PackageName: gvs.PackageName,
|
||||
Group: newGV.Group,
|
||||
Versions: gvs.Versions,
|
||||
}
|
||||
newGroups = append(newGroups, newGVS)
|
||||
} else {
|
||||
// No override.
|
||||
newGroups = append(newGroups, gvs)
|
||||
}
|
||||
}
|
||||
customArgs.Groups = newGroups
|
||||
}
|
||||
|
||||
// Packages makes the client package definition.
|
||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs, ok := arguments.CustomArgs.(*clientgenargs.CustomArgs)
|
||||
if !ok {
|
||||
klog.Fatalf("cannot convert arguments.CustomArgs to clientgenargs.CustomArgs")
|
||||
}
|
||||
includedTypesOverrides := customArgs.IncludedTypesOverrides
|
||||
|
||||
applyGroupOverrides(context.Universe, customArgs)
|
||||
|
||||
gvToTypes := map[clientgentypes.GroupVersion][]*types.Type{}
|
||||
groupGoNames := make(map[clientgentypes.GroupVersion]string)
|
||||
for gv, inputDir := range customArgs.GroupVersionPackages() {
|
||||
p := context.Universe.Package(path.Vendorless(inputDir))
|
||||
|
||||
// If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as
|
||||
// the Go group identifier in CamelCase. It defaults
|
||||
groupGoNames[gv] = namer.IC(strings.Split(gv.Group.NonEmpty(), ".")[0])
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupGoName"]; override != nil {
|
||||
groupGoNames[gv] = namer.IC(override[0])
|
||||
}
|
||||
|
||||
// Package are indexed with the vendor prefix stripped
|
||||
for n, t := range p.Types {
|
||||
// filter out types which are not included in user specified overrides.
|
||||
typesOverride, ok := includedTypesOverrides[gv]
|
||||
if ok {
|
||||
found := false
|
||||
for _, typeStr := range typesOverride {
|
||||
if typeStr == n {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
// User has not specified any override for this group version.
|
||||
// filter out types which dont have genclient.
|
||||
if tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)); !tags.GenerateClient {
|
||||
continue
|
||||
}
|
||||
}
|
||||
if _, found := gvToTypes[gv]; !found {
|
||||
gvToTypes[gv] = []*types.Type{}
|
||||
}
|
||||
gvToTypes[gv] = append(gvToTypes[gv], t)
|
||||
}
|
||||
}
|
||||
|
||||
var packageList []generator.Package
|
||||
clientsetPackage := filepath.Join(arguments.OutputPackagePath, customArgs.ClientsetName)
|
||||
|
||||
packageList = append(packageList, packageForClientset(customArgs, clientsetPackage, groupGoNames, boilerplate))
|
||||
packageList = append(packageList, packageForScheme(customArgs, clientsetPackage, arguments.OutputBase, groupGoNames, boilerplate))
|
||||
if customArgs.FakeClient {
|
||||
packageList = append(packageList, fake.PackageForClientset(customArgs, clientsetPackage, groupGoNames, boilerplate))
|
||||
}
|
||||
|
||||
// If --clientset-only=true, we don't regenerate the individual typed clients.
|
||||
if customArgs.ClientsetOnly {
|
||||
return generator.Packages(packageList)
|
||||
}
|
||||
|
||||
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
|
||||
gvPackages := customArgs.GroupVersionPackages()
|
||||
for _, group := range customArgs.Groups {
|
||||
for _, version := range group.Versions {
|
||||
gv := clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}
|
||||
types := gvToTypes[gv]
|
||||
inputPath := gvPackages[gv]
|
||||
packageList = append(packageList, packageForGroup(gv, orderer.OrderTypes(types), clientsetPackage, group.PackageName, groupGoNames[gv], customArgs.ClientsetAPIPath, arguments.OutputBase, inputPath, boilerplate))
|
||||
if customArgs.FakeClient {
|
||||
packageList = append(packageList, fake.PackageForGroup(gv, orderer.OrderTypes(types), clientsetPackage, group.PackageName, groupGoNames[gv], inputPath, boilerplate))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return generator.Packages(packageList)
|
||||
}
|
130
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/fake_client_generator.go
generated
vendored
Normal file
130
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/fake_client_generator.go
generated
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 fake
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
clientgenargs "k8s.io/code-generator/cmd/client-gen/args"
|
||||
scheme "k8s.io/code-generator/cmd/client-gen/generators/scheme"
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
)
|
||||
|
||||
func PackageForGroup(gv clientgentypes.GroupVersion, typeList []*types.Type, clientsetPackage string, groupPackageName string, groupGoName string, inputPackage string, boilerplate []byte) generator.Package {
|
||||
outputPackage := filepath.Join(clientsetPackage, "typed", strings.ToLower(groupPackageName), strings.ToLower(gv.Version.NonEmpty()), "fake")
|
||||
// TODO: should make this a function, called by here and in client-generator.go
|
||||
realClientPackage := filepath.Join(clientsetPackage, "typed", strings.ToLower(groupPackageName), strings.ToLower(gv.Version.NonEmpty()))
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: "fake",
|
||||
PackagePath: outputPackage,
|
||||
HeaderText: boilerplate,
|
||||
PackageDocumentation: []byte(
|
||||
`// Package fake has the automatically generated clients.
|
||||
`),
|
||||
// GeneratorFunc returns a list of generators. Each generator makes a
|
||||
// single file.
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = []generator.Generator{
|
||||
// Always generate a "doc.go" file.
|
||||
generator.DefaultGen{OptionalName: "doc"},
|
||||
}
|
||||
// Since we want a file per type that we generate a client for, we
|
||||
// have to provide a function for this.
|
||||
for _, t := range typeList {
|
||||
generators = append(generators, &genFakeForType{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "fake_" + strings.ToLower(c.Namers["private"].Name(t)),
|
||||
},
|
||||
outputPackage: outputPackage,
|
||||
inputPackage: inputPackage,
|
||||
group: gv.Group.NonEmpty(),
|
||||
version: gv.Version.String(),
|
||||
groupGoName: groupGoName,
|
||||
typeToMatch: t,
|
||||
imports: generator.NewImportTracker(),
|
||||
})
|
||||
}
|
||||
|
||||
generators = append(generators, &genFakeForGroup{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "fake_" + groupPackageName + "_client",
|
||||
},
|
||||
outputPackage: outputPackage,
|
||||
realClientPackage: realClientPackage,
|
||||
group: gv.Group.NonEmpty(),
|
||||
version: gv.Version.String(),
|
||||
groupGoName: groupGoName,
|
||||
types: typeList,
|
||||
imports: generator.NewImportTracker(),
|
||||
})
|
||||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
return util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func PackageForClientset(customArgs *clientgenargs.CustomArgs, clientsetPackage string, groupGoNames map[clientgentypes.GroupVersion]string, boilerplate []byte) generator.Package {
|
||||
return &generator.DefaultPackage{
|
||||
// TODO: we'll generate fake clientset for different release in the future.
|
||||
// Package name and path are hard coded for now.
|
||||
PackageName: "fake",
|
||||
PackagePath: filepath.Join(clientsetPackage, "fake"),
|
||||
HeaderText: boilerplate,
|
||||
PackageDocumentation: []byte(
|
||||
`// This package has the automatically generated fake clientset.
|
||||
`),
|
||||
// GeneratorFunc returns a list of generators. Each generator generates a
|
||||
// single file.
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = []generator.Generator{
|
||||
// Always generate a "doc.go" file.
|
||||
generator.DefaultGen{OptionalName: "doc"},
|
||||
|
||||
&genClientset{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "clientset_generated",
|
||||
},
|
||||
groups: customArgs.Groups,
|
||||
groupGoNames: groupGoNames,
|
||||
fakeClientsetPackage: clientsetPackage,
|
||||
outputPackage: "fake",
|
||||
imports: generator.NewImportTracker(),
|
||||
realClientsetPackage: clientsetPackage,
|
||||
},
|
||||
&scheme.GenScheme{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "register",
|
||||
},
|
||||
InputPackages: customArgs.GroupVersionPackages(),
|
||||
OutputPackage: clientsetPackage,
|
||||
Groups: customArgs.Groups,
|
||||
GroupGoNames: groupGoNames,
|
||||
ImportTracker: generator.NewImportTracker(),
|
||||
PrivateScheme: true,
|
||||
},
|
||||
}
|
||||
return generators
|
||||
},
|
||||
}
|
||||
}
|
169
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_clientset.go
generated
vendored
Normal file
169
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_clientset.go
generated
vendored
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 fake
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genClientset generates a package for a clientset.
|
||||
type genClientset struct {
|
||||
generator.DefaultGen
|
||||
groups []clientgentypes.GroupVersions
|
||||
groupGoNames map[clientgentypes.GroupVersion]string
|
||||
fakeClientsetPackage string
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
clientsetGenerated bool
|
||||
// the import path of the generated real clientset.
|
||||
realClientsetPackage string
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genClientset{}
|
||||
|
||||
func (g *genClientset) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
// We only want to call GenerateType() once.
|
||||
func (g *genClientset) Filter(c *generator.Context, t *types.Type) bool {
|
||||
ret := !g.clientsetGenerated
|
||||
g.clientsetGenerated = true
|
||||
return ret
|
||||
}
|
||||
|
||||
func (g *genClientset) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
for _, group := range g.groups {
|
||||
for _, version := range group.Versions {
|
||||
groupClientPackage := filepath.Join(g.fakeClientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty()))
|
||||
fakeGroupClientPackage := filepath.Join(groupClientPackage, "fake")
|
||||
|
||||
groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}])
|
||||
imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), groupClientPackage))
|
||||
imports = append(imports, fmt.Sprintf("fake%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), fakeGroupClientPackage))
|
||||
}
|
||||
}
|
||||
// the package that has the clientset Interface
|
||||
imports = append(imports, fmt.Sprintf("clientset \"%s\"", g.realClientsetPackage))
|
||||
// imports for the code in commonTemplate
|
||||
imports = append(imports,
|
||||
"k8s.io/client-go/testing",
|
||||
"k8s.io/client-go/discovery",
|
||||
"fakediscovery \"k8s.io/client-go/discovery/fake\"",
|
||||
"k8s.io/apimachinery/pkg/runtime",
|
||||
"k8s.io/apimachinery/pkg/watch",
|
||||
)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
// TODO: We actually don't need any type information to generate the clientset,
|
||||
// perhaps we can adapt the go2ild framework to this kind of usage.
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames)
|
||||
|
||||
sw.Do(common, nil)
|
||||
sw.Do(checkImpl, nil)
|
||||
|
||||
for _, group := range allGroups {
|
||||
m := map[string]interface{}{
|
||||
"group": group.Group,
|
||||
"version": group.Version,
|
||||
"PackageAlias": group.PackageAlias,
|
||||
"GroupGoName": group.GroupGoName,
|
||||
"Version": namer.IC(group.Version.String()),
|
||||
}
|
||||
|
||||
sw.Do(clientsetInterfaceImplTemplate, m)
|
||||
}
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
// This part of code is version-independent, unchanging.
|
||||
var common = `
|
||||
// NewSimpleClientset returns a clientset that will respond with the provided objects.
|
||||
// It's backed by a very simple object tracker that processes creates, updates and deletions as-is,
|
||||
// without applying any validations and/or defaults. It shouldn't be considered a replacement
|
||||
// for a real clientset and is mostly useful in simple unit tests.
|
||||
func NewSimpleClientset(objects ...runtime.Object) *Clientset {
|
||||
o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder())
|
||||
for _, obj := range objects {
|
||||
if err := o.Add(obj); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
cs := &Clientset{}
|
||||
cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake}
|
||||
cs.AddReactor("*", "*", testing.ObjectReaction(o))
|
||||
cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) {
|
||||
gvr := action.GetResource()
|
||||
ns := action.GetNamespace()
|
||||
watch, err := o.Watch(gvr, ns)
|
||||
if err != nil {
|
||||
return false, nil, err
|
||||
}
|
||||
return true, watch, nil
|
||||
})
|
||||
|
||||
return cs
|
||||
}
|
||||
|
||||
// Clientset implements clientset.Interface. Meant to be embedded into a
|
||||
// struct to get a default implementation. This makes faking out just the method
|
||||
// you want to test easier.
|
||||
type Clientset struct {
|
||||
testing.Fake
|
||||
discovery *fakediscovery.FakeDiscovery
|
||||
}
|
||||
|
||||
func (c *Clientset) Discovery() discovery.DiscoveryInterface {
|
||||
return c.discovery
|
||||
}
|
||||
`
|
||||
|
||||
var checkImpl = `
|
||||
var _ clientset.Interface = &Clientset{}
|
||||
`
|
||||
|
||||
var clientsetInterfaceImplTemplate = `
|
||||
// $.GroupGoName$$.Version$ retrieves the $.GroupGoName$$.Version$Client
|
||||
func (c *Clientset) $.GroupGoName$$.Version$() $.PackageAlias$.$.GroupGoName$$.Version$Interface {
|
||||
return &fake$.PackageAlias$.Fake$.GroupGoName$$.Version${Fake: &c.Fake}
|
||||
}
|
||||
`
|
||||
|
||||
var clientsetInterfaceDefaultVersionImpl = `
|
||||
// $.GroupGoName$ retrieves the $.GroupGoName$$.Version$Client
|
||||
func (c *Clientset) $.GroupGoName$() $.PackageAlias$.$.GroupGoName$$.Version$Interface {
|
||||
return &fake$.PackageAlias$.Fake$.GroupGoName$$.Version${Fake: &c.Fake}
|
||||
}
|
||||
`
|
130
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_group.go
generated
vendored
Normal file
130
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_group.go
generated
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 fake
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
)
|
||||
|
||||
// genFakeForGroup produces a file for a group client, e.g. ExtensionsClient for the extension group.
|
||||
type genFakeForGroup struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
realClientPackage string
|
||||
group string
|
||||
version string
|
||||
groupGoName string
|
||||
// types in this group
|
||||
types []*types.Type
|
||||
imports namer.ImportTracker
|
||||
// If the genGroup has been called. This generator should only execute once.
|
||||
called bool
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genFakeForGroup{}
|
||||
|
||||
// We only want to call GenerateType() once per group.
|
||||
func (g *genFakeForGroup) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.called {
|
||||
g.called = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *genFakeForGroup) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genFakeForGroup) Imports(c *generator.Context) (imports []string) {
|
||||
imports = g.imports.ImportLines()
|
||||
if len(g.types) != 0 {
|
||||
imports = append(imports, fmt.Sprintf("%s \"%s\"", strings.ToLower(filepath.Base(g.realClientPackage)), g.realClientPackage))
|
||||
}
|
||||
return imports
|
||||
}
|
||||
|
||||
func (g *genFakeForGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
m := map[string]interface{}{
|
||||
"GroupGoName": g.groupGoName,
|
||||
"Version": namer.IC(g.version),
|
||||
"Fake": c.Universe.Type(types.Name{Package: "k8s.io/client-go/testing", Name: "Fake"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
|
||||
"RESTClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClient"}),
|
||||
}
|
||||
|
||||
sw.Do(groupClientTemplate, m)
|
||||
for _, t := range g.types {
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrapper := map[string]interface{}{
|
||||
"type": t,
|
||||
"GroupGoName": g.groupGoName,
|
||||
"Version": namer.IC(g.version),
|
||||
"realClientPackage": strings.ToLower(filepath.Base(g.realClientPackage)),
|
||||
}
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(getterImplNonNamespaced, wrapper)
|
||||
continue
|
||||
}
|
||||
sw.Do(getterImplNamespaced, wrapper)
|
||||
}
|
||||
sw.Do(getRESTClient, m)
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var groupClientTemplate = `
|
||||
type Fake$.GroupGoName$$.Version$ struct {
|
||||
*$.Fake|raw$
|
||||
}
|
||||
`
|
||||
|
||||
var getterImplNamespaced = `
|
||||
func (c *Fake$.GroupGoName$$.Version$) $.type|publicPlural$(namespace string) $.realClientPackage$.$.type|public$Interface {
|
||||
return &Fake$.type|publicPlural${c, namespace}
|
||||
}
|
||||
`
|
||||
|
||||
var getterImplNonNamespaced = `
|
||||
func (c *Fake$.GroupGoName$$.Version$) $.type|publicPlural$() $.realClientPackage$.$.type|public$Interface {
|
||||
return &Fake$.type|publicPlural${c}
|
||||
}
|
||||
`
|
||||
|
||||
var getRESTClient = `
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *Fake$.GroupGoName$$.Version$) RESTClient() $.RESTClientInterface|raw$ {
|
||||
var ret *$.RESTClient|raw$
|
||||
return ret
|
||||
}
|
||||
`
|
479
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_type.go
generated
vendored
Normal file
479
vendor/k8s.io/code-generator/cmd/client-gen/generators/fake/generator_fake_for_type.go
generated
vendored
Normal file
|
@ -0,0 +1,479 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 fake
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
"k8s.io/code-generator/cmd/client-gen/path"
|
||||
)
|
||||
|
||||
// genFakeForType produces a file for each top-level type.
|
||||
type genFakeForType struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
group string
|
||||
version string
|
||||
groupGoName string
|
||||
inputPackage string
|
||||
typeToMatch *types.Type
|
||||
imports namer.ImportTracker
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genFakeForType{}
|
||||
|
||||
// Filter ignores all but one type because we're making a single file per type.
|
||||
func (g *genFakeForType) Filter(c *generator.Context, t *types.Type) bool { return t == g.typeToMatch }
|
||||
|
||||
func (g *genFakeForType) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genFakeForType) Imports(c *generator.Context) (imports []string) {
|
||||
return g.imports.ImportLines()
|
||||
}
|
||||
|
||||
// Ideally, we'd like genStatus to return true if there is a subresource path
|
||||
// registered for "status" in the API server, but we do not have that
|
||||
// information, so genStatus returns true if the type has a status field.
|
||||
func genStatus(t *types.Type) bool {
|
||||
// Default to true if we have a Status member
|
||||
hasStatus := false
|
||||
for _, m := range t.Members {
|
||||
if m.Name == "Status" {
|
||||
hasStatus = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return hasStatus && !tags.NoStatus
|
||||
}
|
||||
|
||||
// hasObjectMeta returns true if the type has a ObjectMeta field.
|
||||
func hasObjectMeta(t *types.Type) bool {
|
||||
for _, m := range t.Members {
|
||||
if m.Embedded == true && m.Name == "ObjectMeta" {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// GenerateType makes the body of a file implementing the individual typed client for type t.
|
||||
func (g *genFakeForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
pkg := filepath.Base(t.Name.Package)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
canonicalGroup := g.group
|
||||
if canonicalGroup == "core" {
|
||||
canonicalGroup = ""
|
||||
}
|
||||
|
||||
groupName := g.group
|
||||
if g.group == "core" {
|
||||
groupName = ""
|
||||
}
|
||||
|
||||
// allow user to define a group name that's different from the one parsed from the directory.
|
||||
p := c.Universe.Package(path.Vendorless(g.inputPackage))
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
|
||||
groupName = override[0]
|
||||
}
|
||||
|
||||
const pkgClientGoTesting = "k8s.io/client-go/testing"
|
||||
m := map[string]interface{}{
|
||||
"type": t,
|
||||
"inputType": t,
|
||||
"resultType": t,
|
||||
"subresourcePath": "",
|
||||
"package": pkg,
|
||||
"Package": namer.IC(pkg),
|
||||
"namespaced": !tags.NonNamespaced,
|
||||
"Group": namer.IC(g.group),
|
||||
"GroupGoName": g.groupGoName,
|
||||
"Version": namer.IC(g.version),
|
||||
"group": canonicalGroup,
|
||||
"groupName": groupName,
|
||||
"version": g.version,
|
||||
"DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}),
|
||||
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
|
||||
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
|
||||
"Everything": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/labels", Name: "Everything"}),
|
||||
"GroupVersionResource": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionResource"}),
|
||||
"GroupVersionKind": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionKind"}),
|
||||
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}),
|
||||
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}),
|
||||
|
||||
"NewRootListAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootListAction"}),
|
||||
"NewListAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewListAction"}),
|
||||
"NewRootGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetAction"}),
|
||||
"NewGetAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetAction"}),
|
||||
"NewRootDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteAction"}),
|
||||
"NewDeleteAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteAction"}),
|
||||
"NewRootDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootDeleteCollectionAction"}),
|
||||
"NewDeleteCollectionAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewDeleteCollectionAction"}),
|
||||
"NewRootUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateAction"}),
|
||||
"NewUpdateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateAction"}),
|
||||
"NewRootCreateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateAction"}),
|
||||
"NewCreateAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateAction"}),
|
||||
"NewRootWatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootWatchAction"}),
|
||||
"NewWatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewWatchAction"}),
|
||||
"NewCreateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewCreateSubresourceAction"}),
|
||||
"NewRootCreateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootCreateSubresourceAction"}),
|
||||
"NewUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewUpdateSubresourceAction"}),
|
||||
"NewGetSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewGetSubresourceAction"}),
|
||||
"NewRootGetSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootGetSubresourceAction"}),
|
||||
"NewRootUpdateSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootUpdateSubresourceAction"}),
|
||||
"NewRootPatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchAction"}),
|
||||
"NewPatchAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchAction"}),
|
||||
"NewRootPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewRootPatchSubresourceAction"}),
|
||||
"NewPatchSubresourceAction": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "NewPatchSubresourceAction"}),
|
||||
"ExtractFromListOptions": c.Universe.Function(types.Name{Package: pkgClientGoTesting, Name: "ExtractFromListOptions"}),
|
||||
}
|
||||
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(structNonNamespaced, m)
|
||||
} else {
|
||||
sw.Do(structNamespaced, m)
|
||||
}
|
||||
|
||||
if tags.NoVerbs {
|
||||
return sw.Error()
|
||||
}
|
||||
sw.Do(resource, m)
|
||||
sw.Do(kind, m)
|
||||
|
||||
if tags.HasVerb("get") {
|
||||
sw.Do(getTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("list") {
|
||||
if hasObjectMeta(t) {
|
||||
sw.Do(listUsingOptionsTemplate, m)
|
||||
} else {
|
||||
sw.Do(listTemplate, m)
|
||||
}
|
||||
}
|
||||
if tags.HasVerb("watch") {
|
||||
sw.Do(watchTemplate, m)
|
||||
}
|
||||
|
||||
if tags.HasVerb("create") {
|
||||
sw.Do(createTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("update") {
|
||||
sw.Do(updateTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("updateStatus") && genStatus(t) {
|
||||
sw.Do(updateStatusTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("delete") {
|
||||
sw.Do(deleteTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("deleteCollection") {
|
||||
sw.Do(deleteCollectionTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("patch") {
|
||||
sw.Do(patchTemplate, m)
|
||||
}
|
||||
|
||||
// generate extended client methods
|
||||
for _, e := range tags.Extensions {
|
||||
inputType := *t
|
||||
resultType := *t
|
||||
if len(e.InputTypeOverride) > 0 {
|
||||
if name, pkg := e.Input(); len(pkg) > 0 {
|
||||
newType := c.Universe.Type(types.Name{Package: pkg, Name: name})
|
||||
inputType = *newType
|
||||
} else {
|
||||
inputType.Name.Name = e.InputTypeOverride
|
||||
}
|
||||
}
|
||||
if len(e.ResultTypeOverride) > 0 {
|
||||
if name, pkg := e.Result(); len(pkg) > 0 {
|
||||
newType := c.Universe.Type(types.Name{Package: pkg, Name: name})
|
||||
resultType = *newType
|
||||
} else {
|
||||
resultType.Name.Name = e.ResultTypeOverride
|
||||
}
|
||||
}
|
||||
m["inputType"] = &inputType
|
||||
m["resultType"] = &resultType
|
||||
m["subresourcePath"] = e.SubResourcePath
|
||||
|
||||
if e.HasVerb("get") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, getSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, getTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
if e.HasVerb("list") {
|
||||
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, listTemplate), m)
|
||||
}
|
||||
|
||||
// TODO: Figure out schemantic for watching a sub-resource.
|
||||
if e.HasVerb("watch") {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, watchTemplate), m)
|
||||
}
|
||||
|
||||
if e.HasVerb("create") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, createSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, createTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
if e.HasVerb("update") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, updateSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, updateTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Figure out schemantic for deleting a sub-resource (what arguments
|
||||
// are passed, does it need two names? etc.
|
||||
if e.HasVerb("delete") {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, deleteTemplate), m)
|
||||
}
|
||||
|
||||
if e.HasVerb("patch") {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, patchTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
// adjustTemplate adjust the origin verb template using the expansion name.
|
||||
// TODO: Make the verbs in templates parametrized so the strings.Replace() is
|
||||
// not needed.
|
||||
func adjustTemplate(name, verbType, template string) string {
|
||||
return strings.Replace(template, " "+strings.Title(verbType), " "+name, -1)
|
||||
}
|
||||
|
||||
// template for the struct that implements the type's interface
|
||||
var structNamespaced = `
|
||||
// Fake$.type|publicPlural$ implements $.type|public$Interface
|
||||
type Fake$.type|publicPlural$ struct {
|
||||
Fake *Fake$.GroupGoName$$.Version$
|
||||
ns string
|
||||
}
|
||||
`
|
||||
|
||||
// template for the struct that implements the type's interface
|
||||
var structNonNamespaced = `
|
||||
// Fake$.type|publicPlural$ implements $.type|public$Interface
|
||||
type Fake$.type|publicPlural$ struct {
|
||||
Fake *Fake$.GroupGoName$$.Version$
|
||||
}
|
||||
`
|
||||
|
||||
var resource = `
|
||||
var $.type|allLowercasePlural$Resource = $.GroupVersionResource|raw${Group: "$.groupName$", Version: "$.version$", Resource: "$.type|resource$"}
|
||||
`
|
||||
|
||||
var kind = `
|
||||
var $.type|allLowercasePlural$Kind = $.GroupVersionKind|raw${Group: "$.groupName$", Version: "$.version$", Kind: "$.type|singularKind$"}
|
||||
`
|
||||
|
||||
var listTemplate = `
|
||||
// List takes label and field selectors, and returns the list of $.type|publicPlural$ that match those selectors.
|
||||
func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type|raw$List, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), &$.type|raw$List{})
|
||||
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), &$.type|raw$List{})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.type|raw$List), err
|
||||
}
|
||||
`
|
||||
|
||||
var listUsingOptionsTemplate = `
|
||||
// List takes label and field selectors, and returns the list of $.type|publicPlural$ that match those selectors.
|
||||
func (c *Fake$.type|publicPlural$) List(opts $.ListOptions|raw$) (result *$.type|raw$List, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, c.ns, opts), &$.type|raw$List{})
|
||||
$else$Invokes($.NewRootListAction|raw$($.type|allLowercasePlural$Resource, $.type|allLowercasePlural$Kind, opts), &$.type|raw$List{})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
label, _, _ := $.ExtractFromListOptions|raw$(opts)
|
||||
if label == nil {
|
||||
label = $.Everything|raw$()
|
||||
}
|
||||
list := &$.type|raw$List{ListMeta: obj.(*$.type|raw$List).ListMeta}
|
||||
for _, item := range obj.(*$.type|raw$List).Items {
|
||||
if label.Matches(labels.Set(item.Labels)) {
|
||||
list.Items = append(list.Items, item)
|
||||
}
|
||||
}
|
||||
return list, err
|
||||
}
|
||||
`
|
||||
|
||||
var getTemplate = `
|
||||
// Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any.
|
||||
func (c *Fake$.type|publicPlural$) Get(name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewGetAction|raw$($.type|allLowercasePlural$Resource, c.ns, name), &$.resultType|raw${})
|
||||
$else$Invokes($.NewRootGetAction|raw$($.type|allLowercasePlural$Resource, name), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var getSubresourceTemplate = `
|
||||
// Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any.
|
||||
func (c *Fake$.type|publicPlural$) Get($.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewGetSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, "$.subresourcePath$", $.type|private$Name), &$.resultType|raw${})
|
||||
$else$Invokes($.NewRootGetSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.type|private$Name), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var deleteTemplate = `
|
||||
// Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
|
||||
func (c *Fake$.type|publicPlural$) Delete(name string, options *$.DeleteOptions|raw$) error {
|
||||
_, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewDeleteAction|raw$($.type|allLowercasePlural$Resource, c.ns, name), &$.type|raw${})
|
||||
$else$Invokes($.NewRootDeleteAction|raw$($.type|allLowercasePlural$Resource, name), &$.type|raw${})$end$
|
||||
return err
|
||||
}
|
||||
`
|
||||
|
||||
var deleteCollectionTemplate = `
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *Fake$.type|publicPlural$) DeleteCollection(options *$.DeleteOptions|raw$, listOptions $.ListOptions|raw$) error {
|
||||
$if .namespaced$action := $.NewDeleteCollectionAction|raw$($.type|allLowercasePlural$Resource, c.ns, listOptions)
|
||||
$else$action := $.NewRootDeleteCollectionAction|raw$($.type|allLowercasePlural$Resource, listOptions)
|
||||
$end$
|
||||
_, err := c.Fake.Invokes(action, &$.type|raw$List{})
|
||||
return err
|
||||
}
|
||||
`
|
||||
var createTemplate = `
|
||||
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *Fake$.type|publicPlural$) Create($.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewCreateAction|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$), &$.resultType|raw${})
|
||||
$else$Invokes($.NewRootCreateAction|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var createSubresourceTemplate = `
|
||||
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *Fake$.type|publicPlural$) Create($.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, $.type|private$Name, "$.subresourcePath$", c.ns, $.inputType|private$), &$.resultType|raw${})
|
||||
$else$Invokes($.NewRootCreateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var updateTemplate = `
|
||||
// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *Fake$.type|publicPlural$) Update($.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewUpdateAction|raw$($.inputType|allLowercasePlural$Resource, c.ns, $.inputType|private$), &$.resultType|raw${})
|
||||
$else$Invokes($.NewRootUpdateAction|raw$($.inputType|allLowercasePlural$Resource, $.inputType|private$), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var updateSubresourceTemplate = `
|
||||
// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *Fake$.type|publicPlural$) Update($.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", c.ns, $.inputType|private$), &$.inputType|raw${})
|
||||
$else$Invokes($.NewRootUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "$.subresourcePath$", $.inputType|private$), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var updateStatusTemplate = `
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
func (c *Fake$.type|publicPlural$) UpdateStatus($.type|private$ *$.type|raw$) (*$.type|raw$, error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "status", c.ns, $.type|private$), &$.type|raw${})
|
||||
$else$Invokes($.NewRootUpdateSubresourceAction|raw$($.type|allLowercasePlural$Resource, "status", $.type|private$), &$.type|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.type|raw$), err
|
||||
}
|
||||
`
|
||||
|
||||
var watchTemplate = `
|
||||
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
|
||||
func (c *Fake$.type|publicPlural$) Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
|
||||
return c.Fake.
|
||||
$if .namespaced$InvokesWatch($.NewWatchAction|raw$($.type|allLowercasePlural$Resource, c.ns, opts))
|
||||
$else$InvokesWatch($.NewRootWatchAction|raw$($.type|allLowercasePlural$Resource, opts))$end$
|
||||
}
|
||||
`
|
||||
|
||||
var patchTemplate = `
|
||||
// Patch applies the patch and returns the patched $.resultType|private$.
|
||||
func (c *Fake$.type|publicPlural$) Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.resultType|raw$, err error) {
|
||||
obj, err := c.Fake.
|
||||
$if .namespaced$Invokes($.NewPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, c.ns, name, pt, data, subresources... ), &$.resultType|raw${})
|
||||
$else$Invokes($.NewRootPatchSubresourceAction|raw$($.type|allLowercasePlural$Resource, name, pt, data, subresources...), &$.resultType|raw${})$end$
|
||||
if obj == nil {
|
||||
return nil, err
|
||||
}
|
||||
return obj.(*$.resultType|raw$), err
|
||||
}
|
||||
`
|
178
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go
generated
vendored
Normal file
178
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_clientset.go
generated
vendored
Normal file
|
@ -0,0 +1,178 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genClientset generates a package for a clientset.
|
||||
type genClientset struct {
|
||||
generator.DefaultGen
|
||||
groups []clientgentypes.GroupVersions
|
||||
groupGoNames map[clientgentypes.GroupVersion]string
|
||||
clientsetPackage string
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
clientsetGenerated bool
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genClientset{}
|
||||
|
||||
func (g *genClientset) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
// We only want to call GenerateType() once.
|
||||
func (g *genClientset) Filter(c *generator.Context, t *types.Type) bool {
|
||||
ret := !g.clientsetGenerated
|
||||
g.clientsetGenerated = true
|
||||
return ret
|
||||
}
|
||||
|
||||
func (g *genClientset) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
for _, group := range g.groups {
|
||||
for _, version := range group.Versions {
|
||||
typedClientPath := filepath.Join(g.clientsetPackage, "typed", strings.ToLower(group.PackageName), strings.ToLower(version.NonEmpty()))
|
||||
groupAlias := strings.ToLower(g.groupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}])
|
||||
imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.NonEmpty()), typedClientPath))
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (g *genClientset) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
// TODO: We actually don't need any type information to generate the clientset,
|
||||
// perhaps we can adapt the go2ild framework to this kind of usage.
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
allGroups := clientgentypes.ToGroupVersionInfo(g.groups, g.groupGoNames)
|
||||
m := map[string]interface{}{
|
||||
"allGroups": allGroups,
|
||||
"Config": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}),
|
||||
"DefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "DefaultKubernetesUserAgent"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
|
||||
"DiscoveryInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/discovery", Name: "DiscoveryInterface"}),
|
||||
"DiscoveryClient": c.Universe.Type(types.Name{Package: "k8s.io/client-go/discovery", Name: "DiscoveryClient"}),
|
||||
"NewDiscoveryClientForConfig": c.Universe.Function(types.Name{Package: "k8s.io/client-go/discovery", Name: "NewDiscoveryClientForConfig"}),
|
||||
"NewDiscoveryClientForConfigOrDie": c.Universe.Function(types.Name{Package: "k8s.io/client-go/discovery", Name: "NewDiscoveryClientForConfigOrDie"}),
|
||||
"NewDiscoveryClient": c.Universe.Function(types.Name{Package: "k8s.io/client-go/discovery", Name: "NewDiscoveryClient"}),
|
||||
"flowcontrolNewTokenBucketRateLimiter": c.Universe.Function(types.Name{Package: "k8s.io/client-go/util/flowcontrol", Name: "NewTokenBucketRateLimiter"}),
|
||||
}
|
||||
sw.Do(clientsetInterface, m)
|
||||
sw.Do(clientsetTemplate, m)
|
||||
for _, g := range allGroups {
|
||||
sw.Do(clientsetInterfaceImplTemplate, g)
|
||||
}
|
||||
sw.Do(getDiscoveryTemplate, m)
|
||||
sw.Do(newClientsetForConfigTemplate, m)
|
||||
sw.Do(newClientsetForConfigOrDieTemplate, m)
|
||||
sw.Do(newClientsetForRESTClientTemplate, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var clientsetInterface = `
|
||||
type Interface interface {
|
||||
Discovery() $.DiscoveryInterface|raw$
|
||||
$range .allGroups$$.GroupGoName$$.Version$() $.PackageAlias$.$.GroupGoName$$.Version$Interface
|
||||
$end$
|
||||
}
|
||||
`
|
||||
|
||||
var clientsetTemplate = `
|
||||
// Clientset contains the clients for groups. Each group has exactly one
|
||||
// version included in a Clientset.
|
||||
type Clientset struct {
|
||||
*$.DiscoveryClient|raw$
|
||||
$range .allGroups$$.LowerCaseGroupGoName$$.Version$ *$.PackageAlias$.$.GroupGoName$$.Version$Client
|
||||
$end$
|
||||
}
|
||||
`
|
||||
|
||||
var clientsetInterfaceImplTemplate = `
|
||||
// $.GroupGoName$$.Version$ retrieves the $.GroupGoName$$.Version$Client
|
||||
func (c *Clientset) $.GroupGoName$$.Version$() $.PackageAlias$.$.GroupGoName$$.Version$Interface {
|
||||
return c.$.LowerCaseGroupGoName$$.Version$
|
||||
}
|
||||
`
|
||||
|
||||
var getDiscoveryTemplate = `
|
||||
// Discovery retrieves the DiscoveryClient
|
||||
func (c *Clientset) Discovery() $.DiscoveryInterface|raw$ {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.DiscoveryClient
|
||||
}
|
||||
`
|
||||
|
||||
var newClientsetForConfigTemplate = `
|
||||
// NewForConfig creates a new Clientset for the given config.
|
||||
func NewForConfig(c *$.Config|raw$) (*Clientset, error) {
|
||||
configShallowCopy := *c
|
||||
if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 {
|
||||
configShallowCopy.RateLimiter = $.flowcontrolNewTokenBucketRateLimiter|raw$(configShallowCopy.QPS, configShallowCopy.Burst)
|
||||
}
|
||||
var cs Clientset
|
||||
var err error
|
||||
$range .allGroups$ cs.$.LowerCaseGroupGoName$$.Version$, err =$.PackageAlias$.NewForConfig(&configShallowCopy)
|
||||
if err!=nil {
|
||||
return nil, err
|
||||
}
|
||||
$end$
|
||||
cs.DiscoveryClient, err = $.NewDiscoveryClientForConfig|raw$(&configShallowCopy)
|
||||
if err!=nil {
|
||||
return nil, err
|
||||
}
|
||||
return &cs, nil
|
||||
}
|
||||
`
|
||||
|
||||
var newClientsetForConfigOrDieTemplate = `
|
||||
// NewForConfigOrDie creates a new Clientset for the given config and
|
||||
// panics if there is an error in the config.
|
||||
func NewForConfigOrDie(c *$.Config|raw$) *Clientset {
|
||||
var cs Clientset
|
||||
$range .allGroups$ cs.$.LowerCaseGroupGoName$$.Version$ =$.PackageAlias$.NewForConfigOrDie(c)
|
||||
$end$
|
||||
cs.DiscoveryClient = $.NewDiscoveryClientForConfigOrDie|raw$(c)
|
||||
return &cs
|
||||
}
|
||||
`
|
||||
|
||||
var newClientsetForRESTClientTemplate = `
|
||||
// New creates a new Clientset for the given RESTClient.
|
||||
func New(c $.RESTClientInterface|raw$) *Clientset {
|
||||
var cs Clientset
|
||||
$range .allGroups$ cs.$.LowerCaseGroupGoName$$.Version$ =$.PackageAlias$.New(c)
|
||||
$end$
|
||||
cs.DiscoveryClient = $.NewDiscoveryClient|raw$(c)
|
||||
return &cs
|
||||
}
|
||||
`
|
54
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_expansion.go
generated
vendored
Normal file
54
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_expansion.go
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genExpansion produces a file for a group client, e.g. ExtensionsClient for the extension group.
|
||||
type genExpansion struct {
|
||||
generator.DefaultGen
|
||||
groupPackagePath string
|
||||
// types in a group
|
||||
types []*types.Type
|
||||
}
|
||||
|
||||
// We only want to call GenerateType() once per group.
|
||||
func (g *genExpansion) Filter(c *generator.Context, t *types.Type) bool {
|
||||
return len(g.types) == 0 || t == g.types[0]
|
||||
}
|
||||
|
||||
func (g *genExpansion) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
for _, t := range g.types {
|
||||
if _, err := os.Stat(filepath.Join(g.groupPackagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
|
||||
sw.Do(expansionInterfaceTemplate, t)
|
||||
}
|
||||
}
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var expansionInterfaceTemplate = `
|
||||
type $.|public$Expansion interface {}
|
||||
`
|
247
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go
generated
vendored
Normal file
247
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_group.go
generated
vendored
Normal file
|
@ -0,0 +1,247 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
"k8s.io/code-generator/cmd/client-gen/path"
|
||||
)
|
||||
|
||||
// genGroup produces a file for a group client, e.g. ExtensionsClient for the extension group.
|
||||
type genGroup struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
group string
|
||||
version string
|
||||
groupGoName string
|
||||
apiPath string
|
||||
// types in this group
|
||||
types []*types.Type
|
||||
imports namer.ImportTracker
|
||||
inputPackage string
|
||||
clientsetPackage string
|
||||
// If the genGroup has been called. This generator should only execute once.
|
||||
called bool
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genGroup{}
|
||||
|
||||
// We only want to call GenerateType() once per group.
|
||||
func (g *genGroup) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.called {
|
||||
g.called = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *genGroup) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genGroup) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
imports = append(imports, filepath.Join(g.clientsetPackage, "scheme"))
|
||||
return
|
||||
}
|
||||
|
||||
func (g *genGroup) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
apiPath := func(group string) string {
|
||||
if group == "core" {
|
||||
return `"/api"`
|
||||
}
|
||||
return `"` + g.apiPath + `"`
|
||||
}
|
||||
|
||||
groupName := g.group
|
||||
if g.group == "core" {
|
||||
groupName = ""
|
||||
}
|
||||
// allow user to define a group name that's different from the one parsed from the directory.
|
||||
p := c.Universe.Package(path.Vendorless(g.inputPackage))
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
|
||||
groupName = override[0]
|
||||
}
|
||||
|
||||
m := map[string]interface{}{
|
||||
"group": g.group,
|
||||
"version": g.version,
|
||||
"groupName": groupName,
|
||||
"GroupGoName": g.groupGoName,
|
||||
"Version": namer.IC(g.version),
|
||||
"types": g.types,
|
||||
"apiPath": apiPath(g.group),
|
||||
"schemaGroupVersion": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}),
|
||||
"runtimeAPIVersionInternal": c.Universe.Variable(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "APIVersionInternal"}),
|
||||
"serializerDirectCodecFactory": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/serializer", Name: "DirectCodecFactory"}),
|
||||
"restConfig": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Config"}),
|
||||
"restDefaultKubernetesUserAgent": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "DefaultKubernetesUserAgent"}),
|
||||
"restRESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
|
||||
"restRESTClientFor": c.Universe.Function(types.Name{Package: "k8s.io/client-go/rest", Name: "RESTClientFor"}),
|
||||
"SchemeGroupVersion": c.Universe.Variable(types.Name{Package: path.Vendorless(g.inputPackage), Name: "SchemeGroupVersion"}),
|
||||
}
|
||||
sw.Do(groupInterfaceTemplate, m)
|
||||
sw.Do(groupClientTemplate, m)
|
||||
for _, t := range g.types {
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrapper := map[string]interface{}{
|
||||
"type": t,
|
||||
"GroupGoName": g.groupGoName,
|
||||
"Version": namer.IC(g.version),
|
||||
}
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(getterImplNonNamespaced, wrapper)
|
||||
} else {
|
||||
sw.Do(getterImplNamespaced, wrapper)
|
||||
}
|
||||
}
|
||||
sw.Do(newClientForConfigTemplate, m)
|
||||
sw.Do(newClientForConfigOrDieTemplate, m)
|
||||
sw.Do(newClientForRESTClientTemplate, m)
|
||||
if g.version == "" {
|
||||
sw.Do(setInternalVersionClientDefaultsTemplate, m)
|
||||
} else {
|
||||
sw.Do(setClientDefaultsTemplate, m)
|
||||
}
|
||||
sw.Do(getRESTClient, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var groupInterfaceTemplate = `
|
||||
type $.GroupGoName$$.Version$Interface interface {
|
||||
RESTClient() $.restRESTClientInterface|raw$
|
||||
$range .types$ $.|publicPlural$Getter
|
||||
$end$
|
||||
}
|
||||
`
|
||||
|
||||
var groupClientTemplate = `
|
||||
// $.GroupGoName$$.Version$Client is used to interact with features provided by the $.groupName$ group.
|
||||
type $.GroupGoName$$.Version$Client struct {
|
||||
restClient $.restRESTClientInterface|raw$
|
||||
}
|
||||
`
|
||||
|
||||
var getterImplNamespaced = `
|
||||
func (c *$.GroupGoName$$.Version$Client) $.type|publicPlural$(namespace string) $.type|public$Interface {
|
||||
return new$.type|publicPlural$(c, namespace)
|
||||
}
|
||||
`
|
||||
|
||||
var getterImplNonNamespaced = `
|
||||
func (c *$.GroupGoName$$.Version$Client) $.type|publicPlural$() $.type|public$Interface {
|
||||
return new$.type|publicPlural$(c)
|
||||
}
|
||||
`
|
||||
|
||||
var newClientForConfigTemplate = `
|
||||
// NewForConfig creates a new $.GroupGoName$$.Version$Client for the given config.
|
||||
func NewForConfig(c *$.restConfig|raw$) (*$.GroupGoName$$.Version$Client, error) {
|
||||
config := *c
|
||||
if err := setConfigDefaults(&config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
client, err := $.restRESTClientFor|raw$(&config)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &$.GroupGoName$$.Version$Client{client}, nil
|
||||
}
|
||||
`
|
||||
|
||||
var newClientForConfigOrDieTemplate = `
|
||||
// NewForConfigOrDie creates a new $.GroupGoName$$.Version$Client for the given config and
|
||||
// panics if there is an error in the config.
|
||||
func NewForConfigOrDie(c *$.restConfig|raw$) *$.GroupGoName$$.Version$Client {
|
||||
client, err := NewForConfig(c)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return client
|
||||
}
|
||||
`
|
||||
|
||||
var getRESTClient = `
|
||||
// RESTClient returns a RESTClient that is used to communicate
|
||||
// with API server by this client implementation.
|
||||
func (c *$.GroupGoName$$.Version$Client) RESTClient() $.restRESTClientInterface|raw$ {
|
||||
if c == nil {
|
||||
return nil
|
||||
}
|
||||
return c.restClient
|
||||
}
|
||||
`
|
||||
|
||||
var newClientForRESTClientTemplate = `
|
||||
// New creates a new $.GroupGoName$$.Version$Client for the given RESTClient.
|
||||
func New(c $.restRESTClientInterface|raw$) *$.GroupGoName$$.Version$Client {
|
||||
return &$.GroupGoName$$.Version$Client{c}
|
||||
}
|
||||
`
|
||||
|
||||
var setInternalVersionClientDefaultsTemplate = `
|
||||
func setConfigDefaults(config *$.restConfig|raw$) error {
|
||||
config.APIPath = $.apiPath$
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = $.restDefaultKubernetesUserAgent|raw$()
|
||||
}
|
||||
if config.GroupVersion == nil || config.GroupVersion.Group != scheme.Scheme.PrioritizedVersionsForGroup("$.groupName$")[0].Group {
|
||||
gv := scheme.Scheme.PrioritizedVersionsForGroup("$.groupName$")[0]
|
||||
config.GroupVersion = &gv
|
||||
}
|
||||
config.NegotiatedSerializer = scheme.Codecs
|
||||
|
||||
if config.QPS == 0 {
|
||||
config.QPS = 5
|
||||
}
|
||||
if config.Burst == 0 {
|
||||
config.Burst = 10
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
`
|
||||
|
||||
var setClientDefaultsTemplate = `
|
||||
func setConfigDefaults(config *$.restConfig|raw$) error {
|
||||
gv := $.SchemeGroupVersion|raw$
|
||||
config.GroupVersion = &gv
|
||||
config.APIPath = $.apiPath$
|
||||
config.NegotiatedSerializer = $.serializerDirectCodecFactory|raw${CodecFactory: scheme.Codecs}
|
||||
|
||||
if config.UserAgent == "" {
|
||||
config.UserAgent = $.restDefaultKubernetesUserAgent|raw$()
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
`
|
599
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_type.go
generated
vendored
Normal file
599
vendor/k8s.io/code-generator/cmd/client-gen/generators/generator_for_type.go
generated
vendored
Normal file
|
@ -0,0 +1,599 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
)
|
||||
|
||||
// genClientForType produces a file for each top-level type.
|
||||
type genClientForType struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
clientsetPackage string
|
||||
group string
|
||||
version string
|
||||
groupGoName string
|
||||
typeToMatch *types.Type
|
||||
imports namer.ImportTracker
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genClientForType{}
|
||||
|
||||
// Filter ignores all but one type because we're making a single file per type.
|
||||
func (g *genClientForType) Filter(c *generator.Context, t *types.Type) bool { return t == g.typeToMatch }
|
||||
|
||||
func (g *genClientForType) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genClientForType) Imports(c *generator.Context) (imports []string) {
|
||||
return g.imports.ImportLines()
|
||||
}
|
||||
|
||||
// Ideally, we'd like genStatus to return true if there is a subresource path
|
||||
// registered for "status" in the API server, but we do not have that
|
||||
// information, so genStatus returns true if the type has a status field.
|
||||
func genStatus(t *types.Type) bool {
|
||||
// Default to true if we have a Status member
|
||||
hasStatus := false
|
||||
for _, m := range t.Members {
|
||||
if m.Name == "Status" {
|
||||
hasStatus = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return hasStatus && !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).NoStatus
|
||||
}
|
||||
|
||||
// GenerateType makes the body of a file implementing the individual typed client for type t.
|
||||
func (g *genClientForType) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
pkg := filepath.Base(t.Name.Package)
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
type extendedInterfaceMethod struct {
|
||||
template string
|
||||
args map[string]interface{}
|
||||
}
|
||||
extendedMethods := []extendedInterfaceMethod{}
|
||||
for _, e := range tags.Extensions {
|
||||
inputType := *t
|
||||
resultType := *t
|
||||
// TODO: Extract this to some helper method as this code is copied into
|
||||
// 2 other places.
|
||||
if len(e.InputTypeOverride) > 0 {
|
||||
if name, pkg := e.Input(); len(pkg) > 0 {
|
||||
newType := c.Universe.Type(types.Name{Package: pkg, Name: name})
|
||||
inputType = *newType
|
||||
} else {
|
||||
inputType.Name.Name = e.InputTypeOverride
|
||||
}
|
||||
}
|
||||
if len(e.ResultTypeOverride) > 0 {
|
||||
if name, pkg := e.Result(); len(pkg) > 0 {
|
||||
newType := c.Universe.Type(types.Name{Package: pkg, Name: name})
|
||||
resultType = *newType
|
||||
} else {
|
||||
resultType.Name.Name = e.ResultTypeOverride
|
||||
}
|
||||
}
|
||||
var updatedVerbtemplate string
|
||||
if _, exists := subresourceDefaultVerbTemplates[e.VerbType]; e.IsSubresource() && exists {
|
||||
updatedVerbtemplate = e.VerbName + "(" + strings.TrimPrefix(subresourceDefaultVerbTemplates[e.VerbType], strings.Title(e.VerbType)+"(")
|
||||
} else {
|
||||
updatedVerbtemplate = e.VerbName + "(" + strings.TrimPrefix(defaultVerbTemplates[e.VerbType], strings.Title(e.VerbType)+"(")
|
||||
}
|
||||
extendedMethods = append(extendedMethods, extendedInterfaceMethod{
|
||||
template: updatedVerbtemplate,
|
||||
args: map[string]interface{}{
|
||||
"type": t,
|
||||
"inputType": &inputType,
|
||||
"resultType": &resultType,
|
||||
"DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}),
|
||||
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
|
||||
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
|
||||
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}),
|
||||
},
|
||||
})
|
||||
}
|
||||
m := map[string]interface{}{
|
||||
"type": t,
|
||||
"inputType": t,
|
||||
"resultType": t,
|
||||
"package": pkg,
|
||||
"Package": namer.IC(pkg),
|
||||
"namespaced": !tags.NonNamespaced,
|
||||
"Group": namer.IC(g.group),
|
||||
"subresource": false,
|
||||
"subresourcePath": "",
|
||||
"GroupGoName": g.groupGoName,
|
||||
"Version": namer.IC(g.version),
|
||||
"DeleteOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "DeleteOptions"}),
|
||||
"ListOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}),
|
||||
"GetOptions": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "GetOptions"}),
|
||||
"PatchType": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/types", Name: "PatchType"}),
|
||||
"watchInterface": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}),
|
||||
"RESTClientInterface": c.Universe.Type(types.Name{Package: "k8s.io/client-go/rest", Name: "Interface"}),
|
||||
"schemeParameterCodec": c.Universe.Variable(types.Name{Package: filepath.Join(g.clientsetPackage, "scheme"), Name: "ParameterCodec"}),
|
||||
}
|
||||
|
||||
sw.Do(getterComment, m)
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(getterNonNamespaced, m)
|
||||
} else {
|
||||
sw.Do(getterNamespaced, m)
|
||||
}
|
||||
|
||||
sw.Do(interfaceTemplate1, m)
|
||||
if !tags.NoVerbs {
|
||||
if !genStatus(t) {
|
||||
tags.SkipVerbs = append(tags.SkipVerbs, "updateStatus")
|
||||
}
|
||||
interfaceSuffix := ""
|
||||
if len(extendedMethods) > 0 {
|
||||
interfaceSuffix = "\n"
|
||||
}
|
||||
sw.Do("\n"+generateInterface(tags)+interfaceSuffix, m)
|
||||
// add extended verbs into interface
|
||||
for _, v := range extendedMethods {
|
||||
sw.Do(v.template+interfaceSuffix, v.args)
|
||||
}
|
||||
|
||||
}
|
||||
sw.Do(interfaceTemplate4, m)
|
||||
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(structNonNamespaced, m)
|
||||
sw.Do(newStructNonNamespaced, m)
|
||||
} else {
|
||||
sw.Do(structNamespaced, m)
|
||||
sw.Do(newStructNamespaced, m)
|
||||
}
|
||||
|
||||
if tags.NoVerbs {
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
if tags.HasVerb("get") {
|
||||
sw.Do(getTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("list") {
|
||||
sw.Do(listTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("watch") {
|
||||
sw.Do(watchTemplate, m)
|
||||
}
|
||||
|
||||
if tags.HasVerb("create") {
|
||||
sw.Do(createTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("update") {
|
||||
sw.Do(updateTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("updateStatus") {
|
||||
sw.Do(updateStatusTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("delete") {
|
||||
sw.Do(deleteTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("deleteCollection") {
|
||||
sw.Do(deleteCollectionTemplate, m)
|
||||
}
|
||||
if tags.HasVerb("patch") {
|
||||
sw.Do(patchTemplate, m)
|
||||
}
|
||||
|
||||
// generate expansion methods
|
||||
for _, e := range tags.Extensions {
|
||||
inputType := *t
|
||||
resultType := *t
|
||||
if len(e.InputTypeOverride) > 0 {
|
||||
if name, pkg := e.Input(); len(pkg) > 0 {
|
||||
newType := c.Universe.Type(types.Name{Package: pkg, Name: name})
|
||||
inputType = *newType
|
||||
} else {
|
||||
inputType.Name.Name = e.InputTypeOverride
|
||||
}
|
||||
}
|
||||
if len(e.ResultTypeOverride) > 0 {
|
||||
if name, pkg := e.Result(); len(pkg) > 0 {
|
||||
newType := c.Universe.Type(types.Name{Package: pkg, Name: name})
|
||||
resultType = *newType
|
||||
} else {
|
||||
resultType.Name.Name = e.ResultTypeOverride
|
||||
}
|
||||
}
|
||||
m["inputType"] = &inputType
|
||||
m["resultType"] = &resultType
|
||||
m["subresourcePath"] = e.SubResourcePath
|
||||
|
||||
if e.HasVerb("get") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, getSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, getTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
if e.HasVerb("list") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, listSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, listTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Figure out schemantic for watching a sub-resource.
|
||||
if e.HasVerb("watch") {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, watchTemplate), m)
|
||||
}
|
||||
|
||||
if e.HasVerb("create") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, createSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, createTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
if e.HasVerb("update") {
|
||||
if e.IsSubresource() {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, updateSubresourceTemplate), m)
|
||||
} else {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, updateTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Figure out schemantic for deleting a sub-resource (what arguments
|
||||
// are passed, does it need two names? etc.
|
||||
if e.HasVerb("delete") {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, deleteTemplate), m)
|
||||
}
|
||||
|
||||
if e.HasVerb("patch") {
|
||||
sw.Do(adjustTemplate(e.VerbName, e.VerbType, patchTemplate), m)
|
||||
}
|
||||
}
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
// adjustTemplate adjust the origin verb template using the expansion name.
|
||||
// TODO: Make the verbs in templates parametrized so the strings.Replace() is
|
||||
// not needed.
|
||||
func adjustTemplate(name, verbType, template string) string {
|
||||
return strings.Replace(template, " "+strings.Title(verbType), " "+name, -1)
|
||||
}
|
||||
|
||||
func generateInterface(tags util.Tags) string {
|
||||
// need an ordered list here to guarantee order of generated methods.
|
||||
out := []string{}
|
||||
for _, m := range util.SupportedVerbs {
|
||||
if tags.HasVerb(m) {
|
||||
out = append(out, defaultVerbTemplates[m])
|
||||
}
|
||||
}
|
||||
return strings.Join(out, "\n")
|
||||
}
|
||||
|
||||
var subresourceDefaultVerbTemplates = map[string]string{
|
||||
"create": `Create($.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (*$.resultType|raw$, error)`,
|
||||
"list": `List($.type|private$Name string, opts $.ListOptions|raw$) (*$.resultType|raw$List, error)`,
|
||||
"update": `Update($.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (*$.resultType|raw$, error)`,
|
||||
"get": `Get($.type|private$Name string, options $.GetOptions|raw$) (*$.resultType|raw$, error)`,
|
||||
}
|
||||
|
||||
var defaultVerbTemplates = map[string]string{
|
||||
"create": `Create(*$.inputType|raw$) (*$.resultType|raw$, error)`,
|
||||
"update": `Update(*$.inputType|raw$) (*$.resultType|raw$, error)`,
|
||||
"updateStatus": `UpdateStatus(*$.type|raw$) (*$.type|raw$, error)`,
|
||||
"delete": `Delete(name string, options *$.DeleteOptions|raw$) error`,
|
||||
"deleteCollection": `DeleteCollection(options *$.DeleteOptions|raw$, listOptions $.ListOptions|raw$) error`,
|
||||
"get": `Get(name string, options $.GetOptions|raw$) (*$.resultType|raw$, error)`,
|
||||
"list": `List(opts $.ListOptions|raw$) (*$.resultType|raw$List, error)`,
|
||||
"watch": `Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error)`,
|
||||
"patch": `Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.resultType|raw$, err error)`,
|
||||
}
|
||||
|
||||
// group client will implement this interface.
|
||||
var getterComment = `
|
||||
// $.type|publicPlural$Getter has a method to return a $.type|public$Interface.
|
||||
// A group's client should implement this interface.`
|
||||
|
||||
var getterNamespaced = `
|
||||
type $.type|publicPlural$Getter interface {
|
||||
$.type|publicPlural$(namespace string) $.type|public$Interface
|
||||
}
|
||||
`
|
||||
|
||||
var getterNonNamespaced = `
|
||||
type $.type|publicPlural$Getter interface {
|
||||
$.type|publicPlural$() $.type|public$Interface
|
||||
}
|
||||
`
|
||||
|
||||
// this type's interface, typed client will implement this interface.
|
||||
var interfaceTemplate1 = `
|
||||
// $.type|public$Interface has methods to work with $.type|public$ resources.
|
||||
type $.type|public$Interface interface {`
|
||||
|
||||
var interfaceTemplate4 = `
|
||||
$.type|public$Expansion
|
||||
}
|
||||
`
|
||||
|
||||
// template for the struct that implements the type's interface
|
||||
var structNamespaced = `
|
||||
// $.type|privatePlural$ implements $.type|public$Interface
|
||||
type $.type|privatePlural$ struct {
|
||||
client $.RESTClientInterface|raw$
|
||||
ns string
|
||||
}
|
||||
`
|
||||
|
||||
// template for the struct that implements the type's interface
|
||||
var structNonNamespaced = `
|
||||
// $.type|privatePlural$ implements $.type|public$Interface
|
||||
type $.type|privatePlural$ struct {
|
||||
client $.RESTClientInterface|raw$
|
||||
}
|
||||
`
|
||||
|
||||
var newStructNamespaced = `
|
||||
// new$.type|publicPlural$ returns a $.type|publicPlural$
|
||||
func new$.type|publicPlural$(c *$.GroupGoName$$.Version$Client, namespace string) *$.type|privatePlural$ {
|
||||
return &$.type|privatePlural${
|
||||
client: c.RESTClient(),
|
||||
ns: namespace,
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var newStructNonNamespaced = `
|
||||
// new$.type|publicPlural$ returns a $.type|publicPlural$
|
||||
func new$.type|publicPlural$(c *$.GroupGoName$$.Version$Client) *$.type|privatePlural$ {
|
||||
return &$.type|privatePlural${
|
||||
client: c.RESTClient(),
|
||||
}
|
||||
}
|
||||
`
|
||||
var listTemplate = `
|
||||
// List takes label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
|
||||
func (c *$.type|privatePlural$) List(opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil{
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &$.resultType|raw$List{}
|
||||
err = c.client.Get().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
VersionedParams(&opts, $.schemeParameterCodec|raw$).
|
||||
Timeout(timeout).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var listSubresourceTemplate = `
|
||||
// List takes $.type|raw$ name, label and field selectors, and returns the list of $.resultType|publicPlural$ that match those selectors.
|
||||
func (c *$.type|privatePlural$) List($.type|private$Name string, opts $.ListOptions|raw$) (result *$.resultType|raw$List, err error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil{
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
result = &$.resultType|raw$List{}
|
||||
err = c.client.Get().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name($.type|private$Name).
|
||||
SubResource("$.subresourcePath$").
|
||||
VersionedParams(&opts, $.schemeParameterCodec|raw$).
|
||||
Timeout(timeout).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var getTemplate = `
|
||||
// Get takes name of the $.type|private$, and returns the corresponding $.resultType|private$ object, and an error if there is any.
|
||||
func (c *$.type|privatePlural$) Get(name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Get().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name(name).
|
||||
VersionedParams(&options, $.schemeParameterCodec|raw$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var getSubresourceTemplate = `
|
||||
// Get takes name of the $.type|private$, and returns the corresponding $.resultType|raw$ object, and an error if there is any.
|
||||
func (c *$.type|privatePlural$) Get($.type|private$Name string, options $.GetOptions|raw$) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Get().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name($.type|private$Name).
|
||||
SubResource("$.subresourcePath$").
|
||||
VersionedParams(&options, $.schemeParameterCodec|raw$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var deleteTemplate = `
|
||||
// Delete takes name of the $.type|private$ and deletes it. Returns an error if one occurs.
|
||||
func (c *$.type|privatePlural$) Delete(name string, options *$.DeleteOptions|raw$) error {
|
||||
return c.client.Delete().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name(name).
|
||||
Body(options).
|
||||
Do().
|
||||
Error()
|
||||
}
|
||||
`
|
||||
|
||||
var deleteCollectionTemplate = `
|
||||
// DeleteCollection deletes a collection of objects.
|
||||
func (c *$.type|privatePlural$) DeleteCollection(options *$.DeleteOptions|raw$, listOptions $.ListOptions|raw$) error {
|
||||
var timeout time.Duration
|
||||
if listOptions.TimeoutSeconds != nil{
|
||||
timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second
|
||||
}
|
||||
return c.client.Delete().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
VersionedParams(&listOptions, $.schemeParameterCodec|raw$).
|
||||
Timeout(timeout).
|
||||
Body(options).
|
||||
Do().
|
||||
Error()
|
||||
}
|
||||
`
|
||||
|
||||
var createSubresourceTemplate = `
|
||||
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *$.type|privatePlural$) Create($.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Post().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name($.type|private$Name).
|
||||
SubResource("$.subresourcePath$").
|
||||
Body($.inputType|private$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var createTemplate = `
|
||||
// Create takes the representation of a $.inputType|private$ and creates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *$.type|privatePlural$) Create($.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Post().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Body($.inputType|private$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var updateSubresourceTemplate = `
|
||||
// Update takes the top resource name and the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *$.type|privatePlural$) Update($.type|private$Name string, $.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Put().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name($.type|private$Name).
|
||||
SubResource("$.subresourcePath$").
|
||||
Body($.inputType|private$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var updateTemplate = `
|
||||
// Update takes the representation of a $.inputType|private$ and updates it. Returns the server's representation of the $.resultType|private$, and an error, if there is any.
|
||||
func (c *$.type|privatePlural$) Update($.inputType|private$ *$.inputType|raw$) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Put().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name($.inputType|private$.Name).
|
||||
Body($.inputType|private$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var updateStatusTemplate = `
|
||||
// UpdateStatus was generated because the type contains a Status member.
|
||||
// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus().
|
||||
|
||||
func (c *$.type|privatePlural$) UpdateStatus($.type|private$ *$.type|raw$) (result *$.type|raw$, err error) {
|
||||
result = &$.type|raw${}
|
||||
err = c.client.Put().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
Name($.type|private$.Name).
|
||||
SubResource("status").
|
||||
Body($.type|private$).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
||||
|
||||
var watchTemplate = `
|
||||
// Watch returns a $.watchInterface|raw$ that watches the requested $.type|privatePlural$.
|
||||
func (c *$.type|privatePlural$) Watch(opts $.ListOptions|raw$) ($.watchInterface|raw$, error) {
|
||||
var timeout time.Duration
|
||||
if opts.TimeoutSeconds != nil{
|
||||
timeout = time.Duration(*opts.TimeoutSeconds) * time.Second
|
||||
}
|
||||
opts.Watch = true
|
||||
return c.client.Get().
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
VersionedParams(&opts, $.schemeParameterCodec|raw$).
|
||||
Timeout(timeout).
|
||||
Watch()
|
||||
}
|
||||
`
|
||||
|
||||
var patchTemplate = `
|
||||
// Patch applies the patch and returns the patched $.resultType|private$.
|
||||
func (c *$.type|privatePlural$) Patch(name string, pt $.PatchType|raw$, data []byte, subresources ...string) (result *$.resultType|raw$, err error) {
|
||||
result = &$.resultType|raw${}
|
||||
err = c.client.Patch(pt).
|
||||
$if .namespaced$Namespace(c.ns).$end$
|
||||
Resource("$.type|resource$").
|
||||
SubResource(subresources...).
|
||||
Name(name).
|
||||
Body(data).
|
||||
Do().
|
||||
Into(result)
|
||||
return
|
||||
}
|
||||
`
|
186
vendor/k8s.io/code-generator/cmd/client-gen/generators/scheme/generator_for_scheme.go
generated
vendored
Normal file
186
vendor/k8s.io/code-generator/cmd/client-gen/generators/scheme/generator_for_scheme.go
generated
vendored
Normal file
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 scheme
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/path"
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// GenScheme produces a package for a clientset with the scheme, codecs and parameter codecs.
|
||||
type GenScheme struct {
|
||||
generator.DefaultGen
|
||||
OutputPackage string
|
||||
Groups []clientgentypes.GroupVersions
|
||||
GroupGoNames map[clientgentypes.GroupVersion]string
|
||||
InputPackages map[clientgentypes.GroupVersion]string
|
||||
OutputPath string
|
||||
ImportTracker namer.ImportTracker
|
||||
PrivateScheme bool
|
||||
CreateRegistry bool
|
||||
schemeGenerated bool
|
||||
}
|
||||
|
||||
func (g *GenScheme) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.OutputPackage, g.ImportTracker),
|
||||
}
|
||||
}
|
||||
|
||||
// We only want to call GenerateType() once.
|
||||
func (g *GenScheme) Filter(c *generator.Context, t *types.Type) bool {
|
||||
ret := !g.schemeGenerated
|
||||
g.schemeGenerated = true
|
||||
return ret
|
||||
}
|
||||
|
||||
func (g *GenScheme) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.ImportTracker.ImportLines()...)
|
||||
for _, group := range g.Groups {
|
||||
for _, version := range group.Versions {
|
||||
packagePath := g.InputPackages[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}]
|
||||
groupAlias := strings.ToLower(g.GroupGoNames[clientgentypes.GroupVersion{Group: group.Group, Version: version.Version}])
|
||||
if g.CreateRegistry {
|
||||
// import the install package for internal clientsets instead of the type package with register.go
|
||||
if version.Version != "" {
|
||||
packagePath = filepath.Dir(packagePath)
|
||||
}
|
||||
packagePath = filepath.Join(packagePath, "install")
|
||||
|
||||
imports = append(imports, fmt.Sprintf("%s \"%s\"", groupAlias, path.Vendorless(packagePath)))
|
||||
break
|
||||
} else {
|
||||
imports = append(imports, fmt.Sprintf("%s%s \"%s\"", groupAlias, strings.ToLower(version.Version.NonEmpty()), path.Vendorless(packagePath)))
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (g *GenScheme) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
allGroupVersions := clientgentypes.ToGroupVersionInfo(g.Groups, g.GroupGoNames)
|
||||
allInstallGroups := clientgentypes.ToGroupInstallPackages(g.Groups, g.GroupGoNames)
|
||||
|
||||
m := map[string]interface{}{
|
||||
"allGroupVersions": allGroupVersions,
|
||||
"allInstallGroups": allInstallGroups,
|
||||
"customRegister": false,
|
||||
"runtimeNewParameterCodec": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "NewParameterCodec"}),
|
||||
"runtimeNewScheme": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "NewScheme"}),
|
||||
"serializerNewCodecFactory": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/serializer", Name: "NewCodecFactory"}),
|
||||
"runtimeScheme": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Scheme"}),
|
||||
"runtimeSchemeBuilder": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "SchemeBuilder"}),
|
||||
"runtimeUtilMust": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/util/runtime", Name: "Must"}),
|
||||
"schemaGroupVersion": c.Universe.Type(types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersion"}),
|
||||
"metav1AddToGroupVersion": c.Universe.Function(types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "AddToGroupVersion"}),
|
||||
}
|
||||
globals := map[string]string{
|
||||
"Scheme": "Scheme",
|
||||
"Codecs": "Codecs",
|
||||
"ParameterCodec": "ParameterCodec",
|
||||
"Registry": "Registry",
|
||||
}
|
||||
for k, v := range globals {
|
||||
if g.PrivateScheme {
|
||||
m[k] = strings.ToLower(v[0:1]) + v[1:]
|
||||
} else {
|
||||
m[k] = v
|
||||
}
|
||||
}
|
||||
|
||||
sw.Do(globalsTemplate, m)
|
||||
|
||||
if g.OutputPath != "" {
|
||||
if _, err := os.Stat(filepath.Join(g.OutputPath, strings.ToLower("register_custom.go"))); err == nil {
|
||||
m["customRegister"] = true
|
||||
}
|
||||
}
|
||||
|
||||
if g.CreateRegistry {
|
||||
sw.Do(registryRegistration, m)
|
||||
} else {
|
||||
sw.Do(simpleRegistration, m)
|
||||
}
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var globalsTemplate = `
|
||||
var $.Scheme$ = $.runtimeNewScheme|raw$()
|
||||
var $.Codecs$ = $.serializerNewCodecFactory|raw$($.Scheme$)
|
||||
var $.ParameterCodec$ = $.runtimeNewParameterCodec|raw$($.Scheme$)`
|
||||
|
||||
var registryRegistration = `
|
||||
|
||||
func init() {
|
||||
$.metav1AddToGroupVersion|raw$($.Scheme$, $.schemaGroupVersion|raw${Version: "v1"})
|
||||
Install($.Scheme$)
|
||||
}
|
||||
|
||||
// Install registers the API group and adds types to a scheme
|
||||
func Install(scheme *$.runtimeScheme|raw$) {
|
||||
$- range .allInstallGroups$
|
||||
$.InstallPackageAlias$.Install(scheme)
|
||||
$- end$
|
||||
$if .customRegister$
|
||||
ExtraInstall(scheme)
|
||||
$end -$
|
||||
}
|
||||
`
|
||||
|
||||
var simpleRegistration = `
|
||||
var localSchemeBuilder = $.runtimeSchemeBuilder|raw${
|
||||
$- range .allGroupVersions$
|
||||
$.PackageAlias$.AddToScheme,
|
||||
$- end$
|
||||
$if .customRegister$
|
||||
ExtraAddToScheme,
|
||||
$end -$
|
||||
}
|
||||
|
||||
// AddToScheme adds all types of this clientset into the given scheme. This allows composition
|
||||
// of clientsets, like in:
|
||||
//
|
||||
// import (
|
||||
// "k8s.io/client-go/kubernetes"
|
||||
// clientsetscheme "k8s.io/client-go/kubernetes/scheme"
|
||||
// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme"
|
||||
// )
|
||||
//
|
||||
// kclientset, _ := kubernetes.NewForConfig(c)
|
||||
// _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme)
|
||||
//
|
||||
// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types
|
||||
// correctly.
|
||||
var AddToScheme = localSchemeBuilder.AddToScheme
|
||||
|
||||
func init() {
|
||||
$.metav1AddToGroupVersion|raw$($.Scheme$, $.schemaGroupVersion|raw${Version: "v1"})
|
||||
$.runtimeUtilMust|raw$(AddToScheme($.Scheme$))
|
||||
}
|
||||
`
|
341
vendor/k8s.io/code-generator/cmd/client-gen/generators/util/tags.go
generated
vendored
Normal file
341
vendor/k8s.io/code-generator/cmd/client-gen/generators/util/tags.go
generated
vendored
Normal file
|
@ -0,0 +1,341 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 util
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
var supportedTags = []string{
|
||||
"genclient",
|
||||
"genclient:nonNamespaced",
|
||||
"genclient:noVerbs",
|
||||
"genclient:onlyVerbs",
|
||||
"genclient:skipVerbs",
|
||||
"genclient:noStatus",
|
||||
"genclient:readonly",
|
||||
"genclient:method",
|
||||
}
|
||||
|
||||
// SupportedVerbs is a list of supported verbs for +onlyVerbs and +skipVerbs.
|
||||
var SupportedVerbs = []string{
|
||||
"create",
|
||||
"update",
|
||||
"updateStatus",
|
||||
"delete",
|
||||
"deleteCollection",
|
||||
"get",
|
||||
"list",
|
||||
"watch",
|
||||
"patch",
|
||||
}
|
||||
|
||||
// ReadonlyVerbs represents a list of read-only verbs.
|
||||
var ReadonlyVerbs = []string{
|
||||
"get",
|
||||
"list",
|
||||
"watch",
|
||||
}
|
||||
|
||||
// genClientPrefix is the default prefix for all genclient tags.
|
||||
const genClientPrefix = "genclient:"
|
||||
|
||||
// unsupportedExtensionVerbs is a list of verbs we don't support generating
|
||||
// extension client functions for.
|
||||
var unsupportedExtensionVerbs = []string{
|
||||
"updateStatus",
|
||||
"deleteCollection",
|
||||
"watch",
|
||||
"delete",
|
||||
}
|
||||
|
||||
// inputTypeSupportedVerbs is a list of verb types that supports overriding the
|
||||
// input argument type.
|
||||
var inputTypeSupportedVerbs = []string{
|
||||
"create",
|
||||
"update",
|
||||
}
|
||||
|
||||
// resultTypeSupportedVerbs is a list of verb types that supports overriding the
|
||||
// resulting type.
|
||||
var resultTypeSupportedVerbs = []string{
|
||||
"create",
|
||||
"update",
|
||||
"get",
|
||||
"list",
|
||||
"patch",
|
||||
}
|
||||
|
||||
// Extensions allows to extend the default set of client verbs
|
||||
// (CRUD+watch+patch+list+deleteCollection) for a given type with custom defined
|
||||
// verbs. Custom verbs can have custom input and result types and also allow to
|
||||
// use a sub-resource in a request instead of top-level resource type.
|
||||
//
|
||||
// Example:
|
||||
//
|
||||
// +genclient:method=UpdateScale,verb=update,subresource=scale,input=Scale,result=Scale
|
||||
//
|
||||
// type ReplicaSet struct { ... }
|
||||
//
|
||||
// The 'method=UpdateScale' is the name of the client function.
|
||||
// The 'verb=update' here means the client function will use 'PUT' action.
|
||||
// The 'subresource=scale' means we will use SubResource template to generate this client function.
|
||||
// The 'input' is the input type used for creation (function argument).
|
||||
// The 'result' (not needed in this case) is the result type returned from the
|
||||
// client function.
|
||||
//
|
||||
type extension struct {
|
||||
// VerbName is the name of the custom verb (Scale, Instantiate, etc..)
|
||||
VerbName string
|
||||
// VerbType is the type of the verb (only verbs from SupportedVerbs are
|
||||
// supported)
|
||||
VerbType string
|
||||
// SubResourcePath defines a path to a sub-resource to use in the request.
|
||||
// (optional)
|
||||
SubResourcePath string
|
||||
// InputTypeOverride overrides the input parameter type for the verb. By
|
||||
// default the original type is used. Overriding the input type only works for
|
||||
// "create" and "update" verb types. The given type must exists in the same
|
||||
// package as the original type.
|
||||
// (optional)
|
||||
InputTypeOverride string
|
||||
// ResultTypeOverride overrides the resulting object type for the verb. By
|
||||
// default the original type is used. Overriding the result type works.
|
||||
// (optional)
|
||||
ResultTypeOverride string
|
||||
}
|
||||
|
||||
// IsSubresource indicates if this extension should generate the sub-resource.
|
||||
func (e *extension) IsSubresource() bool {
|
||||
return len(e.SubResourcePath) > 0
|
||||
}
|
||||
|
||||
// HasVerb checks if the extension matches the given verb.
|
||||
func (e *extension) HasVerb(verb string) bool {
|
||||
return e.VerbType == verb
|
||||
}
|
||||
|
||||
// Input returns the input override package path and the type.
|
||||
func (e *extension) Input() (string, string) {
|
||||
parts := strings.Split(e.InputTypeOverride, ".")
|
||||
return parts[len(parts)-1], strings.Join(parts[0:len(parts)-1], ".")
|
||||
}
|
||||
|
||||
// Result returns the result override package path and the type.
|
||||
func (e *extension) Result() (string, string) {
|
||||
parts := strings.Split(e.ResultTypeOverride, ".")
|
||||
return parts[len(parts)-1], strings.Join(parts[0:len(parts)-1], ".")
|
||||
}
|
||||
|
||||
// Tags represents a genclient configuration for a single type.
|
||||
type Tags struct {
|
||||
// +genclient
|
||||
GenerateClient bool
|
||||
// +genclient:nonNamespaced
|
||||
NonNamespaced bool
|
||||
// +genclient:noStatus
|
||||
NoStatus bool
|
||||
// +genclient:noVerbs
|
||||
NoVerbs bool
|
||||
// +genclient:skipVerbs=get,update
|
||||
// +genclient:onlyVerbs=create,delete
|
||||
SkipVerbs []string
|
||||
// +genclient:method=UpdateScale,verb=update,subresource=scale,input=Scale,result=Scale
|
||||
Extensions []extension
|
||||
}
|
||||
|
||||
// HasVerb returns true if we should include the given verb in final client interface and
|
||||
// generate the function for it.
|
||||
func (t Tags) HasVerb(verb string) bool {
|
||||
if len(t.SkipVerbs) == 0 {
|
||||
return true
|
||||
}
|
||||
for _, s := range t.SkipVerbs {
|
||||
if verb == s {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MustParseClientGenTags calls ParseClientGenTags but instead of returning error it panics.
|
||||
func MustParseClientGenTags(lines []string) Tags {
|
||||
tags, err := ParseClientGenTags(lines)
|
||||
if err != nil {
|
||||
panic(err.Error())
|
||||
}
|
||||
return tags
|
||||
}
|
||||
|
||||
// ParseClientGenTags parse the provided genclient tags and validates that no unknown
|
||||
// tags are provided.
|
||||
func ParseClientGenTags(lines []string) (Tags, error) {
|
||||
ret := Tags{}
|
||||
values := types.ExtractCommentTags("+", lines)
|
||||
value := []string{}
|
||||
value, ret.GenerateClient = values["genclient"]
|
||||
// Check the old format and error when used to avoid generating client when //+genclient=false
|
||||
if len(value) > 0 && len(value[0]) > 0 {
|
||||
return ret, fmt.Errorf("+genclient=%s is invalid, use //+genclient if you want to generate client or omit it when you want to disable generation", value)
|
||||
}
|
||||
_, ret.NonNamespaced = values[genClientPrefix+"nonNamespaced"]
|
||||
// Check the old format and error when used
|
||||
if value := values["nonNamespaced"]; len(value) > 0 && len(value[0]) > 0 {
|
||||
return ret, fmt.Errorf("+nonNamespaced=%s is invalid, use //+genclient:nonNamespaced instead", value[0])
|
||||
}
|
||||
_, ret.NoVerbs = values[genClientPrefix+"noVerbs"]
|
||||
_, ret.NoStatus = values[genClientPrefix+"noStatus"]
|
||||
onlyVerbs := []string{}
|
||||
if _, isReadonly := values[genClientPrefix+"readonly"]; isReadonly {
|
||||
onlyVerbs = ReadonlyVerbs
|
||||
}
|
||||
// Check the old format and error when used
|
||||
if value := values["readonly"]; len(value) > 0 && len(value[0]) > 0 {
|
||||
return ret, fmt.Errorf("+readonly=%s is invalid, use //+genclient:readonly instead", value[0])
|
||||
}
|
||||
if v, exists := values[genClientPrefix+"skipVerbs"]; exists {
|
||||
ret.SkipVerbs = strings.Split(v[0], ",")
|
||||
}
|
||||
if v, exists := values[genClientPrefix+"onlyVerbs"]; exists || len(onlyVerbs) > 0 {
|
||||
if len(v) > 0 {
|
||||
onlyVerbs = append(onlyVerbs, strings.Split(v[0], ",")...)
|
||||
}
|
||||
skipVerbs := []string{}
|
||||
for _, m := range SupportedVerbs {
|
||||
skip := true
|
||||
for _, o := range onlyVerbs {
|
||||
if o == m {
|
||||
skip = false
|
||||
break
|
||||
}
|
||||
}
|
||||
// Check for conflicts
|
||||
for _, v := range skipVerbs {
|
||||
if v == m {
|
||||
return ret, fmt.Errorf("verb %q used both in genclient:skipVerbs and genclient:onlyVerbs", v)
|
||||
}
|
||||
}
|
||||
if skip {
|
||||
skipVerbs = append(skipVerbs, m)
|
||||
}
|
||||
}
|
||||
ret.SkipVerbs = skipVerbs
|
||||
}
|
||||
var err error
|
||||
if ret.Extensions, err = parseClientExtensions(values); err != nil {
|
||||
return ret, err
|
||||
}
|
||||
return ret, validateClientGenTags(values)
|
||||
}
|
||||
|
||||
func parseClientExtensions(tags map[string][]string) ([]extension, error) {
|
||||
var ret []extension
|
||||
for name, values := range tags {
|
||||
if !strings.HasPrefix(name, genClientPrefix+"method") {
|
||||
continue
|
||||
}
|
||||
for _, value := range values {
|
||||
// the value comes in this form: "Foo,verb=create"
|
||||
ext := extension{}
|
||||
parts := strings.Split(value, ",")
|
||||
if len(parts) == 0 {
|
||||
return nil, fmt.Errorf("invalid of empty extension verb name: %q", value)
|
||||
}
|
||||
// The first part represents the name of the extension
|
||||
ext.VerbName = parts[0]
|
||||
if len(ext.VerbName) == 0 {
|
||||
return nil, fmt.Errorf("must specify a verb name (// +genclient:method=Foo,verb=create)")
|
||||
}
|
||||
// Parse rest of the arguments
|
||||
params := parts[1:]
|
||||
for _, p := range params {
|
||||
parts := strings.Split(p, "=")
|
||||
if len(parts) != 2 {
|
||||
return nil, fmt.Errorf("invalid extension tag specification %q", p)
|
||||
}
|
||||
key, val := strings.TrimSpace(parts[0]), strings.TrimSpace(parts[1])
|
||||
if len(val) == 0 {
|
||||
return nil, fmt.Errorf("empty value of %q for %q extension", key, ext.VerbName)
|
||||
}
|
||||
switch key {
|
||||
case "verb":
|
||||
ext.VerbType = val
|
||||
case "subresource":
|
||||
ext.SubResourcePath = val
|
||||
case "input":
|
||||
ext.InputTypeOverride = val
|
||||
case "result":
|
||||
ext.ResultTypeOverride = val
|
||||
default:
|
||||
return nil, fmt.Errorf("unknown extension configuration key %q", key)
|
||||
}
|
||||
}
|
||||
// Validate resulting extension configuration
|
||||
if len(ext.VerbType) == 0 {
|
||||
return nil, fmt.Errorf("verb type must be specified (use '// +genclient:method=%s,verb=create')", ext.VerbName)
|
||||
}
|
||||
if len(ext.ResultTypeOverride) > 0 {
|
||||
supported := false
|
||||
for _, v := range resultTypeSupportedVerbs {
|
||||
if ext.VerbType == v {
|
||||
supported = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !supported {
|
||||
return nil, fmt.Errorf("%s: result type is not supported for %q verbs (supported verbs: %#v)", ext.VerbName, ext.VerbType, resultTypeSupportedVerbs)
|
||||
}
|
||||
}
|
||||
if len(ext.InputTypeOverride) > 0 {
|
||||
supported := false
|
||||
for _, v := range inputTypeSupportedVerbs {
|
||||
if ext.VerbType == v {
|
||||
supported = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !supported {
|
||||
return nil, fmt.Errorf("%s: input type is not supported for %q verbs (supported verbs: %#v)", ext.VerbName, ext.VerbType, inputTypeSupportedVerbs)
|
||||
}
|
||||
}
|
||||
for _, t := range unsupportedExtensionVerbs {
|
||||
if ext.VerbType == t {
|
||||
return nil, fmt.Errorf("verb %q is not supported by extension generator", ext.VerbType)
|
||||
}
|
||||
}
|
||||
ret = append(ret, ext)
|
||||
}
|
||||
}
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
// validateTags validates that only supported genclient tags were provided.
|
||||
func validateClientGenTags(values map[string][]string) error {
|
||||
for _, k := range supportedTags {
|
||||
delete(values, k)
|
||||
}
|
||||
for key := range values {
|
||||
if strings.HasPrefix(key, strings.TrimSuffix(genClientPrefix, ":")) {
|
||||
return errors.New("unknown tag detected: " + key)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
66
vendor/k8s.io/code-generator/cmd/client-gen/main.go
generated
vendored
Normal file
66
vendor/k8s.io/code-generator/cmd/client-gen/main.go
generated
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
/*
|
||||
Copyright 2015 The Kubernetes Authors.
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
// client-gen makes the individual typed clients using gengo.
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/client-gen/args"
|
||||
"k8s.io/code-generator/cmd/client-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of client-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/clientset_generated/"
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine, "k8s.io/kubernetes/pkg/apis") // TODO: move this input path out of client-gen
|
||||
flag.Set("logtostderr", "true")
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.Parse()
|
||||
|
||||
// add group version package as input dirs for gengo
|
||||
for _, pkg := range customArgs.Groups {
|
||||
for _, v := range pkg.Versions {
|
||||
genericArgs.InputDirs = append(genericArgs.InputDirs, v.Package)
|
||||
}
|
||||
}
|
||||
|
||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
||||
if err := genericArgs.Execute(
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.Packages,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
}
|
31
vendor/k8s.io/code-generator/cmd/client-gen/path/path.go
generated
vendored
Normal file
31
vendor/k8s.io/code-generator/cmd/client-gen/path/path.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 path
|
||||
|
||||
import "strings"
|
||||
|
||||
// Vendorless removes the longest match of "*/vendor/" from the front of p.
|
||||
// It is useful if a package locates in vendor/, e.g.,
|
||||
// k8s.io/kubernetes/vendor/k8s.io/apimachinery/pkg/apis/meta/v1, because gengo
|
||||
// indexes the package with its import path, e.g.,
|
||||
// k8s.io/apimachinery/pkg/apis/meta/v1,
|
||||
func Vendorless(p string) string {
|
||||
if pos := strings.LastIndex(p, "/vendor/"); pos != -1 {
|
||||
return p[pos+len("/vendor/"):]
|
||||
}
|
||||
return p
|
||||
}
|
121
vendor/k8s.io/code-generator/cmd/client-gen/types/helpers.go
generated
vendored
Normal file
121
vendor/k8s.io/code-generator/cmd/client-gen/types/helpers.go
generated
vendored
Normal file
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/namer"
|
||||
)
|
||||
|
||||
// ToGroupVersion turns "group/version" string into a GroupVersion struct. It reports error
|
||||
// if it cannot parse the string.
|
||||
func ToGroupVersion(gv string) (GroupVersion, error) {
|
||||
// this can be the internal version for the legacy kube types
|
||||
// TODO once we've cleared the last uses as strings, this special case should be removed.
|
||||
if (len(gv) == 0) || (gv == "/") {
|
||||
return GroupVersion{}, nil
|
||||
}
|
||||
|
||||
switch strings.Count(gv, "/") {
|
||||
case 0:
|
||||
return GroupVersion{Group(gv), ""}, nil
|
||||
case 1:
|
||||
i := strings.Index(gv, "/")
|
||||
return GroupVersion{Group(gv[:i]), Version(gv[i+1:])}, nil
|
||||
default:
|
||||
return GroupVersion{}, fmt.Errorf("unexpected GroupVersion string: %v", gv)
|
||||
}
|
||||
}
|
||||
|
||||
type sortableSliceOfVersions []string
|
||||
|
||||
func (a sortableSliceOfVersions) Len() int { return len(a) }
|
||||
func (a sortableSliceOfVersions) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
|
||||
func (a sortableSliceOfVersions) Less(i, j int) bool {
|
||||
vi, vj := strings.TrimLeft(a[i], "v"), strings.TrimLeft(a[j], "v")
|
||||
major := regexp.MustCompile("^[0-9]+")
|
||||
viMajor, vjMajor := major.FindString(vi), major.FindString(vj)
|
||||
viRemaining, vjRemaining := strings.TrimLeft(vi, viMajor), strings.TrimLeft(vj, vjMajor)
|
||||
switch {
|
||||
case len(viRemaining) == 0 && len(vjRemaining) == 0:
|
||||
return viMajor < vjMajor
|
||||
case len(viRemaining) == 0 && len(vjRemaining) != 0:
|
||||
// stable version is greater than unstable version
|
||||
return false
|
||||
case len(viRemaining) != 0 && len(vjRemaining) == 0:
|
||||
// stable version is greater than unstable version
|
||||
return true
|
||||
}
|
||||
// neither are stable versions
|
||||
if viMajor != vjMajor {
|
||||
return viMajor < vjMajor
|
||||
}
|
||||
// assuming at most we have one alpha or one beta version, so if vi contains "alpha", it's the lesser one.
|
||||
return strings.Contains(viRemaining, "alpha")
|
||||
}
|
||||
|
||||
// Determine the default version among versions. If a user calls a group client
|
||||
// without specifying the version (e.g., c.CoreV1(), instead of c.CoreV1()), the
|
||||
// default version will be returned.
|
||||
func defaultVersion(versions []PackageVersion) Version {
|
||||
var versionStrings []string
|
||||
for _, version := range versions {
|
||||
versionStrings = append(versionStrings, version.Version.String())
|
||||
}
|
||||
sort.Sort(sortableSliceOfVersions(versionStrings))
|
||||
return Version(versionStrings[len(versionStrings)-1])
|
||||
}
|
||||
|
||||
// ToGroupVersionInfo is a helper function used by generators for groups.
|
||||
func ToGroupVersionInfo(groups []GroupVersions, groupGoNames map[GroupVersion]string) []GroupVersionInfo {
|
||||
var groupVersionPackages []GroupVersionInfo
|
||||
for _, group := range groups {
|
||||
for _, version := range group.Versions {
|
||||
groupGoName := groupGoNames[GroupVersion{Group: group.Group, Version: version.Version}]
|
||||
groupVersionPackages = append(groupVersionPackages, GroupVersionInfo{
|
||||
Group: Group(namer.IC(group.Group.NonEmpty())),
|
||||
Version: Version(namer.IC(version.Version.String())),
|
||||
PackageAlias: strings.ToLower(groupGoName + version.Version.NonEmpty()),
|
||||
GroupGoName: groupGoName,
|
||||
LowerCaseGroupGoName: namer.IL(groupGoName),
|
||||
})
|
||||
}
|
||||
}
|
||||
return groupVersionPackages
|
||||
}
|
||||
|
||||
func ToGroupInstallPackages(groups []GroupVersions, groupGoNames map[GroupVersion]string) []GroupInstallPackage {
|
||||
var groupInstallPackages []GroupInstallPackage
|
||||
for _, group := range groups {
|
||||
defaultVersion := defaultVersion(group.Versions)
|
||||
groupGoName := groupGoNames[GroupVersion{Group: group.Group, Version: defaultVersion}]
|
||||
groupInstallPackages = append(groupInstallPackages, GroupInstallPackage{
|
||||
Group: Group(namer.IC(group.Group.NonEmpty())),
|
||||
InstallPackageAlias: strings.ToLower(groupGoName),
|
||||
})
|
||||
}
|
||||
return groupInstallPackages
|
||||
}
|
||||
|
||||
// NormalizeGroupVersion calls normalizes the GroupVersion.
|
||||
//func NormalizeGroupVersion(gv GroupVersion) GroupVersion {
|
||||
// return GroupVersion{Group: gv.Group.NonEmpty(), Version: gv.Version, NonEmptyVersion: normalization.Version(gv.Version)}
|
||||
//}
|
75
vendor/k8s.io/code-generator/cmd/client-gen/types/types.go
generated
vendored
Normal file
75
vendor/k8s.io/code-generator/cmd/client-gen/types/types.go
generated
vendored
Normal file
|
@ -0,0 +1,75 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 types
|
||||
|
||||
type Version string
|
||||
|
||||
func (v Version) String() string {
|
||||
return string(v)
|
||||
}
|
||||
|
||||
func (v Version) NonEmpty() string {
|
||||
if v == "" {
|
||||
return "internalVersion"
|
||||
}
|
||||
return v.String()
|
||||
}
|
||||
|
||||
type Group string
|
||||
|
||||
func (g Group) String() string {
|
||||
return string(g)
|
||||
}
|
||||
|
||||
func (g Group) NonEmpty() string {
|
||||
if g == "api" {
|
||||
return "core"
|
||||
}
|
||||
return string(g)
|
||||
}
|
||||
|
||||
type PackageVersion struct {
|
||||
Version
|
||||
// The fully qualified package, e.g. k8s.io/kubernetes/pkg/apis/apps, where the types.go is found.
|
||||
Package string
|
||||
}
|
||||
|
||||
type GroupVersion struct {
|
||||
Group Group
|
||||
Version Version
|
||||
}
|
||||
|
||||
type GroupVersions struct {
|
||||
// The name of the package for this group, e.g. apps.
|
||||
PackageName string
|
||||
Group Group
|
||||
Versions []PackageVersion
|
||||
}
|
||||
|
||||
// GroupVersionInfo contains all the info around a group version.
|
||||
type GroupVersionInfo struct {
|
||||
Group Group
|
||||
Version Version
|
||||
PackageAlias string
|
||||
GroupGoName string
|
||||
LowerCaseGroupGoName string
|
||||
}
|
||||
|
||||
type GroupInstallPackage struct {
|
||||
Group Group
|
||||
InstallPackageAlias string
|
||||
}
|
77
vendor/k8s.io/code-generator/cmd/informer-gen/args/args.go
generated
vendored
Normal file
77
vendor/k8s.io/code-generator/cmd/informer-gen/args/args.go
generated
vendored
Normal file
|
@ -0,0 +1,77 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 args
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
codegenutil "k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
)
|
||||
|
||||
// CustomArgs is used by the gengo framework to pass args specific to this generator.
|
||||
type CustomArgs struct {
|
||||
VersionedClientSetPackage string
|
||||
InternalClientSetPackage string
|
||||
ListersPackage string
|
||||
SingleDirectory bool
|
||||
}
|
||||
|
||||
// NewDefaults returns default arguments for the generator.
|
||||
func NewDefaults() (*args.GeneratorArgs, *CustomArgs) {
|
||||
genericArgs := args.Default().WithoutDefaultFlagParsing()
|
||||
customArgs := &CustomArgs{
|
||||
SingleDirectory: false,
|
||||
}
|
||||
genericArgs.CustomArgs = customArgs
|
||||
|
||||
if pkg := codegenutil.CurrentPackage(); len(pkg) != 0 {
|
||||
genericArgs.OutputPackagePath = path.Join(pkg, "pkg/client/informers")
|
||||
customArgs.VersionedClientSetPackage = path.Join(pkg, "pkg/client/clientset/versioned")
|
||||
customArgs.InternalClientSetPackage = path.Join(pkg, "pkg/client/clientset/internalversion")
|
||||
customArgs.ListersPackage = path.Join(pkg, "pkg/client/listers")
|
||||
}
|
||||
|
||||
return genericArgs, customArgs
|
||||
}
|
||||
|
||||
// AddFlags add the generator flags to the flag set.
|
||||
func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {
|
||||
fs.StringVar(&ca.InternalClientSetPackage, "internal-clientset-package", ca.InternalClientSetPackage, "the full package name for the internal clientset to use")
|
||||
fs.StringVar(&ca.VersionedClientSetPackage, "versioned-clientset-package", ca.VersionedClientSetPackage, "the full package name for the versioned clientset to use")
|
||||
fs.StringVar(&ca.ListersPackage, "listers-package", ca.ListersPackage, "the full package name for the listers to use")
|
||||
fs.BoolVar(&ca.SingleDirectory, "single-directory", ca.SingleDirectory, "if true, omit the intermediate \"internalversion\" and \"externalversions\" subdirectories")
|
||||
}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
func Validate(genericArgs *args.GeneratorArgs) error {
|
||||
customArgs := genericArgs.CustomArgs.(*CustomArgs)
|
||||
|
||||
if len(genericArgs.OutputPackagePath) == 0 {
|
||||
return fmt.Errorf("output package cannot be empty")
|
||||
}
|
||||
if len(customArgs.VersionedClientSetPackage) == 0 {
|
||||
return fmt.Errorf("versioned clientset package cannot be empty")
|
||||
}
|
||||
if len(customArgs.ListersPackage) == 0 {
|
||||
return fmt.Errorf("listers package cannot be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
258
vendor/k8s.io/code-generator/cmd/informer-gen/generators/factory.go
generated
vendored
Normal file
258
vendor/k8s.io/code-generator/cmd/informer-gen/generators/factory.go
generated
vendored
Normal file
|
@ -0,0 +1,258 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path"
|
||||
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// factoryGenerator produces a file of listers for a given GroupVersion and
|
||||
// type.
|
||||
type factoryGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
groupVersions map[string]clientgentypes.GroupVersions
|
||||
gvGoNames map[string]string
|
||||
clientSetPackage string
|
||||
internalInterfacesPackage string
|
||||
filtered bool
|
||||
}
|
||||
|
||||
var _ generator.Generator = &factoryGenerator{}
|
||||
|
||||
func (g *factoryGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.filtered {
|
||||
g.filtered = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *factoryGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *factoryGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (g *factoryGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
||||
|
||||
klog.V(5).Infof("processing type %v", t)
|
||||
|
||||
gvInterfaces := make(map[string]*types.Type)
|
||||
gvNewFuncs := make(map[string]*types.Type)
|
||||
for groupPkgName := range g.groupVersions {
|
||||
gvInterfaces[groupPkgName] = c.Universe.Type(types.Name{Package: path.Join(g.outputPackage, groupPkgName), Name: "Interface"})
|
||||
gvNewFuncs[groupPkgName] = c.Universe.Function(types.Name{Package: path.Join(g.outputPackage, groupPkgName), Name: "New"})
|
||||
}
|
||||
m := map[string]interface{}{
|
||||
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
|
||||
"groupVersions": g.groupVersions,
|
||||
"gvInterfaces": gvInterfaces,
|
||||
"gvNewFuncs": gvNewFuncs,
|
||||
"gvGoNames": g.gvGoNames,
|
||||
"interfacesNewInformerFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "NewInformerFunc"}),
|
||||
"interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}),
|
||||
"informerFactoryInterface": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}),
|
||||
"clientSetInterface": c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"}),
|
||||
"reflectType": c.Universe.Type(reflectType),
|
||||
"runtimeObject": c.Universe.Type(runtimeObject),
|
||||
"schemaGroupVersionResource": c.Universe.Type(schemaGroupVersionResource),
|
||||
"syncMutex": c.Universe.Type(syncMutex),
|
||||
"timeDuration": c.Universe.Type(timeDuration),
|
||||
"namespaceAll": c.Universe.Type(metav1NamespaceAll),
|
||||
"object": c.Universe.Type(metav1Object),
|
||||
}
|
||||
|
||||
sw.Do(sharedInformerFactoryStruct, m)
|
||||
sw.Do(sharedInformerFactoryInterface, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var sharedInformerFactoryStruct = `
|
||||
// SharedInformerOption defines the functional option type for SharedInformerFactory.
|
||||
type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory
|
||||
|
||||
type sharedInformerFactory struct {
|
||||
client {{.clientSetInterface|raw}}
|
||||
namespace string
|
||||
tweakListOptions {{.interfacesTweakListOptionsFunc|raw}}
|
||||
lock {{.syncMutex|raw}}
|
||||
defaultResync {{.timeDuration|raw}}
|
||||
customResync map[{{.reflectType|raw}}]{{.timeDuration|raw}}
|
||||
|
||||
informers map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}
|
||||
// startedInformers is used for tracking which informers have been started.
|
||||
// This allows Start() to be called multiple times safely.
|
||||
startedInformers map[{{.reflectType|raw}}]bool
|
||||
}
|
||||
|
||||
// WithCustomResyncConfig sets a custom resync period for the specified informer types.
|
||||
func WithCustomResyncConfig(resyncConfig map[{{.object|raw}}]{{.timeDuration|raw}}) SharedInformerOption {
|
||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
||||
for k, v := range resyncConfig {
|
||||
factory.customResync[reflect.TypeOf(k)] = v
|
||||
}
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory.
|
||||
func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption {
|
||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
||||
factory.tweakListOptions = tweakListOptions
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
// WithNamespace limits the SharedInformerFactory to the specified namespace.
|
||||
func WithNamespace(namespace string) SharedInformerOption {
|
||||
return func(factory *sharedInformerFactory) *sharedInformerFactory {
|
||||
factory.namespace = namespace
|
||||
return factory
|
||||
}
|
||||
}
|
||||
|
||||
// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces.
|
||||
func NewSharedInformerFactory(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}) SharedInformerFactory {
|
||||
return NewSharedInformerFactoryWithOptions(client, defaultResync)
|
||||
}
|
||||
|
||||
// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory.
|
||||
// Listers obtained via this SharedInformerFactory will be subject to the same filters
|
||||
// as specified here.
|
||||
// Deprecated: Please use NewSharedInformerFactoryWithOptions instead
|
||||
func NewFilteredSharedInformerFactory(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, namespace string, tweakListOptions {{.interfacesTweakListOptionsFunc|raw}}) SharedInformerFactory {
|
||||
return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions))
|
||||
}
|
||||
|
||||
// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options.
|
||||
func NewSharedInformerFactoryWithOptions(client {{.clientSetInterface|raw}}, defaultResync {{.timeDuration|raw}}, options ...SharedInformerOption) SharedInformerFactory {
|
||||
factory := &sharedInformerFactory{
|
||||
client: client,
|
||||
namespace: v1.NamespaceAll,
|
||||
defaultResync: defaultResync,
|
||||
informers: make(map[{{.reflectType|raw}}]{{.cacheSharedIndexInformer|raw}}),
|
||||
startedInformers: make(map[{{.reflectType|raw}}]bool),
|
||||
customResync: make(map[{{.reflectType|raw}}]{{.timeDuration|raw}}),
|
||||
}
|
||||
|
||||
// Apply all options
|
||||
for _, opt := range options {
|
||||
factory = opt(factory)
|
||||
}
|
||||
|
||||
return factory
|
||||
}
|
||||
|
||||
// Start initializes all requested informers.
|
||||
func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) {
|
||||
f.lock.Lock()
|
||||
defer f.lock.Unlock()
|
||||
|
||||
for informerType, informer := range f.informers {
|
||||
if !f.startedInformers[informerType] {
|
||||
go informer.Run(stopCh)
|
||||
f.startedInformers[informerType] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// WaitForCacheSync waits for all started informers' cache were synced.
|
||||
func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool {
|
||||
informers := func()map[reflect.Type]cache.SharedIndexInformer{
|
||||
f.lock.Lock()
|
||||
defer f.lock.Unlock()
|
||||
|
||||
informers := map[reflect.Type]cache.SharedIndexInformer{}
|
||||
for informerType, informer := range f.informers {
|
||||
if f.startedInformers[informerType] {
|
||||
informers[informerType] = informer
|
||||
}
|
||||
}
|
||||
return informers
|
||||
}()
|
||||
|
||||
res := map[reflect.Type]bool{}
|
||||
for informType, informer := range informers {
|
||||
res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// InternalInformerFor returns the SharedIndexInformer for obj using an internal
|
||||
// client.
|
||||
func (f *sharedInformerFactory) InformerFor(obj {{.runtimeObject|raw}}, newFunc {{.interfacesNewInformerFunc|raw}}) {{.cacheSharedIndexInformer|raw}} {
|
||||
f.lock.Lock()
|
||||
defer f.lock.Unlock()
|
||||
|
||||
informerType := reflect.TypeOf(obj)
|
||||
informer, exists := f.informers[informerType]
|
||||
if exists {
|
||||
return informer
|
||||
}
|
||||
|
||||
resyncPeriod, exists := f.customResync[informerType]
|
||||
if !exists {
|
||||
resyncPeriod = f.defaultResync
|
||||
}
|
||||
|
||||
informer = newFunc(f.client, resyncPeriod)
|
||||
f.informers[informerType] = informer
|
||||
|
||||
return informer
|
||||
}
|
||||
|
||||
`
|
||||
|
||||
var sharedInformerFactoryInterface = `
|
||||
// SharedInformerFactory provides shared informers for resources in all known
|
||||
// API group versions.
|
||||
type SharedInformerFactory interface {
|
||||
{{.informerFactoryInterface|raw}}
|
||||
ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericInformer, error)
|
||||
WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool
|
||||
|
||||
{{$gvInterfaces := .gvInterfaces}}
|
||||
{{$gvGoNames := .gvGoNames}}
|
||||
{{range $groupName, $group := .groupVersions}}{{index $gvGoNames $groupName}}() {{index $gvInterfaces $groupName|raw}}
|
||||
{{end}}
|
||||
}
|
||||
|
||||
{{$gvNewFuncs := .gvNewFuncs}}
|
||||
{{$gvGoNames := .gvGoNames}}
|
||||
{{range $groupPkgName, $group := .groupVersions}}
|
||||
func (f *sharedInformerFactory) {{index $gvGoNames $groupPkgName}}() {{index $gvInterfaces $groupPkgName|raw}} {
|
||||
return {{index $gvNewFuncs $groupPkgName|raw}}(f, f.namespace, f.tweakListOptions)
|
||||
}
|
||||
{{end}}
|
||||
`
|
90
vendor/k8s.io/code-generator/cmd/informer-gen/generators/factoryinterface.go
generated
vendored
Normal file
90
vendor/k8s.io/code-generator/cmd/informer-gen/generators/factoryinterface.go
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// factoryInterfaceGenerator produces a file of interfaces used to break a dependency cycle for
|
||||
// informer registration
|
||||
type factoryInterfaceGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
clientSetPackage string
|
||||
filtered bool
|
||||
}
|
||||
|
||||
var _ generator.Generator = &factoryInterfaceGenerator{}
|
||||
|
||||
func (g *factoryInterfaceGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.filtered {
|
||||
g.filtered = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *factoryInterfaceGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *factoryInterfaceGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (g *factoryInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
||||
|
||||
klog.V(5).Infof("processing type %v", t)
|
||||
|
||||
m := map[string]interface{}{
|
||||
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
|
||||
"clientSetPackage": c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"}),
|
||||
"runtimeObject": c.Universe.Type(runtimeObject),
|
||||
"timeDuration": c.Universe.Type(timeDuration),
|
||||
"v1ListOptions": c.Universe.Type(v1ListOptions),
|
||||
}
|
||||
|
||||
sw.Do(externalSharedInformerFactoryInterface, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var externalSharedInformerFactoryInterface = `
|
||||
// NewInformerFunc takes {{.clientSetPackage|raw}} and {{.timeDuration|raw}} to return a SharedIndexInformer.
|
||||
type NewInformerFunc func({{.clientSetPackage|raw}}, {{.timeDuration|raw}}) cache.SharedIndexInformer
|
||||
|
||||
// SharedInformerFactory a small interface to allow for adding an informer without an import cycle
|
||||
type SharedInformerFactory interface {
|
||||
Start(stopCh <-chan struct{})
|
||||
InformerFor(obj {{.runtimeObject|raw}}, newFunc NewInformerFunc) {{.cacheSharedIndexInformer|raw}}
|
||||
}
|
||||
|
||||
// TweakListOptionsFunc is a function that transforms a {{.v1ListOptions|raw}}.
|
||||
type TweakListOptionsFunc func(*{{.v1ListOptions|raw}})
|
||||
`
|
184
vendor/k8s.io/code-generator/cmd/informer-gen/generators/generic.go
generated
vendored
Normal file
184
vendor/k8s.io/code-generator/cmd/informer-gen/generators/generic.go
generated
vendored
Normal file
|
@ -0,0 +1,184 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
codegennamer "k8s.io/code-generator/pkg/namer"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// genericGenerator generates the generic informer.
|
||||
type genericGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
groupVersions map[string]clientgentypes.GroupVersions
|
||||
groupGoNames map[string]string
|
||||
typesForGroupVersion map[clientgentypes.GroupVersion][]*types.Type
|
||||
filtered bool
|
||||
}
|
||||
|
||||
var _ generator.Generator = &genericGenerator{}
|
||||
|
||||
func (g *genericGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.filtered {
|
||||
g.filtered = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *genericGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
pluralExceptions := map[string]string{
|
||||
"Endpoints": "Endpoints",
|
||||
}
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
"allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions),
|
||||
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
|
||||
"resource": codegennamer.NewTagOverrideNamer("resourceName", namer.NewAllLowercasePluralNamer(pluralExceptions)),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *genericGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
imports = append(imports, "fmt")
|
||||
return
|
||||
}
|
||||
|
||||
type group struct {
|
||||
GroupGoName string
|
||||
Name string
|
||||
Versions []*version
|
||||
}
|
||||
|
||||
type groupSort []group
|
||||
|
||||
func (g groupSort) Len() int { return len(g) }
|
||||
func (g groupSort) Less(i, j int) bool { return strings.ToLower(g[i].Name) < strings.ToLower(g[j].Name) }
|
||||
func (g groupSort) Swap(i, j int) { g[i], g[j] = g[j], g[i] }
|
||||
|
||||
type version struct {
|
||||
Name string
|
||||
GoName string
|
||||
Resources []*types.Type
|
||||
}
|
||||
|
||||
type versionSort []*version
|
||||
|
||||
func (v versionSort) Len() int { return len(v) }
|
||||
func (v versionSort) Less(i, j int) bool {
|
||||
return strings.ToLower(v[i].Name) < strings.ToLower(v[j].Name)
|
||||
}
|
||||
func (v versionSort) Swap(i, j int) { v[i], v[j] = v[j], v[i] }
|
||||
|
||||
func (g *genericGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "{{", "}}")
|
||||
|
||||
groups := []group{}
|
||||
schemeGVs := make(map[*version]*types.Type)
|
||||
|
||||
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
|
||||
for groupPackageName, groupVersions := range g.groupVersions {
|
||||
group := group{
|
||||
GroupGoName: g.groupGoNames[groupPackageName],
|
||||
Name: groupVersions.Group.NonEmpty(),
|
||||
Versions: []*version{},
|
||||
}
|
||||
for _, v := range groupVersions.Versions {
|
||||
gv := clientgentypes.GroupVersion{Group: groupVersions.Group, Version: v.Version}
|
||||
version := &version{
|
||||
Name: v.Version.NonEmpty(),
|
||||
GoName: namer.IC(v.Version.NonEmpty()),
|
||||
Resources: orderer.OrderTypes(g.typesForGroupVersion[gv]),
|
||||
}
|
||||
func() {
|
||||
schemeGVs[version] = c.Universe.Variable(types.Name{Package: g.typesForGroupVersion[gv][0].Name.Package, Name: "SchemeGroupVersion"})
|
||||
}()
|
||||
group.Versions = append(group.Versions, version)
|
||||
}
|
||||
sort.Sort(versionSort(group.Versions))
|
||||
groups = append(groups, group)
|
||||
}
|
||||
sort.Sort(groupSort(groups))
|
||||
|
||||
m := map[string]interface{}{
|
||||
"cacheGenericLister": c.Universe.Type(cacheGenericLister),
|
||||
"cacheNewGenericLister": c.Universe.Function(cacheNewGenericLister),
|
||||
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
|
||||
"groups": groups,
|
||||
"schemeGVs": schemeGVs,
|
||||
"schemaGroupResource": c.Universe.Type(schemaGroupResource),
|
||||
"schemaGroupVersionResource": c.Universe.Type(schemaGroupVersionResource),
|
||||
}
|
||||
|
||||
sw.Do(genericInformer, m)
|
||||
sw.Do(forResource, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var genericInformer = `
|
||||
// GenericInformer is type of SharedIndexInformer which will locate and delegate to other
|
||||
// sharedInformers based on type
|
||||
type GenericInformer interface {
|
||||
Informer() {{.cacheSharedIndexInformer|raw}}
|
||||
Lister() {{.cacheGenericLister|raw}}
|
||||
}
|
||||
|
||||
type genericInformer struct {
|
||||
informer {{.cacheSharedIndexInformer|raw}}
|
||||
resource {{.schemaGroupResource|raw}}
|
||||
}
|
||||
|
||||
// Informer returns the SharedIndexInformer.
|
||||
func (f *genericInformer) Informer() {{.cacheSharedIndexInformer|raw}} {
|
||||
return f.informer
|
||||
}
|
||||
|
||||
// Lister returns the GenericLister.
|
||||
func (f *genericInformer) Lister() {{.cacheGenericLister|raw}} {
|
||||
return {{.cacheNewGenericLister|raw}}(f.Informer().GetIndexer(), f.resource)
|
||||
}
|
||||
`
|
||||
|
||||
var forResource = `
|
||||
// ForResource gives generic access to a shared informer of the matching type
|
||||
// TODO extend this to unknown resources with a client pool
|
||||
func (f *sharedInformerFactory) ForResource(resource {{.schemaGroupVersionResource|raw}}) (GenericInformer, error) {
|
||||
switch resource {
|
||||
{{range $group := .groups -}}{{$GroupGoName := .GroupGoName -}}
|
||||
{{range $version := .Versions -}}
|
||||
// Group={{$group.Name}}, Version={{.Name}}
|
||||
{{range .Resources -}}
|
||||
case {{index $.schemeGVs $version|raw}}.WithResource("{{.|resource}}"):
|
||||
return &genericInformer{resource: resource.GroupResource(), informer: f.{{$GroupGoName}}().{{$version.GoName}}().{{.|publicPlural}}().Informer()}, nil
|
||||
{{end}}
|
||||
{{end}}
|
||||
{{end -}}
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("no informer found for %v", resource)
|
||||
}
|
||||
`
|
118
vendor/k8s.io/code-generator/cmd/informer-gen/generators/groupinterface.go
generated
vendored
Normal file
118
vendor/k8s.io/code-generator/cmd/informer-gen/generators/groupinterface.go
generated
vendored
Normal file
|
@ -0,0 +1,118 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// groupInterfaceGenerator generates the per-group interface file.
|
||||
type groupInterfaceGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
groupVersions clientgentypes.GroupVersions
|
||||
filtered bool
|
||||
internalInterfacesPackage string
|
||||
}
|
||||
|
||||
var _ generator.Generator = &groupInterfaceGenerator{}
|
||||
|
||||
func (g *groupInterfaceGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.filtered {
|
||||
g.filtered = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *groupInterfaceGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *groupInterfaceGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
return
|
||||
}
|
||||
|
||||
type versionData struct {
|
||||
Name string
|
||||
Interface *types.Type
|
||||
New *types.Type
|
||||
}
|
||||
|
||||
func (g *groupInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
versions := make([]versionData, 0, len(g.groupVersions.Versions))
|
||||
for _, version := range g.groupVersions.Versions {
|
||||
gv := clientgentypes.GroupVersion{Group: g.groupVersions.Group, Version: version.Version}
|
||||
versionPackage := filepath.Join(g.outputPackage, strings.ToLower(gv.Version.NonEmpty()))
|
||||
iface := c.Universe.Type(types.Name{Package: versionPackage, Name: "Interface"})
|
||||
versions = append(versions, versionData{
|
||||
Name: namer.IC(version.Version.NonEmpty()),
|
||||
Interface: iface,
|
||||
New: c.Universe.Function(types.Name{Package: versionPackage, Name: "New"}),
|
||||
})
|
||||
}
|
||||
m := map[string]interface{}{
|
||||
"interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}),
|
||||
"interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}),
|
||||
"versions": versions,
|
||||
}
|
||||
|
||||
sw.Do(groupTemplate, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var groupTemplate = `
|
||||
// Interface provides access to each of this group's versions.
|
||||
type Interface interface {
|
||||
$range .versions -$
|
||||
// $.Name$ provides access to shared informers for resources in $.Name$.
|
||||
$.Name$() $.Interface|raw$
|
||||
$end$
|
||||
}
|
||||
|
||||
type group struct {
|
||||
factory $.interfacesSharedInformerFactory|raw$
|
||||
namespace string
|
||||
tweakListOptions $.interfacesTweakListOptionsFunc|raw$
|
||||
}
|
||||
|
||||
// New returns a new Interface.
|
||||
func New(f $.interfacesSharedInformerFactory|raw$, namespace string, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) Interface {
|
||||
return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
|
||||
}
|
||||
|
||||
$range .versions$
|
||||
// $.Name$ returns a new $.Interface|raw$.
|
||||
func (g *group) $.Name$() $.Interface|raw$ {
|
||||
return $.New|raw$(g.factory, g.namespace, g.tweakListOptions)
|
||||
}
|
||||
$end$
|
||||
`
|
186
vendor/k8s.io/code-generator/cmd/informer-gen/generators/informer.go
generated
vendored
Normal file
186
vendor/k8s.io/code-generator/cmd/informer-gen/generators/informer.go
generated
vendored
Normal file
|
@ -0,0 +1,186 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// informerGenerator produces a file of listers for a given GroupVersion and
|
||||
// type.
|
||||
type informerGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
groupPkgName string
|
||||
groupVersion clientgentypes.GroupVersion
|
||||
groupGoName string
|
||||
typeToGenerate *types.Type
|
||||
imports namer.ImportTracker
|
||||
clientSetPackage string
|
||||
listersPackage string
|
||||
internalInterfacesPackage string
|
||||
}
|
||||
|
||||
var _ generator.Generator = &informerGenerator{}
|
||||
|
||||
func (g *informerGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
return t == g.typeToGenerate
|
||||
}
|
||||
|
||||
func (g *informerGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *informerGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
klog.V(5).Infof("processing type %v", t)
|
||||
|
||||
listerPackage := fmt.Sprintf("%s/%s/%s", g.listersPackage, g.groupPkgName, strings.ToLower(g.groupVersion.Version.NonEmpty()))
|
||||
clientSetInterface := c.Universe.Type(types.Name{Package: g.clientSetPackage, Name: "Interface"})
|
||||
informerFor := "InformerFor"
|
||||
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
m := map[string]interface{}{
|
||||
"apiScheme": c.Universe.Type(apiScheme),
|
||||
"cacheIndexers": c.Universe.Type(cacheIndexers),
|
||||
"cacheListWatch": c.Universe.Type(cacheListWatch),
|
||||
"cacheMetaNamespaceIndexFunc": c.Universe.Function(cacheMetaNamespaceIndexFunc),
|
||||
"cacheNamespaceIndex": c.Universe.Variable(cacheNamespaceIndex),
|
||||
"cacheNewSharedIndexInformer": c.Universe.Function(cacheNewSharedIndexInformer),
|
||||
"cacheSharedIndexInformer": c.Universe.Type(cacheSharedIndexInformer),
|
||||
"clientSetInterface": clientSetInterface,
|
||||
"group": namer.IC(g.groupGoName),
|
||||
"informerFor": informerFor,
|
||||
"interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}),
|
||||
"interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}),
|
||||
"listOptions": c.Universe.Type(listOptions),
|
||||
"lister": c.Universe.Type(types.Name{Package: listerPackage, Name: t.Name.Name + "Lister"}),
|
||||
"namespaceAll": c.Universe.Type(metav1NamespaceAll),
|
||||
"namespaced": !tags.NonNamespaced,
|
||||
"newLister": c.Universe.Function(types.Name{Package: listerPackage, Name: "New" + t.Name.Name + "Lister"}),
|
||||
"runtimeObject": c.Universe.Type(runtimeObject),
|
||||
"timeDuration": c.Universe.Type(timeDuration),
|
||||
"type": t,
|
||||
"v1ListOptions": c.Universe.Type(v1ListOptions),
|
||||
"version": namer.IC(g.groupVersion.Version.String()),
|
||||
"watchInterface": c.Universe.Type(watchInterface),
|
||||
}
|
||||
|
||||
sw.Do(typeInformerInterface, m)
|
||||
sw.Do(typeInformerStruct, m)
|
||||
sw.Do(typeInformerPublicConstructor, m)
|
||||
sw.Do(typeFilteredInformerPublicConstructor, m)
|
||||
sw.Do(typeInformerConstructor, m)
|
||||
sw.Do(typeInformerInformer, m)
|
||||
sw.Do(typeInformerLister, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var typeInformerInterface = `
|
||||
// $.type|public$Informer provides access to a shared informer and lister for
|
||||
// $.type|publicPlural$.
|
||||
type $.type|public$Informer interface {
|
||||
Informer() $.cacheSharedIndexInformer|raw$
|
||||
Lister() $.lister|raw$
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerStruct = `
|
||||
type $.type|private$Informer struct {
|
||||
factory $.interfacesSharedInformerFactory|raw$
|
||||
tweakListOptions $.interfacesTweakListOptionsFunc|raw$
|
||||
$if .namespaced$namespace string$end$
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerPublicConstructor = `
|
||||
// New$.type|public$Informer constructs a new informer for $.type|public$ type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func New$.type|public$Informer(client $.clientSetInterface|raw$$if .namespaced$, namespace string$end$, resyncPeriod $.timeDuration|raw$, indexers $.cacheIndexers|raw$) $.cacheSharedIndexInformer|raw$ {
|
||||
return NewFiltered$.type|public$Informer(client$if .namespaced$, namespace$end$, resyncPeriod, indexers, nil)
|
||||
}
|
||||
`
|
||||
|
||||
var typeFilteredInformerPublicConstructor = `
|
||||
// NewFiltered$.type|public$Informer constructs a new informer for $.type|public$ type.
|
||||
// Always prefer using an informer factory to get a shared informer instead of getting an independent
|
||||
// one. This reduces memory footprint and number of connections to the server.
|
||||
func NewFiltered$.type|public$Informer(client $.clientSetInterface|raw$$if .namespaced$, namespace string$end$, resyncPeriod $.timeDuration|raw$, indexers $.cacheIndexers|raw$, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) $.cacheSharedIndexInformer|raw$ {
|
||||
return $.cacheNewSharedIndexInformer|raw$(
|
||||
&$.cacheListWatch|raw${
|
||||
ListFunc: func(options $.v1ListOptions|raw$) ($.runtimeObject|raw$, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).List(options)
|
||||
},
|
||||
WatchFunc: func(options $.v1ListOptions|raw$) ($.watchInterface|raw$, error) {
|
||||
if tweakListOptions != nil {
|
||||
tweakListOptions(&options)
|
||||
}
|
||||
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch(options)
|
||||
},
|
||||
},
|
||||
&$.type|raw${},
|
||||
resyncPeriod,
|
||||
indexers,
|
||||
)
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerConstructor = `
|
||||
func (f *$.type|private$Informer) defaultInformer(client $.clientSetInterface|raw$, resyncPeriod $.timeDuration|raw$) $.cacheSharedIndexInformer|raw$ {
|
||||
return NewFiltered$.type|public$Informer(client$if .namespaced$, f.namespace$end$, resyncPeriod, $.cacheIndexers|raw${$.cacheNamespaceIndex|raw$: $.cacheMetaNamespaceIndexFunc|raw$}, f.tweakListOptions)
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerInformer = `
|
||||
func (f *$.type|private$Informer) Informer() $.cacheSharedIndexInformer|raw$ {
|
||||
return f.factory.$.informerFor$(&$.type|raw${}, f.defaultInformer)
|
||||
}
|
||||
`
|
||||
|
||||
var typeInformerLister = `
|
||||
func (f *$.type|private$Informer) Lister() $.lister|raw$ {
|
||||
return $.newLister|raw$(f.Informer().GetIndexer())
|
||||
}
|
||||
`
|
352
vendor/k8s.io/code-generator/cmd/informer-gen/generators/packages.go
generated
vendored
Normal file
352
vendor/k8s.io/code-generator/cmd/informer-gen/generators/packages.go
generated
vendored
Normal file
|
@ -0,0 +1,352 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/klog"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
informergenargs "k8s.io/code-generator/cmd/informer-gen/args"
|
||||
)
|
||||
|
||||
// NameSystems returns the name system used by the generators in this package.
|
||||
func NameSystems() namer.NameSystems {
|
||||
pluralExceptions := map[string]string{
|
||||
"Endpoints": "Endpoints",
|
||||
}
|
||||
return namer.NameSystems{
|
||||
"public": namer.NewPublicNamer(0),
|
||||
"private": namer.NewPrivateNamer(0),
|
||||
"raw": namer.NewRawNamer("", nil),
|
||||
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
|
||||
"allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions),
|
||||
"lowercaseSingular": &lowercaseSingularNamer{},
|
||||
}
|
||||
}
|
||||
|
||||
// lowercaseSingularNamer implements Namer
|
||||
type lowercaseSingularNamer struct{}
|
||||
|
||||
// Name returns t's name in all lowercase.
|
||||
func (n *lowercaseSingularNamer) Name(t *types.Type) string {
|
||||
return strings.ToLower(t.Name.Name)
|
||||
}
|
||||
|
||||
// DefaultNameSystem returns the default name system for ordering the types to be
|
||||
// processed by the generators in this package.
|
||||
func DefaultNameSystem() string {
|
||||
return "public"
|
||||
}
|
||||
|
||||
// objectMetaForPackage returns the type of ObjectMeta used by package p.
|
||||
func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
|
||||
generatingForPackage := false
|
||||
for _, t := range p.Types {
|
||||
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
|
||||
continue
|
||||
}
|
||||
generatingForPackage = true
|
||||
for _, member := range t.Members {
|
||||
if member.Name == "ObjectMeta" {
|
||||
return member.Type, isInternal(member), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if generatingForPackage {
|
||||
return nil, false, fmt.Errorf("unable to find ObjectMeta for any types in package %s", p.Path)
|
||||
}
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
// isInternal returns true if the tags for a member do not contain a json tag
|
||||
func isInternal(m types.Member) bool {
|
||||
return !strings.Contains(m.Tags, "json")
|
||||
}
|
||||
|
||||
func packageForInternalInterfaces(base string) string {
|
||||
return filepath.Join(base, "internalinterfaces")
|
||||
}
|
||||
|
||||
func vendorless(p string) string {
|
||||
if pos := strings.LastIndex(p, "/vendor/"); pos != -1 {
|
||||
return p[pos+len("/vendor/"):]
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
||||
// Packages makes the client package definition.
|
||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
customArgs, ok := arguments.CustomArgs.(*informergenargs.CustomArgs)
|
||||
if !ok {
|
||||
klog.Fatalf("Wrong CustomArgs type: %T", arguments.CustomArgs)
|
||||
}
|
||||
|
||||
internalVersionPackagePath := filepath.Join(arguments.OutputPackagePath)
|
||||
externalVersionPackagePath := filepath.Join(arguments.OutputPackagePath)
|
||||
if !customArgs.SingleDirectory {
|
||||
internalVersionPackagePath = filepath.Join(arguments.OutputPackagePath, "internalversion")
|
||||
externalVersionPackagePath = filepath.Join(arguments.OutputPackagePath, "externalversions")
|
||||
}
|
||||
|
||||
var packageList generator.Packages
|
||||
typesForGroupVersion := make(map[clientgentypes.GroupVersion][]*types.Type)
|
||||
|
||||
externalGroupVersions := make(map[string]clientgentypes.GroupVersions)
|
||||
internalGroupVersions := make(map[string]clientgentypes.GroupVersions)
|
||||
groupGoNames := make(map[string]string)
|
||||
for _, inputDir := range arguments.InputDirs {
|
||||
p := context.Universe.Package(vendorless(inputDir))
|
||||
|
||||
objectMeta, internal, err := objectMetaForPackage(p)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
if objectMeta == nil {
|
||||
// no types in this package had genclient
|
||||
continue
|
||||
}
|
||||
|
||||
var gv clientgentypes.GroupVersion
|
||||
var targetGroupVersions map[string]clientgentypes.GroupVersions
|
||||
|
||||
if internal {
|
||||
lastSlash := strings.LastIndex(p.Path, "/")
|
||||
if lastSlash == -1 {
|
||||
klog.Fatalf("error constructing internal group version for package %q", p.Path)
|
||||
}
|
||||
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
|
||||
targetGroupVersions = internalGroupVersions
|
||||
} else {
|
||||
parts := strings.Split(p.Path, "/")
|
||||
gv.Group = clientgentypes.Group(parts[len(parts)-2])
|
||||
gv.Version = clientgentypes.Version(parts[len(parts)-1])
|
||||
targetGroupVersions = externalGroupVersions
|
||||
}
|
||||
groupPackageName := gv.Group.NonEmpty()
|
||||
gvPackage := path.Clean(p.Path)
|
||||
|
||||
// If there's a comment of the form "// +groupName=somegroup" or
|
||||
// "// +groupName=somegroup.foo.bar.io", use the first field (somegroup) as the name of the
|
||||
// group when generating.
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
|
||||
gv.Group = clientgentypes.Group(override[0])
|
||||
}
|
||||
|
||||
// If there's a comment of the form "// +groupGoName=SomeUniqueShortName", use that as
|
||||
// the Go group identifier in CamelCase. It defaults
|
||||
groupGoNames[groupPackageName] = namer.IC(strings.Split(gv.Group.NonEmpty(), ".")[0])
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupGoName"]; override != nil {
|
||||
groupGoNames[groupPackageName] = namer.IC(override[0])
|
||||
}
|
||||
|
||||
var typesToGenerate []*types.Type
|
||||
for _, t := range p.Types {
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if !tags.GenerateClient || tags.NoVerbs || !tags.HasVerb("list") || !tags.HasVerb("watch") {
|
||||
continue
|
||||
}
|
||||
|
||||
typesToGenerate = append(typesToGenerate, t)
|
||||
|
||||
if _, ok := typesForGroupVersion[gv]; !ok {
|
||||
typesForGroupVersion[gv] = []*types.Type{}
|
||||
}
|
||||
typesForGroupVersion[gv] = append(typesForGroupVersion[gv], t)
|
||||
}
|
||||
if len(typesToGenerate) == 0 {
|
||||
continue
|
||||
}
|
||||
|
||||
groupVersionsEntry, ok := targetGroupVersions[groupPackageName]
|
||||
if !ok {
|
||||
groupVersionsEntry = clientgentypes.GroupVersions{
|
||||
PackageName: groupPackageName,
|
||||
Group: gv.Group,
|
||||
}
|
||||
}
|
||||
groupVersionsEntry.Versions = append(groupVersionsEntry.Versions, clientgentypes.PackageVersion{Version: gv.Version, Package: gvPackage})
|
||||
targetGroupVersions[groupPackageName] = groupVersionsEntry
|
||||
|
||||
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
|
||||
typesToGenerate = orderer.OrderTypes(typesToGenerate)
|
||||
|
||||
if internal {
|
||||
packageList = append(packageList, versionPackage(internalVersionPackagePath, groupPackageName, gv, groupGoNames[groupPackageName], boilerplate, typesToGenerate, customArgs.InternalClientSetPackage, customArgs.ListersPackage))
|
||||
} else {
|
||||
packageList = append(packageList, versionPackage(externalVersionPackagePath, groupPackageName, gv, groupGoNames[groupPackageName], boilerplate, typesToGenerate, customArgs.VersionedClientSetPackage, customArgs.ListersPackage))
|
||||
}
|
||||
}
|
||||
|
||||
if len(externalGroupVersions) != 0 {
|
||||
packageList = append(packageList, factoryInterfacePackage(externalVersionPackagePath, boilerplate, customArgs.VersionedClientSetPackage))
|
||||
packageList = append(packageList, factoryPackage(externalVersionPackagePath, boilerplate, groupGoNames, externalGroupVersions, customArgs.VersionedClientSetPackage, typesForGroupVersion))
|
||||
for _, gvs := range externalGroupVersions {
|
||||
packageList = append(packageList, groupPackage(externalVersionPackagePath, gvs, boilerplate))
|
||||
}
|
||||
}
|
||||
|
||||
if len(internalGroupVersions) != 0 {
|
||||
packageList = append(packageList, factoryInterfacePackage(internalVersionPackagePath, boilerplate, customArgs.InternalClientSetPackage))
|
||||
packageList = append(packageList, factoryPackage(internalVersionPackagePath, boilerplate, groupGoNames, internalGroupVersions, customArgs.InternalClientSetPackage, typesForGroupVersion))
|
||||
for _, gvs := range internalGroupVersions {
|
||||
packageList = append(packageList, groupPackage(internalVersionPackagePath, gvs, boilerplate))
|
||||
}
|
||||
}
|
||||
|
||||
return packageList
|
||||
}
|
||||
|
||||
func factoryPackage(basePackage string, boilerplate []byte, groupGoNames map[string]string, groupVersions map[string]clientgentypes.GroupVersions, clientSetPackage string, typesForGroupVersion map[clientgentypes.GroupVersion][]*types.Type) generator.Package {
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: filepath.Base(basePackage),
|
||||
PackagePath: basePackage,
|
||||
HeaderText: boilerplate,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = append(generators, &factoryGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "factory",
|
||||
},
|
||||
outputPackage: basePackage,
|
||||
imports: generator.NewImportTracker(),
|
||||
groupVersions: groupVersions,
|
||||
clientSetPackage: clientSetPackage,
|
||||
internalInterfacesPackage: packageForInternalInterfaces(basePackage),
|
||||
gvGoNames: groupGoNames,
|
||||
})
|
||||
|
||||
generators = append(generators, &genericGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "generic",
|
||||
},
|
||||
outputPackage: basePackage,
|
||||
imports: generator.NewImportTracker(),
|
||||
groupVersions: groupVersions,
|
||||
typesForGroupVersion: typesForGroupVersion,
|
||||
groupGoNames: groupGoNames,
|
||||
})
|
||||
|
||||
return generators
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func factoryInterfacePackage(basePackage string, boilerplate []byte, clientSetPackage string) generator.Package {
|
||||
packagePath := packageForInternalInterfaces(basePackage)
|
||||
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: filepath.Base(packagePath),
|
||||
PackagePath: packagePath,
|
||||
HeaderText: boilerplate,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = append(generators, &factoryInterfaceGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "factory_interfaces",
|
||||
},
|
||||
outputPackage: packagePath,
|
||||
imports: generator.NewImportTracker(),
|
||||
clientSetPackage: clientSetPackage,
|
||||
})
|
||||
|
||||
return generators
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func groupPackage(basePackage string, groupVersions clientgentypes.GroupVersions, boilerplate []byte) generator.Package {
|
||||
packagePath := filepath.Join(basePackage, groupVersions.PackageName)
|
||||
groupPkgName := strings.Split(string(groupVersions.Group), ".")[0]
|
||||
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: groupPkgName,
|
||||
PackagePath: packagePath,
|
||||
HeaderText: boilerplate,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = append(generators, &groupInterfaceGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "interface",
|
||||
},
|
||||
outputPackage: packagePath,
|
||||
groupVersions: groupVersions,
|
||||
imports: generator.NewImportTracker(),
|
||||
internalInterfacesPackage: packageForInternalInterfaces(basePackage),
|
||||
})
|
||||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func versionPackage(basePackage string, groupPkgName string, gv clientgentypes.GroupVersion, groupGoName string, boilerplate []byte, typesToGenerate []*types.Type, clientSetPackage, listersPackage string) generator.Package {
|
||||
packagePath := filepath.Join(basePackage, groupPkgName, strings.ToLower(gv.Version.NonEmpty()))
|
||||
|
||||
return &generator.DefaultPackage{
|
||||
PackageName: strings.ToLower(gv.Version.NonEmpty()),
|
||||
PackagePath: packagePath,
|
||||
HeaderText: boilerplate,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = append(generators, &versionInterfaceGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "interface",
|
||||
},
|
||||
outputPackage: packagePath,
|
||||
imports: generator.NewImportTracker(),
|
||||
types: typesToGenerate,
|
||||
internalInterfacesPackage: packageForInternalInterfaces(basePackage),
|
||||
})
|
||||
|
||||
for _, t := range typesToGenerate {
|
||||
generators = append(generators, &informerGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: strings.ToLower(t.Name.Name),
|
||||
},
|
||||
outputPackage: packagePath,
|
||||
groupPkgName: groupPkgName,
|
||||
groupVersion: gv,
|
||||
groupGoName: groupGoName,
|
||||
typeToGenerate: t,
|
||||
imports: generator.NewImportTracker(),
|
||||
clientSetPackage: clientSetPackage,
|
||||
listersPackage: listersPackage,
|
||||
internalInterfacesPackage: packageForInternalInterfaces(basePackage),
|
||||
})
|
||||
}
|
||||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("watch")
|
||||
},
|
||||
}
|
||||
}
|
33
vendor/k8s.io/code-generator/cmd/informer-gen/generators/tags.go
generated
vendored
Normal file
33
vendor/k8s.io/code-generator/cmd/informer-gen/generators/tags.go
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||
// it exists, the value is boolean. If the tag did not exist, it returns
|
||||
// false.
|
||||
func extractBoolTagOrDie(key string, lines []string) bool {
|
||||
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
return val
|
||||
}
|
42
vendor/k8s.io/code-generator/cmd/informer-gen/generators/types.go
generated
vendored
Normal file
42
vendor/k8s.io/code-generator/cmd/informer-gen/generators/types.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import "k8s.io/gengo/types"
|
||||
|
||||
var (
|
||||
apiScheme = types.Name{Package: "k8s.io/kubernetes/pkg/api/legacyscheme", Name: "Scheme"}
|
||||
cacheGenericLister = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "GenericLister"}
|
||||
cacheIndexers = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "Indexers"}
|
||||
cacheListWatch = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "ListWatch"}
|
||||
cacheMetaNamespaceIndexFunc = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "MetaNamespaceIndexFunc"}
|
||||
cacheNamespaceIndex = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NamespaceIndex"}
|
||||
cacheNewGenericLister = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NewGenericLister"}
|
||||
cacheNewSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "NewSharedIndexInformer"}
|
||||
cacheSharedIndexInformer = types.Name{Package: "k8s.io/client-go/tools/cache", Name: "SharedIndexInformer"}
|
||||
listOptions = types.Name{Package: "k8s.io/kubernetes/pkg/apis/core", Name: "ListOptions"}
|
||||
reflectType = types.Name{Package: "reflect", Name: "Type"}
|
||||
runtimeObject = types.Name{Package: "k8s.io/apimachinery/pkg/runtime", Name: "Object"}
|
||||
schemaGroupResource = types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupResource"}
|
||||
schemaGroupVersionResource = types.Name{Package: "k8s.io/apimachinery/pkg/runtime/schema", Name: "GroupVersionResource"}
|
||||
syncMutex = types.Name{Package: "sync", Name: "Mutex"}
|
||||
timeDuration = types.Name{Package: "time", Name: "Duration"}
|
||||
v1ListOptions = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "ListOptions"}
|
||||
metav1NamespaceAll = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "NamespaceAll"}
|
||||
metav1Object = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "Object"}
|
||||
watchInterface = types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}
|
||||
)
|
109
vendor/k8s.io/code-generator/cmd/informer-gen/generators/versioninterface.go
generated
vendored
Normal file
109
vendor/k8s.io/code-generator/cmd/informer-gen/generators/versioninterface.go
generated
vendored
Normal file
|
@ -0,0 +1,109 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
)
|
||||
|
||||
// versionInterfaceGenerator generates the per-version interface file.
|
||||
type versionInterfaceGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
imports namer.ImportTracker
|
||||
types []*types.Type
|
||||
filtered bool
|
||||
internalInterfacesPackage string
|
||||
}
|
||||
|
||||
var _ generator.Generator = &versionInterfaceGenerator{}
|
||||
|
||||
func (g *versionInterfaceGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
if !g.filtered {
|
||||
g.filtered = true
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (g *versionInterfaceGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *versionInterfaceGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
return
|
||||
}
|
||||
|
||||
func (g *versionInterfaceGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
m := map[string]interface{}{
|
||||
"interfacesTweakListOptionsFunc": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "TweakListOptionsFunc"}),
|
||||
"interfacesSharedInformerFactory": c.Universe.Type(types.Name{Package: g.internalInterfacesPackage, Name: "SharedInformerFactory"}),
|
||||
"types": g.types,
|
||||
}
|
||||
|
||||
sw.Do(versionTemplate, m)
|
||||
for _, typeDef := range g.types {
|
||||
tags, err := util.ParseClientGenTags(typeDef.SecondClosestCommentLines)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m["namespaced"] = !tags.NonNamespaced
|
||||
m["type"] = typeDef
|
||||
sw.Do(versionFuncTemplate, m)
|
||||
}
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var versionTemplate = `
|
||||
// Interface provides access to all the informers in this group version.
|
||||
type Interface interface {
|
||||
$range .types -$
|
||||
// $.|publicPlural$ returns a $.|public$Informer.
|
||||
$.|publicPlural$() $.|public$Informer
|
||||
$end$
|
||||
}
|
||||
|
||||
type version struct {
|
||||
factory $.interfacesSharedInformerFactory|raw$
|
||||
namespace string
|
||||
tweakListOptions $.interfacesTweakListOptionsFunc|raw$
|
||||
}
|
||||
|
||||
// New returns a new Interface.
|
||||
func New(f $.interfacesSharedInformerFactory|raw$, namespace string, tweakListOptions $.interfacesTweakListOptionsFunc|raw$) Interface {
|
||||
return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions}
|
||||
}
|
||||
`
|
||||
|
||||
var versionFuncTemplate = `
|
||||
// $.type|publicPlural$ returns a $.type|public$Informer.
|
||||
func (v *version) $.type|publicPlural$() $.type|public$Informer {
|
||||
return &$.type|private$Informer{factory: v.factory$if .namespaced$, namespace: v.namespace$end$, tweakListOptions: v.tweakListOptions}
|
||||
}
|
||||
`
|
63
vendor/k8s.io/code-generator/cmd/informer-gen/main.go
generated
vendored
Normal file
63
vendor/k8s.io/code-generator/cmd/informer-gen/main.go
generated
vendored
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/code-generator/cmd/informer-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/informer-gen/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move out of informer-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/informers/informers_generated"
|
||||
customArgs.VersionedClientSetPackage = "k8s.io/kubernetes/pkg/client/clientset_generated/clientset"
|
||||
customArgs.InternalClientSetPackage = "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
|
||||
customArgs.ListersPackage = "k8s.io/kubernetes/pkg/client/listers"
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine)
|
||||
flag.Set("logtostderr", "true")
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.Parse()
|
||||
|
||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
||||
// Run it.
|
||||
if err := genericArgs.Execute(
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.Packages,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
klog.V(2).Info("Completed successfully.")
|
||||
}
|
1
vendor/k8s.io/code-generator/cmd/lister-gen/.import-restrictions
generated
vendored
Normal file
1
vendor/k8s.io/code-generator/cmd/lister-gen/.import-restrictions
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
{}
|
56
vendor/k8s.io/code-generator/cmd/lister-gen/args/args.go
generated
vendored
Normal file
56
vendor/k8s.io/code-generator/cmd/lister-gen/args/args.go
generated
vendored
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
Copyright 2017 The Kubernetes Authors.
|
||||
|
||||
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 args
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"path"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
codegenutil "k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
)
|
||||
|
||||
// CustomArgs is used by the gengo framework to pass args specific to this generator.
|
||||
type CustomArgs struct{}
|
||||
|
||||
// NewDefaults returns default arguments for the generator.
|
||||
func NewDefaults() (*args.GeneratorArgs, *CustomArgs) {
|
||||
genericArgs := args.Default().WithoutDefaultFlagParsing()
|
||||
customArgs := &CustomArgs{}
|
||||
genericArgs.CustomArgs = customArgs
|
||||
|
||||
if pkg := codegenutil.CurrentPackage(); len(pkg) != 0 {
|
||||
genericArgs.OutputPackagePath = path.Join(pkg, "pkg/client/listers")
|
||||
}
|
||||
|
||||
return genericArgs, customArgs
|
||||
}
|
||||
|
||||
// AddFlags add the generator flags to the flag set.
|
||||
func (ca *CustomArgs) AddFlags(fs *pflag.FlagSet) {}
|
||||
|
||||
// Validate checks the given arguments.
|
||||
func Validate(genericArgs *args.GeneratorArgs) error {
|
||||
_ = genericArgs.CustomArgs.(*CustomArgs)
|
||||
|
||||
if len(genericArgs.OutputPackagePath) == 0 {
|
||||
return fmt.Errorf("output package cannot be empty")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
67
vendor/k8s.io/code-generator/cmd/lister-gen/generators/expansion.go
generated
vendored
Normal file
67
vendor/k8s.io/code-generator/cmd/lister-gen/generators/expansion.go
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
)
|
||||
|
||||
// expansionGenerator produces a file for a expansion interfaces.
|
||||
type expansionGenerator struct {
|
||||
generator.DefaultGen
|
||||
packagePath string
|
||||
types []*types.Type
|
||||
}
|
||||
|
||||
// We only want to call GenerateType() once per group.
|
||||
func (g *expansionGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
return t == g.types[0]
|
||||
}
|
||||
|
||||
func (g *expansionGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
for _, t := range g.types {
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if _, err := os.Stat(filepath.Join(g.packagePath, strings.ToLower(t.Name.Name+"_expansion.go"))); os.IsNotExist(err) {
|
||||
sw.Do(expansionInterfaceTemplate, t)
|
||||
if !tags.NonNamespaced {
|
||||
sw.Do(namespacedExpansionInterfaceTemplate, t)
|
||||
}
|
||||
}
|
||||
}
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var expansionInterfaceTemplate = `
|
||||
// $.|public$ListerExpansion allows custom methods to be added to
|
||||
// $.|public$Lister.
|
||||
type $.|public$ListerExpansion interface {}
|
||||
`
|
||||
|
||||
var namespacedExpansionInterfaceTemplate = `
|
||||
// $.|public$NamespaceListerExpansion allows custom methods to be added to
|
||||
// $.|public$NamespaceLister.
|
||||
type $.|public$NamespaceListerExpansion interface {}
|
||||
`
|
371
vendor/k8s.io/code-generator/cmd/lister-gen/generators/lister.go
generated
vendored
Normal file
371
vendor/k8s.io/code-generator/cmd/lister-gen/generators/lister.go
generated
vendored
Normal file
|
@ -0,0 +1,371 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/gengo/generator"
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
|
||||
"k8s.io/code-generator/cmd/client-gen/generators/util"
|
||||
clientgentypes "k8s.io/code-generator/cmd/client-gen/types"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// NameSystems returns the name system used by the generators in this package.
|
||||
func NameSystems() namer.NameSystems {
|
||||
pluralExceptions := map[string]string{
|
||||
"Endpoints": "Endpoints",
|
||||
}
|
||||
return namer.NameSystems{
|
||||
"public": namer.NewPublicNamer(0),
|
||||
"private": namer.NewPrivateNamer(0),
|
||||
"raw": namer.NewRawNamer("", nil),
|
||||
"publicPlural": namer.NewPublicPluralNamer(pluralExceptions),
|
||||
"allLowercasePlural": namer.NewAllLowercasePluralNamer(pluralExceptions),
|
||||
"lowercaseSingular": &lowercaseSingularNamer{},
|
||||
}
|
||||
}
|
||||
|
||||
// lowercaseSingularNamer implements Namer
|
||||
type lowercaseSingularNamer struct{}
|
||||
|
||||
// Name returns t's name in all lowercase.
|
||||
func (n *lowercaseSingularNamer) Name(t *types.Type) string {
|
||||
return strings.ToLower(t.Name.Name)
|
||||
}
|
||||
|
||||
// DefaultNameSystem returns the default name system for ordering the types to be
|
||||
// processed by the generators in this package.
|
||||
func DefaultNameSystem() string {
|
||||
return "public"
|
||||
}
|
||||
|
||||
// Packages makes the client package definition.
|
||||
func Packages(context *generator.Context, arguments *args.GeneratorArgs) generator.Packages {
|
||||
boilerplate, err := arguments.LoadGoBoilerplate()
|
||||
if err != nil {
|
||||
klog.Fatalf("Failed loading boilerplate: %v", err)
|
||||
}
|
||||
|
||||
var packageList generator.Packages
|
||||
for _, inputDir := range arguments.InputDirs {
|
||||
p := context.Universe.Package(inputDir)
|
||||
|
||||
objectMeta, internal, err := objectMetaForPackage(p)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
if objectMeta == nil {
|
||||
// no types in this package had genclient
|
||||
continue
|
||||
}
|
||||
|
||||
var gv clientgentypes.GroupVersion
|
||||
var internalGVPkg string
|
||||
|
||||
if internal {
|
||||
lastSlash := strings.LastIndex(p.Path, "/")
|
||||
if lastSlash == -1 {
|
||||
klog.Fatalf("error constructing internal group version for package %q", p.Path)
|
||||
}
|
||||
gv.Group = clientgentypes.Group(p.Path[lastSlash+1:])
|
||||
internalGVPkg = p.Path
|
||||
} else {
|
||||
parts := strings.Split(p.Path, "/")
|
||||
gv.Group = clientgentypes.Group(parts[len(parts)-2])
|
||||
gv.Version = clientgentypes.Version(parts[len(parts)-1])
|
||||
|
||||
internalGVPkg = strings.Join(parts[0:len(parts)-1], "/")
|
||||
}
|
||||
groupPackageName := strings.ToLower(gv.Group.NonEmpty())
|
||||
|
||||
// If there's a comment of the form "// +groupName=somegroup" or
|
||||
// "// +groupName=somegroup.foo.bar.io", use the first field (somegroup) as the name of the
|
||||
// group when generating.
|
||||
if override := types.ExtractCommentTags("+", p.Comments)["groupName"]; override != nil {
|
||||
gv.Group = clientgentypes.Group(strings.SplitN(override[0], ".", 2)[0])
|
||||
}
|
||||
|
||||
var typesToGenerate []*types.Type
|
||||
for _, t := range p.Types {
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if !tags.GenerateClient || !tags.HasVerb("list") || !tags.HasVerb("get") {
|
||||
continue
|
||||
}
|
||||
typesToGenerate = append(typesToGenerate, t)
|
||||
}
|
||||
if len(typesToGenerate) == 0 {
|
||||
continue
|
||||
}
|
||||
orderer := namer.Orderer{Namer: namer.NewPrivateNamer(0)}
|
||||
typesToGenerate = orderer.OrderTypes(typesToGenerate)
|
||||
|
||||
packagePath := filepath.Join(arguments.OutputPackagePath, groupPackageName, strings.ToLower(gv.Version.NonEmpty()))
|
||||
packageList = append(packageList, &generator.DefaultPackage{
|
||||
PackageName: strings.ToLower(gv.Version.NonEmpty()),
|
||||
PackagePath: packagePath,
|
||||
HeaderText: boilerplate,
|
||||
GeneratorFunc: func(c *generator.Context) (generators []generator.Generator) {
|
||||
generators = append(generators, &expansionGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: "expansion_generated",
|
||||
},
|
||||
packagePath: filepath.Join(arguments.OutputBase, packagePath),
|
||||
types: typesToGenerate,
|
||||
})
|
||||
|
||||
for _, t := range typesToGenerate {
|
||||
generators = append(generators, &listerGenerator{
|
||||
DefaultGen: generator.DefaultGen{
|
||||
OptionalName: strings.ToLower(t.Name.Name),
|
||||
},
|
||||
outputPackage: arguments.OutputPackagePath,
|
||||
groupVersion: gv,
|
||||
internalGVPkg: internalGVPkg,
|
||||
typeToGenerate: t,
|
||||
imports: generator.NewImportTracker(),
|
||||
objectMeta: objectMeta,
|
||||
})
|
||||
}
|
||||
return generators
|
||||
},
|
||||
FilterFunc: func(c *generator.Context, t *types.Type) bool {
|
||||
tags := util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
return tags.GenerateClient && tags.HasVerb("list") && tags.HasVerb("get")
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return packageList
|
||||
}
|
||||
|
||||
// objectMetaForPackage returns the type of ObjectMeta used by package p.
|
||||
func objectMetaForPackage(p *types.Package) (*types.Type, bool, error) {
|
||||
generatingForPackage := false
|
||||
for _, t := range p.Types {
|
||||
// filter out types which dont have genclient.
|
||||
if !util.MustParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...)).GenerateClient {
|
||||
continue
|
||||
}
|
||||
generatingForPackage = true
|
||||
for _, member := range t.Members {
|
||||
if member.Name == "ObjectMeta" {
|
||||
return member.Type, isInternal(member), nil
|
||||
}
|
||||
}
|
||||
}
|
||||
if generatingForPackage {
|
||||
return nil, false, fmt.Errorf("unable to find ObjectMeta for any types in package %s", p.Path)
|
||||
}
|
||||
return nil, false, nil
|
||||
}
|
||||
|
||||
// isInternal returns true if the tags for a member do not contain a json tag
|
||||
func isInternal(m types.Member) bool {
|
||||
return !strings.Contains(m.Tags, "json")
|
||||
}
|
||||
|
||||
// listerGenerator produces a file of listers for a given GroupVersion and
|
||||
// type.
|
||||
type listerGenerator struct {
|
||||
generator.DefaultGen
|
||||
outputPackage string
|
||||
groupVersion clientgentypes.GroupVersion
|
||||
internalGVPkg string
|
||||
typeToGenerate *types.Type
|
||||
imports namer.ImportTracker
|
||||
objectMeta *types.Type
|
||||
}
|
||||
|
||||
var _ generator.Generator = &listerGenerator{}
|
||||
|
||||
func (g *listerGenerator) Filter(c *generator.Context, t *types.Type) bool {
|
||||
return t == g.typeToGenerate
|
||||
}
|
||||
|
||||
func (g *listerGenerator) Namers(c *generator.Context) namer.NameSystems {
|
||||
return namer.NameSystems{
|
||||
"raw": namer.NewRawNamer(g.outputPackage, g.imports),
|
||||
}
|
||||
}
|
||||
|
||||
func (g *listerGenerator) Imports(c *generator.Context) (imports []string) {
|
||||
imports = append(imports, g.imports.ImportLines()...)
|
||||
imports = append(imports, "k8s.io/apimachinery/pkg/api/errors")
|
||||
imports = append(imports, "k8s.io/apimachinery/pkg/labels")
|
||||
// for Indexer
|
||||
imports = append(imports, "k8s.io/client-go/tools/cache")
|
||||
return
|
||||
}
|
||||
|
||||
func (g *listerGenerator) GenerateType(c *generator.Context, t *types.Type, w io.Writer) error {
|
||||
sw := generator.NewSnippetWriter(w, c, "$", "$")
|
||||
|
||||
klog.V(5).Infof("processing type %v", t)
|
||||
m := map[string]interface{}{
|
||||
"Resource": c.Universe.Function(types.Name{Package: t.Name.Package, Name: "Resource"}),
|
||||
"type": t,
|
||||
"objectMeta": g.objectMeta,
|
||||
}
|
||||
|
||||
tags, err := util.ParseClientGenTags(append(t.SecondClosestCommentLines, t.CommentLines...))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(typeListerInterface_NonNamespaced, m)
|
||||
} else {
|
||||
sw.Do(typeListerInterface, m)
|
||||
}
|
||||
|
||||
sw.Do(typeListerStruct, m)
|
||||
sw.Do(typeListerConstructor, m)
|
||||
sw.Do(typeLister_List, m)
|
||||
|
||||
if tags.NonNamespaced {
|
||||
sw.Do(typeLister_NonNamespacedGet, m)
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
sw.Do(typeLister_NamespaceLister, m)
|
||||
sw.Do(namespaceListerInterface, m)
|
||||
sw.Do(namespaceListerStruct, m)
|
||||
sw.Do(namespaceLister_List, m)
|
||||
sw.Do(namespaceLister_Get, m)
|
||||
|
||||
return sw.Error()
|
||||
}
|
||||
|
||||
var typeListerInterface = `
|
||||
// $.type|public$Lister helps list $.type|publicPlural$.
|
||||
type $.type|public$Lister interface {
|
||||
// List lists all $.type|publicPlural$ in the indexer.
|
||||
List(selector labels.Selector) (ret []*$.type|raw$, err error)
|
||||
// $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$.
|
||||
$.type|publicPlural$(namespace string) $.type|public$NamespaceLister
|
||||
$.type|public$ListerExpansion
|
||||
}
|
||||
`
|
||||
|
||||
var typeListerInterface_NonNamespaced = `
|
||||
// $.type|public$Lister helps list $.type|publicPlural$.
|
||||
type $.type|public$Lister interface {
|
||||
// List lists all $.type|publicPlural$ in the indexer.
|
||||
List(selector labels.Selector) (ret []*$.type|raw$, err error)
|
||||
// Get retrieves the $.type|public$ from the index for a given name.
|
||||
Get(name string) (*$.type|raw$, error)
|
||||
$.type|public$ListerExpansion
|
||||
}
|
||||
`
|
||||
|
||||
var typeListerStruct = `
|
||||
// $.type|private$Lister implements the $.type|public$Lister interface.
|
||||
type $.type|private$Lister struct {
|
||||
indexer cache.Indexer
|
||||
}
|
||||
`
|
||||
|
||||
var typeListerConstructor = `
|
||||
// New$.type|public$Lister returns a new $.type|public$Lister.
|
||||
func New$.type|public$Lister(indexer cache.Indexer) $.type|public$Lister {
|
||||
return &$.type|private$Lister{indexer: indexer}
|
||||
}
|
||||
`
|
||||
|
||||
var typeLister_List = `
|
||||
// List lists all $.type|publicPlural$ in the indexer.
|
||||
func (s *$.type|private$Lister) List(selector labels.Selector) (ret []*$.type|raw$, err error) {
|
||||
err = cache.ListAll(s.indexer, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*$.type|raw$))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
`
|
||||
|
||||
var typeLister_NamespaceLister = `
|
||||
// $.type|publicPlural$ returns an object that can list and get $.type|publicPlural$.
|
||||
func (s *$.type|private$Lister) $.type|publicPlural$(namespace string) $.type|public$NamespaceLister {
|
||||
return $.type|private$NamespaceLister{indexer: s.indexer, namespace: namespace}
|
||||
}
|
||||
`
|
||||
|
||||
var typeLister_NonNamespacedGet = `
|
||||
// Get retrieves the $.type|public$ from the index for a given name.
|
||||
func (s *$.type|private$Lister) Get(name string) (*$.type|raw$, error) {
|
||||
obj, exists, err := s.indexer.GetByKey(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.NewNotFound($.Resource|raw$("$.type|lowercaseSingular$"), name)
|
||||
}
|
||||
return obj.(*$.type|raw$), nil
|
||||
}
|
||||
`
|
||||
|
||||
var namespaceListerInterface = `
|
||||
// $.type|public$NamespaceLister helps list and get $.type|publicPlural$.
|
||||
type $.type|public$NamespaceLister interface {
|
||||
// List lists all $.type|publicPlural$ in the indexer for a given namespace.
|
||||
List(selector labels.Selector) (ret []*$.type|raw$, err error)
|
||||
// Get retrieves the $.type|public$ from the indexer for a given namespace and name.
|
||||
Get(name string) (*$.type|raw$, error)
|
||||
$.type|public$NamespaceListerExpansion
|
||||
}
|
||||
`
|
||||
|
||||
var namespaceListerStruct = `
|
||||
// $.type|private$NamespaceLister implements the $.type|public$NamespaceLister
|
||||
// interface.
|
||||
type $.type|private$NamespaceLister struct {
|
||||
indexer cache.Indexer
|
||||
namespace string
|
||||
}
|
||||
`
|
||||
|
||||
var namespaceLister_List = `
|
||||
// List lists all $.type|publicPlural$ in the indexer for a given namespace.
|
||||
func (s $.type|private$NamespaceLister) List(selector labels.Selector) (ret []*$.type|raw$, err error) {
|
||||
err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) {
|
||||
ret = append(ret, m.(*$.type|raw$))
|
||||
})
|
||||
return ret, err
|
||||
}
|
||||
`
|
||||
|
||||
var namespaceLister_Get = `
|
||||
// Get retrieves the $.type|public$ from the indexer for a given namespace and name.
|
||||
func (s $.type|private$NamespaceLister) Get(name string) (*$.type|raw$, error) {
|
||||
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if !exists {
|
||||
return nil, errors.NewNotFound($.Resource|raw$("$.type|lowercaseSingular$"), name)
|
||||
}
|
||||
return obj.(*$.type|raw$), nil
|
||||
}
|
||||
`
|
33
vendor/k8s.io/code-generator/cmd/lister-gen/generators/tags.go
generated
vendored
Normal file
33
vendor/k8s.io/code-generator/cmd/lister-gen/generators/tags.go
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 generators
|
||||
|
||||
import (
|
||||
"k8s.io/gengo/types"
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// extractBoolTagOrDie gets the comment-tags for the key and asserts that, if
|
||||
// it exists, the value is boolean. If the tag did not exist, it returns
|
||||
// false.
|
||||
func extractBoolTagOrDie(key string, lines []string) bool {
|
||||
val, err := types.ExtractSingleBoolCommentTag("+", key, false, lines)
|
||||
if err != nil {
|
||||
klog.Fatal(err)
|
||||
}
|
||||
return val
|
||||
}
|
60
vendor/k8s.io/code-generator/cmd/lister-gen/main.go
generated
vendored
Normal file
60
vendor/k8s.io/code-generator/cmd/lister-gen/main.go
generated
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/spf13/pflag"
|
||||
"k8s.io/code-generator/cmd/lister-gen/generators"
|
||||
"k8s.io/code-generator/pkg/util"
|
||||
"k8s.io/gengo/args"
|
||||
"k8s.io/klog"
|
||||
|
||||
generatorargs "k8s.io/code-generator/cmd/lister-gen/args"
|
||||
)
|
||||
|
||||
func main() {
|
||||
klog.InitFlags(nil)
|
||||
genericArgs, customArgs := generatorargs.NewDefaults()
|
||||
|
||||
// Override defaults.
|
||||
// TODO: move this out of lister-gen
|
||||
genericArgs.GoHeaderFilePath = filepath.Join(args.DefaultSourceTree(), util.BoilerplatePath())
|
||||
genericArgs.OutputPackagePath = "k8s.io/kubernetes/pkg/client/listers"
|
||||
|
||||
genericArgs.AddFlags(pflag.CommandLine)
|
||||
customArgs.AddFlags(pflag.CommandLine)
|
||||
flag.Set("logtostderr", "true")
|
||||
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
|
||||
pflag.Parse()
|
||||
|
||||
if err := generatorargs.Validate(genericArgs); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
|
||||
// Run it.
|
||||
if err := genericArgs.Execute(
|
||||
generators.NameSystems(),
|
||||
generators.DefaultNameSystem(),
|
||||
generators.Packages,
|
||||
); err != nil {
|
||||
klog.Fatalf("Error: %v", err)
|
||||
}
|
||||
klog.V(2).Info("Completed successfully.")
|
||||
}
|
58
vendor/k8s.io/code-generator/pkg/namer/tag-override.go
generated
vendored
Normal file
58
vendor/k8s.io/code-generator/pkg/namer/tag-override.go
generated
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
Copyright 2016 The Kubernetes Authors.
|
||||
|
||||
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 namer
|
||||
|
||||
import (
|
||||
"k8s.io/gengo/namer"
|
||||
"k8s.io/gengo/types"
|
||||
)
|
||||
|
||||
// TagOverrideNamer is a namer which pulls names from a given tag, if specified,
|
||||
// and otherwise falls back to a different namer.
|
||||
type TagOverrideNamer struct {
|
||||
tagName string
|
||||
fallback namer.Namer
|
||||
}
|
||||
|
||||
// Name returns the tag value if it exists. It no tag was found the fallback namer will be used
|
||||
func (n *TagOverrideNamer) Name(t *types.Type) string {
|
||||
if nameOverride := extractTag(n.tagName, append(t.SecondClosestCommentLines, t.CommentLines...)); nameOverride != "" {
|
||||
return nameOverride
|
||||
}
|
||||
|
||||
return n.fallback.Name(t)
|
||||
}
|
||||
|
||||
// NewTagOverrideNamer creates a namer.Namer which uses the contents of the given tag as
|
||||
// the name, or falls back to another Namer if the tag is not present.
|
||||
func NewTagOverrideNamer(tagName string, fallback namer.Namer) namer.Namer {
|
||||
return &TagOverrideNamer{
|
||||
tagName: tagName,
|
||||
fallback: fallback,
|
||||
}
|
||||
}
|
||||
|
||||
// extractTag gets the comment-tags for the key. If the tag did not exist, it
|
||||
// returns the empty string.
|
||||
func extractTag(key string, lines []string) string {
|
||||
val, present := types.ExtractCommentTags("+", lines)[key]
|
||||
if !present || len(val) < 1 {
|
||||
return ""
|
||||
}
|
||||
|
||||
return val[0]
|
||||
}
|
33
vendor/modules.txt
vendored
33
vendor/modules.txt
vendored
|
@ -13,6 +13,8 @@ github.com/ant31/crd-validation/pkg
|
|||
github.com/beorn7/perks/quantile
|
||||
# github.com/blang/semver v3.5.1+incompatible
|
||||
github.com/blang/semver
|
||||
# github.com/brancz/gojsontoyaml v0.0.0-20190425155809-e8bd32d46b3d
|
||||
github.com/brancz/gojsontoyaml
|
||||
# github.com/campoy/embedmd v1.0.0
|
||||
github.com/campoy/embedmd
|
||||
github.com/campoy/embedmd/embedmd
|
||||
|
@ -23,6 +25,8 @@ github.com/emicklei/go-restful
|
|||
github.com/emicklei/go-restful/log
|
||||
# github.com/evanphx/json-patch v4.1.0+incompatible
|
||||
github.com/evanphx/json-patch
|
||||
# github.com/fatih/color v1.7.0
|
||||
github.com/fatih/color
|
||||
# github.com/fsnotify/fsnotify v1.4.7
|
||||
github.com/fsnotify/fsnotify
|
||||
# github.com/ghodss/yaml v1.0.0
|
||||
|
@ -67,6 +71,10 @@ github.com/improbable-eng/thanos/pkg/reloader
|
|||
github.com/improbable-eng/thanos/pkg/runutil
|
||||
# github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3
|
||||
github.com/json-iterator/go
|
||||
# github.com/jsonnet-bundler/jsonnet-bundler v0.1.0
|
||||
github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb
|
||||
github.com/jsonnet-bundler/jsonnet-bundler/pkg
|
||||
github.com/jsonnet-bundler/jsonnet-bundler/spec
|
||||
# github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515
|
||||
github.com/kr/logfmt
|
||||
# github.com/kylelemons/godebug v0.0.0-20170820004349-d65d576e9348
|
||||
|
@ -76,6 +84,10 @@ github.com/kylelemons/godebug/diff
|
|||
github.com/mailru/easyjson/jlexer
|
||||
github.com/mailru/easyjson/jwriter
|
||||
github.com/mailru/easyjson/buffer
|
||||
# github.com/mattn/go-colorable v0.0.9
|
||||
github.com/mattn/go-colorable
|
||||
# github.com/mattn/go-isatty v0.0.6
|
||||
github.com/mattn/go-isatty
|
||||
# github.com/matttproud/golang_protobuf_extensions v1.0.1
|
||||
github.com/matttproud/golang_protobuf_extensions/pbutil
|
||||
# github.com/mitchellh/hashstructure v0.0.0-20170609045927-2bca23e0e452
|
||||
|
@ -107,7 +119,7 @@ github.com/prometheus/procfs/xfs
|
|||
github.com/prometheus/procfs/internal/util
|
||||
# github.com/spf13/pflag v1.0.3
|
||||
github.com/spf13/pflag
|
||||
# github.com/stretchr/testify v1.2.2
|
||||
# github.com/stretchr/testify v1.3.0
|
||||
github.com/stretchr/testify/require
|
||||
github.com/stretchr/testify/assert
|
||||
# golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d
|
||||
|
@ -313,16 +325,31 @@ k8s.io/client-go/util/connrotation
|
|||
k8s.io/client-go/util/keyutil
|
||||
k8s.io/client-go/tools/clientcmd/api/v1
|
||||
# k8s.io/code-generator v0.0.0-20190311093542-50b561225d70
|
||||
k8s.io/code-generator/cmd/client-gen
|
||||
k8s.io/code-generator/cmd/deepcopy-gen
|
||||
k8s.io/code-generator/cmd/deepcopy-gen/args
|
||||
k8s.io/code-generator/cmd/informer-gen
|
||||
k8s.io/code-generator/cmd/lister-gen
|
||||
k8s.io/code-generator/cmd/client-gen/args
|
||||
k8s.io/code-generator/cmd/client-gen/generators
|
||||
k8s.io/code-generator/pkg/util
|
||||
k8s.io/code-generator/cmd/deepcopy-gen/args
|
||||
k8s.io/code-generator/cmd/informer-gen/args
|
||||
k8s.io/code-generator/cmd/informer-gen/generators
|
||||
k8s.io/code-generator/cmd/lister-gen/args
|
||||
k8s.io/code-generator/cmd/lister-gen/generators
|
||||
k8s.io/code-generator/cmd/client-gen/types
|
||||
k8s.io/code-generator/cmd/client-gen/generators/fake
|
||||
k8s.io/code-generator/cmd/client-gen/generators/scheme
|
||||
k8s.io/code-generator/cmd/client-gen/generators/util
|
||||
k8s.io/code-generator/cmd/client-gen/path
|
||||
k8s.io/code-generator/pkg/namer
|
||||
# k8s.io/gengo v0.0.0-20190327210449-e17681d19d3a
|
||||
k8s.io/gengo/args
|
||||
k8s.io/gengo/examples/deepcopy-gen/generators
|
||||
k8s.io/gengo/generator
|
||||
k8s.io/gengo/namer
|
||||
k8s.io/gengo/parser
|
||||
k8s.io/gengo/types
|
||||
k8s.io/gengo/parser
|
||||
k8s.io/gengo/examples/set-gen/sets
|
||||
# k8s.io/klog v0.3.0
|
||||
k8s.io/klog
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue