diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..963b3289 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# Compiled Object files, Static and Dynamic libs (Shared Objects) +*.o +*.a +*.so + +# Folders +_obj +_test + +# Architecture specific extensions/prefixes +*.[568vq] +[568vq].out + +*.cgo1.go +*.cgo2.c +_cgo_defun.c +_cgo_gotypes.go +_cgo_export.* + +_testmain.go + +*.exe +*.test +*.prof +.idea/ +dist/ +**/junit.xml +**/.env +.vscode/ +vendor/ +coverage.txt diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 00000000..ee8e4750 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,23 @@ +language: go +go: + - 1.x + - tip + +env: + - DEP_VERSION="0.4.1" + +before_install: + # Download the binary to bin folder in $GOPATH + - curl -L -s https://github.com/golang/dep/releases/download/v${DEP_VERSION}/dep-linux-amd64 -o $GOPATH/bin/dep + # Make the binary executable + - chmod +x $GOPATH/bin/dep + +install: + - dep ensure + +script: + - go build ./... + - ./hack/coverage.sh + +after_success: + - bash <(curl -s https://codecov.io/bash) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..771f2e48 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,38 @@ +# How to Contribute + +AppsCode projects are [Apache 2.0 licensed](LICENSE) and accept contributions via +GitHub pull requests. This document outlines some of the conventions on +development workflow, commit message formatting, contact points and other +resources to make it easier to get your contribution accepted. + +## Certificate of Origin + +By contributing to this project you agree to the Developer Certificate of +Origin (DCO). This document was created by the Linux Kernel community and is a +simple statement that you, as a contributor, have the legal right to make the +contribution. See the [DCO](DCO) file for details. + +## Developer Guide +We have a [Developer Guide](/docs/developer-guide/README.md) that outlines everything you need to know from setting up your +dev environment to how to build and test Kutil. If you find something undocumented or incorrect along the way, +please feel free to send a Pull Request. + +## Getting Help +If you have a question about Kutil or having problem using it, you can contact us on our public Slack channel. Follow [this link](https://slack.appscode.com) to get invitation to our Slack channel. + +## Bugs/Feature request +If you have found a bug with Kutil or want to request for new features, please [file an issue](https://github.com/appscode/Kutil/issues/new). + +## Contribution Flow +If you fix a bug or developed a new feature, feel free to submit a PR. In either case, please file a [Github issue]((https://github.com/appscode/kutil/issues/new)) first, so that we can have a discussion on it. This is a rough outline of what a contributor's workflow looks like: + +- Create a topic branch from where you want to base your work (usually master). +- Make commits of logical units. +- Push your changes to a topic branch in your fork of the repository. +- Make sure the tests pass, and add any new tests as appropriate. +- Submit a pull request to the original repository. + +Thanks for your contributions! + +## Spread the word +If you have written blog post or tutorial on Kutil, please share it with us on [Twitter](https://twitter.com/AppsCodeHQ) or [Slack](https://slack.appscode.com). diff --git a/DCO b/DCO new file mode 100644 index 00000000..716561d5 --- /dev/null +++ b/DCO @@ -0,0 +1,36 @@ +Developer Certificate of Origin +Version 1.1 + +Copyright (C) 2004, 2006 The Linux Foundation and its contributors. +660 York Street, Suite 102, +San Francisco, CA 94110 USA + +Everyone is permitted to copy and distribute verbatim copies of this +license document, but changing it is not allowed. + + +Developer's Certificate of Origin 1.1 + +By making a contribution to this project, I certify that: + +(a) The contribution was created in whole or in part by me and I + have the right to submit it under the open source license + indicated in the file; or + +(b) The contribution is based upon previous work that, to the best + of my knowledge, is covered under an appropriate open source + license and I have the right under that license to submit that + work with modifications, whether created in whole or in part + by me, under the same open source license (unless I am + permitted to submit under a different license), as indicated + in the file; or + +(c) The contribution was provided directly to me by some other + person who certified (a), (b) or (c) and I have not modified + it. + +(d) I understand and agree that this project and the contribution + are public and that a record of the contribution (including all + personal information I submit with it, including my sign-off) is + maintained indefinitely and may be redistributed consistent with + this project or the open source license(s) involved. diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 00000000..d0a03ada --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,453 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + name = "cloud.google.com/go" + packages = ["compute/metadata"] + revision = "20d4028b8a750c2aca76bf9fefa8ed2d0109b573" + version = "v0.19.0" + +[[projects]] + name = "github.com/Azure/go-autorest" + packages = [ + "autorest", + "autorest/adal", + "autorest/azure", + "autorest/date" + ] + revision = "fc3b03a2d2d1f43fad3007038bd16f044f870722" + version = "v9.10.0" + +[[projects]] + name = "github.com/PuerkitoBio/purell" + packages = ["."] + revision = "0bcb03f4b4d0a9428594752bd2a3b9aa0a9d4bd4" + version = "v1.1.0" + +[[projects]] + branch = "master" + name = "github.com/PuerkitoBio/urlesc" + packages = ["."] + revision = "de5bf2ad457846296e2031421a34e2568e304e35" + +[[projects]] + branch = "master" + name = "github.com/appscode/jsonpatch" + packages = ["."] + revision = "3e75a56b8967932466984d4432401e1c1a7ff61e" + +[[projects]] + branch = "master" + name = "github.com/appscode/kutil" + packages = [ + "admission", + "runtime/serializer/versioning", + "workload/v1" + ] + revision = "436b54978ae275a61a06baa3f0a119864691cf12" + +[[projects]] + name = "github.com/dgrijalva/jwt-go" + packages = ["."] + revision = "06ea1031745cb8b3dab3f6a236daf2b0aa468b7e" + version = "v3.2.0" + +[[projects]] + name = "github.com/docker/distribution" + packages = [ + "digestset", + "reference" + ] + revision = "edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c" + +[[projects]] + name = "github.com/emicklei/go-restful" + packages = [ + ".", + "log" + ] + revision = "26b41036311f2da8242db402557a0dbd09dc83da" + version = "v2.6.0" + +[[projects]] + name = "github.com/ghodss/yaml" + packages = ["."] + revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" + version = "v1.0.0" + +[[projects]] + branch = "master" + name = "github.com/go-openapi/jsonpointer" + packages = ["."] + revision = "779f45308c19820f1a69e9a4cd965f496e0da10f" + +[[projects]] + branch = "master" + name = "github.com/go-openapi/jsonreference" + packages = ["."] + revision = "36d33bfe519efae5632669801b180bf1a245da3b" + +[[projects]] + branch = "master" + name = "github.com/go-openapi/spec" + packages = ["."] + revision = "d8000b5bfbd1147255710505a27c735b6b2ae2ac" + +[[projects]] + branch = "master" + name = "github.com/go-openapi/swag" + packages = ["."] + revision = "ceb469cb0fdf2d792f28d771bc05da6c606f55e5" + +[[projects]] + name = "github.com/gogo/protobuf" + packages = [ + "proto", + "sortkeys" + ] + revision = "1adfc126b41513cc696b209667c8656ea7aac67c" + version = "v1.0.0" + +[[projects]] + branch = "master" + name = "github.com/golang/glog" + packages = ["."] + revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" + +[[projects]] + name = "github.com/golang/protobuf" + packages = ["proto"] + revision = "925541529c1fa6821df4e44ce2723319eb2be768" + version = "v1.0.0" + +[[projects]] + branch = "master" + name = "github.com/google/btree" + packages = ["."] + revision = "e89373fe6b4a7413d7acd6da1725b83ef713e6e4" + +[[projects]] + branch = "master" + name = "github.com/google/gofuzz" + packages = ["."] + revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" + +[[projects]] + branch = "master" + name = "github.com/gophercloud/gophercloud" + packages = [ + ".", + "openstack", + "openstack/identity/v2/tenants", + "openstack/identity/v2/tokens", + "openstack/identity/v3/tokens", + "openstack/utils", + "pagination" + ] + revision = "3aef8e417612ddbdd8f7a76004af4307296cd1b6" + +[[projects]] + branch = "master" + name = "github.com/gregjones/httpcache" + packages = [ + ".", + "diskcache" + ] + revision = "9cad4c3443a7200dd6400aef47183728de563a38" + +[[projects]] + name = "github.com/json-iterator/go" + packages = ["."] + revision = "ca39e5af3ece67bbcda3d0f4f56a8e24d9f2dad4" + version = "1.1.3" + +[[projects]] + name = "github.com/juju/ratelimit" + packages = ["."] + revision = "59fac5042749a5afb9af70e813da1dd5474f0167" + version = "1.0.1" + +[[projects]] + branch = "master" + name = "github.com/mailru/easyjson" + packages = [ + "buffer", + "jlexer", + "jwriter" + ] + revision = "517203d186eb343d3df4068565cc0446b450d2c4" + +[[projects]] + name = "github.com/modern-go/concurrent" + packages = ["."] + revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" + version = "1.0.3" + +[[projects]] + name = "github.com/modern-go/reflect2" + packages = ["."] + revision = "1df9eeb2bb81f327b96228865c5687bc2194af3f" + version = "1.0.0" + +[[projects]] + name = "github.com/opencontainers/go-digest" + packages = ["."] + revision = "279bed98673dd5bef374d3b6e4b09e2af76183bf" + version = "v1.0.0-rc1" + +[[projects]] + name = "github.com/pborman/uuid" + packages = ["."] + revision = "e790cca94e6cc75c7064b1332e63811d4aae1a53" + version = "v1.1" + +[[projects]] + branch = "master" + name = "github.com/petar/GoLLRB" + packages = ["llrb"] + revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" + +[[projects]] + name = "github.com/peterbourgon/diskv" + packages = ["."] + revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" + version = "v2.0.1" + +[[projects]] + name = "github.com/spf13/pflag" + packages = ["."] + revision = "e57e3eeb33f795204c1ca35f56c44f83227c6e66" + version = "v1.0.0" + +[[projects]] + branch = "release-branch.go1.9" + name = "golang.org/x/net" + packages = [ + "context", + "context/ctxhttp", + "http2", + "http2/hpack", + "idna", + "lex/httplex" + ] + revision = "44b7c21cbf19450f38b337eb6b6fe4f6496fb5b3" + +[[projects]] + branch = "master" + name = "golang.org/x/oauth2" + packages = [ + ".", + "google", + "internal", + "jws", + "jwt" + ] + revision = "fdc9e635145ae97e6c2cb777c48305600cf515cb" + +[[projects]] + name = "golang.org/x/text" + packages = [ + "collate", + "collate/build", + "internal/colltab", + "internal/gen", + "internal/tag", + "internal/triegen", + "internal/ucd", + "language", + "secure/bidirule", + "transform", + "unicode/bidi", + "unicode/cldr", + "unicode/norm", + "unicode/rangetable", + "width" + ] + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + +[[projects]] + name = "google.golang.org/appengine" + packages = [ + ".", + "internal", + "internal/app_identity", + "internal/base", + "internal/datastore", + "internal/log", + "internal/modules", + "internal/remote_api", + "internal/urlfetch", + "urlfetch" + ] + revision = "150dc57a1b433e64154302bdc40b6bb8aefa313a" + version = "v1.0.0" + +[[projects]] + name = "gopkg.in/inf.v0" + packages = ["."] + revision = "3887ee99ecf07df5b447e9b00d9c0b2adaa9f3e4" + version = "v0.9.0" + +[[projects]] + name = "gopkg.in/yaml.v2" + packages = ["."] + revision = "7f97868eec74b32b0982dd158a51a446d1da7eb5" + version = "v2.1.1" + +[[projects]] + name = "k8s.io/api" + packages = [ + "admission/v1beta1", + "apps/v1", + "apps/v1beta1", + "apps/v1beta2", + "authentication/v1", + "batch/v1", + "batch/v1beta1", + "batch/v2alpha1", + "core/v1", + "extensions/v1beta1" + ] + revision = "af4bc157c3a209798fc897f6d4aaaaeb6c2e0d6a" + version = "kubernetes-1.9.0" + +[[projects]] + branch = "master" + name = "k8s.io/apiextensions-apiserver" + packages = ["pkg/features"] + revision = "d8502160be313d4caef49987736fd30723a763d4" + +[[projects]] + name = "k8s.io/apimachinery" + packages = [ + "pkg/api/equality", + "pkg/api/errors", + "pkg/api/meta", + "pkg/api/resource", + "pkg/api/validation", + "pkg/api/validation/path", + "pkg/apimachinery", + "pkg/apimachinery/announced", + "pkg/apimachinery/registered", + "pkg/apis/meta/internalversion", + "pkg/apis/meta/v1", + "pkg/apis/meta/v1/unstructured", + "pkg/apis/meta/v1/validation", + "pkg/apis/meta/v1alpha1", + "pkg/conversion", + "pkg/conversion/queryparams", + "pkg/fields", + "pkg/labels", + "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/errors", + "pkg/util/framer", + "pkg/util/intstr", + "pkg/util/json", + "pkg/util/net", + "pkg/util/rand", + "pkg/util/runtime", + "pkg/util/sets", + "pkg/util/uuid", + "pkg/util/validation", + "pkg/util/validation/field", + "pkg/util/wait", + "pkg/util/yaml", + "pkg/version", + "pkg/watch", + "third_party/forked/golang/reflect" + ] + revision = "180eddb345a5be3a157cea1c624700ad5bd27b8f" + version = "kubernetes-1.9.0" + +[[projects]] + name = "k8s.io/apiserver" + packages = [ + "pkg/admission", + "pkg/apis/apiserver", + "pkg/apis/apiserver/v1alpha1", + "pkg/apis/audit", + "pkg/authentication/user", + "pkg/endpoints/request", + "pkg/features", + "pkg/registry/rest", + "pkg/storage/names", + "pkg/util/feature" + ] + revision = "91e14f394e4796abf5a994a349a222e7081d86b6" + version = "kubernetes-1.9.0" + +[[projects]] + name = "k8s.io/client-go" + packages = [ + "pkg/version", + "plugin/pkg/client/auth", + "plugin/pkg/client/auth/azure", + "plugin/pkg/client/auth/gcp", + "plugin/pkg/client/auth/oidc", + "plugin/pkg/client/auth/openstack", + "rest", + "rest/watch", + "third_party/forked/golang/template", + "tools/clientcmd/api", + "tools/metrics", + "transport", + "util/cert", + "util/flowcontrol", + "util/integer", + "util/jsonpath" + ] + revision = "78700dec6369ba22221b72770783300f143df150" + version = "v6.0.0" + +[[projects]] + branch = "master" + name = "k8s.io/kube-openapi" + packages = ["pkg/common"] + revision = "50ae88d24ede7b8bad68e23c805b5d3da5c8abaf" + +[[projects]] + name = "k8s.io/kubernetes" + packages = [ + "pkg/api/legacyscheme", + "pkg/apis/apps", + "pkg/apis/apps/install", + "pkg/apis/apps/v1", + "pkg/apis/apps/v1beta1", + "pkg/apis/apps/v1beta2", + "pkg/apis/autoscaling", + "pkg/apis/batch", + "pkg/apis/batch/install", + "pkg/apis/batch/v1", + "pkg/apis/batch/v1beta1", + "pkg/apis/batch/v2alpha1", + "pkg/apis/core", + "pkg/apis/core/install", + "pkg/apis/core/v1", + "pkg/apis/extensions", + "pkg/apis/extensions/install", + "pkg/apis/extensions/v1beta1", + "pkg/apis/networking", + "pkg/features", + "pkg/util/parsers", + "pkg/util/pointer" + ] + revision = "925c127ec6b946659ad0fd596fa959be43f0cc05" + version = "v1.9.0" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + inputs-digest = "73f3c618546e4f8bdbe31763d1bc5777bb7c2f966eb3c14c4d5a822e4497d7e8" + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 00000000..63079bb6 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,94 @@ +# Gopkg.toml example +# +# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md +# for detailed Gopkg.toml documentation. +# +# required = ["github.com/user/thing/cmd/thing"] +# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"] +# +# [[constraint]] +# name = "github.com/user/project" +# version = "1.0.0" +# +# [[constraint]] +# name = "github.com/user/project2" +# branch = "dev" +# source = "github.com/myfork/project2" +# +# [[override]] +# name = "github.com/x/y" +# version = "2.4.0" +# +# [prune] +# non-go = false +# go-tests = true +# unused-packages = true + + +[[constraint]] + branch = "master" + name = "github.com/appscode/jsonpatch" + +[[constraint]] + branch = "release-6.0" + name = "github.com/appscode/kutil" + +[[constraint]] + name = "github.com/json-iterator/go" + version = "1.1.3" + +[[constraint]] + name = "k8s.io/api" + version = "kubernetes-1.9.0" + +[[constraint]] + name = "k8s.io/apimachinery" + version = "kubernetes-1.9.0" + +[[constraint]] + name = "k8s.io/apiserver" + version = "kubernetes-1.9.0" + +[[constraint]] + name = "k8s.io/client-go" + version = "6.0.0" + +[[constraint]] + name = "k8s.io/kubernetes" + version = "=v1.9.0" + +[[override]] + branch = "release-branch.go1.9" + name = "golang.org/x/net" + +[[override]] + name = "github.com/Azure/azure-sdk-for-go" + version = "v11.1.1-beta" + +[[override]] + name = "github.com/Azure/go-autorest" + version = "v9.1.0" + +[[override]] + name = "github.com/docker/distribution" + revision = "edc3ab29cdff8694dd6feb85cfeb4b5f1b38ed9c" + +[[override]] + name = "github.com/docker/docker" + revision = "4f3616fb1c112e206b88cb7a9922bf49067a7756" + +[[override]] + name = "github.com/docker/go-connections" + version = "v0.3.0" + +[[override]] + name = "github.com/docker/go-units" + revision = "9e638d38cf6977a37a8ea0078f3ee75a7cdb2dd1" + +[[override]] + name = "github.com/docker/libtrust" + revision = "9cbd2a1374f46905c68a4eb3694a130610adc62a" + +[prune] + go-tests = true + unused-packages = true diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..8dada3ed --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "{}" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright {yyyy} {name of copyright owner} + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/README.md b/README.md new file mode 100644 index 00000000..b6270812 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +[![Go Report Card](https://goreportcard.com/badge/github.com/appscode/kubernetes-webhook-util)](https://goreportcard.com/report/github.com/appscode/kubernetes-webhook-util) +[![GoDoc](https://godoc.org/github.com/appscode/kubernetes-webhook-util?status.svg "GoDoc")](https://godoc.org/github.com/appscode/kubernetes-webhook-util) +[![Build Status](https://travis-ci.org/appscode/kubernetes-webhook-util.svg?branch=master)](https://travis-ci.org/appscode/kubernetes-webhook-util) +[![codecov](https://codecov.io/gh/appscode/kubernetes-webhook-util/branch/master/graph/badge.svg)](https://codecov.io/gh/appscode/kubernetes-webhook-util) +[![Slack](https://slack.appscode.com/badge.svg)](https://slack.appscode.com) +[![Twitter](https://img.shields.io/twitter/follow/appscodehq.svg?style=social&logo=twitter&label=Follow)](https://twitter.com/intent/follow?screen_name=AppsCodeHQ) + +# kubernetes-webhook-util +Kubernetes webhook utils diff --git a/admission/v1beta1/generic.go b/admission/v1beta1/generic.go index 1b981d55..cbf64276 100644 --- a/admission/v1beta1/generic.go +++ b/admission/v1beta1/generic.go @@ -5,8 +5,8 @@ import ( "sync" jp "github.com/appscode/jsonpatch" - "github.com/appscode/kutil/admission" - "github.com/appscode/kutil/runtime/serializer/versioning" + "github.com/appscode/kubernetes-webhook-util/admission" + "github.com/appscode/kubernetes-webhook-util/runtime/serializer/versioning" "k8s.io/api/admission/v1beta1" kerr "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime/schema" diff --git a/admission/v1beta1/workload.go b/admission/v1beta1/workload.go index a414e25d..6bd4ebfe 100644 --- a/admission/v1beta1/workload.go +++ b/admission/v1beta1/workload.go @@ -5,9 +5,9 @@ import ( "sync" jp "github.com/appscode/jsonpatch" - "github.com/appscode/kutil/admission" - "github.com/appscode/kutil/runtime/serializer/versioning" - workload "github.com/appscode/kutil/workload/v1" + "github.com/appscode/kubernetes-webhook-util/admission" + "github.com/appscode/kubernetes-webhook-util/runtime/serializer/versioning" + workload "github.com/appscode/kubernetes-webhook-util/workload/v1" "k8s.io/api/admission/v1beta1" appsv1 "k8s.io/api/apps/v1" batchv1 "k8s.io/api/batch/v1" diff --git a/hack/builddeps.sh b/hack/builddeps.sh new file mode 100755 index 00000000..935e79cb --- /dev/null +++ b/hack/builddeps.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +# https://github.com/ellisonbg/antipackage +pip install git+https://github.com/ellisonbg/antipackage.git#egg=antipackage +pip install pyyaml + +go get -u golang.org/x/tools/cmd/goimports +go get github.com/Masterminds/glide +go get github.com/sgotti/glide-vc diff --git a/hack/codegen.sh b/hack/codegen.sh new file mode 100755 index 00000000..6b80b102 --- /dev/null +++ b/hack/codegen.sh @@ -0,0 +1,22 @@ +#!/bin/bash + +set -x + +GOPATH=$(go env GOPATH) +PACKAGE_NAME=github.com/appscode/kubernetes-webhook-util +REPO_ROOT="$GOPATH/src/$PACKAGE_NAME" +DOCKER_REPO_ROOT="/go/src/$PACKAGE_NAME" + +pushd $REPO_ROOT + +# Generate deep copies +docker run --rm -ti -u $(id -u):$(id -g) \ + -v "$REPO_ROOT":"$DOCKER_REPO_ROOT" \ + -w "$DOCKER_REPO_ROOT" \ + appscode/gengo:release-1.9 deepcopy-gen \ + --v 1 --logtostderr \ + --go-header-file "hack/gengo/boilerplate.go.txt" \ + --input-dirs "$PACKAGE_NAME/workload/v1" \ + --output-file-base zz_generated.deepcopy + +popd diff --git a/hack/coverage.sh b/hack/coverage.sh new file mode 100755 index 00000000..4b81dd99 --- /dev/null +++ b/hack/coverage.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash +set -eou pipefail + +GOPATH=$(go env GOPATH) +REPO_ROOT="$GOPATH/src/github.com/appscode/kubernetes-webhook-util" + +pushd $REPO_ROOT + +echo "" > coverage.txt + +for d in $(go list ./... | grep -v -e vendor -e test); do + go test -v -race -coverprofile=profile.out -covermode=atomic "$d" + if [ -f profile.out ]; then + cat profile.out >> coverage.txt + rm profile.out + fi +done + +popd diff --git a/hack/gengo/boilerplate.go.txt b/hack/gengo/boilerplate.go.txt new file mode 100644 index 00000000..fbebcce5 --- /dev/null +++ b/hack/gengo/boilerplate.go.txt @@ -0,0 +1,16 @@ +/* +Copyright YEAR The kubernetes-webhook-util Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + diff --git a/hack/make.py b/hack/make.py new file mode 100755 index 00000000..08ba110d --- /dev/null +++ b/hack/make.py @@ -0,0 +1,102 @@ +#!/usr/bin/env python + + +# http://stackoverflow.com/a/14050282 +def check_antipackage(): + from sys import version_info + sys_version = version_info[:2] + found = True + if sys_version < (3, 0): + # 'python 2' + from pkgutil import find_loader + found = find_loader('antipackage') is not None + elif sys_version <= (3, 3): + # 'python <= 3.3' + from importlib import find_loader + found = find_loader('antipackage') is not None + else: + # 'python >= 3.4' + from importlib import util + found = util.find_spec('antipackage') is not None + if not found: + print('Install missing package "antipackage"') + print('Example: pip install git+https://github.com/ellisonbg/antipackage.git#egg=antipackage') + from sys import exit + exit(1) +check_antipackage() + +# ref: https://github.com/ellisonbg/antipackage +import antipackage +from github.appscode.libbuild import libbuild, pydotenv + +import os +import os.path +import subprocess +import sys +from os.path import expandvars, join, dirname + +libbuild.REPO_ROOT = expandvars('$GOPATH') + '/src/github.com/appscode/kubernetes-webhook-util' +BUILD_METADATA = libbuild.metadata(libbuild.REPO_ROOT) + + +def call(cmd, stdin=None, cwd=libbuild.REPO_ROOT): + print(cmd) + return subprocess.call([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) + + +def die(status): + if status: + sys.exit(status) + + +def check_output(cmd, stdin=None, cwd=libbuild.REPO_ROOT): + print(cmd) + return subprocess.check_output([expandvars(cmd)], shell=True, stdin=stdin, cwd=cwd) + + +def version(): + # json.dump(BUILD_METADATA, sys.stdout, sort_keys=True, indent=2) + for k in sorted(BUILD_METADATA): + print(k + '=' + BUILD_METADATA[k]) + + +def fmt(): + libbuild.ungroup_go_imports('admission', 'registry', 'runtime', 'workload') + die(call('goimports -w admission registry runtime workload')) + call('gofmt -s -w admission registry runtime workload') + + +def vet(): + call('go vet ./admission/... ./registry/... ./runtime/... ./workload/...') + + +def lint(): + call('golint *.go') + call('golint ./admission/...') + call('golint ./registry/...') + call('golint ./runtime/...') + call('golint ./workload/...') + + +def gen(): + return + + +def install(): + die(call('GO15VENDOREXPERIMENT=1 ' + libbuild.GOC + ' install ./...')) + + +def default(): + gen() + fmt() + vet() + install() + + +if __name__ == "__main__": + if len(sys.argv) > 1: + # http://stackoverflow.com/a/834451 + # http://stackoverflow.com/a/817296 + globals()[sys.argv[1]](*sys.argv[2:]) + else: + default() \ No newline at end of file diff --git a/runtime/serializer/versioning/codec.go b/runtime/serializer/versioning/codec.go index 5f9a2e4b..91dd6c4d 100644 --- a/runtime/serializer/versioning/codec.go +++ b/runtime/serializer/versioning/codec.go @@ -34,8 +34,8 @@ var YAMLSerializer = func() runtime.Codec { }() type codec struct { - encoder runtime.Encoder - decoder runtime.Decoder + encoder runtime.Encoder + decoder runtime.Decoder scheme *runtime.Scheme defaulter runtime.ObjectDefaulter encodeVersion schema.GroupVersion @@ -52,8 +52,8 @@ func NewDefaultingCodecForScheme( decodeVersion schema.GroupVersion, ) runtime.Codec { return codec{ - encoder: encoder, - decoder: decoder, + encoder: encoder, + decoder: decoder, scheme: scheme, defaulter: defaulter, encodeVersion: encodeVersion, diff --git a/workload/v1/factory.go b/workload/v1/factory.go index ff381781..ed7a5fd6 100644 --- a/workload/v1/factory.go +++ b/workload/v1/factory.go @@ -24,7 +24,7 @@ func New(t metav1.TypeMeta, o metav1.ObjectMeta, tpl core.PodTemplateSpec) *Work } } -func newWithObject(t metav1.TypeMeta, o metav1.ObjectMeta, sel *metav1.LabelSelector, tpl core.PodTemplateSpec, obj runtime.Object) *Workload { +func newWithObject(t metav1.TypeMeta, o metav1.ObjectMeta, sel *metav1.LabelSelector, tpl core.PodTemplateSpec, obj runtime.Object) *Workload { return &Workload{ TypeMeta: t, ObjectMeta: o, @@ -32,7 +32,7 @@ func newWithObject(t metav1.TypeMeta, o metav1.ObjectMeta, sel *metav1.LabelSele Selector: sel, Template: tpl, }, - Object: obj, + Object: obj, } } @@ -46,7 +46,7 @@ func ConvertToWorkload(obj runtime.Object) (*Workload, error) { if t.Spec.Template == nil { t.Spec.Template = &core.PodTemplateSpec{} } - return newWithObject(t.TypeMeta, t.ObjectMeta, &metav1.LabelSelector{MatchLabels: t.Spec.Selector}, *t.Spec.Template, obj), nil + return newWithObject(t.TypeMeta, t.ObjectMeta, &metav1.LabelSelector{MatchLabels: t.Spec.Selector}, *t.Spec.Template, obj), nil // Deployment case *extensions.Deployment: return newWithObject(t.TypeMeta, t.ObjectMeta, t.Spec.Selector, t.Spec.Template, obj), nil