mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Merge remote-tracking branch 'upstream/master' into release-cmd/kubectl-v0.0
This commit is contained in:
@@ -36,6 +36,7 @@ install: true
|
||||
script:
|
||||
- make verify-kustomize
|
||||
- ./travis/kyaml-pre-commit.sh
|
||||
- ./travis/check-go-mod.sh
|
||||
|
||||
# TBD. Suppressing for now.
|
||||
notifications:
|
||||
|
||||
@@ -52,7 +52,7 @@ func (p *NamespaceTransformerPlugin) Transform(m resmap.ResMap) error {
|
||||
|
||||
matches := m.GetMatchingResourcesByCurrentId(r.CurId().Equals)
|
||||
if len(matches) != 1 {
|
||||
return fmt.Errorf("namespace tranformation produces ID conflict: %#v", matches)
|
||||
return fmt.Errorf("namespace tranformation produces ID conflict: %+v", matches)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -7,7 +7,6 @@ require (
|
||||
github.com/go-openapi/spec v0.19.4
|
||||
github.com/golangci/golangci-lint v1.21.0
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
|
||||
github.com/monopole/mdrip v1.0.1
|
||||
github.com/pkg/errors v0.8.1
|
||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff
|
||||
gopkg.in/yaml.v2 v2.2.4
|
||||
|
||||
62
api/go.sum
62
api/go.sum
@@ -2,14 +2,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||
github.com/Azure/go-autorest/autorest v0.9.2/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc=
|
||||
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
|
||||
github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM=
|
||||
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
|
||||
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
@@ -49,14 +45,9 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
|
||||
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633 h1:H2pdYOb3KQ1/YsqVWoWNLQO+fusocsw354rqGTZtAgw=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/emicklei/go-restful v2.9.6+incompatible h1:tfrHha8zJ01ywiOEC1miGY8st1/igzWB8OmvPgoYX7w=
|
||||
github.com/emicklei/go-restful v2.9.6+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
@@ -119,13 +110,10 @@ github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7a
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b h1:VKtxabqXZkF25pY9ekfRL6a582T4P37/31XEstQ5p58=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@@ -145,15 +133,12 @@ github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3 h1:pe9JHs3cHHDQgO
|
||||
github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3/go.mod h1:JXrF4TWy4tXYn62/9x8Wm/K/dm06p8tCKwFRDPZG/1o=
|
||||
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee h1:J2XAy40+7yz70uaOiMbNnluTg7gyQhtGqLQncQh+4J8=
|
||||
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee/go.mod h1:ozx7R9SIwqmqf5pRP90DhR2Oay2UIjGuKheCBCNwAYU=
|
||||
github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
|
||||
github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a h1:iR3fYXUjHCR97qWS8ch1y9zPNsgXThGwjKPrYfqMPks=
|
||||
github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
|
||||
github.com/golangci/golangci-lint v1.19.1/go.mod h1:2CEc4Fxx3vxDv7g8DyXkHCBF73AOzAymcJAprs2vCps=
|
||||
github.com/golangci/golangci-lint v1.21.0 h1:HxAxpR8Z0M8omihvQdsD3PF0qPjlqYqp2vMJzstoKeI=
|
||||
github.com/golangci/golangci-lint v1.21.0/go.mod h1:phxpHK52q7SE+5KpPnti4oZTdFCEsn/tKN+nFvCKXfk=
|
||||
github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc h1:gLLhTLMk2/SutryVJ6D4VZCU3CUqr8YloG7FPIBWFpI=
|
||||
github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU=
|
||||
github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg=
|
||||
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0 h1:MfyDlzVjl1hoaPzPD4Gpb/QgoRfSBR0jdhwGyAWwMSA=
|
||||
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg=
|
||||
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca h1:kNY3/svz5T29MYHubXix4aDDuE3RWHkPvopM/EDv/MA=
|
||||
@@ -169,9 +154,8 @@ github.com/golangci/unconvert v0.0.0-20180507085042-28b1c447d1f4/go.mod h1:Izgrg
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
@@ -184,31 +168,16 @@ github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0=
|
||||
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
|
||||
github.com/gophercloud/gophercloud v0.6.0/go.mod h1:GICNByuaEBibcjmjvI7QvYJSZEbGkcYwAR7EZK2WMqM=
|
||||
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f h1:9oNbS1z4rVpbnkHBdPZU4jo9bSmrLpII768arSyMFgk=
|
||||
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.0 h1:UykbtMB/w5No2LmE16gINgLj+r/vbziTgaoERQv6U+0=
|
||||
github.com/gorilla/mux v1.6.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/securecookie v0.0.0-20160422134519-667fe4e3466a h1:YH0IojQwndMQdeRWdw1aPT8bkbiWaYR3WD+Zf5e09DU=
|
||||
github.com/gorilla/securecookie v0.0.0-20160422134519-667fe4e3466a/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/gorilla/sessions v0.0.0-20160922145804-ca9ada445741 h1:OuuPl66BpF1q3OEkaPpp+VfzxrBBY62ATGdWqql/XX8=
|
||||
github.com/gorilla/sessions v0.0.0-20160922145804-ca9ada445741/go.mod h1:+WVp8kdw6VhyKExm03PAMRn2ZxnPtm58pV0dBVPdhHE=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3 h1:JVnpOZS+qxli+rgVl98ILOXVNbW+kb5wcxeGx8ShUIw=
|
||||
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/grpc-ecosystem/go-grpc-middleware v1.0.0/go.mod h1:FiyG127CGDf3tlThmgyCl78X/SZQqEOJBCDaAfeWzPs=
|
||||
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgfV/d3M/q6VIi02HzZEHgUlZvzk=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
@@ -248,10 +217,8 @@ github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
|
||||
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb h1:RHba4YImhrUVQDHUCe2BNSOz4tVy2yGyXhvYDvxGgeE=
|
||||
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||
@@ -270,10 +237,6 @@ github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lN
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/monopole/mdrip v1.0.0 h1:RFDBa+tab6mW+gX4Ww2SZDc4kS6p01FwnLtgz64Il+I=
|
||||
github.com/monopole/mdrip v1.0.0/go.mod h1:N1/ppRG9CaPeUKAUHZ3dUlfOT81lTpKZLkyhCvTETwM=
|
||||
github.com/monopole/mdrip v1.0.1 h1:LzwNWb8ge3+4iBZmxIE6VfUR5KIxhF7DKdf85t8Yvos=
|
||||
github.com/monopole/mdrip v1.0.1/go.mod h1:/7E04hlzRG9Jrp6WILZfYYm/REoJWL2l+MlsCO1eH74=
|
||||
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
|
||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
@@ -308,12 +271,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/russross/blackfriday v2.0.0+incompatible h1:cBXrhZNUf9C+La9/YpS+UHpUT8YD6Td9ZMSU9APFcsk=
|
||||
github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/securego/gosec v0.0.0-20190912120752-140048b2a218/go.mod h1:q6oYAujd2qyeU4cJqIri4LBIgdHXGvxWHZ1E29HNFRE=
|
||||
github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d h1:BzRvVq1EHuIjxpijCEKpAxzKUUMurOQ4sknehIATRh8=
|
||||
github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d/go.mod h1:w5+eXa0mYznDkHaMCXA4XYffjlH+cy1oyKbfzJXa2Do=
|
||||
github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc=
|
||||
@@ -322,8 +281,6 @@ github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e h1:MZM7FHLqUHYI0Y/mQAt
|
||||
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
|
||||
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041 h1:llrF3Fs4018ePo4+G/HV/uQUqEI1HMDjCeOf2V6puPc=
|
||||
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
@@ -356,7 +313,6 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/timakin/bodyclose v0.0.0-20190721030226-87058b9bfcec/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
|
||||
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e h1:RumXZ56IrCj4CL+g1b9OL/oH0QnsF976bC8xQFYUD5Q=
|
||||
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
@@ -364,7 +320,6 @@ github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGr
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/ultraware/funlen v0.0.2 h1:Av96YVBwwNSe4MLR7iI/BIa3VyI7/djnto/pK3Uxbdo=
|
||||
github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
|
||||
github.com/ultraware/whitespace v0.0.3/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA=
|
||||
github.com/ultraware/whitespace v0.0.4 h1:If7Va4cM03mpgrNH9k49/VOicWpGoG70XPBFFODYDsg=
|
||||
github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA=
|
||||
github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517 h1:ChMKTho2hWKpks/nD/FL2KqM1wuVt62oJeiE8+eFpGs=
|
||||
@@ -387,7 +342,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@@ -410,8 +364,6 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7MvYXnkV9/iQNo1lX6g=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
@@ -437,7 +389,6 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190911201528-7ad0cfa0b7b5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM=
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -447,7 +398,6 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/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-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -462,12 +412,11 @@ golang.org/x/tools v0.0.0-20190311215038-5c2858a9cfe5/go.mod h1:LCzVGOaR6xXOjkQ3
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190322203728-c1a832b0ad89/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
golang.org/x/tools v0.0.0-20190521203540-521d6ed310dd/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
|
||||
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59 h1:QjA/9ArTfVTLfEhClDCG7SGrZkZixxWpwNCDiwJfh88=
|
||||
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||
golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190911230505-6bfd74cf029c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190912215617-3720d1ec3678/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff h1:XdBG6es/oFDr1HwaxkxgVve7NB281QhxgK/i4voubFs=
|
||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
@@ -492,8 +441,6 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/russross/blackfriday.v2 v2.0.0 h1:+FlnIV8DSQnT7NZ43hcVKcdJdzZoeCmJj4Ql8gq5keA=
|
||||
gopkg.in/russross/blackfriday.v2 v2.0.0/go.mod h1:6sSBNz/GtOm/pJTuh5UmBK2ZHfmnxGbl2NZg1UliSOI=
|
||||
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.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
@@ -518,7 +465,6 @@ k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
||||
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
|
||||
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed h1:WX1yoOaKQfddO/mLzdV4wptyWgoH/6hwLs7QHTixo0I=
|
||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
||||
@@ -526,10 +472,6 @@ mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b h1:DxJ5nJdkhDlLok9K6qO+5290kphD
|
||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f h1:Cq7MalBHYACRd6EesksG1Q8EoIAKOsiZviGKbOLIej4=
|
||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||
sigs.k8s.io/kustomize/api v0.2.0/go.mod h1:zVtMg179jW1gr74jo9fc2Ac9dLYLTZZThc3DDb9lDW4=
|
||||
sigs.k8s.io/kustomize/pluginator/v2 v2.0.0 h1:sES7e09G19Q0VjRp4ATSYKpTXoWaX8WMSHfw6u3G2Ok=
|
||||
sigs.k8s.io/kustomize/pluginator/v2 v2.0.0/go.mod h1:zrXhTv8BAKt0egmZX/8AtMOSFUSWM9YuoHvvqz8/eHE=
|
||||
sigs.k8s.io/kustomize/pseudo/k8s v0.1.0/go.mod h1:bl/gVJgYYhJZCZdYU2BfnaKYAlqFkgbJEkpl302jEss=
|
||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
||||
@@ -3,6 +3,7 @@ package main
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"os"
|
||||
"time"
|
||||
@@ -21,14 +22,53 @@ const (
|
||||
redisCacheURL = "REDIS_CACHE_URL"
|
||||
redisKeyURL = "REDIS_KEY_URL"
|
||||
retryCount = 3
|
||||
githubUserEnv = "GITHUB_USER"
|
||||
githubRepoEnv = "GITHUB_REPO"
|
||||
)
|
||||
|
||||
func main() {
|
||||
githubUser := os.Getenv(githubUserEnv)
|
||||
githubRepo := os.Getenv(githubRepoEnv)
|
||||
type CrawlMode int
|
||||
const (
|
||||
CrawlUnknown CrawlMode = iota
|
||||
// Crawl all the kustomization files in all the repositories of a Github user
|
||||
CrawlUser
|
||||
// Crawl all the kustomization files in a Github repo
|
||||
CrawlRepo
|
||||
// Crawl all the documents in the index
|
||||
CrawlIndex
|
||||
// Crawl all the kustomization files on Github
|
||||
CrawlGithub
|
||||
// Crawl all the documents in the index and crawling all the kustomization files on Github
|
||||
CrawlIndexAndGithub
|
||||
)
|
||||
|
||||
func NewCrawlMode(s string) CrawlMode {
|
||||
switch s {
|
||||
case "github-user":
|
||||
return CrawlUser
|
||||
case "github-repo":
|
||||
return CrawlRepo
|
||||
case "":
|
||||
return CrawlIndexAndGithub
|
||||
case "index":
|
||||
return CrawlIndex
|
||||
case "github":
|
||||
return CrawlGithub
|
||||
default:
|
||||
return CrawlUnknown
|
||||
}
|
||||
}
|
||||
|
||||
func Usage() {
|
||||
fmt.Printf("Usage: %s [mode] [githubUser|githubRepo]\n", os.Args[0])
|
||||
fmt.Printf("\tmode can be one of [github-user, github-repo, index, github]\n")
|
||||
fmt.Printf("%s: crawl all the documents in the index and crawling all the kustomization files on Github\n", os.Args[0])
|
||||
fmt.Printf("%s index: crawl all the documents in the index\n", os.Args[0])
|
||||
fmt.Printf("%s gihub: crawl all the kustomization files on Github\n", os.Args[0])
|
||||
fmt.Printf("%s github-user <github-user>: Crawl all the kustomization files in all the repositories of a Github user\n", os.Args[0])
|
||||
fmt.Printf("\tFor example, %s github-user kubernetes-sigs\n", os.Args[0])
|
||||
fmt.Printf("%s github-repo <github-repo>: Crawl all the kustomization files in a Github repo\n", os.Args[0])
|
||||
fmt.Printf("\tFor example, %s github-repo kubernetes-sigs/kustomize\n", os.Args[0])
|
||||
}
|
||||
|
||||
func main() {
|
||||
githubToken := os.Getenv(githubAccessTokenVar)
|
||||
if githubToken == "" {
|
||||
fmt.Printf("Must set the variable '%s' to make github requests.\n",
|
||||
@@ -43,8 +83,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
seedDocs := make(crawler.CrawlSeed, 0)
|
||||
|
||||
cacheURL := os.Getenv(redisCacheURL)
|
||||
cache, err := redis.DialURL(cacheURL)
|
||||
clientCache := &http.Client{}
|
||||
@@ -65,12 +103,17 @@ func main() {
|
||||
}
|
||||
|
||||
// Index updates the value in the index.
|
||||
index := func(cdoc crawler.CrawledDocument, crwlr crawler.Crawler) error {
|
||||
indexFunc := func(cdoc crawler.CrawledDocument, mode index.Mode) error {
|
||||
switch d := cdoc.(type) {
|
||||
case *doc.KustomizationDocument:
|
||||
fmt.Println("Inserting: ", d)
|
||||
_, err := idx.Put(d.ID(), d)
|
||||
return err
|
||||
switch mode {
|
||||
case index.Delete:
|
||||
fmt.Println("Deleting: ", d)
|
||||
return idx.Delete(d.ID())
|
||||
default:
|
||||
fmt.Println("Inserting: ", d)
|
||||
return idx.Put(d.ID(), d)
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("type %T not supported", d)
|
||||
}
|
||||
@@ -80,30 +123,44 @@ func main() {
|
||||
// This helps avoid indexing a given document multiple times.
|
||||
seen := make(map[string]struct{})
|
||||
|
||||
var ghCrawler crawler.Crawler
|
||||
|
||||
if githubRepo != "" {
|
||||
ghCrawler = github.NewCrawler(githubToken, retryCount, clientCache,
|
||||
github.QueryWith(
|
||||
github.Filename("kustomization.yaml"),
|
||||
github.Filename("kustomization.yml"),
|
||||
github.Repo(githubRepo)),
|
||||
)
|
||||
} else if githubUser != "" {
|
||||
ghCrawler = github.NewCrawler(githubToken, retryCount, clientCache,
|
||||
github.QueryWith(
|
||||
github.Filename("kustomization.yaml"),
|
||||
github.Filename("kustomization.yml"),
|
||||
github.User(githubUser)),
|
||||
)
|
||||
var mode CrawlMode
|
||||
if len(os.Args) == 1 {
|
||||
mode = CrawlIndexAndGithub
|
||||
} else {
|
||||
ghCrawler = github.NewCrawler(githubToken, retryCount, clientCache,
|
||||
github.QueryWith(
|
||||
github.Filename("kustomization.yaml"),
|
||||
github.Filename("kustomization.yml")),
|
||||
)
|
||||
mode = NewCrawlMode(os.Args[1])
|
||||
}
|
||||
|
||||
// get all the documents in the index
|
||||
ghCrawlerConstructor := func(user, repo string) crawler.Crawler {
|
||||
if user != "" {
|
||||
return github.NewCrawler(githubToken, retryCount, clientCache,
|
||||
github.QueryWith(
|
||||
github.Filename("kustomization.yaml"),
|
||||
github.Filename("kustomization.yml"),
|
||||
github.Filename("kustomization"),
|
||||
github.User(user)),
|
||||
)
|
||||
} else if repo != "" {
|
||||
return github.NewCrawler(githubToken, retryCount, clientCache,
|
||||
github.QueryWith(
|
||||
github.Filename("kustomization.yaml"),
|
||||
github.Filename("kustomization.yml"),
|
||||
github.Filename("kustomization"),
|
||||
github.Repo(repo)),
|
||||
)
|
||||
} else {
|
||||
return github.NewCrawler(githubToken, retryCount, clientCache,
|
||||
github.QueryWith(
|
||||
github.Filename("kustomization.yaml"),
|
||||
github.Filename("kustomization.yml"),
|
||||
github.Filename("kustomization")),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
seedDocs := make(crawler.CrawlSeed, 0)
|
||||
|
||||
// get all the documents in the index
|
||||
getSeedDocsFunc := func() {
|
||||
query := []byte(`{ "query":{ "match_all":{} } }`)
|
||||
it := idx.IterateQuery(query, 10000, 60*time.Second)
|
||||
for it.Next() {
|
||||
@@ -116,7 +173,35 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
crawlers := []crawler.Crawler{ghCrawler}
|
||||
crawler.CrawlFromSeed(ctx, seedDocs, crawlers, docConverter, index, seen)
|
||||
crawler.CrawlGithub(ctx, crawlers, docConverter, index, seen)
|
||||
switch mode {
|
||||
case CrawlIndexAndGithub:
|
||||
getSeedDocsFunc()
|
||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
||||
crawler.CrawlFromSeed(ctx, seedDocs, crawlers, docConverter, indexFunc, seen)
|
||||
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
||||
case CrawlIndex:
|
||||
getSeedDocsFunc()
|
||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
||||
crawler.CrawlFromSeed(ctx, seedDocs, crawlers, docConverter, indexFunc, seen)
|
||||
case CrawlGithub:
|
||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", "")}
|
||||
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
||||
case CrawlUser:
|
||||
if len(os.Args) < 3 {
|
||||
Usage()
|
||||
log.Fatalf("Please specify a github user!")
|
||||
}
|
||||
crawlers := []crawler.Crawler{ghCrawlerConstructor(os.Args[2], "")}
|
||||
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
||||
case CrawlRepo:
|
||||
if len(os.Args) < 3 {
|
||||
Usage()
|
||||
log.Fatalf("Please specify a github repo!")
|
||||
}
|
||||
crawlers := []crawler.Crawler{ghCrawlerConstructor("", os.Args[2])}
|
||||
crawler.CrawlGithub(ctx, crawlers, docConverter, indexFunc, seen)
|
||||
case CrawlUnknown:
|
||||
Usage()
|
||||
log.Fatalf("The crawler mode must be one of [github-user, github-repo, index, github]")
|
||||
}
|
||||
}
|
||||
|
||||
14
api/internal/crawl/cmd/kustomize_stats/Dockerfile
Normal file
14
api/internal/crawl/cmd/kustomize_stats/Dockerfile
Normal file
@@ -0,0 +1,14 @@
|
||||
FROM golang:1.11 AS build
|
||||
|
||||
ARG GO111MODULE=on
|
||||
|
||||
WORKDIR /go/src/sigs.k8s.io/kustomize/api/internal/crawl
|
||||
COPY . /go/src/sigs.k8s.io/kustomize/api/internal/crawl
|
||||
|
||||
RUN go mod download
|
||||
RUN CGO_ENABLED=0 go install ./cmd/kustomize_stats
|
||||
|
||||
FROM scratch
|
||||
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
||||
COPY --from=build /go/bin/kustomize_stats /
|
||||
ENTRYPOINT ["/kustomize_stats"]
|
||||
150
api/internal/crawl/cmd/kustomize_stats/main.go
Normal file
150
api/internal/crawl/cmd/kustomize_stats/main.go
Normal file
@@ -0,0 +1,150 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/internal/crawl/index"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
)
|
||||
|
||||
// iterateArr adds each item in arr into countMap.
|
||||
func iterateArr(arr []string, countMap map[string]int) {
|
||||
for _, item := range arr {
|
||||
if _, ok := countMap[item]; !ok {
|
||||
countMap[item] = 1
|
||||
} else {
|
||||
countMap[item]++
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// isKustomizationFile determines whether a file path is a kustomization file
|
||||
func isKustomizationFile(path string) bool {
|
||||
basename := filepath.Base(path)
|
||||
for _, name := range konfig.RecognizedKustomizationFileNames() {
|
||||
if basename == name {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SortMapKeyByValue takes a map as its input, sorts its keys according to their values
|
||||
// in the map, and outputs the sorted keys as a slice.
|
||||
func SortMapKeyByValue(m map[string]int) []string {
|
||||
keys := make([]string, 0, len(m))
|
||||
for key := range m {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
// sort keys according to their values in the map m
|
||||
sort.Slice(keys, func(i, j int) bool {return m[keys[i]] > m[keys[j]]})
|
||||
return keys
|
||||
}
|
||||
|
||||
func main() {
|
||||
topKindsPtr := flag.Int(
|
||||
"kinds", -1,
|
||||
`the number of kubernetes object kinds to be listed according to their popularities.
|
||||
By default, all the kinds will be listed.
|
||||
If you only want to list the 10 most popular kinds, set the flag to 10.`)
|
||||
topIdentifiersPtr := flag.Int(
|
||||
"identifiers", -1,
|
||||
`the number of identifiers to be listed according to their popularities.
|
||||
By default, all the identifiers will be listed.
|
||||
If you only want to list the 10 most popular identifiers, set the flag to 10.`)
|
||||
topKustomizeFeaturesPtr := flag.Int(
|
||||
"kustomize-features", -1,
|
||||
`the number of kustomize features to be listed according to their popularities.
|
||||
By default, all the features will be listed.
|
||||
If you only want to list the 10 most popular features, set the flag to 10.`)
|
||||
flag.Parse()
|
||||
|
||||
ctx := context.Background()
|
||||
idx, err := index.NewKustomizeIndex(ctx)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not create an index: %v\n", err)
|
||||
}
|
||||
|
||||
// count tracks the number of documents in the index
|
||||
count := 0
|
||||
|
||||
// kustomizationFilecount tracks the number of kustomization files in the index
|
||||
kustomizationFilecount := 0
|
||||
|
||||
kindsMap := make(map[string]int)
|
||||
identifiersMap := make(map[string]int)
|
||||
kustomizeIdentifiersMap := make(map[string]int)
|
||||
|
||||
// ids tracks the unique IDs of the documents in the index
|
||||
ids := make(map[string]struct{})
|
||||
|
||||
// get all the documents in the index
|
||||
query := []byte(`{ "query":{ "match_all":{} } }`)
|
||||
it := idx.IterateQuery(query, 10000, 60*time.Second)
|
||||
for it.Next() {
|
||||
for _, hit := range it.Value().Hits.Hits {
|
||||
// check whether there is any duplicate IDs in the index
|
||||
if _, ok := ids[hit.ID]; !ok {
|
||||
ids[hit.ID] = struct{}{}
|
||||
} else {
|
||||
fmt.Printf("Found duplicate ID (%s)\n", hit.ID)
|
||||
}
|
||||
|
||||
count++
|
||||
iterateArr(hit.Document.Kinds, kindsMap)
|
||||
iterateArr(hit.Document.Identifiers, identifiersMap)
|
||||
|
||||
if isKustomizationFile(hit.Document.FilePath) {
|
||||
kustomizationFilecount++
|
||||
iterateArr(hit.Document.Identifiers, kustomizeIdentifiersMap)
|
||||
}
|
||||
}
|
||||
}
|
||||
if err := it.Err(); err != nil {
|
||||
fmt.Printf("Error iterating: %v\n", err)
|
||||
}
|
||||
|
||||
sortedKindsMapKeys := SortMapKeyByValue(kindsMap)
|
||||
sortedIdentifiersMapKeys := SortMapKeyByValue(identifiersMap)
|
||||
sortedKustomizeIdentifiersMapKeys := SortMapKeyByValue(kustomizeIdentifiersMap)
|
||||
|
||||
fmt.Printf(`The count of unique document IDs in the kustomize index: %d
|
||||
There are %d documents in the kustomize index.
|
||||
%d kinds of kubernetes objects are customized:`, len(ids), count, len(kindsMap))
|
||||
fmt.Printf("\n")
|
||||
|
||||
kindCount := 0
|
||||
for _, key := range sortedKindsMapKeys {
|
||||
if *topKindsPtr < 0 || (*topKindsPtr >= 0 && kindCount < *topKindsPtr) {
|
||||
fmt.Printf("\tkind `%s` is customimzed in %d documents\n", key, kindsMap[key])
|
||||
kindCount++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf("%d kinds of identifiers are found:\n", len(identifiersMap))
|
||||
identifierCount := 0
|
||||
for _, key := range sortedIdentifiersMapKeys {
|
||||
if *topIdentifiersPtr < 0 || (*topIdentifiersPtr >= 0 && identifierCount < *topIdentifiersPtr) {
|
||||
fmt.Printf("\tidentifier `%s` appears in %d documents\n", key, identifiersMap[key])
|
||||
identifierCount++
|
||||
}
|
||||
}
|
||||
|
||||
fmt.Printf(`There are %d kustomization files in the kustomize index.
|
||||
%d kinds of kustomize features are found:`, kustomizationFilecount, len(kustomizeIdentifiersMap))
|
||||
fmt.Printf("\n")
|
||||
kustomizeFeatureCount := 0
|
||||
for _, key := range sortedKustomizeIdentifiersMapKeys {
|
||||
if *topKustomizeFeaturesPtr < 0 || (*topKustomizeFeaturesPtr >= 0 && kustomizeFeatureCount < *topKustomizeFeaturesPtr) {
|
||||
fmt.Printf("\tfeature `%s` is used in %d documents\n", key, kustomizeIdentifiersMap[key])
|
||||
kustomizeFeatureCount++
|
||||
}
|
||||
}
|
||||
}
|
||||
8
api/internal/crawl/cmd/log-parser/README.md
Normal file
8
api/internal/crawl/cmd/log-parser/README.md
Normal file
@@ -0,0 +1,8 @@
|
||||
This binary takes as its input a json file including GKE logs (which can be
|
||||
[exported](https://cloud.google.com/logging/docs/export/configure_export_v2) into
|
||||
[Cloud Storage](https://cloud.google.com/storage/docs/)),
|
||||
and extracts the `textPayload` field of each log entry.
|
||||
|
||||
Here is an log entry example:
|
||||
|
||||
{"insertId":"1sxuh4jg5lw6w10","labels":{"compute.googleapis.com/resource_name":"gke-crawler2-default-pool-5e55ea05-gzgv","container.googleapis.com/namespace_name":"default","container.googleapis.com/pod_name":"kustomize-stats-5bczg","container.googleapis.com/stream":"stdout"},"logName":"projects/haiyanmeng-gke-dev/logs/kustomize-stats","receiveTimestamp":"2020-01-06T23:33:07.012831742Z","resource":{"labels":{"cluster_name":"crawler2","container_name":"kustomize-stats","instance_id":"8183086081854184383","namespace_id":"default","pod_id":"kustomize-stats-5bczg","project_id":"haiyanmeng-gke-dev","zone":"us-central1-a"},"type":"container"},"severity":"INFO","textPayload":"The kustomize index already exists\n","timestamp":"2020-01-06T23:32:46.628930547Z"}
|
||||
48
api/internal/crawl/cmd/log-parser/main.go
Normal file
48
api/internal/crawl/cmd/log-parser/main.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if len(os.Args) != 2 {
|
||||
log.Fatalf("The usage of the command is: \n\t%s <log-file.json>", os.Args[0])
|
||||
}
|
||||
|
||||
file, err := os.Open(os.Args[1])
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
closeFile := func(file *os.File) {
|
||||
if err := file.Close(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
defer closeFile(file)
|
||||
|
||||
scanner := bufio.NewScanner(file)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
|
||||
var entry interface{}
|
||||
if err := json.Unmarshal([]byte(line), &entry); err != nil {
|
||||
log.Printf("failed to unmarshal a log entry: %s\n", line)
|
||||
}
|
||||
|
||||
m := entry.(map[string]interface{})
|
||||
if payload, ok := m["textPayload"]; ok {
|
||||
fmt.Printf("%s", payload)
|
||||
} else {
|
||||
log.Printf("the log entry does not have the `textPayload` field: %s\n", line)
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
54
api/internal/crawl/config/crawler/job/README.md
Normal file
54
api/internal/crawl/config/crawler/job/README.md
Normal file
@@ -0,0 +1,54 @@
|
||||
There are three ways of running the crawler job.
|
||||
|
||||
# Crawling all the documents in the index and crawling all the kustomization files on Github
|
||||
|
||||
This is the default setting of the crawler job. The `command` and `args` field
|
||||
of the container should be:
|
||||
|
||||
```
|
||||
command: ["/crawler"]
|
||||
args: []
|
||||
```
|
||||
|
||||
Or
|
||||
|
||||
```
|
||||
command: ["/crawler"]
|
||||
args: [""]
|
||||
```
|
||||
|
||||
# Crawling all the documents in the index
|
||||
|
||||
The `command` and `args` field of the container should be:
|
||||
|
||||
```
|
||||
command: ["/crawler"]
|
||||
args: ["index"]
|
||||
```
|
||||
|
||||
# Crawling all the kustomization files on Github
|
||||
|
||||
The `command` and `args` field of the container should be:
|
||||
|
||||
```
|
||||
command: ["/crawler"]
|
||||
args: ["github"]
|
||||
```
|
||||
|
||||
# Crawling all the kustomization files in a Github repo
|
||||
|
||||
The `command` and `args` field of the container should be like:
|
||||
|
||||
```
|
||||
command: ["/crawler"]
|
||||
args: ["github-repo", "kubernetes-sigs/kustomize"]
|
||||
```
|
||||
|
||||
# Crawling all the kustomization files in all the repositories of a Github user
|
||||
|
||||
The `command` and `args` field of the container should be like:
|
||||
|
||||
```
|
||||
command: ["/crawler"]
|
||||
args: ["github-user", "kubernetes-sigs"]
|
||||
```
|
||||
@@ -8,8 +8,10 @@ spec:
|
||||
restartPolicy: OnFailure
|
||||
containers:
|
||||
- name: crawler
|
||||
image: gcr.io/kustomize-search/crawler:latest
|
||||
image: gcr.io/haiyanmeng-gke-dev/crawler:v1
|
||||
imagePullPolicy: Always
|
||||
command: ["/crawler"]
|
||||
args: ["github-repo", "kubernetes-sigs/kustomize"]
|
||||
env:
|
||||
- name: GITHUB_ACCESS_TOKEN
|
||||
valueFrom:
|
||||
|
||||
20
api/internal/crawl/config/crawler/kustomize_stats/job.yaml
Normal file
20
api/internal/crawl/config/crawler/kustomize_stats/job.yaml
Normal file
@@ -0,0 +1,20 @@
|
||||
apiVersion: batch/v1
|
||||
kind: Job
|
||||
metadata:
|
||||
name: kustomize-stats
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
restartPolicy: OnFailure
|
||||
containers:
|
||||
- name: kustomize-stats
|
||||
image: gcr.io/haiyanmeng-gke-dev/kustomize_stats:v1
|
||||
imagePullPolicy: Always
|
||||
command: ["/kustomize_stats"]
|
||||
args: ["--kinds=50", "--identifiers=50", "--kustomize-features=50"]
|
||||
env:
|
||||
- name: ELASTICSEARCH_URL
|
||||
valueFrom:
|
||||
configMapKeyRef:
|
||||
name: elasticsearch-config
|
||||
key: es-url
|
||||
@@ -0,0 +1,3 @@
|
||||
resources:
|
||||
- ../base
|
||||
- job.yaml
|
||||
@@ -10,6 +10,8 @@ import (
|
||||
"os"
|
||||
"sync"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/internal/crawl/index"
|
||||
|
||||
_ "github.com/gomodule/redigo/redis"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/internal/crawl/doc"
|
||||
@@ -47,7 +49,7 @@ type CrawledDocument interface {
|
||||
|
||||
type CrawlSeed []*doc.Document
|
||||
|
||||
type IndexFunc func(CrawledDocument, Crawler) error
|
||||
type IndexFunc func(CrawledDocument, index.Mode) error
|
||||
type Converter func(*doc.Document) (CrawledDocument, error)
|
||||
|
||||
func logIfErr(err error) {
|
||||
@@ -72,17 +74,18 @@ func addBranches(cdoc CrawledDocument, match Crawler, indx IndexFunc,
|
||||
seen[cdoc.ID()] = struct{}{}
|
||||
|
||||
// Insert into index
|
||||
err := indx(cdoc, match)
|
||||
logIfErr(err)
|
||||
if err != nil {
|
||||
if err := indx(cdoc, index.InsertOrUpdate); err != nil {
|
||||
logger.Printf("Failed to insert or update %s %s: %v",
|
||||
cdoc.GetDocument().RepositoryURL, cdoc.GetDocument().FilePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
deps, err := cdoc.GetResources()
|
||||
logIfErr(err)
|
||||
if err != nil {
|
||||
logger.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, dep := range deps {
|
||||
if _, ok := seen[dep.ID()]; ok {
|
||||
continue
|
||||
@@ -93,7 +96,16 @@ func addBranches(cdoc CrawledDocument, match Crawler, indx IndexFunc,
|
||||
|
||||
func doCrawl(ctx context.Context, docsPtr *CrawlSeed, crawlers []Crawler, conv Converter, indx IndexFunc,
|
||||
seen map[string]struct{}, stack *CrawlSeed) {
|
||||
docCount := 0
|
||||
|
||||
UpdatedDocCount := 0
|
||||
seenDocCount := 0
|
||||
cachedDocCount := 0
|
||||
findMatchErrCount := 0
|
||||
FetchDocumentErrCount := 0
|
||||
SetCreatedErrCount := 0
|
||||
convErrCount := 0
|
||||
deleteDocCount := 0
|
||||
|
||||
// During the execution of the for loop, more Documents may be added into (*docsPtr).
|
||||
for len(*docsPtr) > 0 {
|
||||
// get the last Document in (*docPtr), which will be crawled in this iteration.
|
||||
@@ -103,38 +115,68 @@ func doCrawl(ctx context.Context, docsPtr *CrawlSeed, crawlers []Crawler, conv C
|
||||
*docsPtr = (*docsPtr)[:(len(*docsPtr) - 1)]
|
||||
|
||||
if _, ok := seen[tail.ID()]; ok {
|
||||
seenDocCount++
|
||||
continue
|
||||
}
|
||||
|
||||
if tail.WasCached() {
|
||||
logger.Printf("%s %s is cached already", tail.RepositoryURL, tail.FilePath)
|
||||
cachedDocCount++
|
||||
continue
|
||||
}
|
||||
docCount++
|
||||
|
||||
match := findMatch(tail, crawlers)
|
||||
if match == nil {
|
||||
logIfErr(fmt.Errorf(
|
||||
"%v could not match any crawler", tail))
|
||||
logIfErr(fmt.Errorf("%v could not match any crawler", tail))
|
||||
findMatchErrCount++
|
||||
continue
|
||||
}
|
||||
|
||||
logger.Println("Crawling ", tail.RepositoryURL, tail.FilePath)
|
||||
err := match.FetchDocument(ctx, tail)
|
||||
logIfErr(err)
|
||||
// If there was no change or there is an error, we don't have
|
||||
// to branch out, since the dependencies are already in the
|
||||
// index, or we cannot find the document.
|
||||
if err != nil || tail.WasCached() {
|
||||
if tail.WasCached() {
|
||||
logger.Println(tail.RepositoryURL, tail.FilePath, "is cached already")
|
||||
if err := match.FetchDocument(ctx, tail); err != nil {
|
||||
logger.Printf("FetchDocument failed on %s %s: %v",
|
||||
tail.RepositoryURL, tail.FilePath, err)
|
||||
FetchDocumentErrCount++
|
||||
// delete the document from the index
|
||||
cdoc := &doc.KustomizationDocument{
|
||||
Document: *tail,
|
||||
}
|
||||
seen[cdoc.ID()] = struct{}{}
|
||||
if err := indx(cdoc, index.Delete); err != nil {
|
||||
logger.Printf("Failed to delete %s %s: %v",
|
||||
cdoc.RepositoryURL, cdoc.FilePath, err)
|
||||
}
|
||||
deleteDocCount++
|
||||
continue
|
||||
}
|
||||
|
||||
logIfErr(match.SetCreated(ctx, tail))
|
||||
if err := match.SetCreated(ctx, tail); err != nil {
|
||||
logger.Printf("SetCreated failed on %s %s: %v",
|
||||
tail.RepositoryURL, tail.FilePath, err)
|
||||
SetCreatedErrCount++
|
||||
}
|
||||
|
||||
cdoc, err := conv(tail)
|
||||
logIfErr(err)
|
||||
// If conv returns an error, cdoc can still be added into the index so that
|
||||
// cdoc.Document can be searched.
|
||||
if err != nil {
|
||||
logger.Printf("conv failed on %s %s: %v",
|
||||
tail.RepositoryURL, tail.FilePath, err)
|
||||
convErrCount++
|
||||
}
|
||||
|
||||
UpdatedDocCount++
|
||||
addBranches(cdoc, match, indx, seen, stack)
|
||||
}
|
||||
logger.Printf("%d documents were crawled by doCrawl\n", docCount)
|
||||
logger.Printf("Summary of doCrawl:\n")
|
||||
logger.Printf("\t%d documents were updated\n", UpdatedDocCount)
|
||||
logger.Printf("\t%d documents were seen by the crawler already and skipped\n", seenDocCount)
|
||||
logger.Printf("\t%d documents were cached already and skipped\n", cachedDocCount)
|
||||
logger.Printf("\t%d documents didn't have a matching crawler and skipped\n", findMatchErrCount)
|
||||
logger.Printf("\t%d documents cannot be fetched, %d out of them are deleted\n",
|
||||
FetchDocumentErrCount, deleteDocCount)
|
||||
logger.Printf("\t%d documents cannot update its creation time but still were inserted or updated in the index\n", SetCreatedErrCount)
|
||||
logger.Printf("\t%d documents cannot be converted but still were inserted or updated in the index\n", convErrCount)
|
||||
}
|
||||
|
||||
// CrawlFromSeed updates all the documents in seed, and crawls all the new
|
||||
|
||||
@@ -11,6 +11,8 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/internal/crawl/index"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/internal/crawl/doc"
|
||||
"sigs.k8s.io/kustomize/api/konfig"
|
||||
)
|
||||
@@ -316,7 +318,7 @@ resources:
|
||||
Document: *d,
|
||||
}, nil
|
||||
},
|
||||
func(d CrawledDocument, cr Crawler) error {
|
||||
func(d CrawledDocument, mode index.Mode) error {
|
||||
visited[d.ID()]++
|
||||
return nil
|
||||
},
|
||||
|
||||
@@ -93,7 +93,21 @@ func (gc githubCrawler) Crawl(
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchDocument first tries to fetch the document with d.FilePath. If it fails,
|
||||
// it will try to add each string in konfig.RecognizedKustomizationFileNames() to
|
||||
// d.FilePath, and try to fetch the document again.
|
||||
func (gc githubCrawler) FetchDocument(_ context.Context, d *doc.Document) error {
|
||||
// set the default branch if it is empty
|
||||
if d.DefaultBranch == "" {
|
||||
url := gc.client.ReposRequest(d.RepositoryFullName())
|
||||
defaultBranch, err := gc.client.GetDefaultBranch(url)
|
||||
if err != nil {
|
||||
logger.Printf(
|
||||
"(error: %v) setting default_branch to master\n", err)
|
||||
defaultBranch = "master"
|
||||
}
|
||||
d.DefaultBranch = defaultBranch
|
||||
}
|
||||
repoURL := d.RepositoryURL + "/" + d.FilePath + "?ref=" + d.DefaultBranch
|
||||
repoSpec, err := git.NewRepoSpecFromUrl(repoURL)
|
||||
if err != nil {
|
||||
@@ -104,9 +118,13 @@ func (gc githubCrawler) FetchDocument(_ context.Context, d *doc.Document) error
|
||||
"/" + repoSpec.Ref + "/" + repoSpec.Path
|
||||
|
||||
handle := func(resp *http.Response, err error, path string) error {
|
||||
if resp == nil {
|
||||
return fmt.Errorf("empty http response (url: %s; path: %s), error: %v",
|
||||
url, path, err)
|
||||
}
|
||||
if err == nil && resp.StatusCode == http.StatusOK {
|
||||
d.IsSame = httpclient.FromCache(resp.Header)
|
||||
defer resp.Body.Close()
|
||||
defer CloseResponseBody(resp)
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -115,18 +133,18 @@ func (gc githubCrawler) FetchDocument(_ context.Context, d *doc.Document) error
|
||||
d.FilePath = d.FilePath + path
|
||||
return nil
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
resp, err := gc.client.GetRawUserContent(url)
|
||||
if err := handle(resp, err, ""); err == nil {
|
||||
resp, errGetRawUserContent := gc.client.GetRawUserContent(url)
|
||||
if err := handle(resp, errGetRawUserContent, ""); err == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, file := range konfig.RecognizedKustomizationFileNames() {
|
||||
resp, err = gc.client.GetRawUserContent(url + "/" + file)
|
||||
err := handle(resp, err, "/"+file)
|
||||
if err != nil {
|
||||
continue
|
||||
resp, errGetRawUserContent = gc.client.GetRawUserContent(url + "/" + file)
|
||||
if err = handle(resp, errGetRawUserContent, "/"+file); err == nil {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("file not found: %s, error: %v", url, err)
|
||||
@@ -293,7 +311,10 @@ func (gcl GhClient) GetFileData(k GhFileSpec) ([]byte, error) {
|
||||
return nil, fmt.Errorf("%+v: could not read '%s' metadata: %v",
|
||||
k, url, err)
|
||||
}
|
||||
resp.Body.Close()
|
||||
|
||||
if err := resp.Body.Close(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
type githubContentRawURL struct {
|
||||
DownloadURL string `json:"download_url,omitempty"`
|
||||
@@ -312,18 +333,24 @@ func (gcl GhClient) GetFileData(k GhFileSpec) ([]byte, error) {
|
||||
k, rawURL.DownloadURL, err)
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
defer CloseResponseBody(resp)
|
||||
data, err = ioutil.ReadAll(resp.Body)
|
||||
return data, err
|
||||
}
|
||||
|
||||
func CloseResponseBody(resp *http.Response) {
|
||||
if err := resp.Body.Close(); err != nil {
|
||||
log.Printf("failed to close response body: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (gcl GhClient) GetDefaultBranch(url string) (string, error) {
|
||||
resp, err := gcl.GetReposData(url)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf(
|
||||
"'%s' could not get default_branch: %v", url, err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer CloseResponseBody(resp)
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf(
|
||||
@@ -375,7 +402,7 @@ func (gcl GhClient) GetFileCreationTime(
|
||||
}
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
defer CloseResponseBody(resp)
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return defaultTime, fmt.Errorf(
|
||||
@@ -498,7 +525,7 @@ func (gcl GhClient) parseGithubResponse(getRequest string) GhResponseInfo {
|
||||
}
|
||||
|
||||
var data []byte
|
||||
defer resp.Body.Close()
|
||||
defer CloseResponseBody(resp)
|
||||
data, requestInfo.Error = ioutil.ReadAll(resp.Body)
|
||||
if requestInfo.Error != nil {
|
||||
return requestInfo
|
||||
@@ -559,7 +586,15 @@ func (gcl GhClient) Do(query string) (*http.Response, error) {
|
||||
return nil, err
|
||||
}
|
||||
req.Header.Add("Authorization", fmt.Sprintf("token %s", gcl.accessToken))
|
||||
return gcl.client.Do(req)
|
||||
|
||||
// gcl.client.Do: a non-2xx status code doesn't cause an error.
|
||||
// See https://golang.org/pkg/net/http/#Client.Do for more info.
|
||||
resp, err := gcl.client.Do(req)
|
||||
if resp != nil && resp.StatusCode != http.StatusOK {
|
||||
err = fmt.Errorf("GhClient.Do(%s) failed with response code: %d",
|
||||
query, resp.StatusCode)
|
||||
}
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func (gcl GhClient) getWithRetry(
|
||||
@@ -569,13 +604,10 @@ func (gcl GhClient) getWithRetry(
|
||||
|
||||
retryCount := gcl.retryCount
|
||||
|
||||
for err == nil &&
|
||||
resp.StatusCode == http.StatusForbidden &&
|
||||
retryCount > 0 {
|
||||
|
||||
for resp != nil && resp.StatusCode == http.StatusForbidden && retryCount > 0 {
|
||||
retryTime := resp.Header.Get("Retry-After")
|
||||
i, err := strconv.Atoi(retryTime)
|
||||
if err != nil {
|
||||
i, errAtoi := strconv.Atoi(retryTime)
|
||||
if errAtoi != nil {
|
||||
return resp, fmt.Errorf(
|
||||
"query '%s' forbidden without 'Retry-After'", query)
|
||||
}
|
||||
|
||||
@@ -116,9 +116,11 @@ type RequestConfig struct {
|
||||
// the URL method to get the string value of the URL. See request.CopyWith, to
|
||||
// understand why the request object is useful.
|
||||
func (rc RequestConfig) CodeSearchRequestWith(query Query) request {
|
||||
req := rc.makeRequest("search/code", query)
|
||||
req.vals.Set("sort", "indexed")
|
||||
req.vals.Set("order", "desc")
|
||||
vals := url.Values{
|
||||
"sort": []string{"indexed"},
|
||||
"order": []string{"desc"},
|
||||
}
|
||||
req := rc.makeRequest("search/code", query, vals)
|
||||
return req
|
||||
}
|
||||
|
||||
@@ -126,27 +128,25 @@ func (rc RequestConfig) CodeSearchRequestWith(query Query) request {
|
||||
// query for the Github API to find the dowload information of this filepath.
|
||||
func (rc RequestConfig) ContentsRequest(fullRepoName, path string) string {
|
||||
uri := fmt.Sprintf("repos/%s/contents/%s", fullRepoName, path)
|
||||
return rc.makeRequest(uri, Query{}).URL()
|
||||
return rc.makeRequest(uri, Query{}, url.Values{}).URL()
|
||||
}
|
||||
|
||||
func (rc RequestConfig) ReposRequest(fullRepoName string) string {
|
||||
uri := fmt.Sprintf("repos/%s", fullRepoName)
|
||||
return rc.makeRequest(uri, Query{}).URL()
|
||||
}
|
||||
|
||||
func escapeSpace(s string) string {
|
||||
return strings.Replace(s, " ", "%20", -1)
|
||||
return rc.makeRequest(uri, Query{}, url.Values{}).URL()
|
||||
}
|
||||
|
||||
// CommitsRequest given the repo name, and a filepath returns a formatted query
|
||||
// for the Github API to find the commits that affect this file.
|
||||
func (rc RequestConfig) CommitsRequest(fullRepoName, path string) string {
|
||||
uri := fmt.Sprintf("repos/%s/commits", fullRepoName)
|
||||
return rc.makeRequest(uri, Query{Path(escapeSpace(path))}).URL()
|
||||
vals := url.Values{
|
||||
"path": []string{path},
|
||||
}
|
||||
return rc.makeRequest(uri, Query{}, vals).URL()
|
||||
}
|
||||
|
||||
func (rc RequestConfig) makeRequest(path string, query Query) request {
|
||||
vals := url.Values{}
|
||||
func (rc RequestConfig) makeRequest(path string, query Query, vals url.Values) request {
|
||||
vals.Set(perPageArg, fmt.Sprint(rc.perPage))
|
||||
|
||||
return request{
|
||||
|
||||
@@ -101,7 +101,7 @@ func TestGithubSearchQuery(t *testing.T) {
|
||||
"examples/helloWorld/kustomization.yaml?per_page=100",
|
||||
|
||||
expectedCommitsQuery: "https://api.github.com/repos/kubernetes-sigs/kustomize/commits?" +
|
||||
"q=path:examples/helloWorld/kustomization.yaml&per_page=100",
|
||||
"path=examples%2FhelloWorld%2Fkustomization.yaml&per_page=100",
|
||||
},
|
||||
{
|
||||
rc: RequestConfig{
|
||||
@@ -121,7 +121,7 @@ func TestGithubSearchQuery(t *testing.T) {
|
||||
"examples%201/helloWorld/kustomization.yaml?per_page=100",
|
||||
|
||||
expectedCommitsQuery: "https://api.github.com/repos/kubernetes-sigs/kustomize/commits?" +
|
||||
"q=path:examples%201/helloWorld/kustomization.yaml&per_page=100",
|
||||
"path=examples+1%2FhelloWorld%2Fkustomization.yaml&per_page=100",
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package doc
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/api/k8sdeps/kunstruct"
|
||||
@@ -46,7 +47,7 @@ type set map[string]struct{}
|
||||
func (doc *KustomizationDocument) String() string {
|
||||
return fmt.Sprintf("%s %s %s %v %v %v len(identifiers):%v len(values):%v",
|
||||
doc.RepositoryURL, doc.FilePath, doc.DefaultBranch, doc.CreationTime,
|
||||
doc.IsSame, doc.Kinds, len(doc.Identifiers), len(doc.Values))
|
||||
doc.IsSame, doc.Kinds, len(doc.Identifiers), len(doc.Values))
|
||||
}
|
||||
|
||||
// Implements the CrawlerDocument interface.
|
||||
@@ -77,6 +78,9 @@ func (doc *KustomizationDocument) GetResources() ([]*Document, error) {
|
||||
|
||||
res := make([]*Document, 0, len(k.Resources))
|
||||
for _, r := range k.Resources {
|
||||
if strings.TrimSpace(r) == "" {
|
||||
continue
|
||||
}
|
||||
next, err := doc.Document.FromRelativePath(r)
|
||||
if err != nil {
|
||||
fmt.Printf("GetResources error: %v\n", err)
|
||||
@@ -116,6 +120,8 @@ func (doc *KustomizationDocument) readBytes() ([]map[string]interface{}, error)
|
||||
return configs, nil
|
||||
}
|
||||
|
||||
// ParseYAML parses doc.Document and sets the following fields of doc:
|
||||
// Kinds, Values, Identifiers.
|
||||
func (doc *KustomizationDocument) ParseYAML() error {
|
||||
doc.Identifiers = make([]string, 0)
|
||||
doc.Values = make([]string, 0)
|
||||
@@ -159,6 +165,13 @@ func (doc *KustomizationDocument) ParseYAML() error {
|
||||
doc.Identifiers = append(doc.Identifiers, key)
|
||||
}
|
||||
|
||||
// Without sorting these fields, every time when the string order in these fields changes,
|
||||
// the document in the index will be updated.
|
||||
// Sorting these fields are necessary to avoid a document being updated unnecessarily.
|
||||
sort.Strings(doc.Kinds)
|
||||
sort.Strings(doc.Values)
|
||||
sort.Strings(doc.Identifiers)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -78,11 +78,17 @@ func (doc *Document) ID() string {
|
||||
}
|
||||
|
||||
func (doc *Document) RepositoryFullName() string {
|
||||
doc.RepositoryURL = strings.TrimRight(doc.RepositoryURL, "/")
|
||||
sections := strings.Split(doc.RepositoryURL, "/")
|
||||
url := strings.TrimRight(doc.RepositoryURL, "/")
|
||||
|
||||
gitPrefix := "git@github.com:"
|
||||
if strings.HasPrefix(url, gitPrefix) {
|
||||
url = url[len(gitPrefix):]
|
||||
}
|
||||
|
||||
sections := strings.Split(url, "/")
|
||||
l := len(sections)
|
||||
if l < 2 {
|
||||
return doc.RepositoryURL
|
||||
return url
|
||||
}
|
||||
return path.Join(sections[l-2], sections[l-1])
|
||||
}
|
||||
|
||||
@@ -92,6 +92,12 @@ func TestDocument_RepositoryFullName(t *testing.T) {
|
||||
},
|
||||
expectedRepositoryFullName: "",
|
||||
},
|
||||
{
|
||||
doc: Document{
|
||||
RepositoryURL: "git@github.com:user/repo",
|
||||
},
|
||||
expectedRepositoryFullName: "user/repo",
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
module sigs.k8s.io/kustomize/api/internal/crawl
|
||||
|
||||
go 1.13
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/elastic/go-elasticsearch/v6 v6.8.2
|
||||
github.com/elastic/go-elasticsearch/v6 v6.8.5
|
||||
github.com/gomodule/redigo v2.0.0+incompatible
|
||||
github.com/gorilla/mux v1.7.3
|
||||
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
|
||||
github.com/rs/cors v1.7.0
|
||||
sigs.k8s.io/kustomize/api v0.3.0
|
||||
sigs.k8s.io/kustomize/api v0.3.1
|
||||
sigs.k8s.io/yaml v1.1.0
|
||||
)
|
||||
|
||||
@@ -2,14 +2,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||
github.com/Azure/go-autorest/autorest v0.9.2/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.8.0/go.mod h1:Z6vX6WXXuyieHAXwMj0S6HY6e6wcHn37qQMBQlvY3lc=
|
||||
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
|
||||
github.com/Azure/go-autorest/autorest/date v0.2.0/go.mod h1:vcORJHLJEh643/Ioh9+vPmf1Ij9AEBM5FuBIXLmIy0g=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.3.0/go.mod h1:a8FDP3DYzQ4RYfVAxAN3SVSiiO77gL2j2ronKKP0syM=
|
||||
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
|
||||
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
@@ -44,14 +40,10 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
|
||||
github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c/go.mod h1:Qh8CwZgvJUkLughtfhJv5dyTYa91l1fOUCrgjqmcifM=
|
||||
github.com/elastic/go-elasticsearch/v6 v6.8.2 h1:rp5DGrd63V5c6nHLjF6QEXUpZSvs0+QM3ld7m9VhV2g=
|
||||
github.com/elastic/go-elasticsearch/v6 v6.8.2/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
|
||||
github.com/elastic/go-elasticsearch/v6 v6.8.5 h1:U2HtkBseC1FNBmDr0TR2tKltL6FxoY+niDAlj5M8TK8=
|
||||
github.com/elastic/go-elasticsearch/v6 v6.8.5/go.mod h1:UwaDJsD3rWLM5rKNFzv9hgox93HoX8utj1kxD9aFUcI=
|
||||
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484/go.mod h1:Ro8st/ElPeALwNFlcTpWmkr6IoMFfkjXAvTHpevnDsM=
|
||||
github.com/elazarl/goproxy/ext v0.0.0-20190711103511-473e67f1d7d2/go.mod h1:gNh8nYJoAm43RfaxurUnxr+N1PwuFV3ZMl/efxlIlY8=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/emicklei/go-restful v2.9.6+incompatible/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible h1:ouOWdg56aJriqS0huScTkVXPC5IcNrDCXZ6OoTAWu7M=
|
||||
github.com/evanphx/json-patch v4.5.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
@@ -95,13 +87,11 @@ github.com/gobwas/glob v0.2.3/go.mod h1:d3Ez4x06l9bZtSvzIay5+Yzi0fmZzPgnTbPcKjJA
|
||||
github.com/gofrs/flock v0.0.0-20190320160742-5135e617513b/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20190129154638-5b532d6fd5ef/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/groupcache v0.0.0-20191027212112-611e8accdfc9/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
@@ -115,12 +105,9 @@ github.com/golangci/errcheck v0.0.0-20181223084120-ef45e06d44b6/go.mod h1:DbHgvL
|
||||
github.com/golangci/go-misc v0.0.0-20180628070357-927a3d87b613/go.mod h1:SyvUF2NxV+sN8upjjeVYr5W7tyxaT1JVtvhKhOn2ii8=
|
||||
github.com/golangci/goconst v0.0.0-20180610141641-041c5f2b40f3/go.mod h1:JXrF4TWy4tXYn62/9x8Wm/K/dm06p8tCKwFRDPZG/1o=
|
||||
github.com/golangci/gocyclo v0.0.0-20180528134321-2becd97e67ee/go.mod h1:ozx7R9SIwqmqf5pRP90DhR2Oay2UIjGuKheCBCNwAYU=
|
||||
github.com/golangci/gofmt v0.0.0-20181222123516-0b8337e80d98/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
|
||||
github.com/golangci/gofmt v0.0.0-20190930125516-244bba706f1a/go.mod h1:9qCChq59u/eW8im404Q2WWTrnBUQKjpNYKMbU4M7EFU=
|
||||
github.com/golangci/golangci-lint v1.19.1/go.mod h1:2CEc4Fxx3vxDv7g8DyXkHCBF73AOzAymcJAprs2vCps=
|
||||
github.com/golangci/golangci-lint v1.21.0/go.mod h1:phxpHK52q7SE+5KpPnti4oZTdFCEsn/tKN+nFvCKXfk=
|
||||
github.com/golangci/ineffassign v0.0.0-20190609212857-42439a7714cc/go.mod h1:e5tpTHCfVze+7EpLEozzMB3eafxo2KT5veNg1k6byQU=
|
||||
github.com/golangci/lint-1 v0.0.0-20190420132249-ee948d087217/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg=
|
||||
github.com/golangci/lint-1 v0.0.0-20191013205115-297bf364a8e0/go.mod h1:66R6K6P6VWk9I95jvqGxkqJxVWGFy9XlDwLwVz1RCFg=
|
||||
github.com/golangci/maligned v0.0.0-20180506175553-b1d89398deca/go.mod h1:tvlJhZqDe4LMs4ZHD0oMUlt9G2LWuDGoisJTBzLMV9o=
|
||||
github.com/golangci/misspell v0.0.0-20180809174111-950f5d19e770/go.mod h1:dEbvlSfYbMQDtrpRMQU675gSDLDNa8sCPPChZ7PhiVA=
|
||||
@@ -132,9 +119,8 @@ github.com/gomodule/redigo v2.0.0+incompatible/go.mod h1:B4C85qUVwatsJoIUNIfCRsp
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/btree v1.0.0/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
|
||||
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
|
||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||
github.com/google/gofuzz v0.0.0-20161122191042-44d81051d367/go.mod h1:HP5RmnzzSNb993RKQDq4+1A4ia9nllfqcQFTQJedwGI=
|
||||
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||
@@ -144,18 +130,11 @@ github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm4
|
||||
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
|
||||
github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d h1:7XGaL1e6bYS1yIonGp9761ExpPPV1ui0SAC59Yube9k=
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/googleapis/gnostic v0.3.0 h1:CcQijm0XKekKjP/YCz28LXVSpgguuB+nCxaSjCe09y0=
|
||||
github.com/googleapis/gnostic v0.3.0/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
|
||||
github.com/gophercloud/gophercloud v0.6.0/go.mod h1:GICNByuaEBibcjmjvI7QvYJSZEbGkcYwAR7EZK2WMqM=
|
||||
github.com/gorilla/context v0.0.0-20160226214623-1ea25387ff6f/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.0/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gorilla/securecookie v0.0.0-20160422134519-667fe4e3466a/go.mod h1:ra0sb63/xPlUeL+yeDciTfxMRAA+MP+HVt/4epWDjd4=
|
||||
github.com/gorilla/sessions v0.0.0-20160922145804-ca9ada445741/go.mod h1:+WVp8kdw6VhyKExm03PAMRn2ZxnPtm58pV0dBVPdhHE=
|
||||
github.com/gorilla/websocket v1.2.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gostaticanalysis/analysisutil v0.0.0-20190318220348-4088753ea4d3/go.mod h1:eEOZF4jCKGi+aprrirO9e7WKB3beBRtWgqGunKl6pKE=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
@@ -166,7 +145,6 @@ github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0/go.mod h1:8NvIoxWQoOIhqOTXgf
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.9.0/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/golang-lru v0.5.3/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hpcloud/tail v1.0.0 h1:nfCOvKYfkgYP8hkirhJocXT2+zOD8yUNjXaWfTlyFKI=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
@@ -200,9 +178,7 @@ github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czP
|
||||
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/matoous/godox v0.0.0-20190910121045-032ad8106c86/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
|
||||
github.com/matoous/godox v0.0.0-20190911065817-5d6d842e92eb/go.mod h1:1BELzlh859Sh1c6+90blK8lbYy0kwQf1bYlBhBysy1s=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/goveralls v0.0.2/go.mod h1:8d1ZMHsd7fW6IRPKQh46F2WRpyib5/X4FOpevwGNQEw=
|
||||
@@ -217,8 +193,6 @@ github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lN
|
||||
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/modern-go/reflect2 v1.0.1 h1:9f412s+6RmYXLWZSEzVVgPGK7C2PphHj5RJrvfx9AWI=
|
||||
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
|
||||
github.com/monopole/mdrip v1.0.0/go.mod h1:N1/ppRG9CaPeUKAUHZ3dUlfOT81lTpKZLkyhCvTETwM=
|
||||
github.com/monopole/mdrip v1.0.1/go.mod h1:/7E04hlzRG9Jrp6WILZfYYm/REoJWL2l+MlsCO1eH74=
|
||||
github.com/mozilla/tls-observatory v0.0.0-20190404164649-a3c1b6cfecfd/go.mod h1:SrKMQvPiws7F7iqYp8/TX+IhxCYhzr6N/1yb8cwHsGk=
|
||||
github.com/munnerz/goautoneg v0.0.0-20120707110453-a547fc61f48d/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
@@ -251,19 +225,15 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
|
||||
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
|
||||
github.com/quasilyte/go-consistent v0.0.0-20190521200055-c6f3937de18c/go.mod h1:5STLWrekHfjyYwxBRVRXNOSewLJ3PWfDJd1VyTS21fI=
|
||||
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
|
||||
github.com/rogpeppe/go-charset v0.0.0-20180617210344-2471d30d28b4/go.mod h1:qgYeAmZ5ZIpBWTGllZSQnw97Dj+woV0toclVaRGI8pc=
|
||||
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
|
||||
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
||||
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/russross/blackfriday v2.0.0+incompatible/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/securego/gosec v0.0.0-20190912120752-140048b2a218/go.mod h1:q6oYAujd2qyeU4cJqIri4LBIgdHXGvxWHZ1E29HNFRE=
|
||||
github.com/securego/gosec v0.0.0-20191002120514-e680875ea14d/go.mod h1:w5+eXa0mYznDkHaMCXA4XYffjlH+cy1oyKbfzJXa2Do=
|
||||
github.com/shirou/gopsutil v0.0.0-20190901111213-e4ec7b275ada/go.mod h1:WWnYX4lzhCH5h/3YBfyVA3VbLYjlMZZAQcW9ojMexNc=
|
||||
github.com/shirou/w32 v0.0.0-20160930032740-bb4de0191aa4/go.mod h1:qsXQc7+bwAM3Q1u/4XEfrquwF8Lw7D7y5cD8CuHnfIc=
|
||||
github.com/shurcooL/go v0.0.0-20180423040247-9e1955d9fb6e/go.mod h1:TDJrrUr11Vxrven61rcy3hJMUqaf/CLWYhHNPmT14Lk=
|
||||
github.com/shurcooL/go-goon v0.0.0-20170922171312-37c2f522c041/go.mod h1:N5mDOmsrJOB+vfqUK+7DmDyjhSLIIBnXo9lvZJj3MWQ=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
@@ -288,13 +258,11 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/timakin/bodyclose v0.0.0-20190721030226-87058b9bfcec/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
|
||||
github.com/timakin/bodyclose v0.0.0-20190930140734-f7f2e9bca95e/go.mod h1:Qimiffbc6q9tBWlVV6x0P9sat/ao1xEkREYPPj9hphk=
|
||||
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
|
||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||
github.com/ugorji/go/codec v0.0.0-20181204163529-d75b2dcb6bc8/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
|
||||
github.com/ultraware/funlen v0.0.2/go.mod h1:Dp4UiAus7Wdb9KUZsYWZEWiRzGuM2kXM1lPbfaF6xhA=
|
||||
github.com/ultraware/whitespace v0.0.3/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA=
|
||||
github.com/ultraware/whitespace v0.0.4/go.mod h1:aVMh/gQve5Maj9hQ/hg+F75lr/X5A89uZnzAmWSineA=
|
||||
github.com/uudashr/gocognit v0.0.0-20190926065955-1655d0de0517/go.mod h1:j44Ayx2KW4+oB6SWMv8KsmHzZrOInQav7D3cQMJ5JUM=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
@@ -315,7 +283,6 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk
|
||||
golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190611184440-5c40567a22f8/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190911031432-227b76d455e7/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
@@ -338,9 +305,8 @@ golang.org/x/net v0.0.0-20190522155817-f3200d17e092/go.mod h1:HSz+uSET+XFnRR8LxR
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc=
|
||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
@@ -364,8 +330,7 @@ golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7w
|
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190616124812-15dcb6c0061f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190911201528-7ad0cfa0b7b5 h1:SW/0nsKCUaozCUtZTakri5laocGx/5bkDSSLrFUsa5s=
|
||||
golang.org/x/sys v0.0.0-20190911201528-7ad0cfa0b7b5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69 h1:rOhMmluY6kLMhdnrivzec6lLgaVbMHMn2ISQXJeJ5EM=
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
@@ -374,7 +339,6 @@ golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/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-20180525024113-a5b4c53f6e8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
@@ -393,8 +357,6 @@ golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgw
|
||||
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190719005602-e377ae9d6386/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
|
||||
golang.org/x/tools v0.0.0-20190910044552-dd2b5c81c578/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190911230505-6bfd74cf029c/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190912215617-3720d1ec3678/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20190930201159-7c411dea38b0/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/tools v0.0.0-20191010075000-0337d82405ff/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
@@ -418,7 +380,6 @@ gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMy
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/resty.v1 v1.12.0/go.mod h1:mDo4pnntr5jdWRML875a/NmxYqAlA73dVijT2AXvQQo=
|
||||
gopkg.in/russross/blackfriday.v2 v2.0.0/go.mod h1:6sSBNz/GtOm/pJTuh5UmBK2ZHfmnxGbl2NZg1UliSOI=
|
||||
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.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||
@@ -429,8 +390,11 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
k8s.io/api v0.17.0 h1:H9d/lw+VkZKEVIUc8F3wgiQ+FUXTTr21M87jXLU7yqM=
|
||||
k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI=
|
||||
k8s.io/apimachinery v0.17.0 h1:xRBnuie9rXcPxUkDizUsGvPf1cnlZCFu210op7J7LJo=
|
||||
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
|
||||
k8s.io/client-go v0.17.0 h1:8QOGvUGdqDMFrm9sD6IUFl256BcffynGoe80sxgTEDg=
|
||||
k8s.io/client-go v0.17.0/go.mod h1:TYgR6EUHs6k45hb6KWjVD6jFZvJV4gHDikv/It0xz+k=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
k8s.io/klog v0.0.0-20181102134211-b9b56d5dfc92/go.mod h1:Gq+BEi5rUBO/HRz0bTSXDUcqjScdoY3a9IHpCEIOOfk=
|
||||
@@ -439,17 +403,12 @@ k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
||||
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
|
||||
k8s.io/utils v0.0.0-20191030222137-2b95a09bc58d/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
mvdan.cc/interfacer v0.0.0-20180901003855-c20040233aed/go.mod h1:Xkxe497xwlCKkIaQYRfC7CSLworTXY9RMqwhhCm+8Nc=
|
||||
mvdan.cc/lint v0.0.0-20170908181259-adc824a0674b/go.mod h1:2odslEg/xrtNQqCYg2/jCoyKnw3vv5biOc3JnIcYfL4=
|
||||
mvdan.cc/unparam v0.0.0-20190720180237-d51796306d8f/go.mod h1:4G1h5nDURzA3bwVMZIVpwbkw+04kSxk3rAtzlimaUJw=
|
||||
sigs.k8s.io/kustomize/api v0.2.0 h1:e++6JpysnnlUbHmFrv6jvfF5rFlgQ103bS1DO7r5bWA=
|
||||
sigs.k8s.io/kustomize/api v0.2.0/go.mod h1:zVtMg179jW1gr74jo9fc2Ac9dLYLTZZThc3DDb9lDW4=
|
||||
sigs.k8s.io/kustomize/api v0.3.0/go.mod h1:4jaPCtRzxfQLFdYq4gYo40dBGW1hyPp/f4AuiZB5dAQ=
|
||||
sigs.k8s.io/kustomize/pluginator/v2 v2.0.0/go.mod h1:zrXhTv8BAKt0egmZX/8AtMOSFUSWM9YuoHvvqz8/eHE=
|
||||
sigs.k8s.io/kustomize/pseudo/k8s v0.1.0 h1:otg4dLFc03c3gzl+2CV8GPGcd1kk8wjXwD+UhhcCn5I=
|
||||
sigs.k8s.io/kustomize/pseudo/k8s v0.1.0/go.mod h1:bl/gVJgYYhJZCZdYU2BfnaKYAlqFkgbJEkpl302jEss=
|
||||
sigs.k8s.io/kustomize/api v0.3.1 h1:oqMIXvS6tFEUVuKIRUKDa05eC4Hh+cb9JYg8Zhp2d24=
|
||||
sigs.k8s.io/kustomize/api v0.3.1/go.mod h1:A+ATnlHqzictQfQC1q3KB/T6MSr0UWQsrrLxMWkge2E=
|
||||
sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:wWxsB5ozmmv/SG7nM11ayaAW51xMvak/t1r0CSlcokI=
|
||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
es "github.com/elastic/go-elasticsearch/v6"
|
||||
@@ -179,44 +178,47 @@ func (idx *index) DeleteIndex() error {
|
||||
}
|
||||
|
||||
// Insert or update the document by ID.
|
||||
func (idx *index) Put(uniqueID string, doc interface{}) (string, error) {
|
||||
body, err := json.Marshal(doc)
|
||||
func (idx *index) Put(uniqueID string, doc interface{}) error {
|
||||
exists, err := idx.Exists(uniqueID)
|
||||
if err != nil {
|
||||
return "", err
|
||||
return err
|
||||
}
|
||||
|
||||
req := esapi.IndexRequest{
|
||||
Index: idx.name,
|
||||
Body: bytes.NewReader(body),
|
||||
DocumentID: uniqueID,
|
||||
}
|
||||
res, err := req.Do(idx.ctx, idx.client)
|
||||
|
||||
var id string
|
||||
readId := func(reader io.Reader) error {
|
||||
type InsertResult struct {
|
||||
ID string `json:"_id,omitempty"`
|
||||
if exists {
|
||||
docBytes, err := json.Marshal(doc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
var ir InsertResult
|
||||
data, err := ioutil.ReadAll(reader)
|
||||
body := byteJoin(`{"doc":`, docBytes, `}`)
|
||||
|
||||
// For a document with a given id, every call of IndexRequest.Do will increase the version of a document.
|
||||
// To avoid increasing the document version unnecessarily, use UpdateRequest here.
|
||||
req := esapi.UpdateRequest{
|
||||
Index: idx.name,
|
||||
Body: bytes.NewReader(body),
|
||||
DocumentID: uniqueID,
|
||||
}
|
||||
res, err := req.Do(idx.ctx, idx.client)
|
||||
|
||||
err = idx.responseErrorOrNil("could not update document",
|
||||
res, err, ignoreResponseBody)
|
||||
} else {
|
||||
body, err := json.Marshal(doc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = json.Unmarshal(data, &ir)
|
||||
if err != nil {
|
||||
return err
|
||||
req := esapi.IndexRequest{
|
||||
Index: idx.name,
|
||||
Body: bytes.NewReader(body),
|
||||
DocumentID: uniqueID,
|
||||
}
|
||||
id = ir.ID
|
||||
res, err := req.Do(idx.ctx, idx.client)
|
||||
|
||||
return nil
|
||||
err = idx.responseErrorOrNil("could not insert document",
|
||||
res, err, ignoreResponseBody)
|
||||
}
|
||||
|
||||
// populates the id field.
|
||||
err = idx.responseErrorOrNil("could not insert document",
|
||||
res, err, readId)
|
||||
|
||||
return id, err
|
||||
return err
|
||||
}
|
||||
|
||||
type scrollUpdater func(string, readerFunc) error
|
||||
@@ -296,3 +298,24 @@ func (idx *index) Delete(id string) error {
|
||||
fmt.Sprintf("could not delete id(%s) from index(%s)", id, idx.name),
|
||||
res, err, ignoreResponseBody)
|
||||
}
|
||||
|
||||
// Check whether a given document id is in the index
|
||||
func (idx *index) Exists(id string) (bool, error) {
|
||||
op := idx.client.Exists
|
||||
res, err := op(
|
||||
idx.name,
|
||||
id,
|
||||
op.WithContext(idx.ctx),
|
||||
op.WithPretty(),
|
||||
)
|
||||
|
||||
if res != nil && !res.IsError() {
|
||||
return true, nil
|
||||
} else if res != nil && res.StatusCode == 404 {
|
||||
return false, nil
|
||||
} else {
|
||||
return false, idx.responseErrorOrNil(
|
||||
fmt.Sprintf("could not check the existence of id(%s) from index(%s)", id, idx.name),
|
||||
res, err, ignoreResponseBody)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,12 @@ const (
|
||||
AggregationKeyword = "aggs"
|
||||
)
|
||||
|
||||
type Mode int
|
||||
const (
|
||||
InsertOrUpdate = iota
|
||||
Delete
|
||||
)
|
||||
|
||||
// Redefinition of Hits structure. Must match the json string of
|
||||
// KustomizeResult.Hits.Hits. Declared as a convenience for iteration.
|
||||
type KustomizeHits []struct {
|
||||
@@ -293,12 +299,13 @@ func (ki *KustomizeIndex) IterateQuery(query []byte, batchSize int,
|
||||
}
|
||||
|
||||
// type specific Put for inserting structured kustomization documents.
|
||||
func (ki *KustomizeIndex) Put(id string, doc *doc.KustomizationDocument) (string, error) {
|
||||
id, err := ki.index.Put(id, doc)
|
||||
if err != nil {
|
||||
return id, fmt.Errorf("could not insert in elastic: %v", err)
|
||||
}
|
||||
return id, nil
|
||||
func (ki *KustomizeIndex) Put(id string, doc *doc.KustomizationDocument) error {
|
||||
return ki.index.Put(id, doc)
|
||||
}
|
||||
|
||||
// Delete a document with a given id from the kustomize index.
|
||||
func (ki *KustomizeIndex) Delete(id string) error {
|
||||
return ki.index.Delete(id)
|
||||
}
|
||||
|
||||
// Kustomize search options: What metrics should be returned? Kind Aggregation,
|
||||
|
||||
180
api/internal/crawl/search_cmds/creationTime.md
Normal file
180
api/internal/crawl/search_cmds/creationTime.md
Normal file
@@ -0,0 +1,180 @@
|
||||
Find out the largest value of the `creationTime` field:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"aggs" : {
|
||||
"max_creationTime" : { "max" : { "field" : "creationTime" } }
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Find out the smallest value of the `creationTime` field:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"aggs" : {
|
||||
"min_creationTime" : { "min" : { "field" : "creationTime" } }
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Find out the smallest value of the `creationTime` field of all the kustomization files:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"min_creationTime" : { "min" : { "field" : "creationTime" } }
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Find out the smallest value of the `creationTime` field of all kustomize resource files:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": {
|
||||
"regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"min_creationTime" : { "min" : { "field" : "creationTime" } }
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Query all the documents whose `creationTime` <= `2016-07-29T17:38:26.000Z`:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"range": {
|
||||
"creationTime": {
|
||||
"lte": "2016-07-29T17:38:26.000Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Query all the documents whose `creationTime` falls within the specific range:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"range": {
|
||||
"creationTime": {
|
||||
"gte": "2016-07-29T17:38:26.000Z",
|
||||
"lte": "2016-08-29T17:38:26.000Z"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Aggregate how many new kustomization files were added into Github each month:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"newFiles_over_time" : {
|
||||
"date_histogram" : {
|
||||
"field" : "creationTime",
|
||||
"interval" : "month"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Aggregate how many new kustomize resource files were added into Github each month:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"newFiles_over_time" : {
|
||||
"date_histogram" : {
|
||||
"field" : "creationTime",
|
||||
"interval" : "month"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Aggregate how many new kustomization files were added into Github each year:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"newFiles_over_time" : {
|
||||
"date_histogram" : {
|
||||
"field" : "creationTime",
|
||||
"interval" : "year"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Aggregate how many new kustomize resource files were added into Github each year:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"newFiles_over_time" : {
|
||||
"date_histogram" : {
|
||||
"field" : "creationTime",
|
||||
"interval" : "year"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
32
api/internal/crawl/search_cmds/defaultBranch.md
Normal file
32
api/internal/crawl/search_cmds/defaultBranch.md
Normal file
@@ -0,0 +1,32 @@
|
||||
Count distinct values of the `defaultBranch` field:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"aggs" : {
|
||||
"defaultBranch_count" : {
|
||||
"cardinality" : {
|
||||
"field" : "defaultBranch",
|
||||
"precision_threshold": 40000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
List all the github branches where kustomization files and kustomize resource files live,
|
||||
and how many kustomization files and kustomize resource files live in each branch:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"aggs" : {
|
||||
"defaultBranch" : {
|
||||
"terms" : {
|
||||
"field" : "defaultBranch",
|
||||
"size": 41
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
55
api/internal/crawl/search_cmds/fieldExistence.md
Normal file
55
api/internal/crawl/search_cmds/fieldExistence.md
Normal file
@@ -0,0 +1,55 @@
|
||||
Count the documents whose `document` field is empty (The reason why the `document` field
|
||||
of a document is empty is because of empty documents):
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"size": 10000,
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": {
|
||||
"exists": {
|
||||
"field": "document"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Find all the documents having the `creationTime` field set:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"exists": {
|
||||
"field": "creationTime"
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Find all the documents whose `creationTime` field is not set:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"size": 10000,
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": {
|
||||
"exists": {
|
||||
"field": "creationTime"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
The following fields of a document in the kustomize index are always non-empty:
|
||||
`repositoryUrl`, `filePath`, `defaultBranch`.
|
||||
|
||||
The following fields of a document in the kustomize index may be empty:
|
||||
`kinds`, `identifiers`, `values`.
|
||||
66
api/internal/crawl/search_cmds/keyword_search.md
Normal file
66
api/internal/crawl/search_cmds/keyword_search.md
Normal file
@@ -0,0 +1,66 @@
|
||||
Count the documents in the index whose `repositoryUrl` field starts with
|
||||
`https://github.com/`:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "repositoryUrl": "https://github.com/.*" }}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Count the documents in the index whose `repositoryUrl` field does not start with
|
||||
`https://github.com/`:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": [
|
||||
{ "regexp": { "repositoryUrl": "https://github.com/.*" }}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search all the documents matching the given `repositoryUrl` and `filePath`, and return
|
||||
a version for each search hit:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"size": 10000,
|
||||
"version": true,
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "repositoryUrl": "git@github.com:talos-systems/talos-controller-manager" }},
|
||||
{ "regexp": { "filePath": "hack/config.*" }}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search all the documents whose filePath ends with one of these following three filenames:
|
||||
`kustomization.yaml`, `kustomization.yml`, `kustomization`:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
19
api/internal/crawl/search_cmds/misc.md
Normal file
19
api/internal/crawl/search_cmds/misc.md
Normal file
@@ -0,0 +1,19 @@
|
||||
Check the health status of an ElasticSearch cluster:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/_cat/health?v&pretty"
|
||||
```
|
||||
|
||||
Check the indices in an ElasticSearch cluster:
|
||||
```
|
||||
curl "${ElasticSearchURL}:9200/_cat/indices?v"
|
||||
```
|
||||
|
||||
Get the mapping of the index:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_mapping?pretty"
|
||||
```
|
||||
|
||||
Delete the kustomize index from the ElasticSearch cluster (**Use this command with caution**):
|
||||
```
|
||||
curl -X DELETE "${ElasticSearchURL}:9200/kustomize?pretty"
|
||||
```
|
||||
125
api/internal/crawl/search_cmds/repositoryUrl.md
Normal file
125
api/internal/crawl/search_cmds/repositoryUrl.md
Normal file
@@ -0,0 +1,125 @@
|
||||
Count distinct values of the `repositoryUrl` field:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"aggs" : {
|
||||
"repositoryUrl_count" : {
|
||||
"cardinality" : {
|
||||
"field" : "repositoryUrl",
|
||||
"precision_threshold": 40000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Count how many Github repositories include kustomization files:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"repositoryUrl_count" : {
|
||||
"cardinality" : {
|
||||
"field" : "repositoryUrl",
|
||||
"precision_threshold": 40000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Count how many Github repositories include kustomize resource files:
|
||||
```
|
||||
curl -X POST "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": {
|
||||
"regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"repositoryUrl_count" : {
|
||||
"cardinality" : {
|
||||
"field" : "repositoryUrl",
|
||||
"precision_threshold": 40000
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
List all the github repositories including kustomization files and kustomize resource files,
|
||||
and how many kustomization files and kustomize resource files each github repository includes
|
||||
(the github repository including the most kustomization files is listed first):
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"aggs" : {
|
||||
"repositoryUrl" : {
|
||||
"terms" : {
|
||||
"field" : "repositoryUrl",
|
||||
"size": 2082
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
List the top 20 Github repositories including the most amount of kustomization files:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }}
|
||||
]
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"repositoryUrl" : {
|
||||
"terms" : {
|
||||
"field" : "repositoryUrl",
|
||||
"size": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
List the top 20 Github repositories including the most amount of kustomize resource files:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?size=0&pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"must_not": {
|
||||
"regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)/*" }
|
||||
}
|
||||
}
|
||||
},
|
||||
"aggs" : {
|
||||
"repositoryUrl" : {
|
||||
"terms" : {
|
||||
"field" : "repositoryUrl",
|
||||
"size": 20
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
148
api/internal/crawl/search_cmds/text_search.md
Normal file
148
api/internal/crawl/search_cmds/text_search.md
Normal file
@@ -0,0 +1,148 @@
|
||||
Search for all the kustomize resource files including a Deployment object:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"kinds" : {
|
||||
"query" : "Deployment"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the kustomize resource files including a Deployment object, but only
|
||||
including the `kinds` field in the result:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"_source": {
|
||||
"includes": ["kinds"]
|
||||
},
|
||||
"query": {
|
||||
"match" : {
|
||||
"kinds" : {
|
||||
"query" : "Deployment"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the kustomize resource files including both a Deployment object and
|
||||
a Service object:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"kinds" : {
|
||||
"query" : "Deployment Service",
|
||||
"operator" : "and"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Count the number of documents including Deployment and the number of documents
|
||||
including Service:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"size": 0,
|
||||
"aggs" : {
|
||||
"messages" : {
|
||||
"filters" : {
|
||||
"filters" : {
|
||||
"Deployment" : { "match" : { "kinds" : "Deployment" }},
|
||||
"Service" : { "match" : { "kinds" : "Service" }}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the kustomization files involving CRDs:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"size": 10000,
|
||||
"query": {
|
||||
"match" : {
|
||||
"identifiers" : {
|
||||
"query" : "crds"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the kustomization files defining configMapGenerator:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"size": 10000,
|
||||
"query": {
|
||||
"match" : {
|
||||
"identifiers" : {
|
||||
"query" : "configMapGenerator"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the documents having a `kind` field:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "match" : { "identifiers" : { "query" : "kind" }}}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the kuostmization files having a `kind` field:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"bool": {
|
||||
"filter": [
|
||||
{ "regexp": { "filePath": ".*/kustomization((.yaml)?|(.yml)?)" }},
|
||||
{ "match" : { "identifiers" : { "query" : "kind" }}}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
|
||||
Search for all the kustomization files defining the `generatorOptions:disableNameSuffixHash` feature:
|
||||
```
|
||||
curl -X GET "${ElasticSearchURL}:9200/kustomize/_search?pretty" -H 'Content-Type: application/json' -d'
|
||||
{
|
||||
"query": {
|
||||
"match" : {
|
||||
"identifiers" : {
|
||||
"query" : "generatorOptions:disableNameSuffixHash"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
'
|
||||
```
|
||||
@@ -15,8 +15,6 @@ import (
|
||||
_ "golang.org/x/tools/cmd/stringer"
|
||||
// for lint checks
|
||||
_ "github.com/golangci/golangci-lint/cmd/golangci-lint"
|
||||
// for integration tests driven by the examples
|
||||
_ "github.com/monopole/mdrip"
|
||||
// REMOVED pluginator from this process, and leaving
|
||||
// this note to discourage its reintroduction,
|
||||
// because pluginator depends on the api, forcing
|
||||
|
||||
@@ -190,5 +190,7 @@ varReference:
|
||||
kind: StatefulSet
|
||||
|
||||
- path: metadata/labels
|
||||
|
||||
- path: metadata/annotations
|
||||
`
|
||||
)
|
||||
|
||||
@@ -153,9 +153,9 @@ FRUIT=banana
|
||||
LEGUME=chickpea
|
||||
`)
|
||||
th.WriteF("/app/overlay/configmap/dummy.txt",
|
||||
`Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua.
|
||||
`Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua.
|
||||
`)
|
||||
th.WriteF("/app/overlay/deployment/deployment.yaml", `
|
||||
apiVersion: apps/v1
|
||||
@@ -292,8 +292,10 @@ metadata:
|
||||
---
|
||||
apiVersion: v1
|
||||
data:
|
||||
nonsense: "Lorem ipsum dolor sit amet, consectetur\nadipiscing elit, sed do eiusmod
|
||||
tempor\nincididunt ut labore et dolore magna aliqua. \n"
|
||||
nonsense: |
|
||||
Lorem ipsum dolor sit amet, consectetur
|
||||
adipiscing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna aliqua.
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
annotations:
|
||||
@@ -302,6 +304,6 @@ metadata:
|
||||
app: mungebot
|
||||
org: kubernetes
|
||||
repo: test-infra
|
||||
name: test-infra-app-config-f462h769f9
|
||||
name: test-infra-app-config-4mt28b5bg2
|
||||
`)
|
||||
}
|
||||
|
||||
@@ -1157,6 +1157,8 @@ vars:
|
||||
name: my-deployment
|
||||
labels:
|
||||
my-label: $(NAMESPACE)
|
||||
annotations:
|
||||
my-annotation: $(NAMESPACE)
|
||||
spec:
|
||||
template:
|
||||
spec:
|
||||
@@ -1176,6 +1178,8 @@ vars:
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
annotations:
|
||||
my-annotation: my-namespace
|
||||
labels:
|
||||
my-label: my-namespace
|
||||
name: my-deployment
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
@@ -85,11 +86,17 @@ func (kvl *loader) keyValuesFromFileSources(sources []string) ([]types.Pair, err
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kvs = append(kvs, types.Pair{Key: k, Value: string(content)})
|
||||
kvs = append(kvs, types.Pair{Key: k, Value: trimTrailingSpacesInLines(string(content))})
|
||||
}
|
||||
return kvs, nil
|
||||
}
|
||||
|
||||
// trimTrailingSpacesInLines takes string with multiple lines and trims the trailing white spaces and tabs from each line.
|
||||
func trimTrailingSpacesInLines(str string) string {
|
||||
re := regexp.MustCompile(`\s*\n`)
|
||||
return re.ReplaceAllString(str, "\n")
|
||||
}
|
||||
|
||||
func (kvl *loader) keyValuesFromEnvFiles(paths []string) ([]types.Pair, error) {
|
||||
var kvs []types.Pair
|
||||
for _, p := range paths {
|
||||
|
||||
@@ -95,3 +95,12 @@ func TestKeyValuesFromFileSources(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTrimTrailingSpacesInLines(t *testing.T) {
|
||||
input := "\"fooKey\": \"fooValue\" \t\n\t\"barKey\": \"barValue\""
|
||||
expected := "\"fooKey\": \"fooValue\"\n\t\"barKey\": \"barValue\""
|
||||
res := trimTrailingSpacesInLines(input)
|
||||
if !reflect.DeepEqual(res, expected) {
|
||||
t.Errorf("Trim trailing spaces in lines should succeed, got: %s exptected: %s", res, expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,6 +52,10 @@ func Complete(cmd *cobra.Command) *complete.Command {
|
||||
Flags: map[string]complete.Predictor{},
|
||||
Sub: map[string]*complete.Command{},
|
||||
}
|
||||
if strings.Contains(cmd.Use, "DIR") {
|
||||
// if usage contains directory, then use a file predictor
|
||||
cc.Args = predict.Dirs("*")
|
||||
}
|
||||
|
||||
// add completion for each subcommand
|
||||
for i := range cmd.Commands() {
|
||||
|
||||
@@ -74,10 +74,14 @@ func NewConfigCommand(name string) *cobra.Command {
|
||||
root.AddCommand(commands.CatCommand(name))
|
||||
root.AddCommand(commands.FmtCommand(name))
|
||||
root.AddCommand(commands.MergeCommand(name))
|
||||
root.AddCommand(commands.Merge3Command(name))
|
||||
root.AddCommand(commands.CountCommand(name))
|
||||
root.AddCommand(commands.RunFnCommand(name))
|
||||
root.AddCommand(commands.SubCommand(name))
|
||||
root.AddCommand(commands.SubSetCommand(name))
|
||||
root.AddCommand(commands.SetCommand(name))
|
||||
root.AddCommand(commands.ListSettersCommand(name))
|
||||
root.AddCommand(commands.CreateSetterCommand(name))
|
||||
root.AddCommand(commands.SinkCommand(name))
|
||||
root.AddCommand(commands.SourceCommand(name))
|
||||
|
||||
root.AddCommand(&cobra.Command{
|
||||
Use: "docs-merge",
|
||||
@@ -91,8 +95,13 @@ func NewConfigCommand(name string) *cobra.Command {
|
||||
})
|
||||
root.AddCommand(&cobra.Command{
|
||||
Use: "docs-fn",
|
||||
Short: "[Alpha] Documentation for writing containerized functions run by run.",
|
||||
Long: api.ConfigFnLong,
|
||||
Short: "[Alpha] Documentation for developing and invoking Configuration Functions.",
|
||||
Long: api.FunctionsImplLong,
|
||||
})
|
||||
root.AddCommand(&cobra.Command{
|
||||
Use: "docs-fn-spec",
|
||||
Short: "[Alpha] Documentation for Configuration Functions Specification.",
|
||||
Long: api.FunctionsSpecLong,
|
||||
})
|
||||
root.AddCommand(&cobra.Command{
|
||||
Use: "docs-io-annotations",
|
||||
|
||||
@@ -1,281 +0,0 @@
|
||||
# Configuration Functions API Semantics
|
||||
|
||||
Configuration Functions are functions packaged as executables in containers which enable
|
||||
**shift-left practices**. They configure applications and infrastructure through
|
||||
Kubernetes style Resource Configuration, but run locally pre-commit.
|
||||
|
||||
Configuration functions enable shift-left practices (client-side) through:
|
||||
|
||||
- Pre-commit / delivery validation and linting of configuration
|
||||
- e.g. Fail if any containers don't have PodSecurityPolicy or CPU / Memory limits
|
||||
- Implementation of abstractions as client actuated APIs (e.g. templating)
|
||||
- e.g. Create a client-side *"CRD"* for generating configuration checked into git
|
||||
- Aspect Orient configuration / Injection of cross-cutting configuration
|
||||
- e.g. T-Shirt size containers by annotating Resources with `small`, `medium`, `large`
|
||||
and inject the cpu and memory resources into containers accordingly.
|
||||
- e.g. Inject `init` and `side-car` containers into Resources based off of Resource
|
||||
Type, annotations, etc.
|
||||
|
||||
Performing these on the client rather than the server enables:
|
||||
|
||||
- Configuration to be reviewed prior to being sent to the API server
|
||||
- Configuration to be validated as part of the CD pipeline
|
||||
- Configuration for Resources to validated holistically rather than individually
|
||||
per-Resource -- e.g. ensure the `Service.selector` and `Deployment.spec.template` labels
|
||||
match.
|
||||
- MutatingWebHooks are scoped to a single Resource instance at a time.
|
||||
- Low-level tweaks to the output of high-level abstractions -- e.g. add an `init container`
|
||||
to a client *"CRD"* Resource after it was generated.
|
||||
- Composition and layering of multiple functions together
|
||||
- Compose generation, injection, validation together
|
||||
|
||||
Configuration Functions are implemented as executable programs published in containers which:
|
||||
|
||||
- Accept as input (stdin):
|
||||
- A list of Resource Configuration
|
||||
- A Function Configuration (to configure the function itself)
|
||||
- Emit as output (stdout + exit):
|
||||
- A list of Resource Configuration
|
||||
- An exit code for success / failure
|
||||
|
||||
### Function Specification
|
||||
|
||||
- Functions **SHOULD** be published as container images containing a `CMD` invoking an executable.
|
||||
- Functions **MUST** accept input on STDIN a `ResourceList` containing the Resources and
|
||||
`functionConfig`.
|
||||
- Functions **MUST** emit output on STDOUT a `ResourceList` containing the modified
|
||||
Resources.
|
||||
- Functions **MUST** exit non-0 on failure, and exit 0 on success.
|
||||
- Functions **MAY** emit output on STDERR with error messaging.
|
||||
- Functions performing validation **SHOULD** exit failure and emit error messaging
|
||||
on a validation failure.
|
||||
- Functions generating Resources **SHOULD** retain non-conflicting changes on the
|
||||
generated Resources -- e.g. 1. the function generates a Deployment, but doesn't
|
||||
specify `cpu`, 2. the user sets the `cpu` on the generated Resource, 3. the
|
||||
function should keep the `cpu` when regenerating the Resource a second time.
|
||||
- Functions **SHOULD** be usable outside `kustomize config run` -- e.g. though pipeline
|
||||
mechanisms such as Tekton.
|
||||
|
||||
#### Input Format
|
||||
|
||||
Functions must accept on STDIN:
|
||||
|
||||
`ResourceList`:
|
||||
- contains `items` field, same as `List.items`
|
||||
- contains `functionConfig` field -- a single item with the configuration for the function itself
|
||||
|
||||
Example `ResourceList` Input:
|
||||
|
||||
apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
functionConfig:
|
||||
apiVersion: example.com/v1beta1
|
||||
kind: Nginx
|
||||
metadata:
|
||||
name: my-instance
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
spec:
|
||||
replicas: 5
|
||||
items:
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
replicas: 3
|
||||
...
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
...
|
||||
|
||||
#### Output Format
|
||||
|
||||
Functions must emit on STDOUT:
|
||||
|
||||
`ResourceList`:
|
||||
- contains `items` field, same as `List.items`
|
||||
|
||||
Example `ResourceList` Output:
|
||||
|
||||
apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
replicas: 5
|
||||
...
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
...
|
||||
|
||||
#### Container Environment
|
||||
|
||||
When run by `kustomize config run`, functions are run in containers with the
|
||||
following environment:
|
||||
|
||||
- Network: `none`
|
||||
- User: `nobody`
|
||||
- Security Options: `no-new-privileges`
|
||||
- Volumes: the volume containing the `functionConfig` yaml is mounted under `/local` as `ro`
|
||||
|
||||
### Example Function Implementation
|
||||
|
||||
Following is an example for implementing an nginx abstraction using a config
|
||||
function.
|
||||
|
||||
#### `nginx-template.sh`
|
||||
|
||||
`nginx-template.sh` is a simple bash script which uses a *heredoc* as a templating solution
|
||||
for generating Resources from the functionConfig input fields.
|
||||
|
||||
The script wraps itself using `config run wrap -- $0` which will:
|
||||
|
||||
1. Parse the `ResourceList.functionConfig` (provided to the container stdin) into env vars
|
||||
2. Merge the stdout into the original list of Resources
|
||||
3. Defaults filenames for newly generated Resources (if they are not set as annotations)
|
||||
to `config/NAME_KIND.yaml`
|
||||
4. Format the output
|
||||
|
||||
#!/bin/bash
|
||||
# script must run wrapped by `kustomize config run wrap`
|
||||
# for parsing input the functionConfig into env vars
|
||||
if [ -z ${WRAPPED} ]; then
|
||||
export WRAPPED=true
|
||||
config run wrap -- $0
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cat <<End-of-message
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
replicas: ${REPLICAS}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
End-of-message
|
||||
|
||||
#### `Dockerfile`
|
||||
|
||||
`Dockerfile` installs `kustomize config` and copies the script into the container image.
|
||||
|
||||
FROM golang:1.13-stretch
|
||||
RUN go get sigs.k8s.io/kustomize/cmd/config
|
||||
RUN mv /go/bin/config /usr/bin/config
|
||||
COPY nginx-template.sh /usr/bin/nginx-template.sh
|
||||
CMD ["nginx-template.sh]
|
||||
|
||||
### Example Function Usage
|
||||
|
||||
Following is an example of running the `kustomize config run` using the preceding API.
|
||||
|
||||
#### `nginx.yaml` (Input)
|
||||
|
||||
`dir/nginx.yaml` contains a reference to the Function. The contents of `nginx.yaml`
|
||||
are passed to the Function through the `ResourceList.functionConfig` field.
|
||||
|
||||
apiVersion: example.com/v1beta1
|
||||
kind: Nginx
|
||||
metadata:
|
||||
name: my-instance
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/example-functions/nginx-template:v1.0.0
|
||||
spec:
|
||||
replicas: 5
|
||||
|
||||
- `configFn.container.image`: the image to use for this API
|
||||
- `annotations[config.kubernetes.io/local-config]`: mark this as not a Resource that should
|
||||
be applied
|
||||
|
||||
#### `kustomize config run dir/` (Output)
|
||||
|
||||
`dir/my-instance_deployment.yaml` contains the Deployment:
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
replicas: 5
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
|
||||
`dir/my-instance_service.yaml` contains the Service:
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
181
cmd/config/docs/api-conventions/functions-impl.md
Normal file
181
cmd/config/docs/api-conventions/functions-impl.md
Normal file
@@ -0,0 +1,181 @@
|
||||
# Running Configuration Functions using kustomize CLI
|
||||
|
||||
Configuration functions can be implemented using any toolchain and invoked using any
|
||||
container workflow orchestrator including Tekton, Cloud Build, or run directly using `docker run`.
|
||||
|
||||
Run `config help docs-fn-spec` to see the Configuration Functions Specification.
|
||||
|
||||
`kustomize config run` is an example orchestrator for invoking Configuration Functions. This
|
||||
document describes how to implement and invoke an example function.
|
||||
|
||||
## Example Function Implementation
|
||||
|
||||
Following is an example for implementing an nginx abstraction using a configuration
|
||||
function.
|
||||
|
||||
### `nginx-template.sh`
|
||||
|
||||
`nginx-template.sh` is a simple bash script which uses a _heredoc_ as a templating solution
|
||||
for generating Resources from the functionConfig input fields.
|
||||
|
||||
The script wraps itself using `config run wrap -- $0` which will:
|
||||
|
||||
1. Parse the `ResourceList.functionConfig` (provided to the container stdin) into env vars
|
||||
2. Merge the stdout into the original list of Resources
|
||||
3. Defaults filenames for newly generated Resources (if they are not set as annotations)
|
||||
to `config/NAME_KIND.yaml`
|
||||
4. Format the output
|
||||
|
||||
```bash
|
||||
#!/bin/bash
|
||||
# script must run wrapped by "kustomize config run wrap"
|
||||
# for parsing input the functionConfig into env vars
|
||||
if [ -z ${WRAPPED} ]; then
|
||||
export WRAPPED=true
|
||||
config run wrap -- $0
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cat <<End-of-message
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
replicas: ${REPLICAS}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
End-of-message
|
||||
```
|
||||
|
||||
### Dockerfile
|
||||
|
||||
`Dockerfile` installs `kustomize config` and copies the script into the container image.
|
||||
|
||||
```
|
||||
FROM golang:1.13-stretch
|
||||
RUN go get sigs.k8s.io/kustomize/cmd/config
|
||||
RUN mv /go/bin/config /usr/bin/config
|
||||
COPY nginx-template.sh /usr/bin/nginx-template.sh
|
||||
CMD ["nginx-template.sh]
|
||||
```
|
||||
|
||||
## Example Function Usage
|
||||
|
||||
Following is an example of running the `kustomize config run` using the preceding API.
|
||||
|
||||
When run by `kustomize config run`, functions are run in containers with the
|
||||
following environment:
|
||||
|
||||
- Network: `none`
|
||||
- User: `nobody`
|
||||
- Security Options: `no-new-privileges`
|
||||
- Volumes: the volume containing the `functionConfig` yaml is mounted under `/local` as `ro`
|
||||
|
||||
### Input
|
||||
|
||||
`dir/nginx.yaml` contains a reference to the Function. The contents of `nginx.yaml`
|
||||
are passed to the Function through the `ResourceList.functionConfig` field.
|
||||
|
||||
```yaml
|
||||
apiVersion: example.com/v1beta1
|
||||
kind: Nginx
|
||||
metadata:
|
||||
name: my-instance
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.k8s.io/function: |
|
||||
container:
|
||||
image: gcr.io/example-functions/nginx-template:v1.0.0
|
||||
spec:
|
||||
replicas: 5
|
||||
```
|
||||
|
||||
- `annotations[config.k8s.io/function].container.image`: the image to use for this API
|
||||
- `annotations[config.kubernetes.io/local-config]`: mark this as not a Resource that should
|
||||
be applied
|
||||
|
||||
### Output
|
||||
|
||||
The function is invoked using by runing `kustomize config run dir/`.
|
||||
|
||||
`dir/my-instance_deployment.yaml` contains the Deployment:
|
||||
|
||||
```yaml
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
replicas: 5
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
```
|
||||
|
||||
`dir/my-instance_service.yaml` contains the Service:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
```
|
||||
186
cmd/config/docs/api-conventions/functions-spec.md
Normal file
186
cmd/config/docs/api-conventions/functions-spec.md
Normal file
@@ -0,0 +1,186 @@
|
||||
# Configuration Functions Specification
|
||||
|
||||
This document specifies a standard for client-side functions that operate on
|
||||
Kubernetes declarative configurations. This standard enables creating
|
||||
small, interoperable, and language-independent executable programs packaged as
|
||||
containers that can be chained together as part of a configuration management pipeline.
|
||||
The end result of such a pipeline are fully rendered configurations that can then be
|
||||
applied to a control plane (e.g. Using ‘kubectl apply’ for Kubernetes control plane).
|
||||
As such, although this document references Kubernetes Resource Model and API conventions,
|
||||
it is completely decoupled from Kuberentes API machinery and does not depend on any
|
||||
in-cluster components.
|
||||
|
||||
This document references terms described in [Kubernetes API Conventions][1].
|
||||
|
||||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
|
||||
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
|
||||
interpreted as described in [RFC 2119][2].
|
||||
|
||||
## Use Cases
|
||||
|
||||
_Configuration functions_ enable shift-left practices (client-side) through:
|
||||
|
||||
- Pre-commit / delivery validation and linting of configuration
|
||||
- e.g. Fail if any containers don't have PodSecurityPolicy or CPU / Memory limits
|
||||
- Implementation of abstractions as client actuated APIs (e.g. templating)
|
||||
- e.g. Create a client-side _"CRD"_ for generating configuration checked into git
|
||||
- Aspect Orient configuration / Injection of cross-cutting configuration
|
||||
- e.g. T-Shirt size containers by annotating Resources with `small`, `medium`, `large`
|
||||
and inject the cpu and memory resources into containers accordingly.
|
||||
- e.g. Inject `init` and `side-car` containers into Resources based off of Resource
|
||||
Type, annotations, etc.
|
||||
|
||||
Performing these on the client rather than the server enables:
|
||||
|
||||
- Configuration to be reviewed prior to being sent to the API server
|
||||
- Configuration to be validated as part of the CI?CD pipeline
|
||||
- Configuration for Resources to validated holistically rather than individually
|
||||
per-Resource
|
||||
- e.g. ensure the `Service.selector` and `Deployment.spec.template` labels
|
||||
match.
|
||||
- e.g. MutatingWebHooks are scoped to a single Resource instance at a time.
|
||||
- Low-level tweaks to the output of high-level abstractions
|
||||
- e.g. add an `init container` to a client _"CRD"_ Resource after it was generated.
|
||||
- Composition and layering of multiple functions together
|
||||
- Compose generation, injection, validation together
|
||||
|
||||
## Spec
|
||||
|
||||
### Input Type
|
||||
|
||||
A function MUST accept as input a single [Kubernetes List type][3].
|
||||
The `items` field in the input will contain a sequence of [Object types][3].
|
||||
A function MAY not support [Simple types][3] and List types.
|
||||
|
||||
An example using `v1/ConfigMapList` as input:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: ConfigMapList
|
||||
items:
|
||||
- apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config1
|
||||
data:
|
||||
p1: v1
|
||||
p2: v2
|
||||
- apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config2
|
||||
```
|
||||
|
||||
An example using `v1/List` as input:
|
||||
|
||||
```yaml
|
||||
apiVersion: v1
|
||||
kind: List
|
||||
items:
|
||||
spec:
|
||||
- apiVersion: foo-corp.com/v1
|
||||
kind: FulfillmentCenter
|
||||
metadata:
|
||||
name: staging
|
||||
address: "100 Main St."
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- resources:
|
||||
- namespaces
|
||||
apiGroups:
|
||||
- ""
|
||||
verbs:
|
||||
- get
|
||||
- watch
|
||||
- list
|
||||
```
|
||||
|
||||
In addition, a function MUST accept as input a List of kind `ResourceList` where the
|
||||
`functionConfig` field, if present, will contain the invocation-specific configuration passed to the function
|
||||
by the orchestrator.
|
||||
Functions MAY consider this field optional so that they can be triggered in an ad-hoc fashion.
|
||||
|
||||
An example using `config.kubernetes.io/v1beta1/ResourceList` as input:
|
||||
|
||||
```yaml
|
||||
apiVersion: config.kubernetes.io/v1beta1
|
||||
kind: ResourceList
|
||||
functionConfig:
|
||||
apiVersion: foo-corp.com/v1
|
||||
kind: FulfillmentCenter
|
||||
metadata:
|
||||
name: staging
|
||||
metadata:
|
||||
annotations:
|
||||
config.k8s.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/foo:v1.0.0
|
||||
spec:
|
||||
address: "100 Main St."
|
||||
items:
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- resources:
|
||||
- namespaces
|
||||
apiGroups:
|
||||
- ""
|
||||
verbs:
|
||||
- get
|
||||
- watch
|
||||
- list
|
||||
```
|
||||
|
||||
Here `FulfillmentCenter` kind with name `staging` is passed as the invocation-specific configuration
|
||||
to the function.
|
||||
|
||||
### Output Type
|
||||
|
||||
A function’s output MUST be the same as the input specification above
|
||||
-- i.e. `ResourceList` or `List`.
|
||||
This is necessary to enable chaining two or more functions together in a pipeline.
|
||||
The serialization format of the output SHOULD match that of its input on each invocation
|
||||
-- e.g. if the input was a `ResourceList`, the output should also be a `ResourceList`.
|
||||
|
||||
### Serialization Format
|
||||
|
||||
A function MUST support YAML as a serialization format for the input and output.
|
||||
A function MUST use utf8 encoding (as YAML is a superset of JSON, JSON will also be supported
|
||||
by any conforming function).
|
||||
|
||||
### Operations
|
||||
|
||||
A function MAY Create, Update, or Delete any number of items in the `items` field and output the
|
||||
resultant list.
|
||||
|
||||
A function MAY modify annotations with prefix `config.kubernetes.io`, but must be careful about
|
||||
doing so since they’re used for orchestration purposes and will likely impact subsequent functions
|
||||
in the pipeline.
|
||||
|
||||
A function SHOULD preserve comments when input serialization format is YAML.
|
||||
This allows for human authoring of configuration to coexist with changes made by functions.
|
||||
|
||||
### Containerization
|
||||
|
||||
A function MUST be implemented as a container.
|
||||
|
||||
A function container MUST be capable of running as a non-root user if it does not require
|
||||
access to host filesystem or makes network calls.
|
||||
|
||||
### stdin/stdout/stderr and Exit Codes
|
||||
|
||||
A function MUST accept input from stdin and emit output to stdout.
|
||||
|
||||
Any error messages MUST be emitted to stderr.
|
||||
|
||||
An exit code of zero indicates function execution was successful.
|
||||
A non-zero exit code indicates a failure.
|
||||
|
||||
[1]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|
||||
[2]: https://tools.ietf.org/html/rfc2119
|
||||
[3]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds
|
||||
93
cmd/config/docs/commands/create-setter.md
Normal file
93
cmd/config/docs/commands/create-setter.md
Normal file
@@ -0,0 +1,93 @@
|
||||
## create-setter
|
||||
|
||||
[Alpha] Create a custom setter for a Resource field
|
||||
|
||||
### Synopsis
|
||||
|
||||
Create a custom setter for a Resource field by inlining OpenAPI as comments.
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
The name of the setter to create.
|
||||
|
||||
VALUE
|
||||
|
||||
The current value of the field, or a substring within the field.
|
||||
|
||||
### Creating a Custom Setter
|
||||
|
||||
**Given the YAML:**
|
||||
|
||||
# resource.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
...
|
||||
spec:
|
||||
...
|
||||
ports:
|
||||
...
|
||||
- name: http
|
||||
port: 8080
|
||||
...
|
||||
|
||||
**Create a new setter:**
|
||||
|
||||
# create a setter for ports
|
||||
$ kustomize config set create DIR/ http-port 8080 --type "integer" --field "port"
|
||||
|
||||
Resources fields with a field name matching `--field` and field value matching `VALUE` will
|
||||
have a line comment added marking this field as settable.
|
||||
|
||||
**Newly modified YAML:**
|
||||
|
||||
# resource.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
...
|
||||
spec:
|
||||
...
|
||||
ports:
|
||||
...
|
||||
- name: http
|
||||
port: 8080 # {"type":"integer","x-kustomize":{"partialFieldSetters":[{"name":"http-port","value":"8080"}]}}
|
||||
...
|
||||
|
||||
Setters may also be defined directly by editing the yaml and adding the comment.
|
||||
|
||||
Users may not set the field value using the `set` command:
|
||||
|
||||
# change the http-port value to 8081
|
||||
$ kustomize config set DIR/ http-port 8081
|
||||
|
||||
### Using default values
|
||||
|
||||
The default values for a setter may be:
|
||||
|
||||
- valid field values (e.g. `8080` or `008080` for a port)
|
||||
- invalid values that adhere to the schema (e.g. `0000` for a port)
|
||||
- values that do not adhere to the schema (e.g. `[PORT]` for port)
|
||||
|
||||
A setter may be for a substring of a full field:
|
||||
|
||||
$ kustomize config set create DIR/ image-tag v1.0.01 --type "string" --field "image"
|
||||
|
||||
image: gcr.io/example/app:v1.0.1 # # {"type":"string","x-kustomize":{"partialFieldSetters":[{"name":"image-tag","value":"v1.0.1"}]}}
|
||||
|
||||
A single field value may have multiple setters applied to it for different parts of the field.
|
||||
|
||||
### Examples
|
||||
|
||||
# create a setter for port fields matching "8080"
|
||||
kustomize config create-setter DIR/ port 8080 --type "integer" --field port \
|
||||
--description "default port used by the app"
|
||||
|
||||
# create a setter for a substring of a field rather than the full field -- e.g. only the
|
||||
# image tag, not the full image
|
||||
kustomize config create-setter DIR/ image-tag v1.0.1 --type "string" \
|
||||
--field image --description "current stable release"
|
||||
23
cmd/config/docs/commands/list-setters.md
Normal file
23
cmd/config/docs/commands/list-setters.md
Normal file
@@ -0,0 +1,23 @@
|
||||
## set
|
||||
|
||||
[Alpha] List setters for Resources.
|
||||
|
||||
### Synopsis
|
||||
|
||||
List setters for Resources.
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
Optional. The name of the setter to display.
|
||||
|
||||
### Examples
|
||||
|
||||
Show setters:
|
||||
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix '' PREFIX string 2
|
||||
23
cmd/config/docs/commands/merge3.md
Normal file
23
cmd/config/docs/commands/merge3.md
Normal file
@@ -0,0 +1,23 @@
|
||||
## merge3
|
||||
|
||||
[Alpha] Merge diff of Resource configuration files into a destination (3-way)
|
||||
|
||||
### Synopsis
|
||||
|
||||
[Alpha] Merge diff of Resource configuration files into a destination (3-way)
|
||||
|
||||
Merge3 performs a 3-way merge by applying the diff between 2 sets of Resources to a 3rd set.
|
||||
|
||||
Merge3 may be for rebasing changes to a forked set of configuration -- e.g. compute the difference between the original
|
||||
set of Resources that was forked and an updated set of those Resources, then apply that difference to the fork.
|
||||
|
||||
If a field value differs between the ORIGINAL_DIR and UPDATED_DIR, the value from the UPDATED_DIR is taken and applied
|
||||
to the Resource in the DEST_DIR.
|
||||
|
||||
For information on merge rules, run:
|
||||
|
||||
kustomize config docs-merge3
|
||||
|
||||
### Examples
|
||||
|
||||
kustomize config merge3 --ancestor a/ --from b/ --to c/
|
||||
@@ -22,8 +22,8 @@ order they appear in the file).
|
||||
|
||||
#### Config Functions:
|
||||
|
||||
Config functions are specified as Kubernetes types containing a metadata.configFn.container.image
|
||||
field. This field tells run how to invoke the container.
|
||||
Config functions are specified as Kubernetes types containing a metadata.annotations.[config.kubernetes.io/function]
|
||||
field specifying an image for the container to run. This image tells run how to invoke the container.
|
||||
|
||||
Example config function:
|
||||
|
||||
@@ -31,17 +31,17 @@ order they appear in the file).
|
||||
apiVersion: fn.example.com/v1beta1
|
||||
kind: ExampleFunctionKind
|
||||
metadata:
|
||||
configFn:
|
||||
container:
|
||||
# function is invoked as a container running this image
|
||||
image: gcr.io/example/examplefunction:v1.0.1
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
# function is invoked as a container running this image
|
||||
image: gcr.io/example/examplefunction:v1.0.1
|
||||
config.kubernetes.io/local-config: "true" # tools should ignore this
|
||||
spec:
|
||||
configField: configValue
|
||||
|
||||
In the preceding example, 'kustomize config run example/' would identify the function by
|
||||
the metadata.configFn field. It would then write all Resources in the directory to
|
||||
the metadata.annotations.[config.kubernetes.io/function] field. It would then write all Resources in the directory to
|
||||
a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It
|
||||
would then write the container stdout back to example/, replacing the directory
|
||||
file contents.
|
||||
|
||||
87
cmd/config/docs/commands/set.md
Normal file
87
cmd/config/docs/commands/set.md
Normal file
@@ -0,0 +1,87 @@
|
||||
## set
|
||||
|
||||
[Alpha] Set values on Resources fields values.
|
||||
|
||||
### Synopsis
|
||||
|
||||
Set values on Resources fields. May set either the complete or partial field value.
|
||||
|
||||
`set` identifies setters using field metadata published as OpenAPI extensions.
|
||||
`set` parses both the Kubernetes OpenAPI, as well OpenAPI published inline in
|
||||
the configuration as comments.
|
||||
|
||||
`set` maybe be used to:
|
||||
|
||||
- edit configuration programmatically from the cli
|
||||
- create reusable bundles of configuration with custom setters
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
Optional. The name of the setter to perform or display.
|
||||
|
||||
VALUE
|
||||
|
||||
Optional. The value to set on the field.
|
||||
|
||||
|
||||
To print the possible setters for the Resources in a directory, run `set` on
|
||||
a directory -- e.g. `kustomize config set DIR/`.
|
||||
|
||||
#### Tips
|
||||
|
||||
- A description of the value may be specified with `--description`.
|
||||
- The last setter for the field's value may be defined with `--set-by`.
|
||||
- Create custom setters on Resources, Kustomization.yaml's, patches, etc
|
||||
|
||||
The description and setBy fields are left unmodified unless specified with flags.
|
||||
|
||||
To create a custom setter for a field see: `kustomize help config create-setter`
|
||||
|
||||
### Examples
|
||||
|
||||
Resource YAML: Name Prefix Setter
|
||||
|
||||
# DIR/resources.yaml
|
||||
...
|
||||
metadata:
|
||||
name: PREFIX-app1 # {"type":"string","x-kustomize":{"partialFieldSetters":[{"name":"name-prefix","value":"PREFIX"}]}}
|
||||
...
|
||||
---
|
||||
...
|
||||
metadata:
|
||||
name: PREFIX-app2 # {"type":"string","x-kustomize":{"partialFieldSetters":[{"name":"name-prefix","value":"PREFIX"}]}}
|
||||
...
|
||||
|
||||
List setters: Show the possible setters
|
||||
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix '' PREFIX string 2
|
||||
|
||||
Perform set: set a new value, owner and description
|
||||
|
||||
$ kustomize config set DIR/ name-prefix "test" --description "test environment" --set-by "dev"
|
||||
set 2 values
|
||||
|
||||
List setters: Show the new values
|
||||
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix 'test environment' test string 2 dev
|
||||
|
||||
New Resource YAML:
|
||||
|
||||
# DIR/resources.yaml
|
||||
...
|
||||
metadata:
|
||||
name: test-app1 # {"description":"test environment","type":"string","x-kustomize":{"setBy":"dev","partialFieldSetters":[{"name":"name-prefix","value":"test"}]}}
|
||||
...
|
||||
---
|
||||
...
|
||||
metadata:
|
||||
name: test-app2 # {"description":"test environment","type":"string","x-kustomize":{"setBy":"dev","partialFieldSetters":[{"name":"name-prefix","value":"test"}]}}
|
||||
...
|
||||
18
cmd/config/docs/commands/sink.md
Normal file
18
cmd/config/docs/commands/sink.md
Normal file
@@ -0,0 +1,18 @@
|
||||
## sink
|
||||
|
||||
[Alpha] Implement a Sink by writing input to a local directory.
|
||||
|
||||
### Synopsis
|
||||
|
||||
[Alpha] Implement a Sink by writing input to a local directory.
|
||||
|
||||
kustomize config sink DIR
|
||||
|
||||
DIR:
|
||||
Path to local directory.
|
||||
|
||||
`sink` writes its input to a directory
|
||||
|
||||
### Examples
|
||||
|
||||
kustomize config source DIR/ | your-function | kustomize config sink DIR/
|
||||
21
cmd/config/docs/commands/source.md
Normal file
21
cmd/config/docs/commands/source.md
Normal file
@@ -0,0 +1,21 @@
|
||||
## source
|
||||
|
||||
[Alpha] Implement a Source by reading a local directory.
|
||||
|
||||
### Synopsis
|
||||
|
||||
[Alpha] Implement a Source by reading a local directory.
|
||||
|
||||
kustomize config source DIR
|
||||
|
||||
DIR:
|
||||
Path to local directory.
|
||||
|
||||
`source` emits configuration to act as input to a function
|
||||
|
||||
### Examples
|
||||
|
||||
# emity configuration directory as input source to a function
|
||||
kustomize config source DIR/
|
||||
|
||||
kustomize config source DIR/ | your-function | kustomize config sink DIR/
|
||||
@@ -1,98 +0,0 @@
|
||||
## set
|
||||
|
||||
[Alpha] Set values on Resources fields by substituting values.
|
||||
|
||||
### Synopsis
|
||||
|
||||
Set values on Resources fields by substituting predefined markers for new values.
|
||||
|
||||
`set` looks for markers specified on Resource fields and substitute a new user defined
|
||||
value for the existing value.
|
||||
|
||||
`set` maybe be used to:
|
||||
|
||||
- edit configuration programmatically from the cli or scripts
|
||||
- create reusable bundles of configuration
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
Optional. The name of the substitution to perform or display.
|
||||
|
||||
VALUE
|
||||
|
||||
Optional. The new value to substitute into the field.
|
||||
|
||||
|
||||
To print the possible substitutions for the Resources in a directory, run `set` on
|
||||
a directory -- e.g. `kustomize config set DIR/`.
|
||||
|
||||
#### Tips
|
||||
|
||||
- A description of the value may be specified with `--description`.
|
||||
- An owner for the field's value may be defined with `--owned-by`.
|
||||
- Prevent overriding previous substitutions with `--override=false`.
|
||||
- Revert previous substitutions with `--revert`.
|
||||
- Create substitutions on Kustomization.yaml's, patches, etc
|
||||
|
||||
When overriding or reverting previous substitutions, the description and owner are left
|
||||
unmodified unless specified with flags.
|
||||
|
||||
To create a substitution for a field see: `kustomize help config set create`
|
||||
|
||||
### Examples
|
||||
|
||||
Resource YAML: Name substitution
|
||||
|
||||
# dir/resources.yaml
|
||||
...
|
||||
metadata:
|
||||
name: PREFIX-app1 # {"substitutions":[{"name":"prefix","marker":"PREFIX-"}]}
|
||||
...
|
||||
---
|
||||
...
|
||||
metadata:
|
||||
name: PREFIX-app2 # {"substitutions":[{"name":"prefix","marker":"PREFIX-"}]}
|
||||
...
|
||||
|
||||
Show substitutions: Show the possible substitutions
|
||||
|
||||
$ config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix '' PREFIX- string 2 false
|
||||
|
||||
Perform substitution: set a new value, owner and description
|
||||
|
||||
$ config set dir prefix "test-" --description "test environment" --owned-by "dev"
|
||||
performed 2 substitutions
|
||||
|
||||
Show substitutions: Show the new values
|
||||
|
||||
$ config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix 'test environment' test- string 2 true dev
|
||||
|
||||
New Resource YAML:
|
||||
|
||||
# dir/resources.yaml
|
||||
...
|
||||
metadata:
|
||||
name: test-app1 # {"substitutions":[{"name":"prefix","marker":"PREFIX-","value":"test-"}],"ownedBy":"dev","description":"test environment"}
|
||||
...
|
||||
---
|
||||
...
|
||||
metadata:
|
||||
name: test-app2 # {"substitutions":[{"name":"prefix","marker":"PREFIX-","value":"test-"}],"ownedBy":"dev","description":"test environment"}
|
||||
...
|
||||
|
||||
Revert substitution:
|
||||
|
||||
config set dir prefix --revert
|
||||
performed 2 substitutions
|
||||
|
||||
config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix 'test environment' PREFIX- string 2 false dev
|
||||
@@ -1,167 +0,0 @@
|
||||
## sub-set-marker
|
||||
|
||||
[Alpha] Create a new substitution for a Resource field
|
||||
|
||||
### Synopsis
|
||||
|
||||
Create a new substitution for a Resource field -- recognized by `kustomize config set`.
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
The name of the substitution to create.
|
||||
|
||||
VALUE
|
||||
|
||||
The current value of the field, or a substring of the field.
|
||||
|
||||
#### Tips: Picking Good Marker
|
||||
|
||||
Substitutions may be defined by directly editing yaml **or** by running `kustomize config set create`
|
||||
to create a new substitution.
|
||||
|
||||
Given the YAML:
|
||||
|
||||
# resource.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
...
|
||||
spec:
|
||||
...
|
||||
ports:
|
||||
...
|
||||
- name: http
|
||||
port: 8080
|
||||
...
|
||||
|
||||
Create a new set marker:
|
||||
|
||||
# create a substitution for ports
|
||||
$ kustomize config set create dir/ http-port 8080 --type "int" --field "port"
|
||||
|
||||
Modified YAML:
|
||||
|
||||
# resource.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
...
|
||||
spec:
|
||||
...
|
||||
ports:
|
||||
...
|
||||
- name: http
|
||||
port: 8080 # {"substitutions":[{"name":"port","marker":"[MARKER]"}],"type":"int"}
|
||||
...
|
||||
|
||||
Change the value using the `set` command:
|
||||
|
||||
# change the http-port value to 8081
|
||||
$ kustomize config set dir/ http-port 8081
|
||||
|
||||
Resources fields with a field name matching `--field` and field value matching `VALUE` will
|
||||
have a line comment added marking this field as settable.
|
||||
|
||||
Substitution markers may be:
|
||||
|
||||
- valid field values (e.g. `8080` for a port)
|
||||
- Note: `008080` would be preferred because it is more recognizable as a marker
|
||||
- invalid values that adhere to the schema (e.g. `0000` for a port)
|
||||
- values that do not adhere to the schema (e.g. `[PORT]` for port)
|
||||
|
||||
Markers **SHOULD be clearly identifiable as a marker and either**:
|
||||
|
||||
- **adhere to the field schema** -- e.g. use a valid value
|
||||
|
||||
|
||||
port: 008080 # {"substitutions":[{"name":"port","marker":"008080"}],"type":"int"}
|
||||
|
||||
- **be pre-filled in with a value** -- e.g. set the value when setting the marker
|
||||
|
||||
|
||||
port: 8080 # {"substitutions":[{"name":"port","marker":"[MARKER]","value":"8080""}],"type":"int"}
|
||||
|
||||
**Note:** The important thing is that in both cases the Resource configuration may be directly
|
||||
applied to a cluster and validated by tools without the tool knowing about the substitution
|
||||
marker.
|
||||
|
||||
The difference between the preceding examples is that:
|
||||
|
||||
- the former will be shown as `SUBSTITUTED=false` (`config sub dir/` exits non-0)
|
||||
- the latter with show up as `SUBSTITUTED=true` (`config sub dir/` exits 0)
|
||||
|
||||
When choosing the which to use, consider that checks for unsubstituted values MAY be
|
||||
configured as pre-commit checks -- if you want to these checks to fail if the value
|
||||
hasn't been substituted, then don't specify a `value`.
|
||||
|
||||
Markers which are invalid field values MAY be chosen in cases where it is preferred to have
|
||||
the create or update request fail rather than succeed if the substitution has not yet been
|
||||
performed.
|
||||
|
||||
A substitution may be a substring of the full field:
|
||||
|
||||
$ kustomize config set create dir/ app-image-tag v1.0.01 --type "string" --field "image"
|
||||
|
||||
image: gcr.io/example/app:v1.0.1 # {"substitutions":[{"name":"app-image-tag","marker":"[MARKER]","value":"v1.0.1"}]}
|
||||
|
||||
|
||||
A single field value may have multiple substitutions applied to it:
|
||||
|
||||
name: PREFIX-app-SUFFIX # {"substitutions":[{"name":"prefix","marker":"PREFIX-"},{"name":"suffix","marker":"-SUFFIX"}]}
|
||||
|
||||
#### Substitution Format
|
||||
|
||||
Substitutions are defined as json encoded FieldMeta comments on fields.
|
||||
|
||||
FieldMeta Schema read by `sub`:
|
||||
|
||||
{
|
||||
"title": "FieldMeta",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"substitutions": {
|
||||
"type": "array",
|
||||
"description": "Possible substitutions that may be performed against this field.",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": "Name of the substitution.",
|
||||
"marker": "Marker for the value to be substituted.",
|
||||
"value": "Current substituted value"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The value type. Defaults to string."
|
||||
"enum": ["string", "int", "float", "bool"]
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "A description of the field's current value. Optional."
|
||||
},
|
||||
"ownedBy": {
|
||||
"type": "string",
|
||||
"description": "The current owner of the field. Optional."
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
### Examples
|
||||
|
||||
# set a substitution for port fields matching "8080"
|
||||
kustomize config sub create dir/ port 8080 --type "int" --field port \
|
||||
--description "default port used by the app"
|
||||
|
||||
# set a substitution for port fields matching "8080", using "0000" as a marker.
|
||||
kustomize config sub dir/ port 8080 --marker "0000" --type "int" \
|
||||
--field port --description "default port used by the app"
|
||||
|
||||
# substitute a substring of a field rather than the full field -- e.g. only the
|
||||
# image tag, not the full image
|
||||
kustomize config sub dir/ app-image-tag v1.0.1 --type "string" --substring \
|
||||
--field port --description "current stable release"
|
||||
@@ -20,8 +20,9 @@ container names, etc.
|
||||
|
||||
kustomize config tree supports printing arbitrary fields using the '--field' flag.
|
||||
|
||||
By default, kustomize config tree uses the directory structure for the tree structure, however when printing
|
||||
from the cluster, the Resource graph structure may be used instead.
|
||||
By default, kustomize config tree uses Resource graph structure if any relationships between resources (ownerReferences)
|
||||
are detected, as is typically the case when printing from a cluster. Otherwise, directory graph structure is used. The
|
||||
graph structure can also be selected explicitly using the '--graph-structure' flag.
|
||||
|
||||
### Examples
|
||||
|
||||
@@ -42,8 +43,7 @@ from the cluster, the Resource graph structure may be used instead.
|
||||
--field="status.conditions[type=Completed].status"
|
||||
|
||||
# print live Resources from a cluster using owners for graph structure
|
||||
kubectl get all -o yaml | kustomize config tree --replicas --name --image \
|
||||
--graph-structure=owners
|
||||
kubectl get all -o yaml | kustomize config tree --replicas --name --image
|
||||
|
||||
# print live Resources with status condition fields
|
||||
kubectl get all -o yaml | kustomize config tree \
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
#### 2. Modify the Generated Resources
|
||||
|
||||
- modify the generated Resources by adding an annotation, sidecar container, etc.
|
||||
- modify the `local-resources/example-use.yaml` by changing the replicas
|
||||
- modify the `local-resource/example-use.yaml` by changing the replicas
|
||||
|
||||
re-run `run`. this will apply the updated replicas to the generated Resources,
|
||||
but keep the fields that you manually added to the generated Resource configuration.
|
||||
@@ -86,7 +86,7 @@
|
||||
#### 2. Modify the Generated Resources
|
||||
|
||||
- modify the generated Resources by adding an annotation, sidecar container, etc.
|
||||
- modify the `local-resources/example-use.yaml` by changing the replicas
|
||||
- modify the `local-resource/example-use.yaml` by changing the replicas
|
||||
|
||||
re-run `run`. this will apply the updated replicas to the generated Resources,
|
||||
but keep the fields that you manually added to the generated Resource configuration.
|
||||
|
||||
@@ -9,7 +9,6 @@ require (
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/spf13/pflag v1.0.5
|
||||
github.com/stretchr/testify v1.4.0
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
k8s.io/apimachinery v0.17.0
|
||||
sigs.k8s.io/kustomize/kyaml v0.0.0
|
||||
)
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE=
|
||||
github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk=
|
||||
@@ -16,16 +19,25 @@ github.com/docker/spdystream v0.0.0-20160310174837-449fdfce4d96/go.mod h1:Qh8CwZ
|
||||
github.com/elazarl/goproxy v0.0.0-20170405201442-c4fc26588b6e/go.mod h1:/Zj4wYkgs4iZTTu3o/KG3Itv/qCCa8VVMlb3i9OVuzc=
|
||||
github.com/emicklei/go-restful v0.0.0-20170410110728-ff4f55a20633/go.mod h1:otzb+WCGbkyDHkqmQmT5YD2WR4BBwUdeQoFo8l/7tVs=
|
||||
github.com/evanphx/json-patch v4.2.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk=
|
||||
github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/go-errors/errors v1.0.1 h1:LUHzmkK3GUKUrL/1gfBUxAHzcev3apQlezX/+O7ma6w=
|
||||
github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm6/TyX73Q=
|
||||
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
|
||||
github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+35s3my2LFTysnkMfxsJBAMHj/DoqoB9knIWoYG/Vk0=
|
||||
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
|
||||
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||
github.com/go-openapi/jsonreference v0.19.2 h1:o20suLFB4Ri0tuzpWtyHlh7E7HnkqTNLq6aR6WVNS1w=
|
||||
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
||||
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
|
||||
github.com/go-openapi/spec v0.19.5 h1:Xm0Ao53uqnk9QE/LlYV5DEU09UAgpliA85QoT9LzqPw=
|
||||
github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
|
||||
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
|
||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d h1:3PaI8p3seN09VjbTYC/QWlUZdZ1qS1zGjy7LH2Wt07I=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
github.com/golang/groupcache v0.0.0-20160516000752-02826c3e7903/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
|
||||
@@ -43,7 +55,6 @@ github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv
|
||||
github.com/hashicorp/go-multierror v1.0.0 h1:iVjPR7a6H0tWELX5NxNe7bYopibicUzc7uPribsnS6o=
|
||||
github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk=
|
||||
github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
|
||||
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/inconshreveable/mousetrap v1.0.0 h1:Z8tu5sraLXCXIcARxBp/8cbvlwVa7Z1NHg9XEKhtSvM=
|
||||
@@ -51,21 +62,20 @@ github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANyt
|
||||
github.com/json-iterator/go v0.0.0-20180612202835-f2b4162afba3/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
|
||||
github.com/json-iterator/go v1.1.8/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
|
||||
github.com/kisielk/gotool v1.0.0 h1:AV2c/EiW3KqPNT9ZKl07ehoAGi4C5/01Cfbblndcapg=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
|
||||
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
|
||||
github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
|
||||
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
|
||||
github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
|
||||
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
github.com/mitchellh/mapstructure v1.1.2 h1:fmNYVwqnSfB9mZU6OS2O6GsXM+wcskZDuKQzvN1EDeE=
|
||||
github.com/mitchellh/mapstructure v1.1.2/go.mod h1:FVVH3fgwuzCH5S8UJGiWEs2h04kUh9fWfEaFds41c1Y=
|
||||
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
|
||||
@@ -81,9 +91,7 @@ github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+W
|
||||
github.com/onsi/ginkgo v1.10.1/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v0.0.0-20170829124025-dcabb60a477c/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA=
|
||||
github.com/onsi/gomega v1.7.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181zc=
|
||||
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
|
||||
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 v0.0.0-20151028094244-d8ed2627bdf0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
@@ -93,12 +101,12 @@ github.com/posener/complete/v2 v2.0.1-alpha.12/go.mod h1://JlL91cS2JV7rOl6LVHrRq
|
||||
github.com/posener/script v1.0.4 h1:nSuXW5ZdmFnQIueLB2s0qvs4oNsUloM1Zydzh75v42w=
|
||||
github.com/posener/script v1.0.4/go.mod h1:Rg3ijooqulo05aGLyGsHoLmIOUzHUVK19WVgrYBPU/E=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
github.com/spf13/cast v1.3.0 h1:oget//CVOEoFewqQxwr0Ej5yjygnqGkvggSE/gB35Q8=
|
||||
github.com/spf13/cast v1.3.0/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE=
|
||||
github.com/spf13/cobra v0.0.5 h1:f0B+LkLX6DtmRH1isoNA9VTtNUK9K8xYd28JNNfOv/s=
|
||||
github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tLCHU=
|
||||
github.com/spf13/jwalterweatherman v1.0.0 h1:XHEdyB+EcvlqZamSM4ZOMGlc93t6AcsBEu9Gc1vn7yk=
|
||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||
@@ -119,6 +127,9 @@ golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnf
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/net v0.0.0-20170114055629-f2499483f923/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20170830134202-bb24a47a89ea/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
@@ -128,12 +139,12 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190826190057-c7b8b68b1456/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181011042414-1f849cf54d09/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -121,6 +121,13 @@ func (r *CatRunner) runE(c *cobra.Command, args []string) error {
|
||||
out = o
|
||||
}
|
||||
|
||||
// remove this annotation explicitly, the ByteWriter won't clear it by
|
||||
// default because it doesn't set it
|
||||
clear := []string{"config.kubernetes.io/path"}
|
||||
if r.KeepAnnotations {
|
||||
clear = nil
|
||||
}
|
||||
|
||||
var outputs []kio.Writer
|
||||
outputs = append(outputs, kio.ByteWriter{
|
||||
Writer: out,
|
||||
@@ -129,6 +136,7 @@ func (r *CatRunner) runE(c *cobra.Command, args []string) error {
|
||||
WrappingAPIVersion: r.WrapApiVersion,
|
||||
FunctionConfig: functionConfig,
|
||||
Style: yaml.GetStyle(r.Styles...),
|
||||
ClearAnnotations: clear,
|
||||
})
|
||||
|
||||
return handleError(c, kio.Pipeline{Inputs: inputs, Filters: fltr, Outputs: outputs}.Execute())
|
||||
|
||||
@@ -90,8 +90,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -100,8 +98,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -114,8 +110,6 @@ metadata:
|
||||
app: nginx
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
spec:
|
||||
replicas: 3
|
||||
`, b.String()) {
|
||||
@@ -196,8 +190,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -206,8 +198,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -218,8 +208,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/example/image:version
|
||||
@@ -233,8 +221,6 @@ metadata:
|
||||
name: bar
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
spec:
|
||||
replicas: 3
|
||||
`, b.String()) {
|
||||
@@ -314,8 +300,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
@@ -414,8 +398,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -424,8 +406,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -438,8 +418,6 @@ metadata:
|
||||
app: nginx
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
spec:
|
||||
replicas: 3
|
||||
`, string(actual)) {
|
||||
@@ -536,8 +514,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -546,8 +522,6 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -560,8 +534,6 @@ metadata:
|
||||
app: nginx
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
spec:
|
||||
replicas: 3
|
||||
`, string(actual)) {
|
||||
|
||||
75
cmd/config/internal/commands/cmdcreatesetter.go
Normal file
75
cmd/config/internal/commands/cmdcreatesetter.go
Normal file
@@ -0,0 +1,75 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/setters"
|
||||
)
|
||||
|
||||
// NewCreateSetterRunner returns a command runner.
|
||||
func NewCreateSetterRunner(parent string) *CreateSetterRunner {
|
||||
r := &CreateSetterRunner{}
|
||||
set := &cobra.Command{
|
||||
Use: "create-setter DIR NAME VALUE",
|
||||
Args: cobra.ExactArgs(3),
|
||||
Short: commands.CreateSetterShort,
|
||||
Long: commands.CreateSetterLong,
|
||||
Example: commands.CreateSetterExamples,
|
||||
PreRunE: r.preRunE,
|
||||
RunE: r.runE,
|
||||
}
|
||||
set.Flags().StringVar(&r.Set.SetPartialField.SetBy, "set-by", "",
|
||||
"set the setBy annotation.")
|
||||
set.Flags().StringVar(&r.Set.SetPartialField.Description, "description", "",
|
||||
"set the description of the field value.")
|
||||
set.Flags().StringVar(&r.Set.SetPartialField.Field, "field", "",
|
||||
"name of the field to set -- e.g. --field port")
|
||||
set.Flags().StringVar(&r.Set.ResourceMeta.Name, "name", "",
|
||||
"name of the Resource on which to create the setter.")
|
||||
set.Flags().StringVar(&r.Set.ResourceMeta.Kind, "kind", "",
|
||||
"kind of the Resource on which to create the setter.")
|
||||
set.Flags().StringVar(&r.Set.SetPartialField.Type, "type", "",
|
||||
"valid OpenAPI field type -- e.g. integer,boolean,string.")
|
||||
set.Flags().BoolVar(&r.Set.SetPartialField.Partial, "partial", false,
|
||||
"create a partial setter for only part of the field value.")
|
||||
fixDocs(parent, set)
|
||||
set.MarkFlagRequired("type")
|
||||
set.MarkFlagRequired("field")
|
||||
r.Command = set
|
||||
return r
|
||||
}
|
||||
|
||||
func CreateSetterCommand(parent string) *cobra.Command {
|
||||
return NewCreateSetterRunner(parent).Command
|
||||
}
|
||||
|
||||
type CreateSetterRunner struct {
|
||||
Command *cobra.Command
|
||||
Set setters.CreateSetter
|
||||
}
|
||||
|
||||
func (r *CreateSetterRunner) runE(c *cobra.Command, args []string) error {
|
||||
return handleError(c, r.set(c, args))
|
||||
}
|
||||
|
||||
func (r *CreateSetterRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
r.Set.SetPartialField.Setter.Name = args[1]
|
||||
r.Set.SetPartialField.Setter.Value = args[2]
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *CreateSetterRunner) set(c *cobra.Command, args []string) error {
|
||||
rw := &kio.LocalPackageReadWriter{PackagePath: args[0]}
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{rw},
|
||||
Filters: []kio.Filter{&r.Set},
|
||||
Outputs: []kio.Writer{rw}}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
47
cmd/config/internal/commands/cmdlistsetters.go
Normal file
47
cmd/config/internal/commands/cmdlistsetters.go
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/setters"
|
||||
)
|
||||
|
||||
// NewListSettersRunner returns a command runner.
|
||||
func NewListSettersRunner(parent string) *ListSettersRunner {
|
||||
r := &ListSettersRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "list-setters DIR [NAME]",
|
||||
Args: cobra.RangeArgs(1, 2),
|
||||
Short: commands.ListSettersShort,
|
||||
Long: commands.ListSettersLong,
|
||||
Example: commands.ListSettersExamples,
|
||||
PreRunE: r.preRunE,
|
||||
RunE: r.runE,
|
||||
}
|
||||
fixDocs(parent, c)
|
||||
r.Command = c
|
||||
return r
|
||||
}
|
||||
|
||||
func ListSettersCommand(parent string) *cobra.Command {
|
||||
return NewListSettersRunner(parent).Command
|
||||
}
|
||||
|
||||
type ListSettersRunner struct {
|
||||
Command *cobra.Command
|
||||
Lookup setters.LookupSetters
|
||||
}
|
||||
|
||||
func (r *ListSettersRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
if len(args) > 1 {
|
||||
r.Lookup.Name = args[1]
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *ListSettersRunner) runE(c *cobra.Command, args []string) error {
|
||||
return handleError(c, lookup(r.Lookup, c, args))
|
||||
}
|
||||
130
cmd/config/internal/commands/cmdset.go
Normal file
130
cmd/config/internal/commands/cmdset.go
Normal file
@@ -0,0 +1,130 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/setters"
|
||||
)
|
||||
|
||||
// NewSetRunner returns a command runner.
|
||||
func NewSetRunner(parent string) *SetRunner {
|
||||
r := &SetRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "set DIR [NAME] [VALUE]",
|
||||
Args: cobra.RangeArgs(1, 3),
|
||||
Short: commands.SetShort,
|
||||
Long: commands.SetLong,
|
||||
Example: commands.SetExamples,
|
||||
PreRunE: r.preRunE,
|
||||
RunE: r.runE,
|
||||
}
|
||||
fixDocs(parent, c)
|
||||
r.Command = c
|
||||
c.Flags().StringVar(&r.Perform.SetBy, "set-by", "",
|
||||
"annotate the field with who set it")
|
||||
c.Flags().StringVar(&r.Perform.Description, "description", "",
|
||||
"annotate the field with a description of its value")
|
||||
|
||||
return r
|
||||
}
|
||||
|
||||
func SetCommand(parent string) *cobra.Command {
|
||||
return NewSetRunner(parent).Command
|
||||
}
|
||||
|
||||
type SetRunner struct {
|
||||
Command *cobra.Command
|
||||
Lookup setters.LookupSetters
|
||||
Perform setters.PerformSetters
|
||||
}
|
||||
|
||||
func (r *SetRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
if len(args) > 1 {
|
||||
r.Perform.Name = args[1]
|
||||
r.Lookup.Name = args[1]
|
||||
}
|
||||
if len(args) > 2 {
|
||||
r.Perform.Value = args[2]
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *SetRunner) runE(c *cobra.Command, args []string) error {
|
||||
|
||||
if len(args) == 3 {
|
||||
return handleError(c, r.perform(c, args))
|
||||
}
|
||||
|
||||
return handleError(c, lookup(r.Lookup, c, args))
|
||||
}
|
||||
|
||||
func lookup(l setters.LookupSetters, c *cobra.Command, args []string) error {
|
||||
// lookup the setters
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{&kio.LocalPackageReader{PackagePath: args[0]}},
|
||||
Filters: []kio.Filter{&l},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
table := tablewriter.NewWriter(c.OutOrStdout())
|
||||
table.SetRowLine(false)
|
||||
table.SetBorder(false)
|
||||
table.SetHeaderLine(false)
|
||||
table.SetColumnSeparator(" ")
|
||||
table.SetCenterSeparator(" ")
|
||||
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||
table.SetHeader([]string{
|
||||
"NAME", "DESCRIPTION", "VALUE", "TYPE", "COUNT", "SETBY",
|
||||
})
|
||||
for i := range l.SetterCounts {
|
||||
s := l.SetterCounts[i]
|
||||
v := s.Value
|
||||
if s.Value == "" {
|
||||
v = s.Value
|
||||
}
|
||||
table.Append([]string{
|
||||
s.Name,
|
||||
"'" + s.Description + "'",
|
||||
v,
|
||||
fmt.Sprintf("%v", s.Type),
|
||||
fmt.Sprintf("%d", s.Count),
|
||||
s.SetBy,
|
||||
})
|
||||
}
|
||||
table.Render()
|
||||
|
||||
if len(l.SetterCounts) == 0 {
|
||||
// exit non-0 if no matching setters are found
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// perform the setters
|
||||
func (r *SetRunner) perform(c *cobra.Command, args []string) error {
|
||||
rw := &kio.LocalPackageReadWriter{
|
||||
PackagePath: args[0],
|
||||
}
|
||||
// perform the setters in the package
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{rw},
|
||||
Filters: []kio.Filter{&r.Perform},
|
||||
Outputs: []kio.Writer{rw},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(c.OutOrStdout(), "set %d fields\n", r.Perform.Count)
|
||||
return nil
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// 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 commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/olekukonko/tablewriter"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/sub"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
)
|
||||
|
||||
// NewSubRunner returns a command runner.
|
||||
func NewSubRunner(parent string) *SubRunner {
|
||||
r := &SubRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "set DIR [NAME] [VALUE]",
|
||||
Args: cobra.RangeArgs(1, 3),
|
||||
Short: commands.SubShort,
|
||||
Long: commands.SubLong,
|
||||
Example: commands.SubExamples,
|
||||
Aliases: []string{"sub"},
|
||||
PreRunE: r.preRunE,
|
||||
RunE: r.runE,
|
||||
}
|
||||
c.Flags().BoolVar(&r.Perform.Override, "override", true,
|
||||
"override previously substituted values.")
|
||||
c.Flags().BoolVar(&r.Perform.Revert, "revert", false,
|
||||
"override previously substituted values.")
|
||||
fixDocs(parent, c)
|
||||
r.Command = c
|
||||
c.AddCommand(SubSetCommand(parent))
|
||||
return r
|
||||
}
|
||||
|
||||
func SubCommand(parent string) *cobra.Command {
|
||||
return NewSubRunner(parent).Command
|
||||
}
|
||||
|
||||
type SubRunner struct {
|
||||
Command *cobra.Command
|
||||
Lookup sub.LookupSubstitutions
|
||||
Perform sub.PerformSubstitutions
|
||||
}
|
||||
|
||||
func (r *SubRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
if len(args) > 1 {
|
||||
r.Perform.Name = args[1]
|
||||
r.Lookup.Name = args[1]
|
||||
}
|
||||
if len(args) > 2 {
|
||||
r.Perform.NewValue = args[2]
|
||||
}
|
||||
if len(args) < 2 && r.Perform.Revert {
|
||||
return errors.Errorf("must specify NAME with --revert")
|
||||
}
|
||||
|
||||
var mutex int
|
||||
if r.Perform.Revert {
|
||||
mutex++
|
||||
}
|
||||
if r.Perform.Override {
|
||||
mutex++
|
||||
}
|
||||
if mutex > 1 {
|
||||
return errors.Errorf("--revert, --override are mutually exclusive")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *SubRunner) runE(c *cobra.Command, args []string) error {
|
||||
|
||||
if len(args) == 3 {
|
||||
return handleError(c, r.perform(c, args))
|
||||
}
|
||||
if len(args) == 2 && r.Perform.Revert {
|
||||
return handleError(c, r.perform(c, args))
|
||||
}
|
||||
|
||||
return handleError(c, r.lookup(c, args))
|
||||
}
|
||||
|
||||
func (r *SubRunner) lookup(c *cobra.Command, args []string) error {
|
||||
// lookup the substitutions
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{&kio.LocalPackageReader{PackagePath: args[0]}},
|
||||
Filters: []kio.Filter{&r.Lookup},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
remaining := false
|
||||
table := tablewriter.NewWriter(c.OutOrStdout())
|
||||
table.SetRowLine(false)
|
||||
table.SetBorder(false)
|
||||
table.SetHeaderLine(false)
|
||||
table.SetColumnSeparator(" ")
|
||||
table.SetCenterSeparator(" ")
|
||||
table.SetAlignment(tablewriter.ALIGN_LEFT)
|
||||
table.SetHeader([]string{
|
||||
"NAME", "DESCRIPTION", "VALUE", "TYPE", "COUNT", "SUBSTITUTED", "OWNER",
|
||||
})
|
||||
for i := range r.Lookup.SubstitutionCounts {
|
||||
s := r.Lookup.SubstitutionCounts[i]
|
||||
remaining = remaining || s.Count > s.CountComplete
|
||||
v := s.CurrentValue
|
||||
if s.CurrentValue == "" {
|
||||
v = s.Marker
|
||||
}
|
||||
table.Append([]string{
|
||||
s.Name,
|
||||
"'" + s.Description + "'",
|
||||
v,
|
||||
fmt.Sprintf("%v", s.Type),
|
||||
fmt.Sprintf("%d", s.Count),
|
||||
fmt.Sprintf("%v", s.Count == s.CountComplete),
|
||||
s.OwnedBy,
|
||||
})
|
||||
}
|
||||
table.Render()
|
||||
|
||||
if remaining {
|
||||
os.Exit(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// perform the substitutions
|
||||
func (r *SubRunner) perform(c *cobra.Command, args []string) error {
|
||||
rw := &kio.LocalPackageReadWriter{
|
||||
PackagePath: args[0],
|
||||
}
|
||||
// perform the substitutions in the package
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{rw},
|
||||
Filters: []kio.Filter{&r.Perform},
|
||||
Outputs: []kio.Writer{rw},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
fmt.Fprintf(c.OutOrStdout(), "performed %d substitutions\n", r.Perform.Count)
|
||||
return nil
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// 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 commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/sub"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
)
|
||||
|
||||
// NewSubSetRunner returns a command runner.
|
||||
func NewSubSetRunner(parent string) *SubSetRunner {
|
||||
r := &SubSetRunner{}
|
||||
set := &cobra.Command{
|
||||
Use: "create PKG_DIR NAME [VALUE]",
|
||||
Args: cobra.ExactArgs(3),
|
||||
Short: commands.SubsetShort,
|
||||
Long: commands.SubsetLong,
|
||||
Example: commands.SubsetExamples,
|
||||
PreRunE: r.preRunE,
|
||||
RunE: r.runE,
|
||||
}
|
||||
set.Flags().StringVar(&r.Set.Marker.OwnedBy, "owned-by", "",
|
||||
"set this owner on for the current value.")
|
||||
set.Flags().StringVar(&r.Set.Marker.Description, "description", "",
|
||||
"set this description for the current value description.")
|
||||
set.Flags().StringVar(&r.Set.Marker.Substitution.Marker, "marker", "[MARKER]",
|
||||
"use this marker.")
|
||||
set.Flags().StringVar(&r.Set.Marker.Field, "field", "",
|
||||
"name of the field to set -- e.g. --field port")
|
||||
set.Flags().StringVar(&r.Set.ResourceMeta.Name, "name", "",
|
||||
"name of the Resource on which to set the substitution.")
|
||||
set.Flags().StringVar(&r.Set.ResourceMeta.Kind, "kind", "",
|
||||
"kind of the Resource on which to set substitution.")
|
||||
set.Flags().StringVar(&r.Set.Marker.Type, "type", "",
|
||||
"field type -- e.g. int,float,bool,string.")
|
||||
set.Flags().BoolVar(&r.Set.Marker.PartialMatch, "substring", false,
|
||||
"if true, the value may be a substring of the current value.")
|
||||
fixDocs(parent, set)
|
||||
set.MarkFlagRequired("type")
|
||||
set.MarkFlagRequired("field")
|
||||
r.Command = set
|
||||
return r
|
||||
}
|
||||
|
||||
func SubSetCommand(parent string) *cobra.Command {
|
||||
return NewSubSetRunner(parent).Command
|
||||
}
|
||||
|
||||
type SubSetRunner struct {
|
||||
Command *cobra.Command
|
||||
Set sub.SetSubstitutionMarker
|
||||
}
|
||||
|
||||
func (r *SubSetRunner) runE(c *cobra.Command, args []string) error {
|
||||
return handleError(c, r.set(c, args))
|
||||
}
|
||||
|
||||
func (r *SubSetRunner) preRunE(c *cobra.Command, args []string) error {
|
||||
r.Set.Marker.Substitution.Name = args[1]
|
||||
r.Set.Marker.Substitution.Value = args[2]
|
||||
return nil
|
||||
}
|
||||
|
||||
// perform the substitutions
|
||||
func (r *SubSetRunner) set(c *cobra.Command, args []string) error {
|
||||
rw := &kio.LocalPackageReadWriter{
|
||||
PackagePath: args[0],
|
||||
}
|
||||
// add the substitution marker to the Resource
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{rw},
|
||||
Filters: []kio.Filter{&r.Set},
|
||||
Outputs: []kio.Writer{rw},
|
||||
}.Execute()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -78,8 +78,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
annotations:
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/path: config/test_deployment.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'config/test_deployment.yaml'
|
||||
spec:
|
||||
replicas: 11
|
||||
selector:
|
||||
@@ -109,8 +109,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
annotations:
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/path: config/test_service.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'config/test_service.yaml'
|
||||
spec:
|
||||
selector:
|
||||
name: test
|
||||
@@ -133,8 +133,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
annotations:
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/path: config/test_deployment.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'config/test_deployment.yaml'
|
||||
spec:
|
||||
replicas: 11
|
||||
selector:
|
||||
@@ -161,8 +161,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
annotations:
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/path: config/test_service.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'config/test_service.yaml'
|
||||
spec:
|
||||
selector:
|
||||
name: test
|
||||
@@ -185,8 +185,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
annotations:
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/path: config/test_deployment.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'config/test_deployment.yaml'
|
||||
spec:
|
||||
replicas: 11
|
||||
selector:
|
||||
@@ -216,8 +216,8 @@ items:
|
||||
name: test
|
||||
app: nginx
|
||||
annotations:
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/path: config/test_service.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'config/test_service.yaml'
|
||||
spec:
|
||||
selector:
|
||||
name: test
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
func GetFmtRunner(name string) *FmtRunner {
|
||||
r := &FmtRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "fmt",
|
||||
Use: "fmt DIR...",
|
||||
Short: commands.FmtShort,
|
||||
Long: commands.FmtLong,
|
||||
Example: commands.FmtExamples,
|
||||
|
||||
@@ -75,9 +75,8 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -86,9 +85,8 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: 1
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
@@ -145,7 +143,7 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: 0
|
||||
config.kubernetes.io/index: '0'
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
@@ -154,7 +152,7 @@ metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: 1
|
||||
config.kubernetes.io/index: '1'
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
|
||||
55
cmd/config/internal/commands/merge3.go
Normal file
55
cmd/config/internal/commands/merge3.go
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio/filters"
|
||||
)
|
||||
|
||||
func GetMerge3Runner(name string) *Merge3Runner {
|
||||
r := &Merge3Runner{}
|
||||
c := &cobra.Command{
|
||||
Use: "merge3 --ancestor [ORIGINAL_DIR] --from [UPDATED_DIR] --to [DESTINATION_DIR]",
|
||||
Short: commands.Merge3Short,
|
||||
Long: commands.Merge3Long,
|
||||
Example: commands.Merge3Examples,
|
||||
RunE: r.runE,
|
||||
}
|
||||
fixDocs(name, c)
|
||||
c.Flags().StringVar(&r.ancestor, "ancestor", "",
|
||||
"Path to original package")
|
||||
c.Flags().StringVar(&r.fromDir, "from", "",
|
||||
"Path to updated package")
|
||||
c.Flags().StringVar(&r.toDir, "to", "",
|
||||
"Path to destination package")
|
||||
|
||||
r.Command = c
|
||||
return r
|
||||
}
|
||||
|
||||
func Merge3Command(name string) *cobra.Command {
|
||||
return GetMerge3Runner(name).Command
|
||||
}
|
||||
|
||||
// Merge3Runner contains the run function
|
||||
type Merge3Runner struct {
|
||||
Command *cobra.Command
|
||||
ancestor string
|
||||
fromDir string
|
||||
toDir string
|
||||
}
|
||||
|
||||
func (r *Merge3Runner) runE(c *cobra.Command, args []string) error {
|
||||
err := filters.Merge3{
|
||||
OriginalPath: r.ancestor,
|
||||
UpdatedPath: r.fromDir,
|
||||
DestPath: r.toDir,
|
||||
}.Merge()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
236
cmd/config/internal/commands/merge3_test.go
Normal file
236
cmd/config/internal/commands/merge3_test.go
Normal file
@@ -0,0 +1,236 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands_test
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||
)
|
||||
|
||||
// TestMerge3Command verifies the merge3 correctly applies the diff between 2 sets of resources into another
|
||||
func TestMerge3Command(t *testing.T) {
|
||||
datadir, err := ioutil.TempDir("", "test-data")
|
||||
defer os.RemoveAll(datadir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(datadir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
labels:
|
||||
app: java
|
||||
spec:
|
||||
replicas: 1
|
||||
selector:
|
||||
matchLabels:
|
||||
app: java
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: java
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
containers:
|
||||
- name: app
|
||||
image: gcr.io/project/app:version
|
||||
command:
|
||||
- java
|
||||
- -jar
|
||||
- /app.jar
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 5
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
expected_dir, err := ioutil.TempDir("", "test-data-expected")
|
||||
defer os.RemoveAll(expected_dir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(expected_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
labels:
|
||||
app: java
|
||||
new-local: label
|
||||
new-remote: label
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: java
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: java
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
containers:
|
||||
- name: app
|
||||
image: gcr.io/project/app:version
|
||||
command:
|
||||
- java
|
||||
- -jar
|
||||
- /app.jar
|
||||
- otherstuff
|
||||
args:
|
||||
- foo
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 20
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
updated_dir, err := ioutil.TempDir("", "test-data-updated")
|
||||
defer os.RemoveAll(updated_dir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(updated_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
labels:
|
||||
app: java
|
||||
new-remote: label
|
||||
spec:
|
||||
replicas: 3
|
||||
selector:
|
||||
matchLabels:
|
||||
app: java
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: java
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
containers:
|
||||
- name: app
|
||||
image: gcr.io/project/app:version
|
||||
command:
|
||||
- java
|
||||
- -jar
|
||||
- /app.jar
|
||||
- otherstuff
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 5
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
dest_dir, err := ioutil.TempDir("", "test-data-dest")
|
||||
defer os.RemoveAll(dest_dir)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(dest_dir, "java-deployment.resource.yaml"), []byte(`apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: app
|
||||
labels:
|
||||
app: java
|
||||
new-local: label
|
||||
spec:
|
||||
replicas: 2
|
||||
selector:
|
||||
matchLabels:
|
||||
app: java
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: java
|
||||
spec:
|
||||
restartPolicy: Always
|
||||
containers:
|
||||
- name: app
|
||||
image: gcr.io/project/app:version
|
||||
command:
|
||||
- java
|
||||
- -jar
|
||||
- /app.jar
|
||||
args:
|
||||
- foo
|
||||
ports:
|
||||
- containerPort: 8080
|
||||
envFrom:
|
||||
- configMapRef:
|
||||
name: app-config
|
||||
env:
|
||||
- name: JAVA_OPTS
|
||||
value: -XX:+UnlockExperimentalVMOptions -XX:+UseCGroupMemoryLimitForHeap
|
||||
-Djava.security.egd=file:/dev/./urandom
|
||||
imagePullPolicy: Always
|
||||
minReadySeconds: 20
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// Perform merge3 with newly created sets
|
||||
r := commands.GetMerge3Runner("")
|
||||
r.Command.SetArgs([]string{
|
||||
"--ancestor",
|
||||
datadir,
|
||||
"--from",
|
||||
updated_dir,
|
||||
"--to",
|
||||
dest_dir,
|
||||
})
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
return
|
||||
}
|
||||
|
||||
diffs, err := copyutil.Diff(dest_dir, expected_dir)
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
// Verify there are no diffs
|
||||
if !assert.Empty(t, diffs.List()) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
48
cmd/config/internal/commands/sink.go
Normal file
48
cmd/config/internal/commands/sink.go
Normal file
@@ -0,0 +1,48 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
)
|
||||
|
||||
// GetSinkRunner returns a command for Sink.
|
||||
func GetSinkRunner(name string) *SinkRunner {
|
||||
r := &SinkRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "sink DIR",
|
||||
Short: commands.SinkShort,
|
||||
Long: commands.SinkLong,
|
||||
Example: commands.SinkExamples,
|
||||
RunE: r.runE,
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
fixDocs(name, c)
|
||||
r.Command = c
|
||||
return r
|
||||
}
|
||||
|
||||
func SinkCommand(name string) *cobra.Command {
|
||||
return GetSinkRunner(name).Command
|
||||
}
|
||||
|
||||
// SinkRunner contains the run function
|
||||
type SinkRunner struct {
|
||||
Command *cobra.Command
|
||||
}
|
||||
|
||||
func (r *SinkRunner) runE(c *cobra.Command, args []string) error {
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{&kio.ByteReader{Reader: c.InOrStdin()}},
|
||||
Outputs: []kio.Writer{
|
||||
&kio.LocalPackageWriter{
|
||||
PackagePath: args[0],
|
||||
ClearAnnotations: []string{"config.kubernetes.io/path"},
|
||||
},
|
||||
},
|
||||
}.Execute()
|
||||
return handleError(c, err)
|
||||
}
|
||||
140
cmd/config/internal/commands/sink_test.go
Normal file
140
cmd/config/internal/commands/sink_test.go
Normal file
@@ -0,0 +1,140 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||
)
|
||||
|
||||
func TestSinkCommand(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
// fmt the files
|
||||
b := &bytes.Buffer{}
|
||||
r := commands.GetSinkRunner("")
|
||||
r.Command.SetIn(bytes.NewBufferString(`apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
replicas: 1
|
||||
- kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
- apiVersion: v1
|
||||
kind: Abstraction
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f2.yaml'
|
||||
spec:
|
||||
replicas: 3
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
name: bar
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f2.yaml'
|
||||
spec:
|
||||
replicas: 3
|
||||
`))
|
||||
r.Command.SetArgs([]string{d})
|
||||
r.Command.SetOut(b)
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
actual, err := ioutil.ReadFile(filepath.Join(d, "f1.yaml"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
expected := `kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
`
|
||||
if !assert.Equal(t, expected, string(actual)) {
|
||||
t.FailNow()
|
||||
}
|
||||
|
||||
actual, err = ioutil.ReadFile(filepath.Join(d, "f2.yaml"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
expected = `apiVersion: v1
|
||||
kind: Abstraction
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
config.kubernetes.io/local-config: "true"
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
name: bar
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
`
|
||||
if !assert.Equal(t, expected, string(actual)) {
|
||||
t.FailNow()
|
||||
}
|
||||
}
|
||||
77
cmd/config/internal/commands/source.go
Normal file
77
cmd/config/internal/commands/source.go
Normal file
@@ -0,0 +1,77 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
// GetSourceRunner returns a command for Source.
|
||||
func GetSourceRunner(name string) *SourceRunner {
|
||||
r := &SourceRunner{}
|
||||
c := &cobra.Command{
|
||||
Use: "source DIR",
|
||||
Short: commands.SourceShort,
|
||||
Long: commands.SourceLong,
|
||||
Example: commands.SourceExamples,
|
||||
RunE: r.runE,
|
||||
Args: cobra.ExactArgs(1),
|
||||
}
|
||||
fixDocs(name, c)
|
||||
c.Flags().StringVar(&r.WrapKind, "wrap-kind", kio.ResourceListKind,
|
||||
"output using this format.")
|
||||
c.Flags().StringVar(&r.WrapApiVersion, "wrap-version", kio.ResourceListAPIVersion,
|
||||
"output using this format.")
|
||||
c.Flags().StringVar(&r.FunctionConfig, "function-config", "",
|
||||
"path to function config.")
|
||||
r.Command = c
|
||||
_ = c.MarkFlagFilename("function-config", "yaml", "json", "yml")
|
||||
return r
|
||||
}
|
||||
|
||||
func SourceCommand(name string) *cobra.Command {
|
||||
return GetSourceRunner(name).Command
|
||||
}
|
||||
|
||||
// SourceRunner contains the run function
|
||||
type SourceRunner struct {
|
||||
WrapKind string
|
||||
WrapApiVersion string
|
||||
FunctionConfig string
|
||||
Command *cobra.Command
|
||||
}
|
||||
|
||||
func (r *SourceRunner) runE(c *cobra.Command, args []string) error {
|
||||
// if there is a function-config specified, emit it
|
||||
var functionConfig *yaml.RNode
|
||||
if r.FunctionConfig != "" {
|
||||
configs, err := kio.LocalPackageReader{PackagePath: r.FunctionConfig}.Read()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(configs) != 1 {
|
||||
return fmt.Errorf("expected exactly 1 functionConfig, found %d", len(configs))
|
||||
}
|
||||
functionConfig = configs[0]
|
||||
}
|
||||
|
||||
var outputs []kio.Writer
|
||||
outputs = append(outputs, kio.ByteWriter{
|
||||
Writer: c.OutOrStdout(),
|
||||
KeepReaderAnnotations: true,
|
||||
WrappingKind: r.WrapKind,
|
||||
WrappingAPIVersion: r.WrapApiVersion,
|
||||
FunctionConfig: functionConfig,
|
||||
})
|
||||
|
||||
err := kio.Pipeline{
|
||||
Inputs: []kio.Reader{kio.LocalPackageReader{PackagePath: args[0]}},
|
||||
Outputs: outputs}.Execute()
|
||||
return handleError(c, err)
|
||||
}
|
||||
136
cmd/config/internal/commands/source_test.go
Normal file
136
cmd/config/internal/commands/source_test.go
Normal file
@@ -0,0 +1,136 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package commands_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/cmd/config/internal/commands"
|
||||
)
|
||||
|
||||
func TestSourceCommand(t *testing.T) {
|
||||
d, err := ioutil.TempDir("", "kustomize-source-test")
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(d)
|
||||
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f1.yaml"), []byte(`
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
spec:
|
||||
replicas: 1
|
||||
---
|
||||
kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
err = ioutil.WriteFile(filepath.Join(d, "f2.yaml"), []byte(`
|
||||
apiVersion: v1
|
||||
kind: Abstraction
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
config.kubernetes.io/local-config: "true"
|
||||
spec:
|
||||
replicas: 3
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
name: bar
|
||||
annotations:
|
||||
app: nginx
|
||||
spec:
|
||||
replicas: 3
|
||||
`), 0600)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
// fmt the files
|
||||
b := &bytes.Buffer{}
|
||||
r := commands.GetSourceRunner("")
|
||||
r.Command.SetArgs([]string{d})
|
||||
r.Command.SetOut(b)
|
||||
if !assert.NoError(t, r.Command.Execute()) {
|
||||
return
|
||||
}
|
||||
|
||||
if !assert.Equal(t, `apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx2
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
replicas: 1
|
||||
- kind: Service
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f1.yaml'
|
||||
spec:
|
||||
selector:
|
||||
app: nginx
|
||||
- apiVersion: v1
|
||||
kind: Abstraction
|
||||
metadata:
|
||||
name: foo
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/reconciler:v1
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.kubernetes.io/index: '0'
|
||||
config.kubernetes.io/path: 'f2.yaml'
|
||||
spec:
|
||||
replicas: 3
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
name: bar
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/index: '1'
|
||||
config.kubernetes.io/path: 'f2.yaml'
|
||||
spec:
|
||||
replicas: 3
|
||||
`, b.String()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func GetTreeRunner(name string) *TreeRunner {
|
||||
"if true, include local-config in the output.")
|
||||
c.Flags().BoolVar(&r.excludeNonLocal, "exclude-non-local", false,
|
||||
"if true, exclude non-local-config in the output.")
|
||||
c.Flags().StringVar(&r.structure, "graph-structure", "directory",
|
||||
c.Flags().StringVar(&r.structure, "graph-structure", "",
|
||||
"Graph structure to use for printing the tree. may be any of: "+
|
||||
strings.Join(kio.GraphStructures, ","))
|
||||
|
||||
|
||||
@@ -104,7 +104,6 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
@@ -118,7 +117,6 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
@@ -132,7 +130,6 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
@@ -146,7 +143,6 @@ metadata:
|
||||
namespace: default2
|
||||
annotations:
|
||||
app: nginx2
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
@@ -160,7 +156,6 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
app: nginx3
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
replicas: 1
|
||||
@@ -171,8 +166,7 @@ metadata:
|
||||
app: nginx
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: bar-package
|
||||
config.kubernetes.io/path: f2.yaml
|
||||
config.kubernetes.io/path: bar-package/f2.yaml
|
||||
name: bar
|
||||
spec:
|
||||
replicas: 3
|
||||
@@ -183,7 +177,6 @@ metadata:
|
||||
namespace: default
|
||||
annotations:
|
||||
app: nginx
|
||||
config.kubernetes.io/package: .
|
||||
config.kubernetes.io/path: f1.yaml
|
||||
spec:
|
||||
selector:
|
||||
|
||||
@@ -4,304 +4,23 @@
|
||||
// Code generated by "mdtogo"; DO NOT EDIT.
|
||||
package api
|
||||
|
||||
var ConfigFnLong = `# Configuration Functions API Semantics
|
||||
|
||||
Configuration Functions are functions packaged as executables in containers which enable
|
||||
**shift-left practices**. They configure applications and infrastructure through
|
||||
Kubernetes style Resource Configuration, but run locally pre-commit.
|
||||
|
||||
Configuration functions enable shift-left practices (client-side) through:
|
||||
|
||||
- Pre-commit / delivery validation and linting of configuration
|
||||
- e.g. Fail if any containers don't have PodSecurityPolicy or CPU / Memory limits
|
||||
- Implementation of abstractions as client actuated APIs (e.g. templating)
|
||||
- e.g. Create a client-side *"CRD"* for generating configuration checked into git
|
||||
- Aspect Orient configuration / Injection of cross-cutting configuration
|
||||
- e.g. T-Shirt size containers by annotating Resources with ` + "`" + `small` + "`" + `, ` + "`" + `medium` + "`" + `, ` + "`" + `large` + "`" + `
|
||||
and inject the cpu and memory resources into containers accordingly.
|
||||
- e.g. Inject ` + "`" + `init` + "`" + ` and ` + "`" + `side-car` + "`" + ` containers into Resources based off of Resource
|
||||
Type, annotations, etc.
|
||||
|
||||
Performing these on the client rather than the server enables:
|
||||
|
||||
- Configuration to be reviewed prior to being sent to the API server
|
||||
- Configuration to be validated as part of the CD pipeline
|
||||
- Configuration for Resources to validated holistically rather than individually
|
||||
per-Resource -- e.g. ensure the ` + "`" + `Service.selector` + "`" + ` and ` + "`" + `Deployment.spec.template` + "`" + ` labels
|
||||
match.
|
||||
- MutatingWebHooks are scoped to a single Resource instance at a time.
|
||||
- Low-level tweaks to the output of high-level abstractions -- e.g. add an ` + "`" + `init container` + "`" + `
|
||||
to a client *"CRD"* Resource after it was generated.
|
||||
- Composition and layering of multiple functions together
|
||||
- Compose generation, injection, validation together
|
||||
|
||||
Configuration Functions are implemented as executable programs published in containers which:
|
||||
|
||||
- Accept as input (stdin):
|
||||
- A list of Resource Configuration
|
||||
- A Function Configuration (to configure the function itself)
|
||||
- Emit as output (stdout + exit):
|
||||
- A list of Resource Configuration
|
||||
- An exit code for success / failure
|
||||
|
||||
### Function Specification
|
||||
|
||||
- Functions **SHOULD** be published as container images containing a ` + "`" + `CMD` + "`" + ` invoking an executable.
|
||||
- Functions **MUST** accept input on STDIN a ` + "`" + `ResourceList` + "`" + ` containing the Resources and
|
||||
` + "`" + `functionConfig` + "`" + `.
|
||||
- Functions **MUST** emit output on STDOUT a ` + "`" + `ResourceList` + "`" + ` containing the modified
|
||||
Resources.
|
||||
- Functions **MUST** exit non-0 on failure, and exit 0 on success.
|
||||
- Functions **MAY** emit output on STDERR with error messaging.
|
||||
- Functions performing validation **SHOULD** exit failure and emit error messaging
|
||||
on a validation failure.
|
||||
- Functions generating Resources **SHOULD** retain non-conflicting changes on the
|
||||
generated Resources -- e.g. 1. the function generates a Deployment, but doesn't
|
||||
specify ` + "`" + `cpu` + "`" + `, 2. the user sets the ` + "`" + `cpu` + "`" + ` on the generated Resource, 3. the
|
||||
function should keep the ` + "`" + `cpu` + "`" + ` when regenerating the Resource a second time.
|
||||
- Functions **SHOULD** be usable outside ` + "`" + `kustomize config run` + "`" + ` -- e.g. though pipeline
|
||||
mechanisms such as Tekton.
|
||||
|
||||
#### Input Format
|
||||
|
||||
Functions must accept on STDIN:
|
||||
|
||||
` + "`" + `ResourceList` + "`" + `:
|
||||
- contains ` + "`" + `items` + "`" + ` field, same as ` + "`" + `List.items` + "`" + `
|
||||
- contains ` + "`" + `functionConfig` + "`" + ` field -- a single item with the configuration for the function itself
|
||||
|
||||
Example ` + "`" + `ResourceList` + "`" + ` Input:
|
||||
|
||||
apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
functionConfig:
|
||||
apiVersion: example.com/v1beta1
|
||||
kind: Nginx
|
||||
metadata:
|
||||
name: my-instance
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
spec:
|
||||
replicas: 5
|
||||
items:
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
replicas: 3
|
||||
...
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
...
|
||||
|
||||
#### Output Format
|
||||
|
||||
Functions must emit on STDOUT:
|
||||
|
||||
` + "`" + `ResourceList` + "`" + `:
|
||||
- contains ` + "`" + `items` + "`" + ` field, same as ` + "`" + `List.items` + "`" + `
|
||||
|
||||
Example ` + "`" + `ResourceList` + "`" + ` Output:
|
||||
|
||||
apiVersion: config.kubernetes.io/v1alpha1
|
||||
kind: ResourceList
|
||||
items:
|
||||
- apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
replicas: 5
|
||||
...
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
spec:
|
||||
...
|
||||
|
||||
#### Container Environment
|
||||
|
||||
When run by ` + "`" + `kustomize config run` + "`" + `, functions are run in containers with the
|
||||
following environment:
|
||||
|
||||
- Network: ` + "`" + `none` + "`" + `
|
||||
- User: ` + "`" + `nobody` + "`" + `
|
||||
- Security Options: ` + "`" + `no-new-privileges` + "`" + `
|
||||
- Volumes: the volume containing the ` + "`" + `functionConfig` + "`" + ` yaml is mounted under ` + "`" + `/local` + "`" + ` as ` + "`" + `ro` + "`" + `
|
||||
|
||||
### Example Function Implementation
|
||||
|
||||
Following is an example for implementing an nginx abstraction using a config
|
||||
function.
|
||||
|
||||
#### ` + "`" + `nginx-template.sh` + "`" + `
|
||||
|
||||
` + "`" + `nginx-template.sh` + "`" + ` is a simple bash script which uses a *heredoc* as a templating solution
|
||||
for generating Resources from the functionConfig input fields.
|
||||
|
||||
The script wraps itself using ` + "`" + `config run wrap -- $0` + "`" + ` which will:
|
||||
|
||||
1. Parse the ` + "`" + `ResourceList.functionConfig` + "`" + ` (provided to the container stdin) into env vars
|
||||
2. Merge the stdout into the original list of Resources
|
||||
3. Defaults filenames for newly generated Resources (if they are not set as annotations)
|
||||
to ` + "`" + `config/NAME_KIND.yaml` + "`" + `
|
||||
4. Format the output
|
||||
|
||||
#!/bin/bash
|
||||
# script must run wrapped by ` + "`" + `kustomize config run wrap` + "`" + `
|
||||
# for parsing input the functionConfig into env vars
|
||||
if [ -z ${WRAPPED} ]; then
|
||||
export WRAPPED=true
|
||||
config run wrap -- $0
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cat <<End-of-message
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
replicas: ${REPLICAS}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
End-of-message
|
||||
|
||||
#### ` + "`" + `Dockerfile` + "`" + `
|
||||
|
||||
` + "`" + `Dockerfile` + "`" + ` installs ` + "`" + `kustomize config` + "`" + ` and copies the script into the container image.
|
||||
|
||||
FROM golang:1.13-stretch
|
||||
RUN go get sigs.k8s.io/kustomize/cmd/config
|
||||
RUN mv /go/bin/config /usr/bin/config
|
||||
COPY nginx-template.sh /usr/bin/nginx-template.sh
|
||||
CMD ["nginx-template.sh]
|
||||
|
||||
### Example Function Usage
|
||||
|
||||
Following is an example of running the ` + "`" + `kustomize config run` + "`" + ` using the preceding API.
|
||||
|
||||
#### ` + "`" + `nginx.yaml` + "`" + ` (Input)
|
||||
|
||||
` + "`" + `dir/nginx.yaml` + "`" + ` contains a reference to the Function. The contents of ` + "`" + `nginx.yaml` + "`" + `
|
||||
are passed to the Function through the ` + "`" + `ResourceList.functionConfig` + "`" + ` field.
|
||||
|
||||
apiVersion: example.com/v1beta1
|
||||
kind: Nginx
|
||||
metadata:
|
||||
name: my-instance
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
configFn:
|
||||
container:
|
||||
image: gcr.io/example-functions/nginx-template:v1.0.0
|
||||
spec:
|
||||
replicas: 5
|
||||
|
||||
- ` + "`" + `configFn.container.image` + "`" + `: the image to use for this API
|
||||
- ` + "`" + `annotations[config.kubernetes.io/local-config]` + "`" + `: mark this as not a Resource that should
|
||||
be applied
|
||||
|
||||
#### ` + "`" + `kustomize config run dir/` + "`" + ` (Output)
|
||||
|
||||
` + "`" + `dir/my-instance_deployment.yaml` + "`" + ` contains the Deployment:
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
replicas: 5
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
|
||||
` + "`" + `dir/my-instance_service.yaml` + "`" + ` contains the Service:
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: my-instance`
|
||||
|
||||
var ConfigIoLong = `# Configuration IO API Semantics
|
||||
|
||||
Resource Configuration may be read / written from / to sources such as directories,
|
||||
stdin|out or network. Tools may be composed using pipes such that the tools writing
|
||||
Resource Configuration may be a different tool from the one that read the configuration.
|
||||
In order for tools to be composed in this way, while preserving origin information --
|
||||
such as the original file, index, etc.
|
||||
such as the original file, index, etc.:
|
||||
|
||||
Tools **SHOULD** write the following annotations when reading from sources,
|
||||
and **SHOULD** respect the annotations when writing to sinks.
|
||||
Tools **SHOULD** insert the following annotations when reading from sources,
|
||||
and **SHOULD** delete the annotations when writing to sinks.
|
||||
|
||||
### ` + "`" + `config.kubernetes.io/path` + "`" + `
|
||||
|
||||
Records the slash-delimited, OS-agnostic, relative file path to a Resource.
|
||||
|
||||
This annotation **SHOULD** be set when reading Resources from files.
|
||||
It **SHOULD** be unset when writing Resources to files.
|
||||
When writing Resources to a directory, the Resource **SHOULD** be written to the corresponding
|
||||
path relative to that directory.
|
||||
|
||||
@@ -313,10 +32,11 @@ Example:
|
||||
|
||||
### ` + "`" + `config.kubernetes.io/index` + "`" + `
|
||||
|
||||
Records the index of a Resource in file. In a multi-object files YAML file, Resources are separated
|
||||
Records the index of a Resource in file. In a multi-object YAML file, Resources are separated
|
||||
by three dashes (` + "`" + `---` + "`" + `), and the index represents the positon of the Resource starting from zero.
|
||||
|
||||
This annotation **SHOULD** be set when reading Resources from files.
|
||||
It **SHOULD** be unset when writing Resources to files.
|
||||
When writing multiple Resources to the same file, the Resource **SHOULD** be written in the
|
||||
relative order matching the index.
|
||||
|
||||
@@ -344,6 +64,355 @@ Example:
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"`
|
||||
|
||||
var FunctionsImplShort = `Following is an example for implementing an nginx abstraction using a configuration`
|
||||
var FunctionsImplLong = `# Running Configuration Functions using kustomize CLI
|
||||
|
||||
Configuration functions can be implemented using any toolchain and invoked using any
|
||||
container workflow orchestrator including Tekton, Cloud Build, or run directly using ` + "`" + `docker run` + "`" + `.
|
||||
|
||||
Run ` + "`" + `config help docs-fn-spec` + "`" + ` to see the Configuration Functions Specification.
|
||||
|
||||
` + "`" + `kustomize config run` + "`" + ` is an example orchestrator for invoking Configuration Functions. This
|
||||
document describes how to implement and invoke an example function.
|
||||
|
||||
function.
|
||||
|
||||
### ` + "`" + `nginx-template.sh` + "`" + `
|
||||
|
||||
` + "`" + `nginx-template.sh` + "`" + ` is a simple bash script which uses a _heredoc_ as a templating solution
|
||||
for generating Resources from the functionConfig input fields.
|
||||
|
||||
The script wraps itself using ` + "`" + `config run wrap -- $0` + "`" + ` which will:
|
||||
|
||||
1. Parse the ` + "`" + `ResourceList.functionConfig` + "`" + ` (provided to the container stdin) into env vars
|
||||
2. Merge the stdout into the original list of Resources
|
||||
3. Defaults filenames for newly generated Resources (if they are not set as annotations)
|
||||
to ` + "`" + `config/NAME_KIND.yaml` + "`" + `
|
||||
4. Format the output
|
||||
|
||||
#!/bin/bash
|
||||
# script must run wrapped by "kustomize config run wrap"
|
||||
# for parsing input the functionConfig into env vars
|
||||
if [ -z ${WRAPPED} ]; then
|
||||
export WRAPPED=true
|
||||
config run wrap -- $0
|
||||
exit $?
|
||||
fi
|
||||
|
||||
cat <<End-of-message
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: ${NAME}
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
replicas: ${REPLICAS}
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: ${NAME}
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
End-of-message
|
||||
|
||||
### Dockerfile
|
||||
|
||||
` + "`" + `Dockerfile` + "`" + ` installs ` + "`" + `kustomize config` + "`" + ` and copies the script into the container image.
|
||||
|
||||
FROM golang:1.13-stretch
|
||||
RUN go get sigs.k8s.io/kustomize/cmd/config
|
||||
RUN mv /go/bin/config /usr/bin/config
|
||||
COPY nginx-template.sh /usr/bin/nginx-template.sh
|
||||
CMD ["nginx-template.sh]
|
||||
|
||||
## Example Function Usage
|
||||
|
||||
Following is an example of running the ` + "`" + `kustomize config run` + "`" + ` using the preceding API.
|
||||
|
||||
When run by ` + "`" + `kustomize config run` + "`" + `, functions are run in containers with the
|
||||
following environment:
|
||||
|
||||
- Network: ` + "`" + `none` + "`" + `
|
||||
- User: ` + "`" + `nobody` + "`" + `
|
||||
- Security Options: ` + "`" + `no-new-privileges` + "`" + `
|
||||
- Volumes: the volume containing the ` + "`" + `functionConfig` + "`" + ` yaml is mounted under ` + "`" + `/local` + "`" + ` as ` + "`" + `ro` + "`" + `
|
||||
|
||||
### Input
|
||||
|
||||
` + "`" + `dir/nginx.yaml` + "`" + ` contains a reference to the Function. The contents of ` + "`" + `nginx.yaml` + "`" + `
|
||||
are passed to the Function through the ` + "`" + `ResourceList.functionConfig` + "`" + ` field.
|
||||
|
||||
apiVersion: example.com/v1beta1
|
||||
kind: Nginx
|
||||
metadata:
|
||||
name: my-instance
|
||||
annotations:
|
||||
config.kubernetes.io/local-config: "true"
|
||||
config.k8s.io/function: |
|
||||
container:
|
||||
image: gcr.io/example-functions/nginx-template:v1.0.0
|
||||
spec:
|
||||
replicas: 5
|
||||
|
||||
- ` + "`" + `annotations[config.k8s.io/function].container.image` + "`" + `: the image to use for this API
|
||||
- ` + "`" + `annotations[config.kubernetes.io/local-config]` + "`" + `: mark this as not a Resource that should
|
||||
be applied
|
||||
|
||||
### Output
|
||||
|
||||
The function is invoked using by runing ` + "`" + `kustomize config run dir/` + "`" + `.
|
||||
|
||||
` + "`" + `dir/my-instance_deployment.yaml` + "`" + ` contains the Deployment:
|
||||
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
replicas: 5
|
||||
selector:
|
||||
matchLabels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
template:
|
||||
metadata:
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
containers:
|
||||
- name: nginx
|
||||
image: nginx:1.7.9
|
||||
ports:
|
||||
- containerPort: 80
|
||||
|
||||
` + "`" + `dir/my-instance_service.yaml` + "`" + ` contains the Service:
|
||||
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: my-instance
|
||||
labels:
|
||||
app: nginx
|
||||
instance: my-instance
|
||||
spec:
|
||||
ports:
|
||||
- port: 80
|
||||
targetPort: 80
|
||||
name: http
|
||||
selector:
|
||||
app: nginx
|
||||
instance: my-instance`
|
||||
|
||||
var FunctionsSpecShort = `_Configuration functions_ enable shift-left practices (client-side) through:`
|
||||
var FunctionsSpecLong = `# Configuration Functions Specification
|
||||
|
||||
This document specifies a standard for client-side functions that operate on
|
||||
Kubernetes declarative configurations. This standard enables creating
|
||||
small, interoperable, and language-independent executable programs packaged as
|
||||
containers that can be chained together as part of a configuration management pipeline.
|
||||
The end result of such a pipeline are fully rendered configurations that can then be
|
||||
applied to a control plane (e.g. Using ‘kubectl apply’ for Kubernetes control plane).
|
||||
As such, although this document references Kubernetes Resource Model and API conventions,
|
||||
it is completely decoupled from Kuberentes API machinery and does not depend on any
|
||||
in-cluster components.
|
||||
|
||||
This document references terms described in [Kubernetes API Conventions][1].
|
||||
|
||||
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD",
|
||||
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be
|
||||
interpreted as described in [RFC 2119][2].
|
||||
|
||||
|
||||
- Pre-commit / delivery validation and linting of configuration
|
||||
- e.g. Fail if any containers don't have PodSecurityPolicy or CPU / Memory limits
|
||||
- Implementation of abstractions as client actuated APIs (e.g. templating)
|
||||
- e.g. Create a client-side _"CRD"_ for generating configuration checked into git
|
||||
- Aspect Orient configuration / Injection of cross-cutting configuration
|
||||
- e.g. T-Shirt size containers by annotating Resources with ` + "`" + `small` + "`" + `, ` + "`" + `medium` + "`" + `, ` + "`" + `large` + "`" + `
|
||||
and inject the cpu and memory resources into containers accordingly.
|
||||
- e.g. Inject ` + "`" + `init` + "`" + ` and ` + "`" + `side-car` + "`" + ` containers into Resources based off of Resource
|
||||
Type, annotations, etc.
|
||||
|
||||
Performing these on the client rather than the server enables:
|
||||
|
||||
- Configuration to be reviewed prior to being sent to the API server
|
||||
- Configuration to be validated as part of the CI?CD pipeline
|
||||
- Configuration for Resources to validated holistically rather than individually
|
||||
per-Resource
|
||||
- e.g. ensure the ` + "`" + `Service.selector` + "`" + ` and ` + "`" + `Deployment.spec.template` + "`" + ` labels
|
||||
match.
|
||||
- e.g. MutatingWebHooks are scoped to a single Resource instance at a time.
|
||||
- Low-level tweaks to the output of high-level abstractions
|
||||
- e.g. add an ` + "`" + `init container` + "`" + ` to a client _"CRD"_ Resource after it was generated.
|
||||
- Composition and layering of multiple functions together
|
||||
- Compose generation, injection, validation together
|
||||
|
||||
## Spec
|
||||
|
||||
### Input Type
|
||||
|
||||
A function MUST accept as input a single [Kubernetes List type][3].
|
||||
The ` + "`" + `items` + "`" + ` field in the input will contain a sequence of [Object types][3].
|
||||
A function MAY not support [Simple types][3] and List types.
|
||||
|
||||
An example using ` + "`" + `v1/ConfigMapList` + "`" + ` as input:
|
||||
|
||||
apiVersion: v1
|
||||
kind: ConfigMapList
|
||||
items:
|
||||
- apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config1
|
||||
data:
|
||||
p1: v1
|
||||
p2: v2
|
||||
- apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: config2
|
||||
|
||||
An example using ` + "`" + `v1/List` + "`" + ` as input:
|
||||
|
||||
apiVersion: v1
|
||||
kind: List
|
||||
items:
|
||||
spec:
|
||||
- apiVersion: foo-corp.com/v1
|
||||
kind: FulfillmentCenter
|
||||
metadata:
|
||||
name: staging
|
||||
address: "100 Main St."
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- resources:
|
||||
- namespaces
|
||||
apiGroups:
|
||||
- ""
|
||||
verbs:
|
||||
- get
|
||||
- watch
|
||||
- list
|
||||
|
||||
In addition, a function MUST accept as input a List of kind ` + "`" + `ResourceList` + "`" + ` where the
|
||||
` + "`" + `functionConfig` + "`" + ` field, if present, will contain the invocation-specific configuration passed to the function
|
||||
by the orchestrator.
|
||||
Functions MAY consider this field optional so that they can be triggered in an ad-hoc fashion.
|
||||
|
||||
An example using ` + "`" + `config.kubernetes.io/v1beta1/ResourceList` + "`" + ` as input:
|
||||
|
||||
apiVersion: config.kubernetes.io/v1beta1
|
||||
kind: ResourceList
|
||||
functionConfig:
|
||||
apiVersion: foo-corp.com/v1
|
||||
kind: FulfillmentCenter
|
||||
metadata:
|
||||
name: staging
|
||||
metadata:
|
||||
annotations:
|
||||
config.k8s.io/function: |
|
||||
container:
|
||||
image: gcr.io/example/foo:v1.0.0
|
||||
spec:
|
||||
address: "100 Main St."
|
||||
items:
|
||||
- apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: namespace-reader
|
||||
rules:
|
||||
- resources:
|
||||
- namespaces
|
||||
apiGroups:
|
||||
- ""
|
||||
verbs:
|
||||
- get
|
||||
- watch
|
||||
- list
|
||||
|
||||
Here ` + "`" + `FulfillmentCenter` + "`" + ` kind with name ` + "`" + `staging` + "`" + ` is passed as the invocation-specific configuration
|
||||
to the function.
|
||||
|
||||
### Output Type
|
||||
|
||||
A function’s output MUST be the same as the input specification above
|
||||
-- i.e. ` + "`" + `ResourceList` + "`" + ` or ` + "`" + `List` + "`" + `.
|
||||
This is necessary to enable chaining two or more functions together in a pipeline.
|
||||
The serialization format of the output SHOULD match that of its input on each invocation
|
||||
-- e.g. if the input was a ` + "`" + `ResourceList` + "`" + `, the output should also be a ` + "`" + `ResourceList` + "`" + `.
|
||||
|
||||
### Serialization Format
|
||||
|
||||
A function MUST support YAML as a serialization format for the input and output.
|
||||
A function MUST use utf8 encoding (as YAML is a superset of JSON, JSON will also be supported
|
||||
by any conforming function).
|
||||
|
||||
### Operations
|
||||
|
||||
A function MAY Create, Update, or Delete any number of items in the ` + "`" + `items` + "`" + ` field and output the
|
||||
resultant list.
|
||||
|
||||
A function MAY modify annotations with prefix ` + "`" + `config.kubernetes.io` + "`" + `, but must be careful about
|
||||
doing so since they’re used for orchestration purposes and will likely impact subsequent functions
|
||||
in the pipeline.
|
||||
|
||||
A function SHOULD preserve comments when input serialization format is YAML.
|
||||
This allows for human authoring of configuration to coexist with changes made by functions.
|
||||
|
||||
### Containerization
|
||||
|
||||
A function MUST be implemented as a container.
|
||||
|
||||
A function container MUST be capable of running as a non-root user if it does not require
|
||||
access to host filesystem or makes network calls.
|
||||
|
||||
### stdin/stdout/stderr and Exit Codes
|
||||
|
||||
A function MUST accept input from stdin and emit output to stdout.
|
||||
|
||||
Any error messages MUST be emitted to stderr.
|
||||
|
||||
An exit code of zero indicates function execution was successful.
|
||||
A non-zero exit code indicates a failure.
|
||||
|
||||
[1]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md
|
||||
[2]: https://tools.ietf.org/html/rfc2119
|
||||
[3]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds`
|
||||
|
||||
var Merge2Long = `# Merge (2-way)
|
||||
|
||||
2-way merges fields from a source to a destination, overriding the destination fields
|
||||
|
||||
@@ -49,6 +49,32 @@ var CountExamples = `
|
||||
# print Resource counts from a directory
|
||||
kustomize config count my-dir/`
|
||||
|
||||
var CreateSetterShort = `[Alpha] Create a custom setter for a Resource field`
|
||||
var CreateSetterLong = `
|
||||
Create a custom setter for a Resource field by inlining OpenAPI as comments.
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
The name of the setter to create.
|
||||
|
||||
VALUE
|
||||
|
||||
The current value of the field, or a substring within the field.
|
||||
`
|
||||
var CreateSetterExamples = `
|
||||
# create a setter for port fields matching "8080"
|
||||
kustomize config create-setter DIR/ port 8080 --type "integer" --field port \
|
||||
--description "default port used by the app"
|
||||
|
||||
# create a setter for a substring of a field rather than the full field -- e.g. only the
|
||||
# image tag, not the full image
|
||||
kustomize config create-setter DIR/ image-tag v1.0.1 --type "string" \
|
||||
--field image --description "current stable release"`
|
||||
|
||||
var FmtShort = `[Alpha] Format yaml configuration files.`
|
||||
var FmtLong = `
|
||||
[Alpha] Format yaml configuration files.
|
||||
@@ -116,6 +142,25 @@ var GrepExamples = `
|
||||
# look for Resources matching a specific container image
|
||||
kustomize config grep "spec.template.spec.containers[name=nginx].image=nginx:1\.7\.9" my-dir/ | kustomize config tree`
|
||||
|
||||
var ListSettersShort = `[Alpha] List setters for Resources.`
|
||||
var ListSettersLong = `
|
||||
List setters for Resources.
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
Optional. The name of the setter to display.
|
||||
`
|
||||
var ListSettersExamples = `
|
||||
Show setters:
|
||||
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix '' PREFIX string 2`
|
||||
|
||||
var MergeShort = `[Alpha] Merge Resource configuration files`
|
||||
var MergeLong = `
|
||||
[Alpha] Merge Resource configuration files
|
||||
@@ -136,6 +181,25 @@ For information on merge rules, run:
|
||||
var MergeExamples = `
|
||||
cat resources_and_patches.yaml | kustomize config merge > merged_resources.yaml`
|
||||
|
||||
var Merge3Short = `[Alpha] Merge diff of Resource configuration files into a destination (3-way)`
|
||||
var Merge3Long = `
|
||||
[Alpha] Merge diff of Resource configuration files into a destination (3-way)
|
||||
|
||||
Merge3 performs a 3-way merge by applying the diff between 2 sets of Resources to a 3rd set.
|
||||
|
||||
Merge3 may be for rebasing changes to a forked set of configuration -- e.g. compute the difference between the original
|
||||
set of Resources that was forked and an updated set of those Resources, then apply that difference to the fork.
|
||||
|
||||
If a field value differs between the ORIGINAL_DIR and UPDATED_DIR, the value from the UPDATED_DIR is taken and applied
|
||||
to the Resource in the DEST_DIR.
|
||||
|
||||
For information on merge rules, run:
|
||||
|
||||
kustomize config docs-merge3
|
||||
`
|
||||
var Merge3Examples = `
|
||||
kustomize config merge3 --ancestor a/ --from b/ --to c/`
|
||||
|
||||
var RunFnsShort = `[Alpha] Reoncile config functions to Resources.`
|
||||
var RunFnsLong = `
|
||||
[Alpha] Reconcile config functions to Resources.
|
||||
@@ -156,8 +220,8 @@ order they appear in the file).
|
||||
|
||||
#### Config Functions:
|
||||
|
||||
Config functions are specified as Kubernetes types containing a metadata.configFn.container.image
|
||||
field. This field tells run how to invoke the container.
|
||||
Config functions are specified as Kubernetes types containing a metadata.annotations.[config.kubernetes.io/function]
|
||||
field specifying an image for the container to run. This image tells run how to invoke the container.
|
||||
|
||||
Example config function:
|
||||
|
||||
@@ -165,17 +229,17 @@ order they appear in the file).
|
||||
apiVersion: fn.example.com/v1beta1
|
||||
kind: ExampleFunctionKind
|
||||
metadata:
|
||||
configFn:
|
||||
container:
|
||||
# function is invoked as a container running this image
|
||||
image: gcr.io/example/examplefunction:v1.0.1
|
||||
annotations:
|
||||
config.kubernetes.io/function: |
|
||||
container:
|
||||
# function is invoked as a container running this image
|
||||
image: gcr.io/example/examplefunction:v1.0.1
|
||||
config.kubernetes.io/local-config: "true" # tools should ignore this
|
||||
spec:
|
||||
configField: configValue
|
||||
|
||||
In the preceding example, 'kustomize config run example/' would identify the function by
|
||||
the metadata.configFn field. It would then write all Resources in the directory to
|
||||
the metadata.annotations.[config.kubernetes.io/function] field. It would then write all Resources in the directory to
|
||||
a container stdin (running the gcr.io/example/examplefunction:v1.0.1 image). It
|
||||
would then write the container stdout back to example/, replacing the directory
|
||||
file contents.
|
||||
@@ -185,17 +249,18 @@ order they appear in the file).
|
||||
var RunFnsExamples = `
|
||||
kustomize config run example/`
|
||||
|
||||
var SubShort = `[Alpha] Set values on Resources fields by substituting values.`
|
||||
var SubLong = `
|
||||
Set values on Resources fields by substituting predefined markers for new values.
|
||||
var SetShort = `[Alpha] Set values on Resources fields values.`
|
||||
var SetLong = `
|
||||
Set values on Resources fields. May set either the complete or partial field value.
|
||||
|
||||
` + "`" + `set` + "`" + ` looks for markers specified on Resource fields and substitute a new user defined
|
||||
value for the existing value.
|
||||
` + "`" + `set` + "`" + ` identifies setters using field metadata published as OpenAPI extensions.
|
||||
` + "`" + `set` + "`" + ` parses both the Kubernetes OpenAPI, as well OpenAPI published inline in
|
||||
the configuration as comments.
|
||||
|
||||
` + "`" + `set` + "`" + ` maybe be used to:
|
||||
|
||||
- edit configuration programmatically from the cli or scripts
|
||||
- create reusable bundles of configuration
|
||||
- edit configuration programmatically from the cli
|
||||
- create reusable bundles of configuration with custom setters
|
||||
|
||||
DIR
|
||||
|
||||
@@ -203,244 +268,100 @@ value for the existing value.
|
||||
|
||||
NAME
|
||||
|
||||
Optional. The name of the substitution to perform or display.
|
||||
Optional. The name of the setter to perform or display.
|
||||
|
||||
VALUE
|
||||
|
||||
Optional. The new value to substitute into the field.
|
||||
Optional. The value to set on the field.
|
||||
|
||||
|
||||
To print the possible substitutions for the Resources in a directory, run ` + "`" + `set` + "`" + ` on
|
||||
To print the possible setters for the Resources in a directory, run ` + "`" + `set` + "`" + ` on
|
||||
a directory -- e.g. ` + "`" + `kustomize config set DIR/` + "`" + `.
|
||||
|
||||
#### Tips
|
||||
|
||||
- A description of the value may be specified with ` + "`" + `--description` + "`" + `.
|
||||
- An owner for the field's value may be defined with ` + "`" + `--owned-by` + "`" + `.
|
||||
- Prevent overriding previous substitutions with ` + "`" + `--override=false` + "`" + `.
|
||||
- Revert previous substitutions with ` + "`" + `--revert` + "`" + `.
|
||||
- Create substitutions on Kustomization.yaml's, patches, etc
|
||||
- The last setter for the field's value may be defined with ` + "`" + `--set-by` + "`" + `.
|
||||
- Create custom setters on Resources, Kustomization.yaml's, patches, etc
|
||||
|
||||
When overriding or reverting previous substitutions, the description and owner are left
|
||||
unmodified unless specified with flags.
|
||||
The description and setBy fields are left unmodified unless specified with flags.
|
||||
|
||||
To create a substitution for a field see: ` + "`" + `kustomize help config set create` + "`" + `
|
||||
To create a custom setter for a field see: ` + "`" + `kustomize help config create-setter` + "`" + `
|
||||
`
|
||||
var SubExamples = `
|
||||
Resource YAML: Name substitution
|
||||
var SetExamples = `
|
||||
Resource YAML: Name Prefix Setter
|
||||
|
||||
# dir/resources.yaml
|
||||
# DIR/resources.yaml
|
||||
...
|
||||
metadata:
|
||||
name: PREFIX-app1 # {"substitutions":[{"name":"prefix","marker":"PREFIX-"}]}
|
||||
name: PREFIX-app1 # {"type":"string","x-kustomize":{"partialFieldSetters":[{"name":"name-prefix","value":"PREFIX"}]}}
|
||||
...
|
||||
---
|
||||
...
|
||||
metadata:
|
||||
name: PREFIX-app2 # {"substitutions":[{"name":"prefix","marker":"PREFIX-"}]}
|
||||
name: PREFIX-app2 # {"type":"string","x-kustomize":{"partialFieldSetters":[{"name":"name-prefix","value":"PREFIX"}]}}
|
||||
...
|
||||
|
||||
Show substitutions: Show the possible substitutions
|
||||
List setters: Show the possible setters
|
||||
|
||||
$ config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix '' PREFIX- string 2 false
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix '' PREFIX string 2
|
||||
|
||||
Perform substitution: set a new value, owner and description
|
||||
Perform set: set a new value, owner and description
|
||||
|
||||
$ config set dir prefix "test-" --description "test environment" --owned-by "dev"
|
||||
performed 2 substitutions
|
||||
$ kustomize config set DIR/ name-prefix "test" --description "test environment" --set-by "dev"
|
||||
set 2 values
|
||||
|
||||
Show substitutions: Show the new values
|
||||
List setters: Show the new values
|
||||
|
||||
$ config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix 'test environment' test- string 2 true dev
|
||||
$ config set DIR/
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SETBY
|
||||
name-prefix 'test environment' test string 2 dev
|
||||
|
||||
New Resource YAML:
|
||||
|
||||
# dir/resources.yaml
|
||||
# DIR/resources.yaml
|
||||
...
|
||||
metadata:
|
||||
name: test-app1 # {"substitutions":[{"name":"prefix","marker":"PREFIX-","value":"test-"}],"ownedBy":"dev","description":"test environment"}
|
||||
name: test-app1 # {"description":"test environment","type":"string","x-kustomize":{"setBy":"dev","partialFieldSetters":[{"name":"name-prefix","value":"test"}]}}
|
||||
...
|
||||
---
|
||||
...
|
||||
metadata:
|
||||
name: test-app2 # {"substitutions":[{"name":"prefix","marker":"PREFIX-","value":"test-"}],"ownedBy":"dev","description":"test environment"}
|
||||
...
|
||||
name: test-app2 # {"description":"test environment","type":"string","x-kustomize":{"setBy":"dev","partialFieldSetters":[{"name":"name-prefix","value":"test"}]}}
|
||||
...`
|
||||
|
||||
Revert substitution:
|
||||
var SinkShort = `[Alpha] Implement a Sink by writing input to a local directory.`
|
||||
var SinkLong = `
|
||||
[Alpha] Implement a Sink by writing input to a local directory.
|
||||
|
||||
config set dir prefix --revert
|
||||
performed 2 substitutions
|
||||
kustomize config sink DIR
|
||||
|
||||
config set dir
|
||||
NAME DESCRIPTION VALUE TYPE COUNT SUBSTITUTED OWNER
|
||||
prefix 'test environment' PREFIX- string 2 false dev `
|
||||
DIR:
|
||||
Path to local directory.
|
||||
|
||||
var SubsetShort = `[Alpha] Create a new substitution for a Resource field`
|
||||
var SubsetLong = `
|
||||
Create a new substitution for a Resource field -- recognized by ` + "`" + `kustomize config set` + "`" + `.
|
||||
|
||||
DIR
|
||||
|
||||
A directory containing Resource configuration.
|
||||
|
||||
NAME
|
||||
|
||||
The name of the substitution to create.
|
||||
|
||||
VALUE
|
||||
|
||||
The current value of the field, or a substring of the field.
|
||||
|
||||
#### Tips: Picking Good Marker
|
||||
|
||||
Substitutions may be defined by directly editing yaml **or** by running ` + "`" + `kustomize config set create` + "`" + `
|
||||
to create a new substitution.
|
||||
|
||||
Given the YAML:
|
||||
|
||||
# resource.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
...
|
||||
spec:
|
||||
...
|
||||
ports:
|
||||
...
|
||||
- name: http
|
||||
port: 8080
|
||||
...
|
||||
|
||||
Create a new set marker:
|
||||
|
||||
# create a substitution for ports
|
||||
$ kustomize config set create dir/ http-port 8080 --type "int" --field "port"
|
||||
|
||||
Modified YAML:
|
||||
|
||||
# resource.yaml
|
||||
apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
...
|
||||
spec:
|
||||
...
|
||||
ports:
|
||||
...
|
||||
- name: http
|
||||
port: 8080 # {"substitutions":[{"name":"port","marker":"[MARKER]"}],"type":"int"}
|
||||
...
|
||||
|
||||
Change the value using the ` + "`" + `set` + "`" + ` command:
|
||||
|
||||
# change the http-port value to 8081
|
||||
$ kustomize config set dir/ http-port 8081
|
||||
|
||||
Resources fields with a field name matching ` + "`" + `--field` + "`" + ` and field value matching ` + "`" + `VALUE` + "`" + ` will
|
||||
have a line comment added marking this field as settable.
|
||||
|
||||
Substitution markers may be:
|
||||
|
||||
- valid field values (e.g. ` + "`" + `8080` + "`" + ` for a port)
|
||||
- Note: ` + "`" + `008080` + "`" + ` would be preferred because it is more recognizable as a marker
|
||||
- invalid values that adhere to the schema (e.g. ` + "`" + `0000` + "`" + ` for a port)
|
||||
- values that do not adhere to the schema (e.g. ` + "`" + `[PORT]` + "`" + ` for port)
|
||||
|
||||
Markers **SHOULD be clearly identifiable as a marker and either**:
|
||||
|
||||
- **adhere to the field schema** -- e.g. use a valid value
|
||||
|
||||
|
||||
port: 008080 # {"substitutions":[{"name":"port","marker":"008080"}],"type":"int"}
|
||||
|
||||
- **be pre-filled in with a value** -- e.g. set the value when setting the marker
|
||||
|
||||
|
||||
port: 8080 # {"substitutions":[{"name":"port","marker":"[MARKER]","value":"8080""}],"type":"int"}
|
||||
|
||||
**Note:** The important thing is that in both cases the Resource configuration may be directly
|
||||
applied to a cluster and validated by tools without the tool knowing about the substitution
|
||||
marker.
|
||||
|
||||
The difference between the preceding examples is that:
|
||||
|
||||
- the former will be shown as ` + "`" + `SUBSTITUTED=false` + "`" + ` (` + "`" + `config sub dir/` + "`" + ` exits non-0)
|
||||
- the latter with show up as ` + "`" + `SUBSTITUTED=true` + "`" + ` (` + "`" + `config sub dir/` + "`" + ` exits 0)
|
||||
|
||||
When choosing the which to use, consider that checks for unsubstituted values MAY be
|
||||
configured as pre-commit checks -- if you want to these checks to fail if the value
|
||||
hasn't been substituted, then don't specify a ` + "`" + `value` + "`" + `.
|
||||
|
||||
Markers which are invalid field values MAY be chosen in cases where it is preferred to have
|
||||
the create or update request fail rather than succeed if the substitution has not yet been
|
||||
performed.
|
||||
|
||||
A substitution may be a substring of the full field:
|
||||
|
||||
$ kustomize config set create dir/ app-image-tag v1.0.01 --type "string" --field "image"
|
||||
|
||||
image: gcr.io/example/app:v1.0.1 # {"substitutions":[{"name":"app-image-tag","marker":"[MARKER]","value":"v1.0.1"}]}
|
||||
|
||||
|
||||
A single field value may have multiple substitutions applied to it:
|
||||
|
||||
name: PREFIX-app-SUFFIX # {"substitutions":[{"name":"prefix","marker":"PREFIX-"},{"name":"suffix","marker":"-SUFFIX"}]}
|
||||
|
||||
#### Substitution Format
|
||||
|
||||
Substitutions are defined as json encoded FieldMeta comments on fields.
|
||||
|
||||
FieldMeta Schema read by ` + "`" + `sub` + "`" + `:
|
||||
|
||||
{
|
||||
"title": "FieldMeta",
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"substitutions": {
|
||||
"type": "array",
|
||||
"description": "Possible substitutions that may be performed against this field.",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"name": "Name of the substitution.",
|
||||
"marker": "Marker for the value to be substituted.",
|
||||
"value": "Current substituted value"
|
||||
}
|
||||
}
|
||||
},
|
||||
"type": {
|
||||
"type": "string",
|
||||
"description": "The value type. Defaults to string."
|
||||
"enum": ["string", "int", "float", "bool"]
|
||||
},
|
||||
"description": {
|
||||
"type": "string",
|
||||
"description": "A description of the field's current value. Optional."
|
||||
},
|
||||
"ownedBy": {
|
||||
"type": "string",
|
||||
"description": "The current owner of the field. Optional."
|
||||
},
|
||||
}
|
||||
}
|
||||
` + "`" + `sink` + "`" + ` writes its input to a directory
|
||||
`
|
||||
var SubsetExamples = `
|
||||
# set a substitution for port fields matching "8080"
|
||||
kustomize config sub create dir/ port 8080 --type "int" --field port \
|
||||
--description "default port used by the app"
|
||||
var SinkExamples = `
|
||||
kustomize config source DIR/ | your-function | kustomize config sink DIR/`
|
||||
|
||||
# set a substitution for port fields matching "8080", using "0000" as a marker.
|
||||
kustomize config sub dir/ port 8080 --marker "0000" --type "int" \
|
||||
--field port --description "default port used by the app"
|
||||
var SourceShort = `[Alpha] Implement a Source by reading a local directory.`
|
||||
var SourceLong = `
|
||||
[Alpha] Implement a Source by reading a local directory.
|
||||
|
||||
# substitute a substring of a field rather than the full field -- e.g. only the
|
||||
# image tag, not the full image
|
||||
kustomize config sub dir/ app-image-tag v1.0.1 --type "string" --substring \
|
||||
--field port --description "current stable release"`
|
||||
kustomize config source DIR
|
||||
|
||||
DIR:
|
||||
Path to local directory.
|
||||
|
||||
` + "`" + `source` + "`" + ` emits configuration to act as input to a function
|
||||
`
|
||||
var SourceExamples = `
|
||||
# emity configuration directory as input source to a function
|
||||
kustomize config source DIR/
|
||||
|
||||
kustomize config source DIR/ | your-function | kustomize config sink DIR/`
|
||||
|
||||
var TreeShort = `[Alpha] Display Resource structure from a directory or stdin.`
|
||||
var TreeLong = `
|
||||
@@ -460,8 +381,9 @@ container names, etc.
|
||||
|
||||
kustomize config tree supports printing arbitrary fields using the '--field' flag.
|
||||
|
||||
By default, kustomize config tree uses the directory structure for the tree structure, however when printing
|
||||
from the cluster, the Resource graph structure may be used instead.
|
||||
By default, kustomize config tree uses Resource graph structure if any relationships between resources (ownerReferences)
|
||||
are detected, as is typically the case when printing from a cluster. Otherwise, directory graph structure is used. The
|
||||
graph structure can also be selected explicitly using the '--graph-structure' flag.
|
||||
`
|
||||
var TreeExamples = `
|
||||
# print Resources using directory structure
|
||||
@@ -481,8 +403,7 @@ var TreeExamples = `
|
||||
--field="status.conditions[type=Completed].status"
|
||||
|
||||
# print live Resources from a cluster using owners for graph structure
|
||||
kubectl get all -o yaml | kustomize config tree --replicas --name --image \
|
||||
--graph-structure=owners
|
||||
kubectl get all -o yaml | kustomize config tree --replicas --name --image
|
||||
|
||||
# print live Resources with status condition fields
|
||||
kubectl get all -o yaml | kustomize config tree \
|
||||
|
||||
@@ -316,7 +316,7 @@ var FunctionBasicsLong = `
|
||||
#### 2. Modify the Generated Resources
|
||||
|
||||
- modify the generated Resources by adding an annotation, sidecar container, etc.
|
||||
- modify the ` + "`" + `local-resources/example-use.yaml` + "`" + ` by changing the replicas
|
||||
- modify the ` + "`" + `local-resource/example-use.yaml` + "`" + ` by changing the replicas
|
||||
|
||||
re-run ` + "`" + `run` + "`" + `. this will apply the updated replicas to the generated Resources,
|
||||
but keep the fields that you manually added to the generated Resource configuration.
|
||||
@@ -363,7 +363,7 @@ var FunctionBasicsLong = `
|
||||
#### 2. Modify the Generated Resources
|
||||
|
||||
- modify the generated Resources by adding an annotation, sidecar container, etc.
|
||||
- modify the ` + "`" + `local-resources/example-use.yaml` + "`" + ` by changing the replicas
|
||||
- modify the ` + "`" + `local-resource/example-use.yaml` + "`" + ` by changing the replicas
|
||||
|
||||
re-run ` + "`" + `run` + "`" + `. this will apply the updated replicas to the generated Resources,
|
||||
but keep the fields that you manually added to the generated Resource configuration.
|
||||
|
||||
@@ -1,105 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
var _ yaml.Filter = &Marker{}
|
||||
|
||||
// substituteResource substitutes a Marker value on a field
|
||||
type Marker struct {
|
||||
// Path is the path of the field to add the substitution for
|
||||
Field string
|
||||
|
||||
// Substitution is the substitution to add
|
||||
Substitution fieldmeta.Substitution
|
||||
|
||||
// PartialMatch if true will match if the Substitution value is a substring of the current
|
||||
// value.
|
||||
PartialMatch bool
|
||||
|
||||
Description string
|
||||
OwnedBy string
|
||||
Type string
|
||||
|
||||
// currentFieldName is the name of the current field being processed
|
||||
currentFieldName string
|
||||
}
|
||||
|
||||
// Filter performs the substitutions for a single object
|
||||
func (m *Marker) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
||||
switch object.YNode().Kind {
|
||||
case yaml.DocumentNode:
|
||||
return m.Filter(yaml.NewRNode(object.YNode().Content[0]))
|
||||
case yaml.MappingNode:
|
||||
return object, object.VisitFields(func(node *yaml.MapNode) error {
|
||||
// set the current field name
|
||||
n := m.currentFieldName
|
||||
defer func() { m.currentFieldName = n }()
|
||||
m.currentFieldName = node.Key.YNode().Value
|
||||
_, err := m.Filter(node.Value)
|
||||
return err
|
||||
})
|
||||
case yaml.SequenceNode:
|
||||
return object, object.VisitElements(func(node *yaml.RNode) error {
|
||||
_, err := m.Filter(node)
|
||||
return err
|
||||
})
|
||||
case yaml.ScalarNode:
|
||||
if m.currentFieldName != m.Field {
|
||||
return object, nil
|
||||
}
|
||||
if err := m.createSub(object); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return object, nil
|
||||
default:
|
||||
return object, nil
|
||||
}
|
||||
}
|
||||
|
||||
func (as *Marker) createSub(field *yaml.RNode) error {
|
||||
// doesn't match the supplied value
|
||||
if field.YNode().Value != as.Substitution.Value {
|
||||
if !as.PartialMatch || !strings.Contains(field.YNode().Value, as.Substitution.Value) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
fm := fieldmeta.FieldMeta{}
|
||||
if err := fm.Read(field); err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
fm.OwnedBy = as.OwnedBy
|
||||
fm.Description = as.Description
|
||||
fm.Type = fieldmeta.FieldValueType(as.Type)
|
||||
if as.Substitution.Marker == "" {
|
||||
as.Substitution.Marker = "[MARKER]"
|
||||
}
|
||||
|
||||
found := false
|
||||
for i := range fm.Substitutions {
|
||||
s := fm.Substitutions[i]
|
||||
if s.Name == as.Substitution.Name {
|
||||
// update the substitution if we find it
|
||||
found = true
|
||||
fm.Substitutions[i] = as.Substitution
|
||||
break
|
||||
}
|
||||
}
|
||||
if !found {
|
||||
// add the substitution if it wasn't found
|
||||
fm.Substitutions = append(fm.Substitutions, as.Substitution)
|
||||
}
|
||||
if err := fm.Write(field); err != nil {
|
||||
return errors.Wrap(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
var _ kio.Filter = &PerformSubstitutions{}
|
||||
|
||||
// Sub performs substitutions
|
||||
type PerformSubstitutions struct {
|
||||
// Name is the name of the substitution to perform
|
||||
Name string
|
||||
|
||||
// NewValue is the substitution value
|
||||
NewValue string
|
||||
|
||||
// Override if set to true will re-substitute already fields with a new value
|
||||
Override bool
|
||||
|
||||
// Revert if set to true will substitute fields back to the marker value
|
||||
Revert bool
|
||||
|
||||
// Description, if set will annotate the field with a description.
|
||||
Description string
|
||||
|
||||
// OwnedBy, if set will annotate the field with an owner.
|
||||
OwnedBy string
|
||||
|
||||
// Count is the number of substitutions performed by Filter.
|
||||
Count int
|
||||
}
|
||||
|
||||
func (s *PerformSubstitutions) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
for i := range input {
|
||||
p := &performSubstitutions{
|
||||
Name: s.Name,
|
||||
Override: s.Override,
|
||||
Revert: s.Revert,
|
||||
NewValue: s.NewValue,
|
||||
OwnedBy: s.OwnedBy,
|
||||
Description: s.Description,
|
||||
}
|
||||
if err := input[i].PipeE(p); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s.Count += p.Count
|
||||
}
|
||||
return input, nil
|
||||
}
|
||||
@@ -1,155 +0,0 @@
|
||||
// Copyright 2019 Google LLC
|
||||
//
|
||||
// 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 sub substitutes strings in fields
|
||||
package sub
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
var _ yaml.Filter = &performSubstitutions{}
|
||||
|
||||
// substituteResource substitutes a Marker value on a field
|
||||
type performSubstitutions struct {
|
||||
// Name of the substitution to perform.
|
||||
Name string
|
||||
|
||||
// Override if set to true will replace previously substituted values
|
||||
Override bool
|
||||
|
||||
// Revert if set to true will undo previously substituted values
|
||||
Revert bool
|
||||
|
||||
// NewValue is the new value to set. Mutually exclusive with Revert.
|
||||
NewValue string
|
||||
|
||||
// Description, if set will annotate the field with a description.
|
||||
Description string
|
||||
|
||||
// OwnedBy, if set will annotate the field with an owner.
|
||||
OwnedBy string
|
||||
|
||||
// Count will be incremented for each substituted value.
|
||||
Count int
|
||||
}
|
||||
|
||||
// Filter performs the substitutions for a single object
|
||||
func (fs *performSubstitutions) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
||||
switch object.YNode().Kind {
|
||||
case yaml.DocumentNode:
|
||||
return fs.Filter(yaml.NewRNode(object.YNode().Content[0]))
|
||||
case yaml.MappingNode:
|
||||
return object, object.VisitFields(func(node *yaml.MapNode) error {
|
||||
_, err := fs.Filter(node.Value)
|
||||
return err
|
||||
})
|
||||
case yaml.SequenceNode:
|
||||
return object, object.VisitElements(func(node *yaml.RNode) error {
|
||||
_, err := fs.Filter(node)
|
||||
return err
|
||||
})
|
||||
case yaml.ScalarNode:
|
||||
s, f, err := fs.findSub(object)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if s == nil {
|
||||
return object, nil
|
||||
}
|
||||
return object, fs.substitute(object, s, f)
|
||||
default:
|
||||
return object, nil
|
||||
}
|
||||
}
|
||||
|
||||
// findSub finds the substitution matching the name if one exists
|
||||
func (fs *performSubstitutions) findSub(field *yaml.RNode) (
|
||||
*fieldmeta.Substitution, *fieldmeta.FieldMeta, error) {
|
||||
// check if there are any substitutions for this field
|
||||
var fm = &fieldmeta.FieldMeta{}
|
||||
if err := fm.Read(field); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
if fs.OwnedBy != "" {
|
||||
fm.OwnedBy = fs.OwnedBy
|
||||
}
|
||||
if fs.Description != "" {
|
||||
fm.Description = fs.Description
|
||||
}
|
||||
|
||||
// check if there is a matching substitution
|
||||
for i := range fm.Substitutions {
|
||||
if fm.Substitutions[i].Name == fs.Name {
|
||||
// validate the value if we are not reverting to the marker.
|
||||
// markers are allowed to be invalid.
|
||||
// only validate if there is a substitution matching the name
|
||||
if !fs.Revert {
|
||||
if err := fm.Type.Validate(fs.NewValue); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
}
|
||||
return &fm.Substitutions[i], fm, nil
|
||||
}
|
||||
}
|
||||
return nil, nil, nil
|
||||
}
|
||||
|
||||
// substitute performs the substitution for the given field, substitution, and metadata
|
||||
func (fs *performSubstitutions) substitute(
|
||||
field *yaml.RNode, s *fieldmeta.Substitution, f *fieldmeta.FieldMeta) error {
|
||||
// undo or override previous substitutions by substituting the marker back
|
||||
// NOTE: check if s.Value != "" so we never try to substitute the empty string back
|
||||
if (fs.Revert || fs.Override) && s.Value != "" {
|
||||
// revert to the marker value
|
||||
if strings.Contains(field.YNode().Value, s.Value) {
|
||||
// revert the substitution
|
||||
field.YNode().Value = strings.ReplaceAll(field.YNode().Value, s.Value, s.Marker)
|
||||
// only use the tag matching the type if the marker parses to that type
|
||||
field.YNode().Tag = f.Type.TagForValue(s.Marker)
|
||||
// record that the config has been modified
|
||||
}
|
||||
}
|
||||
if fs.Revert {
|
||||
fs.Count++
|
||||
s.Value = "" // value has been cleared and replaced with marker
|
||||
if err := f.Write(field); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if s.Value == fs.NewValue || !strings.Contains(field.YNode().Value, s.Marker) {
|
||||
// no substitutions necessary -- already substituted or doesn't have the marker
|
||||
return nil
|
||||
}
|
||||
|
||||
// replace the marker with the new value
|
||||
field.YNode().Value = strings.ReplaceAll(field.YNode().Value, s.Marker, fs.NewValue)
|
||||
// be sure to set the tag so the yaml doesn't incorrectly quote ints, bools or floats
|
||||
field.YNode().Tag = f.Type.Tag()
|
||||
field.YNode().Style = 0
|
||||
// record that the config has been modified
|
||||
fs.Count++
|
||||
|
||||
// update the comment on the field
|
||||
s.Value = fs.NewValue
|
||||
if err := f.Write(field); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
var _ kio.Filter = &LookupSubstitutions{}
|
||||
|
||||
// Sub performs substitutions
|
||||
type LookupSubstitutions struct {
|
||||
// Name is the name of the substitution to match. If unspecified, all substitutions will
|
||||
// be matched.
|
||||
Name string
|
||||
|
||||
// SubstitutionCounts are the aggregate substitutions matched.
|
||||
SubstitutionCounts []FieldSubstitutionCount
|
||||
}
|
||||
|
||||
type FieldSubstitutionCount struct {
|
||||
// Count is the number of substitutions possible to perform
|
||||
Count int
|
||||
|
||||
// CountComplete is the number of substitutions that have already been performed
|
||||
// independent of this object.
|
||||
CountComplete int
|
||||
|
||||
// FieldSubstitution is the substitution found
|
||||
FieldSubstitution
|
||||
}
|
||||
|
||||
func (l *LookupSubstitutions) Filter(input []*yaml.RNode) ([]*yaml.RNode, error) {
|
||||
subs := map[string]*FieldSubstitutionCount{}
|
||||
for i := range input {
|
||||
// lookup substitutions for this object
|
||||
ls := &lookupSubstitutions{Name: l.Name}
|
||||
if err := input[i].PipeE(ls); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// aggregate counts for each substitution
|
||||
for j := range ls.Substitutions {
|
||||
sub := ls.Substitutions[j]
|
||||
curr, found := subs[sub.Name]
|
||||
if !found {
|
||||
curr = &FieldSubstitutionCount{FieldSubstitution: sub}
|
||||
subs[sub.Name] = curr
|
||||
}
|
||||
curr.Count++
|
||||
if sub.CurrentValue != "" {
|
||||
curr.CountComplete++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// pull out and sort the results
|
||||
for _, v := range subs {
|
||||
l.SubstitutionCounts = append(l.SubstitutionCounts, *v)
|
||||
}
|
||||
sort.Slice(l.SubstitutionCounts, func(i, j int) bool {
|
||||
return l.SubstitutionCounts[i].Name < l.SubstitutionCounts[j].Name
|
||||
})
|
||||
return input, nil
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
|
||||
"sigs.k8s.io/kustomize/kyaml/yaml"
|
||||
)
|
||||
|
||||
var _ yaml.Filter = &lookupSubstitutions{}
|
||||
|
||||
// substituteResource substitutes a Marker value on a field
|
||||
type lookupSubstitutions struct {
|
||||
// Name of the substitution to lookup. If unspecified lookup all substitutions.
|
||||
Name string
|
||||
|
||||
// FieldSubstitution is the list of substitutions that were found
|
||||
Substitutions []FieldSubstitution
|
||||
}
|
||||
|
||||
func (ls *lookupSubstitutions) Filter(object *yaml.RNode) (*yaml.RNode, error) {
|
||||
switch object.YNode().Kind {
|
||||
case yaml.DocumentNode:
|
||||
return ls.Filter(yaml.NewRNode(object.YNode().Content[0]))
|
||||
case yaml.MappingNode:
|
||||
return object, object.VisitFields(func(node *yaml.MapNode) error {
|
||||
_, err := ls.Filter(node.Value)
|
||||
return err
|
||||
})
|
||||
case yaml.SequenceNode:
|
||||
return object, object.VisitElements(func(node *yaml.RNode) error {
|
||||
_, err := ls.Filter(node)
|
||||
return err
|
||||
})
|
||||
case yaml.ScalarNode:
|
||||
return object, ls.lookup(object)
|
||||
default:
|
||||
return object, nil
|
||||
}
|
||||
}
|
||||
|
||||
// lookup finds any substitutions for this field
|
||||
func (ls *lookupSubstitutions) lookup(field *yaml.RNode) error {
|
||||
// check if there is a substitution for this field
|
||||
var fm = &fieldmeta.FieldMeta{}
|
||||
if err := fm.Read(field); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for i := range fm.Substitutions {
|
||||
s := fm.Substitutions[i]
|
||||
if ls.Name == "" || ls.Name == s.Name {
|
||||
ls.Substitutions = append(ls.Substitutions, FieldSubstitution{
|
||||
Name: s.Name,
|
||||
CurrentValue: s.Value,
|
||||
Description: fm.Description,
|
||||
Marker: s.Marker,
|
||||
Type: fm.Type,
|
||||
OwnedBy: fm.OwnedBy,
|
||||
})
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sub
|
||||
|
||||
import (
|
||||
"sigs.k8s.io/kustomize/kyaml/fieldmeta"
|
||||
)
|
||||
|
||||
// FieldSubstitution is a possible field substitution read from a field
|
||||
type FieldSubstitution struct {
|
||||
// Name is the name of the substitution
|
||||
Name string
|
||||
|
||||
// Description is a description of the fields current value
|
||||
Description string
|
||||
|
||||
// Value is the current substituted value for the field.
|
||||
CurrentValue string
|
||||
|
||||
// Type is the type of the substitution
|
||||
Type fieldmeta.FieldValueType
|
||||
|
||||
// Marker is the marker used
|
||||
Marker string
|
||||
|
||||
// OwnedBy, if set will annotate the field with an owner.
|
||||
OwnedBy string
|
||||
}
|
||||
@@ -9,6 +9,7 @@ package main
|
||||
import (
|
||||
"os"
|
||||
|
||||
"sigs.k8s.io/kustomize/cmd/config/complete"
|
||||
"sigs.k8s.io/kustomize/cmd/config/configcobra"
|
||||
"sigs.k8s.io/kustomize/kyaml/commandutil"
|
||||
)
|
||||
@@ -16,7 +17,10 @@ import (
|
||||
func main() {
|
||||
// enable the config commands
|
||||
os.Setenv(commandutil.EnableAlphaCommmandsEnvName, "true")
|
||||
if err := configcobra.NewConfigCommand("").Execute(); err != nil {
|
||||
cmd := configcobra.NewConfigCommand("")
|
||||
complete.Complete(cmd).Complete("config")
|
||||
|
||||
if err := cmd.Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,8 +4,11 @@ go 1.13
|
||||
|
||||
require (
|
||||
github.com/spf13/cobra v0.0.5
|
||||
k8s.io/api v0.17.0
|
||||
k8s.io/apimachinery v0.17.0
|
||||
k8s.io/cli-runtime v0.17.0
|
||||
k8s.io/client-go v0.17.0
|
||||
k8s.io/kubectl v0.17.0
|
||||
sigs.k8s.io/kustomize/kyaml v0.0.2
|
||||
k8s.io/component-base v0.17.0 // indirect
|
||||
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd
|
||||
sigs.k8s.io/kustomize/kyaml v0.0.6
|
||||
)
|
||||
|
||||
@@ -85,6 +85,8 @@ github.com/go-openapi/jsonreference v0.19.3/go.mod h1:rjx6GuL8TTa9VaixXglHmQmIL9
|
||||
github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nAiCcj+friV/PDoE1/3eeccG9LYBs0tYvLOWc=
|
||||
github.com/go-openapi/spec v0.19.3 h1:0XRyw8kguri6Yw4SxhsQA/atC88yqrk0+G4YhI2wabc=
|
||||
github.com/go-openapi/spec v0.19.3/go.mod h1:FpwSN1ksY1eteniUU7X0N/BgJ7a4WvBFVA8Lj9mJglo=
|
||||
github.com/go-openapi/spec v0.19.5 h1:Xm0Ao53uqnk9QE/LlYV5DEU09UAgpliA85QoT9LzqPw=
|
||||
github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
|
||||
github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dpr1UfpPtxFw+EFuQ41HhCWZfha5jSVRG7C7I=
|
||||
github.com/go-openapi/swag v0.19.2 h1:jvO6bCMBEilGwMfHhrd61zIID4oIFdwb76V17SM88dE=
|
||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
@@ -211,6 +213,7 @@ github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsT
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
|
||||
github.com/russross/blackfriday v1.5.2 h1:HyvC0ARfnZBqnXwABFeSZHpKvJHJJfPz81GNueLj0oo=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
@@ -329,6 +332,8 @@ gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLks
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7 h1:xOHLXZwVvI9hhs+cLKq5+I5onOuwQLhQwiu63xxlHs4=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/inf.v0 v0.9.1 h1:73M5CoZyi3ZLMOyDlQh031Cx6N9NDJ2Vvfl76EDAgDc=
|
||||
@@ -344,15 +349,22 @@ gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
|
||||
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
k8s.io/api v0.0.0-20191214185829-ca1d04f8b0d3/go.mod h1:itOjKREfmUTvcjantxOsyYU5mbFsU7qUnyUuRfF5+5M=
|
||||
k8s.io/api v0.17.0 h1:H9d/lw+VkZKEVIUc8F3wgiQ+FUXTTr21M87jXLU7yqM=
|
||||
k8s.io/api v0.17.0/go.mod h1:npsyOePkeP0CPwyGfXDHxvypiYMJxBWAMpQxCaJ4ZxI=
|
||||
k8s.io/apimachinery v0.0.0-20191214185652-442f8fb2f03a/go.mod h1:Ng1IY8TS7sC44KJxT/WUR6qFRfWwahYYYpNXyYRKOCY=
|
||||
k8s.io/apimachinery v0.0.0-20191216025728-0ee8b4573e3a/go.mod h1:Ng1IY8TS7sC44KJxT/WUR6qFRfWwahYYYpNXyYRKOCY=
|
||||
k8s.io/apimachinery v0.17.0 h1:xRBnuie9rXcPxUkDizUsGvPf1cnlZCFu210op7J7LJo=
|
||||
k8s.io/apimachinery v0.17.0/go.mod h1:b9qmWdKlLuU9EBh+06BtLcSf/Mu89rWL33naRxs1uZg=
|
||||
k8s.io/cli-runtime v0.0.0-20191214191754-e6dc6d5c8724/go.mod h1:wzlq80lvjgHW9if6MlE4OIGC86MDKsy5jtl9nxz/IYY=
|
||||
k8s.io/cli-runtime v0.17.0 h1:XEuStbJBHCQlEKFyTQmceDKEWOSYHZkcYWKp3SsQ9Hk=
|
||||
k8s.io/cli-runtime v0.17.0/go.mod h1:1E5iQpMODZq2lMWLUJELwRu2MLWIzwvMgDBpn3Y81Qo=
|
||||
k8s.io/client-go v0.0.0-20191214190045-a32a6f7a3052/go.mod h1:tAaoc/sYuIL0+njJefSAmE28CIcxyaFV4kbIujBlY2s=
|
||||
k8s.io/client-go v0.0.0-20191219150334-0b8da7416048/go.mod h1:ZEe8ZASDUAuqVGJ+UN0ka0PfaR+b6a6E1PGsSNZRui8=
|
||||
k8s.io/client-go v0.17.0 h1:8QOGvUGdqDMFrm9sD6IUFl256BcffynGoe80sxgTEDg=
|
||||
k8s.io/client-go v0.17.0/go.mod h1:TYgR6EUHs6k45hb6KWjVD6jFZvJV4gHDikv/It0xz+k=
|
||||
k8s.io/code-generator v0.17.0/go.mod h1:DVmfPQgxQENqDIzVR2ddLXMH34qeszkKSdH/N+s+38s=
|
||||
k8s.io/code-generator v0.0.0-20191214185510-0b9b3c99f9f2/go.mod h1:BjGKcoq1MRUmcssvHiSxodCco1T6nVIt4YeCT5CMSao=
|
||||
k8s.io/component-base v0.0.0-20191214190519-d868452632e2/go.mod h1:wupxkh1T/oUDqyTtcIjiEfpbmIHGm8By/vqpSKC6z8c=
|
||||
k8s.io/component-base v0.17.0 h1:BnDFcmBDq+RPpxXjmuYnZXb59XNN9CaFrX8ba9+3xrA=
|
||||
k8s.io/component-base v0.17.0/go.mod h1:rKuRAokNMY2nn2A6LP/MiwpoaMRHpfRnrPaUJJj1Yoc=
|
||||
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=
|
||||
@@ -363,9 +375,9 @@ k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
|
||||
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a h1:UcxjrRMyNx/i/y8G7kPvLyy7rfbeuf1PYyBf973pgyU=
|
||||
k8s.io/kube-openapi v0.0.0-20191107075043-30be4d16710a/go.mod h1:1TqjTSzOxsLGIKfj0lK8EeCP7K1iUG65v09OM0/WG5E=
|
||||
k8s.io/kubectl v0.17.0 h1:xD4EWlL+epc/JTO1gvSjmV9yiYF0Z2wiHK2DIek6URY=
|
||||
k8s.io/kubectl v0.17.0/go.mod h1:jIPrUAW656Vzn9wZCCe0PC+oTcu56u2HgFD21Xbfk1s=
|
||||
k8s.io/metrics v0.17.0/go.mod h1:EH1D3YAwN6d7bMelrElnLhLg72l/ERStyv2SIQVt6Do=
|
||||
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd h1:nZX5+wEqTu/EBIYjrZlFOA63z4+Zcy96lDkCZPU9a9c=
|
||||
k8s.io/kubectl v0.0.0-20191219154910-1528d4eea6dd/go.mod h1:9ehGcuUGjXVZh0qbYSB0vvofQw2JQe6c6cO0k4wu/Oo=
|
||||
k8s.io/metrics v0.0.0-20191214191643-6b1944c9f765/go.mod h1:5V7rewilItwK0cz4nomU0b3XCcees2Ka5EBYWS1HBeM=
|
||||
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f h1:GiPwtSzdP43eI1hpPCbROQCCIgCuiMMNF8YUVLF3vJo=
|
||||
k8s.io/utils v0.0.0-20191114184206-e782cd3c129f/go.mod h1:sZAwmy6armz5eXlNoLmJcl4F1QuKu7sr+mFQ0byX7Ew=
|
||||
modernc.org/cc v1.0.0/go.mod h1:1Sk4//wdnYJiUIxnW8ddKpaOJCF37yAdqYnkxUpaYxw=
|
||||
|
||||
@@ -17,9 +17,6 @@ import (
|
||||
cmdutil "k8s.io/kubectl/pkg/cmd/util"
|
||||
"k8s.io/kubectl/pkg/util/i18n"
|
||||
"sigs.k8s.io/kustomize/kyaml/commandutil"
|
||||
|
||||
// initialize auth
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
)
|
||||
|
||||
// GetCommand returns a command from kubectl to install
|
||||
|
||||
59
cmd/kubectl/kubectlcobra/grouping.go
Normal file
59
cmd/kubectl/kubectlcobra/grouping.go
Normal file
@@ -0,0 +1,59 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// package kubectlcobra contains cobra commands from kubectl
|
||||
package kubectlcobra
|
||||
|
||||
import (
|
||||
"k8s.io/apimachinery/pkg/api/meta"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
)
|
||||
|
||||
const GroupingLabel = "kustomize.k8s.io/group-id"
|
||||
|
||||
// isGroupingObject returns true if the passed object has the
|
||||
// grouping label.
|
||||
// TODO(seans3): Check type is ConfigMap.
|
||||
func isGroupingObject(obj runtime.Object) bool {
|
||||
if obj == nil {
|
||||
return false
|
||||
}
|
||||
accessor, err := meta.Accessor(obj)
|
||||
if err == nil {
|
||||
labels := accessor.GetLabels()
|
||||
_, exists := labels[GroupingLabel]
|
||||
if exists {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// findGroupingObject returns the "Grouping" object (ConfigMap with
|
||||
// grouping label) if it exists, and a boolean describing if it was found.
|
||||
func findGroupingObject(infos []*resource.Info) (*resource.Info, bool) {
|
||||
for _, info := range infos {
|
||||
if info != nil && isGroupingObject(info.Object) {
|
||||
return info, true
|
||||
}
|
||||
}
|
||||
return nil, false
|
||||
}
|
||||
|
||||
// sortGroupingObject reorders the infos slice to place the grouping
|
||||
// object in the first position. Returns true if grouping object found,
|
||||
// false otherwise.
|
||||
func sortGroupingObject(infos []*resource.Info) bool {
|
||||
for i, info := range infos {
|
||||
if info != nil && isGroupingObject(info.Object) {
|
||||
// If the grouping object is not already in the first position,
|
||||
// swap the grouping object with the first object.
|
||||
if i > 0 {
|
||||
infos[0], infos[i] = infos[i], infos[0]
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
217
cmd/kubectl/kubectlcobra/grouping_test.go
Normal file
217
cmd/kubectl/kubectlcobra/grouping_test.go
Normal file
@@ -0,0 +1,217 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// package kubectlcobra contains cobra commands from kubectl
|
||||
package kubectlcobra
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/runtime"
|
||||
"k8s.io/cli-runtime/pkg/resource"
|
||||
)
|
||||
|
||||
var testNamespace = "test-grouping-namespace"
|
||||
var groupingObjName = "test-grouping-obj"
|
||||
var pod1Name = "pod-1"
|
||||
var pod2Name = "pod-2"
|
||||
var pod3Name = "pod-3"
|
||||
|
||||
var groupingObj = corev1.ConfigMap{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
Name: groupingObjName,
|
||||
Labels: map[string]string{
|
||||
GroupingLabel: "true",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var groupingInfo = &resource.Info{
|
||||
Namespace: testNamespace,
|
||||
Name: groupingObjName,
|
||||
Object: &groupingObj,
|
||||
}
|
||||
|
||||
var pod1 = corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
Name: pod1Name,
|
||||
},
|
||||
}
|
||||
|
||||
var pod1Info = &resource.Info{
|
||||
Namespace: testNamespace,
|
||||
Name: pod1Name,
|
||||
Object: &pod1,
|
||||
}
|
||||
|
||||
var pod2 = corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
Name: pod2Name,
|
||||
},
|
||||
}
|
||||
|
||||
var pod2Info = &resource.Info{
|
||||
Namespace: testNamespace,
|
||||
Name: pod2Name,
|
||||
Object: &pod2,
|
||||
}
|
||||
|
||||
var pod3 = corev1.Pod{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: testNamespace,
|
||||
Name: pod3Name,
|
||||
},
|
||||
}
|
||||
|
||||
var pod3Info = &resource.Info{
|
||||
Namespace: testNamespace,
|
||||
Name: pod3Name,
|
||||
Object: &pod3,
|
||||
}
|
||||
|
||||
func TestIsGroupingObject(t *testing.T) {
|
||||
tests := []struct {
|
||||
obj runtime.Object
|
||||
isGrouping bool
|
||||
}{
|
||||
{
|
||||
obj: nil,
|
||||
isGrouping: false,
|
||||
},
|
||||
{
|
||||
obj: &groupingObj,
|
||||
isGrouping: true,
|
||||
},
|
||||
{
|
||||
obj: &pod2,
|
||||
isGrouping: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
grouping := isGroupingObject(test.obj)
|
||||
if test.isGrouping && !grouping {
|
||||
t.Errorf("Grouping object not identified: %#v", test.obj)
|
||||
}
|
||||
if !test.isGrouping && grouping {
|
||||
t.Errorf("Non-grouping object identifed as grouping obj: %#v", test.obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFindGroupingObject(t *testing.T) {
|
||||
tests := []struct {
|
||||
infos []*resource.Info
|
||||
exists bool
|
||||
name string
|
||||
}{
|
||||
{
|
||||
infos: []*resource.Info{},
|
||||
exists: false,
|
||||
name: "",
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{nil},
|
||||
exists: false,
|
||||
name: "",
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{groupingInfo},
|
||||
exists: true,
|
||||
name: groupingObjName,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info},
|
||||
exists: false,
|
||||
name: "",
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info, pod2Info, pod3Info},
|
||||
exists: false,
|
||||
name: "",
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info, pod2Info, groupingInfo, pod3Info},
|
||||
exists: true,
|
||||
name: groupingObjName,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
groupingObj, found := findGroupingObject(test.infos)
|
||||
if test.exists && !found {
|
||||
t.Errorf("Should have found grouping object")
|
||||
}
|
||||
if !test.exists && found {
|
||||
t.Errorf("Grouping object found, but it does not exist: %#v", groupingObj)
|
||||
}
|
||||
if test.exists && found && test.name != groupingObj.Name {
|
||||
t.Errorf("Grouping object name does not match: %s/%s", test.name, groupingObj.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSortGroupingObject(t *testing.T) {
|
||||
tests := []struct {
|
||||
infos []*resource.Info
|
||||
sorted bool
|
||||
}{
|
||||
{
|
||||
infos: []*resource.Info{},
|
||||
sorted: false,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{groupingInfo},
|
||||
sorted: true,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info},
|
||||
sorted: false,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info, pod2Info},
|
||||
sorted: false,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{groupingInfo, pod1Info},
|
||||
sorted: true,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info, groupingInfo},
|
||||
sorted: true,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info, pod2Info, groupingInfo, pod3Info},
|
||||
sorted: true,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{pod1Info, pod2Info, pod3Info, groupingInfo},
|
||||
sorted: true,
|
||||
},
|
||||
{
|
||||
infos: []*resource.Info{groupingInfo, pod1Info, pod2Info, pod3Info},
|
||||
sorted: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
wasSorted := sortGroupingObject(test.infos)
|
||||
if wasSorted && !test.sorted {
|
||||
t.Errorf("Grouping object was sorted, but it shouldn't have been")
|
||||
}
|
||||
if !wasSorted && test.sorted {
|
||||
t.Errorf("Grouping object was NOT sorted, but it should have been")
|
||||
}
|
||||
if wasSorted {
|
||||
first := test.infos[0]
|
||||
if !isGroupingObject(first.Object) {
|
||||
t.Errorf("Grouping object was not sorted into first position")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
83
cmd/kubectl/kubectlcobra/inventory.go
Normal file
83
cmd/kubectl/kubectlcobra/inventory.go
Normal file
@@ -0,0 +1,83 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// package kubectlcobra contains cobra commands from kubectl
|
||||
package kubectlcobra
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
// Separates inventory fields. This string is allowable as a
|
||||
// ConfigMap key, but it is not allowed as a character in
|
||||
// resource name.
|
||||
const fieldSeparator = "_"
|
||||
|
||||
// Inventory organizes and stores the indentifying information
|
||||
// for an object. This struct (as a string) is stored in a
|
||||
// grouping object to keep track of sets of applied objects.
|
||||
type Inventory struct {
|
||||
Namespace string
|
||||
Name string
|
||||
GroupKind schema.GroupKind
|
||||
}
|
||||
|
||||
// createInventory returns a pointer to an Inventory struct filled
|
||||
// with the passed values. This function validates the passed fields
|
||||
// and returns an error for bad parameters.
|
||||
func createInventory(namespace string,
|
||||
name string, gk schema.GroupKind) (*Inventory, error) {
|
||||
|
||||
// Namespace can be empty, but name cannot.
|
||||
name = strings.TrimSpace(name)
|
||||
if name == "" {
|
||||
return nil, fmt.Errorf("Empty name for inventory object")
|
||||
}
|
||||
if gk.Empty() {
|
||||
return nil, fmt.Errorf("Empty GroupKind for inventory object")
|
||||
}
|
||||
|
||||
return &Inventory{
|
||||
Namespace: strings.TrimSpace(namespace),
|
||||
Name: name,
|
||||
GroupKind: gk,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// parseInventory takes a string, splits it into its five fields,
|
||||
// and returns a pointer to an Inventory struct storing the
|
||||
// five fields. Example inventory string:
|
||||
//
|
||||
// test-namespace/test-name/apps/v1/ReplicaSet
|
||||
//
|
||||
// Returns an error if unable to parse and create the Inventory
|
||||
// struct.
|
||||
func parseInventory(inv string) (*Inventory, error) {
|
||||
parts := strings.Split(inv, fieldSeparator)
|
||||
if len(parts) == 4 {
|
||||
gk := schema.GroupKind{
|
||||
Group: strings.TrimSpace(parts[2]),
|
||||
Kind: strings.TrimSpace(parts[3]),
|
||||
}
|
||||
return createInventory(parts[0], parts[1], gk)
|
||||
}
|
||||
return nil, fmt.Errorf("Unable to decode inventory: %s\n", inv)
|
||||
}
|
||||
|
||||
// Equals returns true if the Inventory structs are identical;
|
||||
// false otherwise.
|
||||
func (i *Inventory) Equals(other *Inventory) bool {
|
||||
return i.String() == other.String()
|
||||
}
|
||||
|
||||
// String create a string version of the Inventory struct.
|
||||
func (i *Inventory) String() string {
|
||||
return fmt.Sprintf("%s%s%s%s%s%s%s",
|
||||
i.Namespace, fieldSeparator,
|
||||
i.Name, fieldSeparator,
|
||||
i.GroupKind.Group, fieldSeparator,
|
||||
i.GroupKind.Kind)
|
||||
}
|
||||
218
cmd/kubectl/kubectlcobra/inventory_test.go
Normal file
218
cmd/kubectl/kubectlcobra/inventory_test.go
Normal file
@@ -0,0 +1,218 @@
|
||||
// Copyright 2020 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// package kubectlcobra contains cobra commands from kubectl
|
||||
package kubectlcobra
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"k8s.io/apimachinery/pkg/runtime/schema"
|
||||
)
|
||||
|
||||
func TestCreateInventory(t *testing.T) {
|
||||
tests := []struct {
|
||||
namespace string
|
||||
name string
|
||||
gk schema.GroupKind
|
||||
expected string
|
||||
isError bool
|
||||
}{
|
||||
{
|
||||
namespace: " \n",
|
||||
name: " test-name\t",
|
||||
gk: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "ReplicaSet",
|
||||
},
|
||||
expected: "_test-name_apps_ReplicaSet",
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
namespace: "test-namespace ",
|
||||
name: " test-name\t",
|
||||
gk: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "ReplicaSet",
|
||||
},
|
||||
expected: "test-namespace_test-name_apps_ReplicaSet",
|
||||
isError: false,
|
||||
},
|
||||
// Error with empty name.
|
||||
{
|
||||
namespace: "test-namespace ",
|
||||
name: " \t",
|
||||
gk: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "ReplicaSet",
|
||||
},
|
||||
expected: "",
|
||||
isError: true,
|
||||
},
|
||||
// Error with empty GroupKind.
|
||||
{
|
||||
namespace: "test-namespace",
|
||||
name: "test-name",
|
||||
gk: schema.GroupKind{},
|
||||
expected: "",
|
||||
isError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
inv, err := createInventory(test.namespace, test.name, test.gk)
|
||||
if !test.isError {
|
||||
if err != nil {
|
||||
t.Errorf("Error creating inventory when it should have worked.")
|
||||
} else if test.expected != inv.String() {
|
||||
t.Errorf("Expected inventory (%s) != created inventory(%s)\n", test.expected, inv.String())
|
||||
}
|
||||
}
|
||||
if test.isError && err == nil {
|
||||
t.Errorf("Should have returned an error in createInventory()")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestInventoryEqual(t *testing.T) {
|
||||
tests := []struct {
|
||||
inventory1 *Inventory
|
||||
inventory2 *Inventory
|
||||
isEqual bool
|
||||
}{
|
||||
// Two equal inventories without a namespace
|
||||
{
|
||||
inventory1: &Inventory{
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
inventory2: &Inventory{
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
isEqual: true,
|
||||
},
|
||||
// Two equal inventories with a namespace
|
||||
{
|
||||
inventory1: &Inventory{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
inventory2: &Inventory{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
isEqual: true,
|
||||
},
|
||||
// One inventory with a namespace, one without -- not equal.
|
||||
{
|
||||
inventory1: &Inventory{
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
inventory2: &Inventory{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
isEqual: false,
|
||||
},
|
||||
// One inventory with a Deployment, one with a ReplicaSet -- not equal.
|
||||
{
|
||||
inventory1: &Inventory{
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
inventory2: &Inventory{
|
||||
Name: "test-inv",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "ReplicaSet",
|
||||
},
|
||||
},
|
||||
isEqual: false,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
actual := test.inventory1.Equals(test.inventory2)
|
||||
if test.isEqual && !actual {
|
||||
t.Errorf("Expected inventories equal, but actual is not: (%s)/(%s)\n", test.inventory1, test.inventory2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseInventory(t *testing.T) {
|
||||
tests := []struct {
|
||||
invStr string
|
||||
inventory *Inventory
|
||||
isError bool
|
||||
}{
|
||||
{
|
||||
invStr: "_test-name_apps_ReplicaSet\t",
|
||||
inventory: &Inventory{
|
||||
Name: "test-name",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "ReplicaSet",
|
||||
},
|
||||
},
|
||||
isError: false,
|
||||
},
|
||||
{
|
||||
invStr: "test-namespace_test-name_apps_Deployment",
|
||||
inventory: &Inventory{
|
||||
Namespace: "test-namespace",
|
||||
Name: "test-name",
|
||||
GroupKind: schema.GroupKind{
|
||||
Group: "apps",
|
||||
Kind: "Deployment",
|
||||
},
|
||||
},
|
||||
isError: false,
|
||||
},
|
||||
// Not enough fields -- error
|
||||
{
|
||||
invStr: "_test-name_apps",
|
||||
inventory: &Inventory{},
|
||||
isError: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
actual, err := parseInventory(test.invStr)
|
||||
if !test.isError {
|
||||
if err != nil {
|
||||
t.Errorf("Error parsing inventory when it should have worked.")
|
||||
} else if !test.inventory.Equals(actual) {
|
||||
t.Errorf("Expected inventory (%s) != parsed inventory (%s)\n", test.inventory, actual)
|
||||
}
|
||||
}
|
||||
if test.isError && err == nil {
|
||||
t.Errorf("Should have returned an error in parseInventory()")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
|
||||
"sigs.k8s.io/kustomize/cmd/kubectl/kubectlcobra"
|
||||
"sigs.k8s.io/kustomize/kyaml/commandutil"
|
||||
|
||||
// This is here rather than in the libraries because of
|
||||
// https://github.com/kubernetes-sigs/kustomize/issues/2060
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -15,7 +15,7 @@ linters:
|
||||
- dogsled
|
||||
- dupl
|
||||
- errcheck
|
||||
- funlen
|
||||
# - funlen
|
||||
# - gochecknoinits
|
||||
- goconst
|
||||
- gocritic
|
||||
|
||||
@@ -17,8 +17,8 @@ fmt:
|
||||
go fmt ./...
|
||||
|
||||
generate:
|
||||
#(which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/resource)
|
||||
#GOBIN=$(GOBIN) go generate ./...
|
||||
(which $(GOBIN)/mdtogo || go get sigs.k8s.io/kustomize/cmd/mdtogo)
|
||||
GOBIN=$(GOBIN) go generate ./...
|
||||
|
||||
license:
|
||||
(which $(GOBIN)/addlicense || go get github.com/google/addlicense)
|
||||
|
||||
@@ -3,9 +3,12 @@ module sigs.k8s.io/kustomize/cmd/resource
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d
|
||||
github.com/pkg/errors v0.8.1
|
||||
github.com/spf13/cobra v0.0.5
|
||||
github.com/stretchr/testify v1.4.0
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 // indirect
|
||||
k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
|
||||
k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
|
||||
k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90
|
||||
sigs.k8s.io/controller-runtime v0.4.0
|
||||
|
||||
@@ -3,21 +3,31 @@ cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT
|
||||
cloud.google.com/go v0.38.0 h1:ROfEUZz+Gh5pa62DJWXSaonyu3StP6EA6lPEXPI6mCo=
|
||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
|
||||
github.com/Azure/go-autorest/autorest v0.9.0 h1:MRvx8gncNaXJqOoLmhNjUAKh33JJF8LyxPhomEtOsjs=
|
||||
github.com/Azure/go-autorest/autorest v0.9.0/go.mod h1:xyHB1BMZT0cuDHU7I0+g046+BFDTQ8rEZB0s4Yfa6bI=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.5.0 h1:q2gDruN08/guU9vAjuPWff0+QIrpH6ediguzdAzXAUU=
|
||||
github.com/Azure/go-autorest/autorest/adal v0.5.0/go.mod h1:8Z9fGy2MpX0PvDjB1pEgQTmVqjGhiHBW7RJJEciWzS0=
|
||||
github.com/Azure/go-autorest/autorest/date v0.1.0 h1:YGrhWfrgtFs84+h0o46rJrlmsZtyZRg470CqAXTZaGM=
|
||||
github.com/Azure/go-autorest/autorest/date v0.1.0/go.mod h1:plvfp3oPSKwf2DNjlBjWF/7vwR+cUD/ELuzDCXwHUVA=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.1.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.2.0 h1:Ww5g4zThfD/6cLb4z6xxgeyDa7QDkizMkJKe0ysZXp0=
|
||||
github.com/Azure/go-autorest/autorest/mocks v0.2.0/go.mod h1:OTyCOPRA2IgIlWxVYxBee2F5Gr4kF2zd2J5cFRaIDN0=
|
||||
github.com/Azure/go-autorest/logger v0.1.0 h1:ruG4BSDXONFRrZZJ2GUXDiUyVpayPmb1GnWeHDdaNKY=
|
||||
github.com/Azure/go-autorest/logger v0.1.0/go.mod h1:oExouG+K6PryycPJfVSxi/koC6LSNgds39diKLz7Vrc=
|
||||
github.com/Azure/go-autorest/tracing v0.5.0 h1:TRn4WjSnkcSy5AEG3pnbtFSwNtwzjr4VYyQflFE619k=
|
||||
github.com/Azure/go-autorest/tracing v0.5.0/go.mod h1:r/s2XiOKccPW3HrqB+W0TQzfbtp2fGCgRFtBroKn4Dk=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
|
||||
github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/purell v1.1.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/purell v1.1.1 h1:WEQqlqaGbrPkxLJWfBwQmfEAE1Z7ONdDLqrN38tNFfI=
|
||||
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
|
||||
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d h1:licZJFw2RwpHMqeKTCYkitsPqHNxTmd4SNR5r94FGM8=
|
||||
github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d/go.mod h1:asat636LX7Bqt5lYEZ27JNDcqxfjdBQuJ/MM4CN/Lzo=
|
||||
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
|
||||
github.com/asaskevich/govalidator v0.0.0-20180720115003-f9ffefc3facf/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a/go.mod h1:lB+ZfQJz7igIIfQNfa7Ml4HSf2uFQQRzpGGRXenZAgY=
|
||||
@@ -39,6 +49,7 @@ github.com/davecgh/go-spew v0.0.0-20151105211317-5215b55f46b2/go.mod h1:J7Y8YcW2
|
||||
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/dgrijalva/jwt-go v3.2.0+incompatible h1:7qlOGliEKZXTDg6OTjfoBKDXWrumCAMpl/TFQ4/5kLM=
|
||||
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
|
||||
github.com/docker/docker v0.7.3-0.20190327010347-be7ac8be2ae0/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
|
||||
github.com/docker/go-units v0.3.3/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
|
||||
@@ -74,9 +85,12 @@ github.com/go-openapi/jsonpointer v0.0.0-20160704185906-46af16f9f7b1/go.mod h1:+
|
||||
github.com/go-openapi/jsonpointer v0.17.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
||||
github.com/go-openapi/jsonpointer v0.18.0/go.mod h1:cOnomiV+CVVwFLk0A/MExoFMjwdsUdVpsRhURCKh+3M=
|
||||
github.com/go-openapi/jsonpointer v0.19.2/go.mod h1:3akKfEdA7DF1sugOqz1dVQHBcuDBPKZGEoHC/NkiQRg=
|
||||
github.com/go-openapi/jsonpointer v0.19.3 h1:gihV7YNZK1iK6Tgwwsxo2rJbD1GTbdm72325Bq8FI3w=
|
||||
github.com/go-openapi/jsonpointer v0.19.3/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg=
|
||||
github.com/go-openapi/jsonreference v0.0.0-20160704190145-13c6e3589ad9/go.mod h1:W3Z9FmVs9qj+KR4zFKmDPGiLdk1D9Rlm7cyMvf57TTg=
|
||||
github.com/go-openapi/jsonreference v0.17.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||
github.com/go-openapi/jsonreference v0.18.0/go.mod h1:g4xxGn04lDIRh0GJb5QlpE3HfopLOL6uZrK/VgnsK9I=
|
||||
github.com/go-openapi/jsonreference v0.19.2 h1:o20suLFB4Ri0tuzpWtyHlh7E7HnkqTNLq6aR6WVNS1w=
|
||||
github.com/go-openapi/jsonreference v0.19.2/go.mod h1:jMjeRr2HHw6nAVajTXJ4eiUwohSTlpa0o73RUL1owJc=
|
||||
github.com/go-openapi/loads v0.17.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
||||
github.com/go-openapi/loads v0.18.0/go.mod h1:72tmFy5wsWx89uEVddd0RjRWPZm92WRLhf7AC+0+OOU=
|
||||
@@ -88,6 +102,8 @@ github.com/go-openapi/spec v0.0.0-20160808142527-6aced65f8501/go.mod h1:J8+jY1nA
|
||||
github.com/go-openapi/spec v0.17.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
|
||||
github.com/go-openapi/spec v0.18.0/go.mod h1:XkF/MOi14NmjsfZ8VtAKf8pIlbZzyoTvZsdfssdxcBI=
|
||||
github.com/go-openapi/spec v0.19.2/go.mod h1:sCxk3jxKgioEJikev4fgkNmwS+3kuYdJtcsZsD5zxMY=
|
||||
github.com/go-openapi/spec v0.19.5 h1:Xm0Ao53uqnk9QE/LlYV5DEU09UAgpliA85QoT9LzqPw=
|
||||
github.com/go-openapi/spec v0.19.5/go.mod h1:Hm2Jr4jv8G1ciIAo+frC/Ft+rR2kQDh8JHKHb3gWUSk=
|
||||
github.com/go-openapi/strfmt v0.17.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
||||
github.com/go-openapi/strfmt v0.18.0/go.mod h1:P82hnJI0CXkErkXi8IKjPbNBM6lV6+5pLP5l494TcyU=
|
||||
github.com/go-openapi/strfmt v0.19.0/go.mod h1:+uW+93UVvGGq2qGaZxdDeJqSAqBqBdl+ZPMF/cC8nDY=
|
||||
@@ -95,6 +111,8 @@ github.com/go-openapi/swag v0.0.0-20160704191624-1d0bd113de87/go.mod h1:DXUve3Dp
|
||||
github.com/go-openapi/swag v0.17.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
||||
github.com/go-openapi/swag v0.18.0/go.mod h1:AByQ+nYG6gQg71GINrmuDXCPWdL640yX49/kXLo40Tg=
|
||||
github.com/go-openapi/swag v0.19.2/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/swag v0.19.5 h1:lTz6Ys4CmqqCQmZPBlbQENR1/GucA2bzYTE12Pw4tFY=
|
||||
github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk=
|
||||
github.com/go-openapi/validate v0.18.0/go.mod h1:Uh4HdOzKt19xGIGm1qHf/ofbX1YQ4Y+MYsct2VUrAJ4=
|
||||
github.com/go-openapi/validate v0.19.2/go.mod h1:1tRCw7m3jtI8eNWEEliiAqUIcBztB2KDnRCRMUi7GTA=
|
||||
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||
@@ -129,6 +147,7 @@ github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+
|
||||
github.com/googleapis/gnostic v0.0.0-20170729233727-0c5108395e2d/go.mod h1:sJBsCZ4ayReDTBIg8b9dl28c5xFWyhBTVRp3pOg5EKY=
|
||||
github.com/googleapis/gnostic v0.3.1 h1:WeAefnSUHlBb0iJKwxFDZdbfGwkd7xRNuV+IpXMJhYk=
|
||||
github.com/googleapis/gnostic v0.3.1/go.mod h1:on+2t9HRStVgn95RSsFWFz+6Q0Snyqv1awfrALZdbtU=
|
||||
github.com/gophercloud/gophercloud v0.1.0 h1:P/nh25+rzXouhytV2pUHBb65fnds26Ghl8/391+sT5o=
|
||||
github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEoIEcSTewFxm1c5g8=
|
||||
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
|
||||
github.com/gregjones/httpcache v0.0.0-20170728041850-787624de3eb7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
@@ -167,6 +186,8 @@ github.com/mailru/easyjson v0.0.0-20160728113105-d5b7844b561a/go.mod h1:C1wdFJiN
|
||||
github.com/mailru/easyjson v0.0.0-20180823135443-60711f1a8329/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190312143242-1de009706dbe/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190614124828-94de47d64c63/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e h1:hB2xlXdHp/pmPZq0y3QnmWAArdw9PqbmotexnWx/FU8=
|
||||
github.com/mailru/easyjson v0.0.0-20190626092158-b2ccc519800e/go.mod h1:C1wdFJiN94OJF2b5HbByQZoLdCWB1Yqtg26g4irojpc=
|
||||
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/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
|
||||
@@ -211,6 +232,7 @@ 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/remyoudompheng/bigfft v0.0.0-20170806203942-52369c62f446/go.mod h1:uYEyJGbgTkfkS4+E/PavXkNJcbFIpEtjt2B0KDQ5+9M=
|
||||
github.com/russross/blackfriday v1.5.2/go.mod h1:JO/DiYxRf+HjHt06OyowR9PTA263kcR/rfWxYHBV53g=
|
||||
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
|
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
|
||||
github.com/soheilhy/cmux v0.1.3/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
|
||||
github.com/spf13/afero v1.1.2/go.mod h1:j4pytiNVoe2o6bmDsKpLACNPDBIoEAkihy7loJ1B0CQ=
|
||||
@@ -280,6 +302,7 @@ golang.org/x/net v0.0.0-20190320064053-1272bf9dcd53/go.mod h1:t9HGtf8HONx5eT2rtn
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/net v0.0.0-20190613194153-d28f0bde5980/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190812203447-cdfb69ac37fc/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190827160401-ba9fcec4b297/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b h1:XfVGCX+0T4WOStkaOsJRllbsiImhB2jgVBGc9L0lPGc=
|
||||
golang.org/x/net v0.0.0-20190909003024-a7b16738d86b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191004110552-13f9640d40b9 h1:rjwSpXsdiK0dV8/Naq3kAw9ymfAeJIyd0upUIElB+lI=
|
||||
@@ -344,8 +367,10 @@ google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190418145605-e7d98fc518a7/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873 h1:nfPFGzJkUDX6uBmpN/pSw7MbOAWegH5QDQuoXFHedLg=
|
||||
google.golang.org/genproto v0.0.0-20190502173448-54afdca5d873/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
google.golang.org/grpc v1.23.0 h1:AzbTB6ux+okLTzP8Ru1Xs41C303zdcfEht7MQnYJt5A=
|
||||
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@@ -7,7 +10,9 @@ import (
|
||||
|
||||
"sigs.k8s.io/kustomize/cmd/resource/status"
|
||||
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
|
||||
// This is here rather than in the libraries because of
|
||||
// https://github.com/kubernetes-sigs/kustomize/issues/2060
|
||||
_ "k8s.io/client-go/plugin/pkg/client/auth"
|
||||
)
|
||||
|
||||
var root = &cobra.Command{
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
@@ -6,23 +9,29 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/resource/status/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kstatus/wait"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
)
|
||||
|
||||
// GetEventsRunner returns a command EventsRunner.
|
||||
func GetEventsRunner() *EventsRunner {
|
||||
r := &EventsRunner{}
|
||||
r := &EventsRunner{
|
||||
createClientFunc: createClient,
|
||||
}
|
||||
c := &cobra.Command{
|
||||
Use: "events",
|
||||
Short: "Events",
|
||||
RunE: r.runE,
|
||||
Use: "events DIR...",
|
||||
Short: commands.EventsShort,
|
||||
Long: commands.EventsLong,
|
||||
Example: commands.EventsExamples,
|
||||
RunE: r.runE,
|
||||
}
|
||||
c.Flags().BoolVar(&r.IncludeSubpackages, "include-subpackages", true,
|
||||
"also print resources from subpackages.")
|
||||
c.Flags().DurationVar(&r.Interval, "interval", 2*time.Second,
|
||||
"check every n seconds. Default is every 2 seconds.")
|
||||
"check every n seconds.")
|
||||
c.Flags().DurationVar(&r.Timeout, "timeout", 60*time.Second,
|
||||
"give up after n seconds. Default is 60 seconds.")
|
||||
"give up after n seconds.")
|
||||
|
||||
r.Command = c
|
||||
return r
|
||||
@@ -32,22 +41,30 @@ func EventsCommand() *cobra.Command {
|
||||
return GetEventsRunner().Command
|
||||
}
|
||||
|
||||
// EventsRunner captures the parameters for the command
|
||||
// and contains the run function.
|
||||
type EventsRunner struct {
|
||||
IncludeSubpackages bool
|
||||
Interval time.Duration
|
||||
Timeout time.Duration
|
||||
Command *cobra.Command
|
||||
|
||||
createClientFunc createClientFunc
|
||||
}
|
||||
|
||||
func (r *EventsRunner) runE(c *cobra.Command, args []string) error {
|
||||
ctx := context.Background()
|
||||
client, err := getClient()
|
||||
|
||||
// Create a client and use it to set up a new resolver.
|
||||
client, err := r.createClientFunc()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating client")
|
||||
}
|
||||
|
||||
resolver := wait.NewResolver(client, r.Interval)
|
||||
|
||||
// Set up a CaptureIdentifierFilter and run all inputs through the
|
||||
// filter with the pipeline to capture the inventory of resources
|
||||
// which we are interested in.
|
||||
captureFilter := &CaptureIdentifiersFilter{}
|
||||
filters := []kio.Filter{captureFilter}
|
||||
|
||||
@@ -70,12 +87,17 @@ func (r *EventsRunner) runE(c *cobra.Command, args []string) error {
|
||||
return errors.Wrap(err, "error reading manifests")
|
||||
}
|
||||
|
||||
// Create a new printer that knows how to print updates about
|
||||
// resourdes and their aggregate status in the events format.
|
||||
printer := newEventPrinter(c.OutOrStdout(), c.OutOrStderr())
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, r.Timeout)
|
||||
defer cancel()
|
||||
resChannel := resolver.WaitForStatus(ctx, captureFilter.Identifiers)
|
||||
|
||||
// Print events until the channel is closed. This will happen
|
||||
// either because all resources has reached the Current status
|
||||
// or it has timed out.
|
||||
for msg := range resChannel {
|
||||
printer.printEvent(msg)
|
||||
}
|
||||
|
||||
298
cmd/resource/status/cmd/events_test.go
Normal file
298
cmd/resource/status/cmd/events_test.go
Normal file
@@ -0,0 +1,298 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"sigs.k8s.io/kustomize/kstatus/status"
|
||||
"sigs.k8s.io/kustomize/kstatus/wait"
|
||||
)
|
||||
|
||||
func TestEventsNoResources(t *testing.T) {
|
||||
inBuffer := &bytes.Buffer{}
|
||||
outBuffer := &bytes.Buffer{}
|
||||
|
||||
fakeClient := &FakeClient{}
|
||||
|
||||
r := GetEventsRunner()
|
||||
r.createClientFunc = newClientFunc(fakeClient)
|
||||
r.Command.SetArgs([]string{})
|
||||
r.Command.SetIn(inBuffer)
|
||||
r.Command.SetOut(outBuffer)
|
||||
|
||||
err := r.Command.Execute()
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
eventOutput := parseEventOutput(t, outBuffer.String())
|
||||
|
||||
if want, got := 1, len(eventOutput.events); want != got {
|
||||
t.Errorf("expected %d events, but got %d", want, got)
|
||||
}
|
||||
|
||||
event := eventOutput.events[0]
|
||||
if want, got := status.CurrentStatus, event.aggStatus; want != got {
|
||||
t.Errorf("expected agg status %s, but got %s", want, got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventsMultipleUpdates(t *testing.T) {
|
||||
inBuffer := &bytes.Buffer{}
|
||||
outBuffer := &bytes.Buffer{}
|
||||
|
||||
_, err := fmt.Fprint(inBuffer, `
|
||||
apiVersion: apps/v1
|
||||
kind: Deployment
|
||||
metadata:
|
||||
name: bar
|
||||
namespace: default
|
||||
`)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
fakeClient := &FakeClient{
|
||||
resourceCallbackMap: map[string]ResourceGetCallback{
|
||||
"Deployment": createDeploymentStatusFunc(),
|
||||
},
|
||||
}
|
||||
|
||||
r := GetEventsRunner()
|
||||
r.createClientFunc = newClientFunc(fakeClient)
|
||||
r.Command.SetArgs([]string{})
|
||||
r.Command.SetIn(inBuffer)
|
||||
r.Command.SetOut(outBuffer)
|
||||
|
||||
err = r.Command.Execute()
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
eventOutput := parseEventOutput(t, outBuffer.String())
|
||||
|
||||
aggStatuses := eventOutput.allAggStatuses()
|
||||
expectedAggStatuses := []status.Status{
|
||||
status.InProgressStatus,
|
||||
status.InProgressStatus,
|
||||
status.InProgressStatus,
|
||||
status.InProgressStatus,
|
||||
status.CurrentStatus,
|
||||
status.CurrentStatus,
|
||||
}
|
||||
if !reflect.DeepEqual(aggStatuses, expectedAggStatuses) {
|
||||
t.Errorf("expected agg statuses to be %s, but got %s", joinStatuses(expectedAggStatuses),
|
||||
joinStatuses(aggStatuses))
|
||||
}
|
||||
|
||||
resources := eventOutput.allResources()
|
||||
if want, got := 1, len(resources); want != got {
|
||||
t.Errorf("expected %d resource, but got %d", want, got)
|
||||
}
|
||||
|
||||
resource := resources[0]
|
||||
resourceStatuses := eventOutput.statusesForResource(resource)
|
||||
expectedResourceStatuses := []status.Status{
|
||||
status.InProgressStatus,
|
||||
status.InProgressStatus,
|
||||
status.InProgressStatus,
|
||||
status.InProgressStatus,
|
||||
status.CurrentStatus,
|
||||
}
|
||||
if !reflect.DeepEqual(resourceStatuses, expectedResourceStatuses) {
|
||||
t.Errorf("expected statuses to be %s, but got %s", joinStatuses(expectedResourceStatuses),
|
||||
joinStatuses(resourceStatuses))
|
||||
}
|
||||
}
|
||||
|
||||
func TestEventsMultipleResources(t *testing.T) {
|
||||
inBuffer := &bytes.Buffer{}
|
||||
outBuffer := &bytes.Buffer{}
|
||||
|
||||
_, err := fmt.Fprint(inBuffer, `
|
||||
apiVersion: v1
|
||||
kind: List
|
||||
items:
|
||||
- apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
name: foo
|
||||
namespace: default
|
||||
- apiVersion: v1
|
||||
kind: Service
|
||||
metadata:
|
||||
name: bar
|
||||
namespace: default
|
||||
`)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
fakeClient := &FakeClient{
|
||||
resourceCallbackMap: map[string]ResourceGetCallback{
|
||||
"Pod": createPodStatusFunc(),
|
||||
"Service": createServiceStatusFunc(),
|
||||
},
|
||||
}
|
||||
|
||||
r := GetEventsRunner()
|
||||
r.createClientFunc = newClientFunc(fakeClient)
|
||||
r.Command.SetArgs([]string{})
|
||||
r.Command.SetIn(inBuffer)
|
||||
r.Command.SetOut(outBuffer)
|
||||
|
||||
err = r.Command.Execute()
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
|
||||
eventOutput := parseEventOutput(t, outBuffer.String())
|
||||
|
||||
aggStatuses := eventOutput.allAggStatuses()
|
||||
expectedAggStatuses := []status.Status{
|
||||
status.UnknownStatus,
|
||||
status.CurrentStatus,
|
||||
status.CurrentStatus,
|
||||
}
|
||||
if !reflect.DeepEqual(aggStatuses, expectedAggStatuses) {
|
||||
t.Errorf("expected agg statuses to be %s, but got %s", joinStatuses(expectedAggStatuses),
|
||||
joinStatuses(aggStatuses))
|
||||
}
|
||||
|
||||
resources := eventOutput.allResources()
|
||||
if want, got := 2, len(resources); got != want {
|
||||
t.Errorf("expected %d resource, but got %d", want, got)
|
||||
}
|
||||
|
||||
for _, resource := range resources {
|
||||
resourceStatuses := eventOutput.statusesForResource(resource)
|
||||
if want, got := status.CurrentStatus, resourceStatuses[len(resourceStatuses)-1]; want != got {
|
||||
t.Errorf("expected resource %q to have final status %s, but got %s", resource.name, want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type EventOutput struct {
|
||||
events []EventOutputLine
|
||||
unknownLines []string
|
||||
}
|
||||
|
||||
func (e *EventOutput) allAggStatuses() []status.Status {
|
||||
var aggStatuses []status.Status
|
||||
for _, event := range e.events {
|
||||
aggStatuses = append(aggStatuses, event.aggStatus)
|
||||
}
|
||||
return aggStatuses
|
||||
}
|
||||
|
||||
func (e *EventOutput) allResources() []ResourceIdentifier {
|
||||
var resources []ResourceIdentifier
|
||||
seenResources := make(map[ResourceIdentifier]bool)
|
||||
for _, event := range e.events {
|
||||
if !event.isResourceUpdateEvent() {
|
||||
continue
|
||||
}
|
||||
r := event.identifier
|
||||
if _, found := seenResources[r]; !found {
|
||||
resources = append(resources, r)
|
||||
seenResources[r] = true
|
||||
}
|
||||
}
|
||||
return resources
|
||||
}
|
||||
|
||||
func (e *EventOutput) statusesForResource(resource ResourceIdentifier) []status.Status {
|
||||
var statuses []status.Status
|
||||
for _, event := range e.events {
|
||||
if !event.isResourceUpdateEvent() {
|
||||
continue
|
||||
}
|
||||
if event.identifier.Equals(resource) {
|
||||
statuses = append(statuses, event.status)
|
||||
}
|
||||
}
|
||||
return statuses
|
||||
}
|
||||
|
||||
type EventOutputLine struct {
|
||||
eventType string
|
||||
aggStatus status.Status
|
||||
identifier ResourceIdentifier
|
||||
status status.Status
|
||||
message string
|
||||
}
|
||||
|
||||
func (e *EventOutputLine) isResourceUpdateEvent() bool {
|
||||
return e.eventType == string(wait.ResourceUpdate)
|
||||
}
|
||||
|
||||
var (
|
||||
eventRegex = regexp.MustCompile(`^\s*` +
|
||||
`(?P<eventType>\S+)\s+` +
|
||||
`(?P<aggStatus>\S+)\s+` +
|
||||
`((?P<resourceType>\S+)\s+` +
|
||||
`(?P<namespace>\S+)\s+` +
|
||||
`(?P<name>\S+)\s+` +
|
||||
`(?P<status>\S+)\s+` +
|
||||
`(?P<message>.*\S)){0,1}` +
|
||||
`\s*$`)
|
||||
eventHeaderRegex = regexp.MustCompile(`^\s*` +
|
||||
`EVENT TYPE\s+` +
|
||||
`AGG STATUS\s+` +
|
||||
`TYPE\s+` +
|
||||
`NAMESPACE\s+` +
|
||||
`NAME\s+` +
|
||||
`STATUS\s+` +
|
||||
`MESSAGE` +
|
||||
`\s*$`)
|
||||
)
|
||||
|
||||
func parseEventOutput(_ *testing.T, output string) EventOutput {
|
||||
var eventOutput EventOutput
|
||||
lines := strings.Split(output, "\n")
|
||||
for _, line := range lines {
|
||||
if len(line) == 0 {
|
||||
continue // Ignore empty lines
|
||||
}
|
||||
match := eventHeaderRegex.FindStringSubmatch(line)
|
||||
if match != nil {
|
||||
continue // Ignore headers
|
||||
}
|
||||
match = eventRegex.FindStringSubmatch(line)
|
||||
if match == nil {
|
||||
eventOutput.unknownLines = append(eventOutput.unknownLines, line)
|
||||
continue
|
||||
}
|
||||
|
||||
eventOutputLine := EventOutputLine{
|
||||
eventType: match[1],
|
||||
aggStatus: status.FromStringOrDie(match[2]),
|
||||
}
|
||||
|
||||
if eventOutputLine.eventType == string(wait.ResourceUpdate) {
|
||||
resourceType := match[4]
|
||||
parts := strings.Split(resourceType, "/")
|
||||
var identifier ResourceIdentifier
|
||||
if len(parts) == 2 {
|
||||
identifier.apiVersion = parts[0]
|
||||
identifier.kind = parts[1]
|
||||
} else {
|
||||
identifier.apiVersion = strings.Join(parts[:2], "/")
|
||||
identifier.kind = parts[2]
|
||||
}
|
||||
identifier.namespace = match[5]
|
||||
identifier.name = match[6]
|
||||
eventOutputLine.identifier = identifier
|
||||
eventOutputLine.status = status.FromStringOrDie(match[7])
|
||||
eventOutputLine.message = match[8]
|
||||
}
|
||||
|
||||
eventOutput.events = append(eventOutput.events, eventOutputLine)
|
||||
}
|
||||
return eventOutput
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
@@ -6,17 +9,23 @@ import (
|
||||
|
||||
"github.com/pkg/errors"
|
||||
"github.com/spf13/cobra"
|
||||
"sigs.k8s.io/kustomize/cmd/resource/status/generateddocs/commands"
|
||||
"sigs.k8s.io/kustomize/kstatus/status"
|
||||
"sigs.k8s.io/kustomize/kstatus/wait"
|
||||
"sigs.k8s.io/kustomize/kyaml/kio"
|
||||
)
|
||||
|
||||
// GetFetchRunner returns a command FetchRunner.
|
||||
func GetFetchRunner() *FetchRunner {
|
||||
r := &FetchRunner{}
|
||||
r := &FetchRunner{
|
||||
createClientFunc: createClient,
|
||||
}
|
||||
c := &cobra.Command{
|
||||
Use: "fetch",
|
||||
Short: "Fetch",
|
||||
RunE: r.runE,
|
||||
Use: "fetch DIR...",
|
||||
Short: commands.FetchShort,
|
||||
Long: commands.FetchLong,
|
||||
Example: commands.FetchExamples,
|
||||
RunE: r.runE,
|
||||
}
|
||||
c.Flags().BoolVar(&r.IncludeSubpackages, "include-subpackages", true,
|
||||
"also print resources from subpackages.")
|
||||
@@ -29,20 +38,29 @@ func FetchCommand() *cobra.Command {
|
||||
return GetFetchRunner().Command
|
||||
}
|
||||
|
||||
// FetchRunner captures the parameters for the command and contains
|
||||
// the run function.
|
||||
type FetchRunner struct {
|
||||
IncludeSubpackages bool
|
||||
Command *cobra.Command
|
||||
|
||||
createClientFunc createClientFunc
|
||||
}
|
||||
|
||||
func (r *FetchRunner) runE(c *cobra.Command, args []string) error {
|
||||
ctx := context.Background()
|
||||
client, err := getClient()
|
||||
|
||||
// Create a new client and use it to set up a resolver.
|
||||
k8sClient, err := r.createClientFunc()
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "error creating client")
|
||||
return errors.Wrap(err, "error creating k8sClient")
|
||||
}
|
||||
|
||||
resolver := wait.NewResolver(client, time.Minute)
|
||||
resolver := wait.NewResolver(k8sClient, time.Minute)
|
||||
|
||||
// Set up a CaptureIdentifierFilter and run all inputs through the
|
||||
// filter with the pipeline to capture the inventory of resources
|
||||
// which we are interested in.
|
||||
captureFilter := &CaptureIdentifiersFilter{}
|
||||
filters := []kio.Filter{captureFilter}
|
||||
|
||||
@@ -65,16 +83,27 @@ func (r *FetchRunner) runE(c *cobra.Command, args []string) error {
|
||||
return errors.Wrap(err, "error reading manifests")
|
||||
}
|
||||
|
||||
// Pass in the inventory of resources to the FetchAndResolve function
|
||||
// on the resolver. It will return the status (or an error) for each
|
||||
// resource in the inventory.
|
||||
results := resolver.FetchAndResolve(ctx, captureFilter.Identifiers)
|
||||
|
||||
// Create new printer that knows how to print resource statuses
|
||||
// in a table format and ask it to print the results.
|
||||
newTablePrinter(FetchStatusInfo{results}, c.OutOrStdout(), c.OutOrStderr(), false).Print()
|
||||
return nil
|
||||
}
|
||||
|
||||
// FetchStatusInfo wraps the results from the FetchAndResolve function
|
||||
// to the format expected in the TablePrinter.
|
||||
type FetchStatusInfo struct {
|
||||
Results []wait.ResourceResult
|
||||
}
|
||||
|
||||
// CurrentStatus returns the latest information known about the
|
||||
// status of each of the resources. For FetchStatusInfo, the result
|
||||
// is never updated, so it just returns the information provided
|
||||
// by the slice of wait.ResourceResult at creation.
|
||||
func (f FetchStatusInfo) CurrentStatus() StatusData {
|
||||
var resourceData []ResourceStatusData
|
||||
for _, res := range f.Results {
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user