├── .gitignore ├── 1.7 ├── README.md └── listing-pods │ ├── Gopkg.lock │ ├── Gopkg.toml │ ├── main.go │ └── test.bats ├── CNAME ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | vendor/ 3 | # Binaries for programs and plugins 4 | *.exe 5 | *.dll 6 | *.so 7 | *.dylib 8 | 9 | # Test binary, build with `go test -c` 10 | *.test 11 | 12 | # Output of the go coverage tool, specifically when used with LiteIDE 13 | *.out 14 | 15 | # Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 16 | .glide/ 17 | -------------------------------------------------------------------------------- /1.7/README.md: -------------------------------------------------------------------------------- 1 | # Using `client-go` with Kubernetes 1.7 2 | 3 | Snippets: 4 | 5 | - [Listing pods](#listing-pods) 6 | - [Watching pods](#watching-pods) 7 | - [Creating deployments](#creating-deployments) 8 | 9 | ## Listing pods 10 | 11 | To list all pods in namespace `abc`, do the following: 12 | 13 | ``` 14 | clientset, _ := kubernetes.NewForConfig(config) 15 | pods, _ := clientset.CoreV1().Pods('abc').List(metav1.ListOptions{}) 16 | for _, p := range pods.Items { 17 | fmt.Println(p.GetName()) 18 | } 19 | ``` 20 | 21 | See also the [standalone example](https://github.com/mhausenblas/using-client-go/blob/master/1.7/listing-pods/main.go) that you can run like so: 22 | 23 | ``` 24 | $ cd $GOPATH/src/mhausenblas/using-client-go/1.7/listing-pods 25 | $ dep ensure 26 | $ go run main.go 27 | ``` 28 | 29 | ## Watching pods 30 | 31 | ## Creating deployments 32 | -------------------------------------------------------------------------------- /1.7/listing-pods/Gopkg.lock: -------------------------------------------------------------------------------- 1 | # This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. 2 | 3 | 4 | [[projects]] 5 | name = "github.com/PuerkitoBio/purell" 6 | packages = ["."] 7 | revision = "0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4" 8 | version = "v1.1.0" 9 | 10 | [[projects]] 11 | branch = "master" 12 | name = "github.com/PuerkitoBio/urlesc" 13 | packages = ["."] 14 | revision = "de5bf2ad457846296e2031421a34e2568e304e35" 15 | 16 | [[projects]] 17 | name = "github.com/asaskevich/govalidator" 18 | packages = ["."] 19 | revision = "4918b99a7cb949bb295f3c7bbaf24b577d806e35" 20 | version = "v6" 21 | 22 | [[projects]] 23 | name = "github.com/davecgh/go-spew" 24 | packages = ["spew"] 25 | revision = "346938d642f2ec3594ed81d874461961cd0faa76" 26 | version = "v1.1.0" 27 | 28 | [[projects]] 29 | name = "github.com/docker/distribution" 30 | packages = ["digest","reference"] 31 | revision = "48294d928ced5dd9b378f7fd7c6f5da3ff3f2c89" 32 | version = "v2.6.2" 33 | 34 | [[projects]] 35 | name = "github.com/emicklei/go-restful" 36 | packages = [".","log"] 37 | revision = "68c9750c36bb8cb433f1b88c807b4b30df4acc40" 38 | version = "v2.2.1" 39 | 40 | [[projects]] 41 | name = "github.com/emicklei/go-restful-swagger12" 42 | packages = ["."] 43 | revision = "dcef7f55730566d41eae5db10e7d6981829720f6" 44 | version = "1.0.1" 45 | 46 | [[projects]] 47 | name = "github.com/ghodss/yaml" 48 | packages = ["."] 49 | revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" 50 | version = "v1.0.0" 51 | 52 | [[projects]] 53 | branch = "master" 54 | name = "github.com/go-openapi/analysis" 55 | packages = ["."] 56 | revision = "8ed83f2ea9f00f945516462951a288eaa68bf0d6" 57 | 58 | [[projects]] 59 | branch = "master" 60 | name = "github.com/go-openapi/errors" 61 | packages = ["."] 62 | revision = "03cfca65330da08a5a440053faf994a3c682b5bf" 63 | 64 | [[projects]] 65 | branch = "master" 66 | name = "github.com/go-openapi/jsonpointer" 67 | packages = ["."] 68 | revision = "779f45308c19820f1a69e9a4cd965f496e0da10f" 69 | 70 | [[projects]] 71 | branch = "master" 72 | name = "github.com/go-openapi/jsonreference" 73 | packages = ["."] 74 | revision = "36d33bfe519efae5632669801b180bf1a245da3b" 75 | 76 | [[projects]] 77 | branch = "master" 78 | name = "github.com/go-openapi/loads" 79 | packages = ["."] 80 | revision = "a80dea3052f00e5f032e860dd7355cd0cc67e24d" 81 | 82 | [[projects]] 83 | branch = "master" 84 | name = "github.com/go-openapi/spec" 85 | packages = ["."] 86 | revision = "3faa0055dbbf2110abc1f3b4e3adbb22721e96e7" 87 | 88 | [[projects]] 89 | branch = "master" 90 | name = "github.com/go-openapi/strfmt" 91 | packages = ["."] 92 | revision = "610b6cacdcde6852f4de68998bd20ce1dac85b22" 93 | 94 | [[projects]] 95 | branch = "master" 96 | name = "github.com/go-openapi/swag" 97 | packages = ["."] 98 | revision = "f3f9494671f93fcff853e3c6e9e948b3eb71e590" 99 | 100 | [[projects]] 101 | name = "github.com/gogo/protobuf" 102 | packages = ["proto","sortkeys"] 103 | revision = "100ba4e885062801d56799d78530b73b178a78f3" 104 | version = "v0.4" 105 | 106 | [[projects]] 107 | branch = "master" 108 | name = "github.com/golang/glog" 109 | packages = ["."] 110 | revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" 111 | 112 | [[projects]] 113 | branch = "master" 114 | name = "github.com/google/gofuzz" 115 | packages = ["."] 116 | revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" 117 | 118 | [[projects]] 119 | branch = "master" 120 | name = "github.com/howeyc/gopass" 121 | packages = ["."] 122 | revision = "bf9dde6d0d2c004a008c27aaee91170c786f6db8" 123 | 124 | [[projects]] 125 | name = "github.com/imdario/mergo" 126 | packages = ["."] 127 | revision = "3e95a51e0639b4cf372f2ccf74c86749d747fbdc" 128 | version = "0.2.2" 129 | 130 | [[projects]] 131 | branch = "master" 132 | name = "github.com/juju/ratelimit" 133 | packages = ["."] 134 | revision = "5b9ff866471762aa2ab2dced63c9fb6f53921342" 135 | 136 | [[projects]] 137 | branch = "master" 138 | name = "github.com/mailru/easyjson" 139 | packages = ["buffer","jlexer","jwriter"] 140 | revision = "3b3bbef4e2d9a6f24d7ee73a894afbc064f0e057" 141 | 142 | [[projects]] 143 | branch = "master" 144 | name = "github.com/mitchellh/mapstructure" 145 | packages = ["."] 146 | revision = "d0303fe809921458f417bcf828397a65db30a7e4" 147 | 148 | [[projects]] 149 | name = "github.com/spf13/pflag" 150 | packages = ["."] 151 | revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66" 152 | version = "v1.0.0" 153 | 154 | [[projects]] 155 | branch = "master" 156 | name = "github.com/ugorji/go" 157 | packages = ["codec"] 158 | revision = "8c0409fcbb70099c748d71f714529204975f6c3f" 159 | 160 | [[projects]] 161 | branch = "master" 162 | name = "golang.org/x/crypto" 163 | packages = ["ssh/terminal"] 164 | revision = "81e90905daefcd6fd217b62423c0908922eadb30" 165 | 166 | [[projects]] 167 | branch = "master" 168 | name = "golang.org/x/net" 169 | packages = ["http2","http2/hpack","idna","lex/httplex"] 170 | revision = "57efc9c3d9f91fb3277f8da1cff370539c4d3dc5" 171 | 172 | [[projects]] 173 | branch = "master" 174 | name = "golang.org/x/sys" 175 | packages = ["unix","windows"] 176 | revision = "2d6f6f883a06fc0d5f4b14a81e4c28705ea64c15" 177 | 178 | [[projects]] 179 | branch = "master" 180 | name = "golang.org/x/text" 181 | packages = ["internal/gen","internal/triegen","internal/ucd","secure/bidirule","transform","unicode/bidi","unicode/cldr","unicode/norm","unicode/rangetable","width"] 182 | revision = "ac87088df8ef557f1e32cd00ed0b6fbc3f7ddafb" 183 | 184 | [[projects]] 185 | name = "gopkg.in/inf.v0" 186 | packages = ["."] 187 | revision = "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4" 188 | version = "v0.9.0" 189 | 190 | [[projects]] 191 | branch = "v2" 192 | name = "gopkg.in/mgo.v2" 193 | packages = ["bson","internal/json"] 194 | revision = "3f83fa5005286a7fe593b055f0d7771a7dce4655" 195 | 196 | [[projects]] 197 | branch = "v2" 198 | name = "gopkg.in/yaml.v2" 199 | packages = ["."] 200 | revision = "eb3733d160e74a9c7e442f435eb3bea458e1d19f" 201 | 202 | [[projects]] 203 | branch = "release-1.7" 204 | name = "k8s.io/apimachinery" 205 | packages = ["pkg/api/equality","pkg/api/errors","pkg/api/meta","pkg/api/resource","pkg/apimachinery","pkg/apimachinery/announced","pkg/apimachinery/registered","pkg/apis/meta/v1","pkg/apis/meta/v1/unstructured","pkg/apis/meta/v1alpha1","pkg/conversion","pkg/conversion/queryparams","pkg/conversion/unstructured","pkg/fields","pkg/labels","pkg/openapi","pkg/runtime","pkg/runtime/schema","pkg/runtime/serializer","pkg/runtime/serializer/json","pkg/runtime/serializer/protobuf","pkg/runtime/serializer/recognizer","pkg/runtime/serializer/streaming","pkg/runtime/serializer/versioning","pkg/selection","pkg/types","pkg/util/clock","pkg/util/diff","pkg/util/errors","pkg/util/framer","pkg/util/intstr","pkg/util/json","pkg/util/net","pkg/util/rand","pkg/util/runtime","pkg/util/sets","pkg/util/validation","pkg/util/validation/field","pkg/util/wait","pkg/util/yaml","pkg/version","pkg/watch","third_party/forked/golang/reflect"] 206 | revision = "1fd2e63a9a370677308a42f24fd40c86438afddf" 207 | 208 | [[projects]] 209 | name = "k8s.io/client-go" 210 | packages = ["discovery","kubernetes","kubernetes/scheme","kubernetes/typed/admissionregistration/v1alpha1","kubernetes/typed/apps/v1beta1","kubernetes/typed/authentication/v1","kubernetes/typed/authentication/v1beta1","kubernetes/typed/authorization/v1","kubernetes/typed/authorization/v1beta1","kubernetes/typed/autoscaling/v1","kubernetes/typed/autoscaling/v2alpha1","kubernetes/typed/batch/v1","kubernetes/typed/batch/v2alpha1","kubernetes/typed/certificates/v1beta1","kubernetes/typed/core/v1","kubernetes/typed/extensions/v1beta1","kubernetes/typed/networking/v1","kubernetes/typed/policy/v1beta1","kubernetes/typed/rbac/v1alpha1","kubernetes/typed/rbac/v1beta1","kubernetes/typed/settings/v1alpha1","kubernetes/typed/storage/v1","kubernetes/typed/storage/v1beta1","pkg/api","pkg/api/v1","pkg/api/v1/ref","pkg/apis/admissionregistration","pkg/apis/admissionregistration/v1alpha1","pkg/apis/apps","pkg/apis/apps/v1beta1","pkg/apis/authentication","pkg/apis/authentication/v1","pkg/apis/authentication/v1beta1","pkg/apis/authorization","pkg/apis/authorization/v1","pkg/apis/authorization/v1beta1","pkg/apis/autoscaling","pkg/apis/autoscaling/v1","pkg/apis/autoscaling/v2alpha1","pkg/apis/batch","pkg/apis/batch/v1","pkg/apis/batch/v2alpha1","pkg/apis/certificates","pkg/apis/certificates/v1beta1","pkg/apis/extensions","pkg/apis/extensions/v1beta1","pkg/apis/networking","pkg/apis/networking/v1","pkg/apis/policy","pkg/apis/policy/v1beta1","pkg/apis/rbac","pkg/apis/rbac/v1alpha1","pkg/apis/rbac/v1beta1","pkg/apis/settings","pkg/apis/settings/v1alpha1","pkg/apis/storage","pkg/apis/storage/v1","pkg/apis/storage/v1beta1","pkg/util","pkg/util/parsers","pkg/version","rest","rest/watch","tools/auth","tools/clientcmd","tools/clientcmd/api","tools/clientcmd/api/latest","tools/clientcmd/api/v1","tools/metrics","transport","util/cert","util/flowcontrol","util/homedir","util/integer"] 211 | revision = "d92e8497f71b7b4e0494e5bd204b48d34bd6f254" 212 | version = "v4.0.0" 213 | 214 | [solve-meta] 215 | analyzer-name = "dep" 216 | analyzer-version = 1 217 | inputs-digest = "d5822457ff688db9ff99e5da616893b6bcf30e0accddd9b6d5305e869be39edd" 218 | solver-name = "gps-cdcl" 219 | solver-version = 1 220 | -------------------------------------------------------------------------------- /1.7/listing-pods/Gopkg.toml: -------------------------------------------------------------------------------- 1 | [[constraint]] 2 | name = "k8s.io/client-go" 3 | version = "v4.0.0" 4 | 5 | [[constraint]] 6 | name = "k8s.io/apimachinery" 7 | branch = "release-1.7" 8 | -------------------------------------------------------------------------------- /1.7/listing-pods/main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "os" 6 | 7 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 8 | "k8s.io/client-go/kubernetes" 9 | "k8s.io/client-go/tools/clientcmd" 10 | ) 11 | 12 | func main() { 13 | pl, _ := listpods() 14 | fmt.Println(pl) 15 | } 16 | 17 | func listpods() ([]string, error) { 18 | var po []string 19 | config, err := clientcmd.BuildConfigFromFlags("", os.Getenv("HOME")+"/.kube/config") 20 | if err != nil { 21 | return po, err 22 | } 23 | cs, err := kubernetes.NewForConfig(config) 24 | if err != nil { 25 | return po, err 26 | } 27 | namespace := "ucg-test" 28 | pods, err := cs.CoreV1().Pods(namespace).List(metav1.ListOptions{}) 29 | if err != nil { 30 | return po, err 31 | } 32 | for _, p := range pods.Items { 33 | po = append(po, p.GetName()) 34 | } 35 | return po, nil 36 | } 37 | -------------------------------------------------------------------------------- /1.7/listing-pods/test.bats: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bats 2 | 3 | function setup() { 4 | echo "Setting up 1.7 test: ucg17 listing pods" 5 | kubectl create namespace ucg-test 6 | kubectl --namespace=ucg-test run ucg17-listing-pods --image=busybox --restart=Never --overrides='{ "apiVersion": "v1", "metadata": { "namespace": "ucg-test" } }' --command -- sleep 3600 7 | } 8 | 9 | function teardown() { 10 | echo "Tearing down 1.7 test: ucg17 listing pods" 11 | kubectl --namespace=ucg-test delete po/ucg17-listing-pods 12 | kubectl delete namespace ucg-test 13 | } 14 | 15 | @test "ucg17 listing pods" { 16 | run go run main.go 17 | [ "$status" -eq 0 ] 18 | [ "${lines[0]}" = "[ucg17-listing-pods]" ] 19 | } 20 | -------------------------------------------------------------------------------- /CNAME: -------------------------------------------------------------------------------- 1 | using-client-go.cloudnative.sh -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Using `client-go` 2 | 3 | A versioned collection of snippets showing how to use [client-go](https://github.com/kubernetes/client-go/). 4 | `client-go` is a bunch of Go packages enabling you to programmatically interact with a Kubernetes cluster. 5 | 6 | Quick links | `client-go` [Go docs](https://godoc.org/k8s.io/client-go/) | `client-go` [repo](https://github.com/kubernetes/client-go/) | [1.7 snippets](1.7/) 7 | 8 | **Table of Contents**: 9 | 10 | - [Prerequisites](#prerequisites) 11 | - [Go](#go) 12 | - [Kubernetes cluster](#kubernetes-cluster) 13 | - [Get snippets](#get-snippets) 14 | - Using `client-go` with [Kubernetes 1.7](#kubernetes-17) 15 | - Using `client-go` with [Kubernetes 1.6](#kubernetes-16) 16 | - Using `client-go` with [Kubernetes 1.5](#kubernetes-15) 17 | - [Related](#related) 18 | 19 | ## Prerequisites 20 | 21 | ### Go 22 | 23 | The snippets shown here have been tested using Go 1.8 and should also work with Go 1.9 (not tested, yet). 24 | 25 | In order to manage dependencies (aka vendoring in Go) we use Go [dep](https://github.com/golang/dep). 26 | If you don't have Go `dep` installed yet, simply do the following: 27 | 28 | ``` 29 | $ go get -u github.com/golang/dep/cmd/dep 30 | $ dep init # only the first time if no Gopkg.* exist in the project 31 | $ dep ensure # every time you add/change dependencies 32 | ``` 33 | 34 | Note that if you're new to Go dep and/or dependency management, you might want to read 35 | [Using Go dep as a project maintainer](https://hackernoon.com/using-go-dep-as-a-project-maintainer-641d1f3006d7) 36 | before you proceed. 37 | 38 | Note also, if you want to contribute a snippet, we're using [Bats](https://github.com/sstephenson/bats) for testing. 39 | 40 | ### Kubernetes cluster 41 | 42 | The snippets assume that you have a Kubernetes cluster running. 43 | You can, for example, install [Minikube](https://github.com/kubernetes/minikube) or [Minishift](https://github.com/minishift/minishift) to test it locally. 44 | 45 | ### Get snippets 46 | 47 | To enjoy all the snippets, do the following now: 48 | 49 | ``` 50 | $ mkdir -p $GOPATH/src/mhausenblas && cd $GOPATH/src/mhausenblas 51 | $ git clone https://github.com/mhausenblas/using-client-go.git 52 | ``` 53 | 54 | ## Kubernetes 1.7 55 | 56 | Once you're using one or more of the snippets, that is, you have imports that reference one or more `client-go` packages, use the following in your `Gopkg.toml` file. Add it if it doesn't exist, otherwise update it: 57 | 58 | ``` 59 | [[constraint]] 60 | name = "k8s.io/client-go" 61 | version = "v4.0.0" 62 | 63 | [[constraint]] 64 | name = "k8s.io/apimachinery" 65 | branch = "release-1.7" 66 | ``` 67 | 68 | After you've updated your `Gopkg.toml` file, do `dep ensure` and commit it to your repo. 69 | 70 | Now you can move on to the [Kubernetes 1.7 snippets](1.7/). 71 | 72 | ## Kubernetes 1.6 73 | 74 | Once you're using one or more of the snippets, that is, you have imports that reference one or more `client-go` packages, use the following in your `Gopkg.toml` file. Add it if it doesn't exist, otherwise update it: 75 | 76 | ``` 77 | [[constraint]] 78 | name = "k8s.io/client-go" 79 | version = "v3.0.0" 80 | 81 | [[override]] 82 | name = "k8s.io/apimachinery" 83 | branch = "release-1.6" 84 | ``` 85 | 86 | After you've updated your `Gopkg.toml` file, do `dep ensure` and commit it to your repo. 87 | 88 | ## Kubernetes 1.5 89 | 90 | TBD 91 | 92 | ## Related 93 | 94 | Resources available on the Web around the 'using client-go' topic: 95 | 96 | - [client-go Examples](https://github.com/kubernetes/client-go/tree/master/examples) from the official repo 97 | - [Using Kubernetes Go Client to Launch a Jupyter Notebook](https://www.rushtehrani.com/post/using-kubernetes-api/) 12/2016 98 | - [Using the Kubernetes Client for Go](https://developers.redhat.com/blog/2016/11/25/using-the-kubernetes-client-for-go/) 11/2016 99 | - StackOverflow [How can I create a simple client app with the Kubernetes Go library?](https://stackoverflow.com/questions/32554893/how-can-i-create-a-simple-client-app-with-the-kubernetes-go-library) 100 | 101 | Related artifacts and activities: 102 | 103 | - SIG [API Machinery](https://github.com/kubernetes/community/tree/master/sig-api-machinery) 104 | - [kubernetes/apimachinery](https://github.com/kubernetes/apimachinery) 105 | - [kubernetes/metrics](https://github.com/kubernetes/metrics) 106 | - [kubernetes/code-generator](https://github.com/kubernetes/code-generator) which is currently empty, see this [PR](https://github.com/kubernetes/kubernetes/pull/49114) for the status 107 | --------------------------------------------------------------------------------