diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..d266575946 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/*.swp +.DS_Store diff --git a/Gopkg.lock b/Gopkg.lock new file mode 100644 index 0000000000..4c3e243b01 --- /dev/null +++ b/Gopkg.lock @@ -0,0 +1,492 @@ +# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'. + + +[[projects]] + branch = "go15" + digest = "1:8dab0033e231d02909f00a501a1f1ac01e63fd267dcb374a5de71b99ba1ee74f" + name = "github.com/ajeddeloh/go-json" + packages = ["."] + pruneopts = "NUT" + revision = "6a2fe990e08303c82d966297ddb29a58678a4783" + +[[projects]] + digest = "1:0ef770954bca104ee99b3b6b7f9b240605ac03517d9f98cbc1893daa03f3c038" + name = "github.com/coreos/go-semver" + packages = ["semver"] + pruneopts = "NUT" + revision = "8ab6407b697782a06568d4b7f1db25550ec2e4c6" + version = "v0.2.0" + +[[projects]] + digest = "1:2ed7e62c94645be6b47be0911035fbabaa6271b20138d3643488716b5c6cad41" + name = "github.com/coreos/go-systemd" + packages = ["unit"] + pruneopts = "NUT" + revision = "39ca1b05acc7ad1220e09f133283b8859a8b71ab" + version = "v17" + +[[projects]] + digest = "1:fcf4d2e23fc77767d79bf9fc1833782ffd0778ac3f84fe318a1a278a7fe4d770" + name = "github.com/coreos/ignition" + packages = [ + "config/shared/errors", + "config/shared/validations", + "config/util", + "config/v1", + "config/v1/types", + "config/v2_0", + "config/v2_0/types", + "config/v2_1", + "config/v2_1/types", + "config/v2_2", + "config/v2_2/types", + "config/v2_3_experimental/types", + "config/validate", + "config/validate/astjson", + "config/validate/astnode", + "config/validate/report", + ] + pruneopts = "NUT" + revision = "76107251acd117c6d3e5b4dae2b47f82f944984b" + version = "v0.26.0" + +[[projects]] + digest = "1:a2c1d0e43bd3baaa071d1b9ed72c27d78169b2b269f71c105ac4ba34b1be4a39" + name = "github.com/davecgh/go-spew" + packages = ["spew"] + pruneopts = "NUT" + revision = "346938d642f2ec3594ed81d874461961cd0faa76" + version = "v1.1.0" + +[[projects]] + digest = "1:81466b4218bf6adddac2572a30ac733a9255919bc2f470b4827a317bd4ee1756" + name = "github.com/ghodss/yaml" + packages = ["."] + pruneopts = "NUT" + revision = "0ca9ea5df5451ffdf184b4428c902747c2c11cd7" + version = "v1.0.0" + +[[projects]] + digest = "1:219b2e7d9a6cbe77079dddc3f26b77cbafaa2f23e5fc4eba4251d04f2a843202" + name = "github.com/gogo/protobuf" + packages = [ + "proto", + "sortkeys", + ] + pruneopts = "NUT" + revision = "636bf0302bc95575d69441b25a2603156ffdddf1" + version = "v1.1.1" + +[[projects]] + branch = "master" + digest = "1:e2b86e41f3d669fc36b50d31d32d22c8ac656c75aa5ea89717ce7177e134ff2a" + name = "github.com/golang/glog" + packages = ["."] + pruneopts = "NUT" + revision = "23def4e6c14b4da8ac2ed8007337bc5eb5007998" + +[[projects]] + digest = "1:713cc7628304d027a7e9edcb52da888a8912d6405250a8d9c8eff6f41dd54398" + name = "github.com/golang/protobuf" + packages = [ + "proto", + "ptypes", + "ptypes/any", + "ptypes/duration", + "ptypes/timestamp", + ] + pruneopts = "NUT" + revision = "b4deda0973fb4c70b50d226b1af49f3da59f5265" + version = "v1.1.0" + +[[projects]] + branch = "master" + digest = "1:245bd4eb633039cd66106a5d340ae826d87f4e36a8602fcc940e14176fd26ea7" + name = "github.com/google/btree" + packages = ["."] + pruneopts = "NUT" + revision = "e89373fe6b4a7413d7acd6da1725b83ef713e6e4" + +[[projects]] + branch = "master" + digest = "1:52c5834e2bebac9030c97cc0798ac11c3aa8a39f098aeb419f142533da6cd3cc" + name = "github.com/google/gofuzz" + packages = ["."] + pruneopts = "NUT" + revision = "24818f796faf91cd76ec7bddd72458fbced7a6c1" + +[[projects]] + digest = "1:add738701bd5b2b985c0c37011092c57218bdc46caf1e682a73dc210ad36b03f" + name = "github.com/googleapis/gnostic" + packages = [ + "OpenAPIv2", + "compiler", + "extensions", + ] + pruneopts = "NUT" + revision = "7c663266750e7d82587642f65e60bc4083f1f84e" + version = "v0.2.0" + +[[projects]] + branch = "master" + digest = "1:a1db0214936912602a7a8cedc09a2e3211f5c097dc89189fb4b3bc86346c9e89" + name = "github.com/gregjones/httpcache" + packages = [ + ".", + "diskcache", + ] + pruneopts = "NUT" + revision = "9cad4c3443a7200dd6400aef47183728de563a38" + +[[projects]] + branch = "master" + digest = "1:13e2fa5735a82a5fb044f290cfd0dba633d1c5e516b27da0509e0dbb3515a18e" + name = "github.com/hashicorp/golang-lru" + packages = [ + ".", + "simplelru", + ] + pruneopts = "NUT" + revision = "0fb14efe8c47ae851c0034ed7a448854d3d34cf3" + +[[projects]] + digest = "1:890dd7615573f096655600bbe7beb2f532a437f6d8ef237831894301fca31f23" + name = "github.com/json-iterator/go" + packages = ["."] + pruneopts = "" + revision = "ab8a2e0c74be9d3be70b3184d9acc634935ded82" + version = "1.1.4" + +[[projects]] + digest = "1:2f42fa12d6911c7b7659738758631bec870b7e9b4c6be5444f963cdcfccc191f" + name = "github.com/modern-go/concurrent" + packages = ["."] + pruneopts = "NUT" + revision = "bacd9c7ef1dd9b15be4a9909b8ac7a4e313eec94" + version = "1.0.3" + +[[projects]] + digest = "1:c6aca19413b13dc59c220ad7430329e2ec454cc310bc6d8de2c7e2b93c18a0f6" + name = "github.com/modern-go/reflect2" + packages = ["."] + pruneopts = "NUT" + revision = "4b7aa43c6742a2c18fdef89dd197aaae7dac7ccd" + version = "1.0.1" + +[[projects]] + branch = "master" + digest = "1:3bf17a6e6eaa6ad24152148a631d18662f7212e21637c2699bff3369b7f00fa2" + name = "github.com/petar/GoLLRB" + packages = ["llrb"] + pruneopts = "NUT" + revision = "53be0d36a84c2a886ca057d34b6aa4468df9ccb4" + +[[projects]] + digest = "1:6c6d91dc326ed6778783cff869c49fb2f61303cdd2ebbcf90abe53505793f3b6" + name = "github.com/peterbourgon/diskv" + packages = ["."] + pruneopts = "NUT" + revision = "5f041e8faa004a95c88a202771f4cc3e991971e6" + version = "v2.0.1" + +[[projects]] + digest = "1:15e5c398fbd9d2c439b635a08ac161b13d04f0c2aa587fe256b65dc0c3efe8b7" + name = "github.com/spf13/pflag" + packages = ["."] + pruneopts = "NUT" + revision = "583c0c0531f06d5278b7d917446061adc344b5cd" + version = "v1.0.1" + +[[projects]] + branch = "master" + digest = "1:c9b456727ce4101594aabddaa816c80464cd21a1e5fcd145297a902303be0085" + name = "github.com/vincent-petithory/dataurl" + packages = ["."] + pruneopts = "NUT" + revision = "9a301d65acbb728fcc3ace14f45f511a4cfeea9c" + +[[projects]] + branch = "master" + digest = "1:91ed6116b126ec7fa7b9f9460356ee6b3005e5ed320b8e85510937f44d3d62d5" + name = "go4.org" + packages = ["errorutil"] + pruneopts = "NUT" + revision = "9599cf28b011184741f249bd9f9330756b506cbc" + +[[projects]] + branch = "master" + digest = "1:3f3a05ae0b95893d90b9b3b5afdb79a9b3d96e4e36e099d841ae602e4aca0da8" + name = "golang.org/x/crypto" + packages = ["ssh/terminal"] + pruneopts = "NUT" + revision = "c126467f60eb25f8f27e5a981f32a87e3965053f" + +[[projects]] + branch = "master" + digest = "1:d33361a6af4178e9ae5f4c00acc605530d132d720991f118673680bf4765f656" + name = "golang.org/x/net" + packages = [ + "context", + "http/httpguts", + "http2", + "http2/hpack", + "idna", + ] + pruneopts = "NUT" + revision = "3673e40ba22529d22c3fd7c93e97b0ce50fa7bdd" + +[[projects]] + branch = "master" + digest = "1:14d9028bd4f05d6817524d1cbd7f98c275e8c89d1ae42f0f7a6d0376d7172f7a" + name = "golang.org/x/sys" + packages = [ + "unix", + "windows", + ] + pruneopts = "NUT" + revision = "e072cadbbdc8dd3d3ffa82b8b4b9304c261d9311" + +[[projects]] + digest = "1:a0f29009397dc27c9dc8440f0945d49e5cbb9b72d0b0fc745474d9bfdea2d9f8" + 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", + ] + pruneopts = "NUT" + revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0" + version = "v0.3.0" + +[[projects]] + branch = "master" + digest = "1:c9e7a4b4d47c0ed205d257648b0e5b0440880cb728506e318f8ac7cd36270bc4" + name = "golang.org/x/time" + packages = ["rate"] + pruneopts = "NUT" + revision = "fbb02b2291d28baffd63558aa44b4b56f178d650" + +[[projects]] + branch = "master" + digest = "1:a464115f461c773a2b5ac42633ded88addc01fa36458345a7620959d839c578b" + name = "golang.org/x/tools" + packages = [ + "go/ast/astutil", + "imports", + "internal/fastwalk", + ] + pruneopts = "NUT" + revision = "475b7a1e12f029fbb4d210958352057952ea9f7a" + +[[projects]] + digest = "1:2d1fbdc6777e5408cabeb02bf336305e724b925ff4546ded0fa8715a7267922a" + name = "gopkg.in/inf.v0" + packages = ["."] + pruneopts = "NUT" + revision = "d2d2541c53f18d2a059457998ce2876cc8e67cbf" + version = "v0.9.1" + +[[projects]] + digest = "1:7c95b35057a0ff2e19f707173cc1a947fa43a6eb5c4d300d196ece0334046082" + name = "gopkg.in/yaml.v2" + packages = ["."] + pruneopts = "NUT" + revision = "5420a8b6744d3b0345ab293f6fcba19c978f1183" + version = "v2.2.1" + +[[projects]] + digest = "1:2b1dcda8169f9c511ebe70133cffab17a3fcc77c8d44b619e1d21dd375817e08" + name = "k8s.io/api" + packages = [ + "admissionregistration/v1alpha1", + "admissionregistration/v1beta1", + "apps/v1", + "apps/v1beta1", + "apps/v1beta2", + "authentication/v1", + "authentication/v1beta1", + "authorization/v1", + "authorization/v1beta1", + "autoscaling/v1", + "autoscaling/v2beta1", + "batch/v1", + "batch/v1beta1", + "batch/v2alpha1", + "certificates/v1beta1", + "core/v1", + "events/v1beta1", + "extensions/v1beta1", + "networking/v1", + "policy/v1beta1", + "rbac/v1", + "rbac/v1alpha1", + "rbac/v1beta1", + "scheduling/v1alpha1", + "scheduling/v1beta1", + "settings/v1alpha1", + "storage/v1", + "storage/v1alpha1", + "storage/v1beta1", + ] + pruneopts = "NUT" + revision = "2d6f90ab1293a1fb871cf149423ebb72aa7423aa" + version = "kubernetes-1.11.1" + +[[projects]] + digest = "1:72beb0d43199b082e859450e712dcf30f70c3f57b23f4b0659c2754b17c05edc" + name = "k8s.io/apimachinery" + packages = [ + "pkg/api/errors", + "pkg/api/meta", + "pkg/api/resource", + "pkg/apis/meta/internalversion", + "pkg/apis/meta/v1", + "pkg/apis/meta/v1/unstructured", + "pkg/apis/meta/v1beta1", + "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/cache", + "pkg/util/clock", + "pkg/util/diff", + "pkg/util/errors", + "pkg/util/framer", + "pkg/util/intstr", + "pkg/util/json", + "pkg/util/mergepatch", + "pkg/util/net", + "pkg/util/runtime", + "pkg/util/sets", + "pkg/util/strategicpatch", + "pkg/util/validation", + "pkg/util/validation/field", + "pkg/util/wait", + "pkg/util/yaml", + "pkg/version", + "pkg/watch", + "third_party/forked/golang/json", + "third_party/forked/golang/reflect", + ] + pruneopts = "NUT" + revision = "103fd098999dc9c0c88536f5c9ad2e5da39373ae" + version = "kubernetes-1.11.1" + +[[projects]] + digest = "1:ea92f7da45ff6f616a64f1cc744a1c7226fecfec802980818e81442c2be07cc5" + name = "k8s.io/client-go" + packages = [ + "discovery", + "discovery/fake", + "kubernetes/scheme", + "pkg/apis/clientauthentication", + "pkg/apis/clientauthentication/v1alpha1", + "pkg/apis/clientauthentication/v1beta1", + "pkg/version", + "plugin/pkg/client/auth/exec", + "rest", + "rest/watch", + "testing", + "tools/cache", + "tools/clientcmd/api", + "tools/metrics", + "tools/pager", + "transport", + "util/buffer", + "util/cert", + "util/connrotation", + "util/flowcontrol", + "util/integer", + "util/retry", + ] + pruneopts = "NUT" + revision = "7d04d0e2a0a1a4d4a1cd6baa432a2301492e4e65" + version = "v8.0.0" + +[[projects]] + digest = "1:277094fe099ad3ae25f5b4f7b5d67a5495b73a17392715083ece6caef89d5fc0" + name = "k8s.io/code-generator" + packages = [ + "cmd/client-gen", + "cmd/client-gen/args", + "cmd/client-gen/generators", + "cmd/client-gen/generators/fake", + "cmd/client-gen/generators/scheme", + "cmd/client-gen/generators/util", + "cmd/client-gen/path", + "cmd/client-gen/types", + "pkg/util", + ] + pruneopts = "" + revision = "6702109cc68eb6fe6350b83e14407c8d7309fd1a" + version = "kubernetes-1.11.1" + +[[projects]] + digest = "1:3ae27658bc8700d70f12b22275206853d6806fa4f21b0df3c3f3de9113d6d218" + name = "k8s.io/gengo" + packages = [ + "args", + "generator", + "namer", + "parser", + "types", + ] + pruneopts = "" + revision = "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2" + +[[projects]] + branch = "master" + digest = "1:a2c842a1e0aed96fd732b535514556323a6f5edfded3b63e5e0ab1bce188aa54" + name = "k8s.io/kube-openapi" + packages = ["pkg/util/proto"] + pruneopts = "NUT" + revision = "d8ea2fe547a448256204cfc68dfee7b26c720acb" + +[solve-meta] + analyzer-name = "dep" + analyzer-version = 1 + input-imports = [ + "github.com/coreos/ignition/config/v2_2", + "github.com/coreos/ignition/config/v2_2/types", + "k8s.io/api/core/v1", + "k8s.io/apimachinery/pkg/api/errors", + "k8s.io/apimachinery/pkg/apis/meta/v1", + "k8s.io/apimachinery/pkg/labels", + "k8s.io/apimachinery/pkg/runtime", + "k8s.io/apimachinery/pkg/runtime/schema", + "k8s.io/apimachinery/pkg/runtime/serializer", + "k8s.io/apimachinery/pkg/types", + "k8s.io/apimachinery/pkg/util/intstr", + "k8s.io/apimachinery/pkg/watch", + "k8s.io/client-go/discovery", + "k8s.io/client-go/discovery/fake", + "k8s.io/client-go/rest", + "k8s.io/client-go/testing", + "k8s.io/client-go/tools/cache", + "k8s.io/client-go/util/flowcontrol", + "k8s.io/code-generator/cmd/client-gen", + "k8s.io/gengo/types", + ] + solver-name = "gps-cdcl" + solver-version = 1 diff --git a/Gopkg.toml b/Gopkg.toml new file mode 100644 index 0000000000..daa1c251b6 --- /dev/null +++ b/Gopkg.toml @@ -0,0 +1,73 @@ +required = ["k8s.io/gengo/types", "k8s.io/code-generator/cmd/client-gen"] + +[prune] + non-go = true + go-tests = true + unused-packages = true + + [[prune.project]] + name = "github.com/json-iterator/go" + non-go = false + go-tests = false + unused-packages = false + + [[prune.project]] + name = "k8s.io/code-generator" + non-go = false + go-tests = false + unused-packages = false + + [[prune.project]] + name = "k8s.io/gengo" + non-go = false + go-tests = false + unused-packages = false + +[[constraint]] + name = "github.com/coreos/ignition" + version = "0.26.0" + +# [[constraint]] +# name = "github.com/coreos/container-linux-config-transpiler" +# version = "v0.9.0" + + +# [[constraint]] +# name = "github.com/ghodss/yaml" +# version = "v1.0.0" + +# [[constraint]] +# name = "github.com/golang/glog" +# revision = "44145f04b68cf362d9c4df2182967c2275eaefed" + +[[constraint]] + name = "k8s.io/api" + version = "kubernetes-1.11.1" + +[[constraint]] + name = "k8s.io/apimachinery" + version = "kubernetes-1.11.1" + +# [[constraint]] +# name = "k8s.io/client-go" +# version = "8.0.0" + +[[override]] + name = "github.com/json-iterator/go" + version = "1.1.3" + +[[constraint]] + name = "k8s.io/code-generator" + version = "kubernetes-1.11.1" + +[[override]] + name = "k8s.io/gengo" + revision = "fdcf9f9480fdd5bf2b3c3df9bf4ecd22b25b87e2" + +# [[constraint]] +# name = "github.com/Masterminds/sprig" +# version = "v2.15.0" + +# [[constraint]] +# name = "github.com/OneOfOne/xxhash" +# version = "v1.2.1" diff --git a/hack/build-go.sh b/hack/build-go.sh new file mode 100755 index 0000000000..9e92c24d38 --- /dev/null +++ b/hack/build-go.sh @@ -0,0 +1,29 @@ +#!/usr/bin/env bash + +set -eu + +REPO=github.com/openshift/machine-config-operator +WHAT=${WHAT:-} +GOFLAGS=${GOFLAGS:-} +GLDFLAGS=${GLDFLAGS:-} + +# Go to the root of the repo +cd "$(git rev-parse --show-cdup)" + +if [ -z ${VERSION+a} ]; then + echo "Using version from git..." + VERSION=$(git describe --abbrev=8 --dirty --always) +fi + +GLDFLAGS+="-X ${REPO}/version.Raw=${VERSION}" + +eval $(go env) + +if [ -z ${BIN_PATH+a} ]; then + export BIN_PATH=_output/bin/${GOOS}/${GOARCH} +fi + +mkdir -p ${BIN_PATH} + +echo "Building ${WHAT}..." +GOOS=${GOOS} GOARCH=${GOARCH} go build ${GOFLAGS} -ldflags "${GLDFLAGS}" -o ${WHAT} ${REPO}/cmd/${WHAT} \ No newline at end of file diff --git a/hack/custom-boilerplate.go.txt b/hack/custom-boilerplate.go.txt new file mode 100644 index 0000000000..e69de29bb2 diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh new file mode 100755 index 0000000000..ddad3b5b28 --- /dev/null +++ b/hack/update-codegen.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_ROOT=$(dirname ${BASH_SOURCE})/.. +# Location of the vendored code-generator package +CODEGEN_PKG="../vendor/k8s.io/code-generator" + +${CODEGEN_PKG}/generate-groups.sh all \ + github.com/openshift/machine-config-operator/pkg/generated github.com/openshift/machine-config-operator/pkg/apis \ + "machineconfiguration.openshift.io:v1" \ + --go-header-file ${SCRIPT_ROOT}/hack/custom-boilerplate.go.txt diff --git a/hack/update-vendor.sh b/hack/update-vendor.sh new file mode 100755 index 0000000000..edba145856 --- /dev/null +++ b/hack/update-vendor.sh @@ -0,0 +1,14 @@ +#!/usr/bin/env bash +# +# This script updates Go vendoring using dep and then fixes BUILD.bazel +# rules. + +set -euo pipefail + +# Go to the root of the repo +cd "$(git rev-parse --show-cdup)" + +# Run dep. +dep ensure + +(cd hack && ./update-codegen.sh) diff --git a/hack/verify-codegen.sh b/hack/verify-codegen.sh new file mode 100755 index 0000000000..f86b5ea0a2 --- /dev/null +++ b/hack/verify-codegen.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +set -o errexit +set -o nounset +set -o pipefail + +SCRIPT_ROOT=$(dirname "${BASH_SOURCE}")/.. + +DIFFROOT="${SCRIPT_ROOT}/pkg" +TMP_DIFFROOT="${SCRIPT_ROOT}/_tmp/pkg" +_tmp="${SCRIPT_ROOT}/_tmp" + +cleanup() { + rm -rf "${_tmp}" +} +trap "cleanup" EXIT SIGINT + +cleanup + +mkdir -p "${TMP_DIFFROOT}" +cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" + +"${SCRIPT_ROOT}/hack/update-codegen.sh" +echo "diffing ${DIFFROOT} against freshly generated codegen" +ret=0 +diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? +cp -a "${TMP_DIFFROOT}"/* "${DIFFROOT}" +if [[ $ret -eq 0 ]] +then + echo "${DIFFROOT} up to date." +else + echo "${DIFFROOT} is out of date. Please run hack/update-codegen.sh" + exit 1 +fi diff --git a/hack/verify-style.sh b/hack/verify-style.sh new file mode 100755 index 0000000000..28fb134166 --- /dev/null +++ b/hack/verify-style.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash +# +# This script invokes tools that should be run prior to pushing +# a repo, such as linters. This is designed to prevent running +# CI on code that will have to be changed. + +set -uo pipefail + +if [[ ! $(which go) ]]; then + echo "go not found on PATH. To install:" + echo "https://golang.org/dl/" + exit 1 +fi +if [[ ! $(which golint) ]]; then + echo "golint not found on PATH. To install:" + echo "go get -u github.com/golang/lint/golint" + exit 1 +fi +if [[ ! $(which yamllint) ]]; then + echo "yamllint not found on PATH. To install:" + echo "https://github.com/adrienverge/yamllint" + exit 1 +fi + +rc=0 +trap 'rc=$?' ERR + +# Go to the root of the repo +cd "$(git rev-parse --show-cdup)" + +GOFILES=$(find . -path ./vendor -prune -o -name '*.go' | grep -v vendor) +GOPKGS=$(go list ./... | grep -v '/vendor/' | grep -v '/generated/') + +echo "Running gofmt..." +gofmt -s -d $GOFILES + +echo "Running go vet..." +go vet $GOPKGS + +echo "Running golint..." +golint -set_exit_status $GOPKGS + +echo "Running yamllint..." +YAMLS=$(find . -path ./vendor -prune -o -name '*.yaml' | grep -v vendor) +yamllint -c hack/yamllint-config.yaml -s $YAMLS + +echo "Running verify code-generators" +(cd hack && ./verify-codegen.sh) + +echo "Done!" +exit ${rc} diff --git a/hack/yamllint-config.yaml b/hack/yamllint-config.yaml new file mode 100644 index 0000000000..489d922fca --- /dev/null +++ b/hack/yamllint-config.yaml @@ -0,0 +1,31 @@ +--- + +extends: default + +rules: + braces: + level: warning + max-spaces-inside: 1 + brackets: + level: warning + max-spaces-inside: 1 + colons: + level: warning + commas: + level: warning + comments: disable + comments-indentation: disable + document-start: disable + empty-lines: + level: warning + hyphens: + level: warning + indentation: + level: warning + indent-sequences: consistent + line-length: disable + truthy: disable + +ignore: | + # The following have yaml-syntax-breaking templating, but are covered + # by other yaml files in the unit tests. diff --git a/pkg/apis/apis.go b/pkg/apis/apis.go new file mode 100644 index 0000000000..87a14e6e92 --- /dev/null +++ b/pkg/apis/apis.go @@ -0,0 +1,4 @@ +package apis + +// GroupName defines the API group for machineconfiguration. +const GroupName = "machineconfiguration.openshift.io" diff --git a/pkg/apis/apis_test.go b/pkg/apis/apis_test.go new file mode 100644 index 0000000000..700b7660c8 --- /dev/null +++ b/pkg/apis/apis_test.go @@ -0,0 +1,11 @@ +package apis + +import ( + "testing" +) + +func TestGroupName(t *testing.T) { + if got, want := GroupName, "machineconfiguration.openshift.io"; got != want { + t.Fatalf("mismatch group name, got: %s want: %s", got, want) + } +} diff --git a/pkg/apis/machineconfiguration.openshift.io/v1/doc.go b/pkg/apis/machineconfiguration.openshift.io/v1/doc.go new file mode 100644 index 0000000000..6015c363ae --- /dev/null +++ b/pkg/apis/machineconfiguration.openshift.io/v1/doc.go @@ -0,0 +1,4 @@ +// +k8s:deepcopy-gen=package + +// Package v1 is the v1 version of the API. +package v1 diff --git a/pkg/apis/machineconfiguration.openshift.io/v1/helpers.go b/pkg/apis/machineconfiguration.openshift.io/v1/helpers.go new file mode 100644 index 0000000000..166c62eea9 --- /dev/null +++ b/pkg/apis/machineconfiguration.openshift.io/v1/helpers.go @@ -0,0 +1,31 @@ +package v1 + +import ( + "sort" + + ignv2_2 "github.com/coreos/ignition/config/v2_2" +) + +// MergeMachineConfigs combines multiple machineconfig objects into one object. +// It sorts all the configs in increasing order of their name. +// It uses the Ign config from first object as base and appends all the rest. +// It only uses the OSImageURL from first object and ignores it from rest. +func MergeMachineConfigs(configs []*MachineConfig) *MachineConfig { + if len(configs) == 0 { + return nil + } + sort.Slice(configs, func(i, j int) bool { return configs[i].Name < configs[j].Name }) + + outOSImageURL := configs[0].Spec.OSImageURL + outIgn := configs[0].Spec.Config + for idx := 1; idx < len(configs); idx++ { + outIgn = ignv2_2.Append(outIgn, configs[idx].Spec.Config) + } + + return &MachineConfig{ + Spec: MachineConfigSpec{ + OSImageURL: outOSImageURL, + Config: outIgn, + }, + } +} diff --git a/pkg/apis/machineconfiguration.openshift.io/v1/machineconfig.deepcopy.go b/pkg/apis/machineconfiguration.openshift.io/v1/machineconfig.deepcopy.go new file mode 100644 index 0000000000..82f984510f --- /dev/null +++ b/pkg/apis/machineconfiguration.openshift.io/v1/machineconfig.deepcopy.go @@ -0,0 +1,87 @@ +package v1 + +import ( + ignv2_2 "github.com/coreos/ignition/config/v2_2" + ignv2_2types "github.com/coreos/ignition/config/v2_2/types" + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfig) DeepCopyInto(out *MachineConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy copying the receiver, creating a new MachineConfig. +func (in *MachineConfig) DeepCopy() *MachineConfig { + if in == nil { + return nil + } + out := new(MachineConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject copying the receiver, creating a new runtime.Object. +func (in *MachineConfig) DeepCopyObject() runtime.Object { + return in.DeepCopy() +} + +// DeepCopyInto copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigList) DeepCopyInto(out *MachineConfigList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachineConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy copying the receiver, creating a new MachineConfigList. +func (in *MachineConfigList) DeepCopy() *MachineConfigList { + if in == nil { + return nil + } + out := new(MachineConfigList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject copying the receiver, creating a new runtime.Object. +func (in *MachineConfigList) DeepCopyObject() runtime.Object { + return in.DeepCopy() +} + +// DeepCopyInto copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigSpec) DeepCopyInto(out *MachineConfigSpec) { + *out = *in + out.Config = deepCopyIgnConfig(in.Config) + return +} + +func deepCopyIgnConfig(in ignv2_2types.Config) ignv2_2types.Config { + var out ignv2_2types.Config + + // https://github.com/coreos/ignition/blob/d19b2021cf397de7c31774c13805bbc3aa655646/config/v2_2/append.go#L41 + out.Ignition.Version = in.Ignition.Version + + return ignv2_2.Append(out, in) +} + +// DeepCopy copying the receiver, creating a new MachineConfigSpec. +func (in *MachineConfigSpec) DeepCopy() *MachineConfigSpec { + if in == nil { + return nil + } + out := new(MachineConfigSpec) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/machineconfiguration.openshift.io/v1/register.go b/pkg/apis/machineconfiguration.openshift.io/v1/register.go new file mode 100644 index 0000000000..1ea9597978 --- /dev/null +++ b/pkg/apis/machineconfiguration.openshift.io/v1/register.go @@ -0,0 +1,52 @@ +package v1 + +import ( + "github.com/openshift/machine-config-operator/pkg/apis" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +const ( + // GroupName defines the API group for machineconfigpools. + GroupName = apis.GroupName +) + +// SchemeGroupVersion is group version used to register these objects +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + // SchemeBuilder is the scheme builder for MachineConfigPools + SchemeBuilder runtime.SchemeBuilder + // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. + localSchemeBuilder = &SchemeBuilder + // AddToScheme is the function alias for AddtoScheme + AddToScheme = localSchemeBuilder.AddToScheme +) + +func init() { + // We only register manually written functions here. The registration of the + // generated functions takes place in the generated files. The separation + // makes the code compile even when the generated files are missing. + localSchemeBuilder.Register(addKnownTypes) +} + +// Adds the list of known types to api.Scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &ControllerConfig{}, + &ControllerConfigList{}, + &MachineConfig{}, + &MachineConfigList{}, + &MachineConfigPool{}, + &MachineConfigPoolList{}, + ) + + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/machineconfiguration.openshift.io/v1/types.go b/pkg/apis/machineconfiguration.openshift.io/v1/types.go new file mode 100644 index 0000000000..208dd2484f --- /dev/null +++ b/pkg/apis/machineconfiguration.openshift.io/v1/types.go @@ -0,0 +1,263 @@ +package v1 + +import ( + ignv2_2types "github.com/coreos/ignition/config/v2_2/types" + corev1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// CustomResourceDefinition for ControllerConfig +// apiVersion: apiextensions.k8s.io/v1beta1 +// kind: CustomResourceDefinition +// metadata: +// # name must match the spec fields below, and be in the form: . +// name: controllerconfigs.machineconfiguration.openshift.io +// spec: +// # group name to use for REST API: /apis// +// group: machineconfiguration.openshift.io +// # list of versions supported by this CustomResourceDefinition +// versions: +// - name: v1 +// # Each version can be enabled/disabled by Served flag. +// served: true +// # One and only one version must be marked as the storage version. +// storage: true +// # either Namespaced or Cluster +// scope: Namespaced +// names: +// # plural name to be used in the URL: /apis/// +// plural: controllerconfigs +// # singular name to be used as an alias on the CLI and for display +// singular: controllerconfig +// # kind is normally the CamelCased singular type. Your resource manifests use this. +// kind: ControllerConfig +// # shortNames allow shorter string to match your resource on the CLI +// shortNames: +// + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ControllerConfig describes configuration for MachineConfigController. +type ControllerConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec ControllerConfigSpec `json:"spec"` +} + +// ControllerConfigSpec is the spec for ControllerConfig resource. +type ControllerConfigSpec struct { + ClusterDNSIP string `json:"clusterDNSIP"` + CloudProviderConfig string `json:"cloudProviderConfig"` + ClusterName string `json:"clusterName"` + + // The openshift platform, e.g. "libvirt" or "aws" + Platform string `json:"platform"` + + BaseDomain string `json:"baseDomain"` + + // Size of the initial etcd cluster. + EtcdInitialCount int `json:"etcdInitialCount"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// ControllerConfigList is a list of ControllerConfig resources +type ControllerConfigList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []ControllerConfig `json:"items"` +} + +// CustomResourceDefinition for MachineConfig +// apiVersion: apiextensions.k8s.io/v1beta1 +// kind: CustomResourceDefinition +// metadata: +// # name must match the spec fields below, and be in the form: . +// name: machineconfigs.machineconfiguration.openshift.io +// spec: +// # group name to use for REST API: /apis// +// group: machineconfiguration.openshift.io +// # list of versions supported by this CustomResourceDefinition +// versions: +// - name: v1 +// # Each version can be enabled/disabled by Served flag. +// served: true +// # One and only one version must be marked as the storage version. +// storage: true +// # either Namespaced or Cluster +// scope: Cluster +// names: +// # plural name to be used in the URL: /apis/// +// plural: machineconfigs +// # singular name to be used as an alias on the CLI and for display +// singular: machineconfig +// # kind is normally the CamelCased singular type. Your resource manifests use this. +// kind: MachineConfig +// # shortNames allow shorter string to match your resource on the CLI +// shortNames: +// - mc + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen=false + +// MachineConfig defines the configuration for a machine +type MachineConfig struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec MachineConfigSpec `json:"spec"` +} + +// MachineConfigSpec is the for MachineConfig +type MachineConfigSpec struct { + // OSImageURL specifies the remote location that will be used to + // fetch the OS. + OSImageURL string `json:"osImageURL"` + // Config is a Ignition Config object. + Config ignv2_2types.Config `json:"config"` +} + +// MachineConfigList is a list of MachineConfig resources +type MachineConfigList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []MachineConfig `json:"items"` +} + +// CustomResourceDefinition for MachineConfigPool +// apiVersion: apiextensions.k8s.io/v1beta1 +// kind: CustomResourceDefinition +// metadata: +// # name must match the spec fields below, and be in the form: . +// name: machineconfigpools.machineconfiguration.openshift.io +// spec: +// # group name to use for REST API: /apis// +// group: machineconfiguration.openshift.io +// # list of versions supported by this CustomResourceDefinition +// versions: +// - name: v1 +// # Each version can be enabled/disabled by Served flag. +// served: true +// # One and only one version must be marked as the storage version. +// storage: true +// # either Namespaced or Cluster +// scope: Cluster +// names: +// # plural name to be used in the URL: /apis/// +// plural: machineconfigpools +// # singular name to be used as an alias on the CLI and for display +// singular: machineconfigpool +// # kind is normally the CamelCased singular type. Your resource manifests use this. +// kind: MachineConfigPool +// # shortNames allow shorter string to match your resource on the CLI +// shortNames: +// + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// MachineConfigPool describes a pool of MachineConfigs. +type MachineConfigPool struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + Spec MachineConfigPoolSpec `json:"spec"` + Status MachineConfigPoolStatus `json:"status"` +} + +// MachineConfigPoolSpec is the spec for MachineConfigPool resource. +type MachineConfigPoolSpec struct { + // Label selector for MachineConfigs. + // Refer https://kubernetes.io/docs/concepts/overview/working-with-objects/labels/ on how label and selectors work. + MachineConfigSelector *metav1.LabelSelector `json:"machineConfigSelector,omitempty"` + + // Label selector for Machines. + MachineSelector *metav1.LabelSelector `json:"machineSelector,omitempty"` + + // If true, changes to this machine pool should be stopped. + // This includes generating new desiredMachineConfig and update of machines. + Paused bool `json:"paused"` + + // MaxUnavailable specifies the percentage or constant number of machines that can be updating at any given time. + // default is 1. + MaxUnavailable *intstr.IntOrString `json:"maxUnavailable"` +} + +// MachineConfigPoolStatus is the status for MachineConfigPool resource. +type MachineConfigPoolStatus struct { + // The generation observed by the controller. + ObservedGeneration int64 `json:"observedGeneration,omitempty"` + + // The current MachineConfig object for the machine pool. + CurrentMachineConfig string `json:"currentMachineConfig"` + + // Total number of machines in the machine pool. + MachineCount int32 `json:"machineCount"` + + // Total number of machines targeted by the pool that have the CurrentMachineConfig as their config. + UpdatedMachineCount int32 `json:"updatedMachineCount"` + + // Total number of ready machines targeted by the pool. + ReadyMachineCount int32 `json:"readyMachineCount"` + + // Total number of unavailable (non-ready) machines targeted by the pool. + // A node is marked unavailable if it is in updating state or NodeReady condition is false. + UnavailableMachineCount int32 `json:"unavailableMachineCount"` + + // Represents the latest available observations of current state. + Conditions []MachineConfigPoolCondition `json:"conditions"` +} + +// MachineConfigPoolCondition contains condition information for an MachineConfigPool. +type MachineConfigPoolCondition struct { + // Type of the condition, currently ('Done', 'Updating', 'Failed'). + Type MachineConfigPoolConditionType `json:"type"` + + // Status of the condition, one of ('True', 'False', 'Unknown'). + Status corev1.ConditionStatus `json:"status"` + + // LastTransitionTime is the timestamp corresponding to the last status + // change of this condition. + LastTransitionTime metav1.Time `json:"lastTransitionTime"` + + // Reason is a brief machine readable explanation for the condition's last + // transition. + Reason string `json:"reason"` + + // Message is a human readable description of the details of the last + // transition, complementing reason. + Message string `json:"message"` +} + +// MachineConfigPoolConditionType valid conditions of a machineconfigpool +type MachineConfigPoolConditionType string + +const ( + // MachineConfigPoolUpdated means machineconfigpool is updated completely. + // When the all the machines in the pool are updated to the correct machine config. + MachineConfigPoolUpdated MachineConfigPoolConditionType = "Updated" + // MachineConfigPoolUpdating means machineconfigpool is updating. + // When at least one of machine is not either not updated or is in the process of updating + // to the desired machine config. + MachineConfigPoolUpdating MachineConfigPoolConditionType = "Updating" + // MachineConfigPoolDegraded means the update for one of the machine is not progressing + // due to an error + MachineConfigPoolDegraded MachineConfigPoolConditionType = "Degraded" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// MachineConfigPoolList is a list of MachineConfigPool resources +type MachineConfigPoolList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata"` + + Items []MachineConfigPool `json:"items"` +} diff --git a/pkg/apis/machineconfiguration.openshift.io/v1/zz_generated.deepcopy.go b/pkg/apis/machineconfiguration.openshift.io/v1/zz_generated.deepcopy.go new file mode 100644 index 0000000000..9e2f0ad20a --- /dev/null +++ b/pkg/apis/machineconfiguration.openshift.io/v1/zz_generated.deepcopy.go @@ -0,0 +1,219 @@ +// +build !ignore_autogenerated + +// Code generated by deepcopy-gen. DO NOT EDIT. + +package v1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + intstr "k8s.io/apimachinery/pkg/util/intstr" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ControllerConfig) DeepCopyInto(out *ControllerConfig) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + out.Spec = in.Spec + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControllerConfig. +func (in *ControllerConfig) DeepCopy() *ControllerConfig { + if in == nil { + return nil + } + out := new(ControllerConfig) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ControllerConfig) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ControllerConfigList) DeepCopyInto(out *ControllerConfigList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ControllerConfig, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControllerConfigList. +func (in *ControllerConfigList) DeepCopy() *ControllerConfigList { + if in == nil { + return nil + } + out := new(ControllerConfigList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ControllerConfigList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ControllerConfigSpec) DeepCopyInto(out *ControllerConfigSpec) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ControllerConfigSpec. +func (in *ControllerConfigSpec) DeepCopy() *ControllerConfigSpec { + if in == nil { + return nil + } + out := new(ControllerConfigSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigPool) DeepCopyInto(out *MachineConfigPool) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineConfigPool. +func (in *MachineConfigPool) DeepCopy() *MachineConfigPool { + if in == nil { + return nil + } + out := new(MachineConfigPool) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachineConfigPool) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigPoolCondition) DeepCopyInto(out *MachineConfigPoolCondition) { + *out = *in + in.LastTransitionTime.DeepCopyInto(&out.LastTransitionTime) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineConfigPoolCondition. +func (in *MachineConfigPoolCondition) DeepCopy() *MachineConfigPoolCondition { + if in == nil { + return nil + } + out := new(MachineConfigPoolCondition) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigPoolList) DeepCopyInto(out *MachineConfigPoolList) { + *out = *in + out.TypeMeta = in.TypeMeta + out.ListMeta = in.ListMeta + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]MachineConfigPool, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineConfigPoolList. +func (in *MachineConfigPoolList) DeepCopy() *MachineConfigPoolList { + if in == nil { + return nil + } + out := new(MachineConfigPoolList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *MachineConfigPoolList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigPoolSpec) DeepCopyInto(out *MachineConfigPoolSpec) { + *out = *in + if in.MachineConfigSelector != nil { + in, out := &in.MachineConfigSelector, &out.MachineConfigSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.MachineSelector != nil { + in, out := &in.MachineSelector, &out.MachineSelector + *out = new(metav1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.MaxUnavailable != nil { + in, out := &in.MaxUnavailable, &out.MaxUnavailable + *out = new(intstr.IntOrString) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineConfigPoolSpec. +func (in *MachineConfigPoolSpec) DeepCopy() *MachineConfigPoolSpec { + if in == nil { + return nil + } + out := new(MachineConfigPoolSpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *MachineConfigPoolStatus) DeepCopyInto(out *MachineConfigPoolStatus) { + *out = *in + if in.Conditions != nil { + in, out := &in.Conditions, &out.Conditions + *out = make([]MachineConfigPoolCondition, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MachineConfigPoolStatus. +func (in *MachineConfigPoolStatus) DeepCopy() *MachineConfigPoolStatus { + if in == nil { + return nil + } + out := new(MachineConfigPoolStatus) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/generated/clientset/versioned/clientset.go b/pkg/generated/clientset/versioned/clientset.go new file mode 100644 index 0000000000..e99b16d801 --- /dev/null +++ b/pkg/generated/clientset/versioned/clientset.go @@ -0,0 +1,82 @@ +// Code generated by client-gen. DO NOT EDIT. + +package versioned + +import ( + machineconfigurationv1 "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1" + discovery "k8s.io/client-go/discovery" + rest "k8s.io/client-go/rest" + flowcontrol "k8s.io/client-go/util/flowcontrol" +) + +type Interface interface { + Discovery() discovery.DiscoveryInterface + MachineconfigurationV1() machineconfigurationv1.MachineconfigurationV1Interface + // Deprecated: please explicitly pick a version if possible. + Machineconfiguration() machineconfigurationv1.MachineconfigurationV1Interface +} + +// Clientset contains the clients for groups. Each group has exactly one +// version included in a Clientset. +type Clientset struct { + *discovery.DiscoveryClient + machineconfigurationV1 *machineconfigurationv1.MachineconfigurationV1Client +} + +// MachineconfigurationV1 retrieves the MachineconfigurationV1Client +func (c *Clientset) MachineconfigurationV1() machineconfigurationv1.MachineconfigurationV1Interface { + return c.machineconfigurationV1 +} + +// Deprecated: Machineconfiguration retrieves the default version of MachineconfigurationClient. +// Please explicitly pick a version. +func (c *Clientset) Machineconfiguration() machineconfigurationv1.MachineconfigurationV1Interface { + return c.machineconfigurationV1 +} + +// Discovery retrieves the DiscoveryClient +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + if c == nil { + return nil + } + return c.DiscoveryClient +} + +// NewForConfig creates a new Clientset for the given config. +func NewForConfig(c *rest.Config) (*Clientset, error) { + configShallowCopy := *c + if configShallowCopy.RateLimiter == nil && configShallowCopy.QPS > 0 { + configShallowCopy.RateLimiter = flowcontrol.NewTokenBucketRateLimiter(configShallowCopy.QPS, configShallowCopy.Burst) + } + var cs Clientset + var err error + cs.machineconfigurationV1, err = machineconfigurationv1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + + cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) + if err != nil { + return nil, err + } + return &cs, nil +} + +// NewForConfigOrDie creates a new Clientset for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *Clientset { + var cs Clientset + cs.machineconfigurationV1 = machineconfigurationv1.NewForConfigOrDie(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) + return &cs +} + +// New creates a new Clientset for the given RESTClient. +func New(c rest.Interface) *Clientset { + var cs Clientset + cs.machineconfigurationV1 = machineconfigurationv1.New(c) + + cs.DiscoveryClient = discovery.NewDiscoveryClient(c) + return &cs +} diff --git a/pkg/generated/clientset/versioned/doc.go b/pkg/generated/clientset/versioned/doc.go new file mode 100644 index 0000000000..0e0c2a8900 --- /dev/null +++ b/pkg/generated/clientset/versioned/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated clientset. +package versioned diff --git a/pkg/generated/clientset/versioned/fake/clientset_generated.go b/pkg/generated/clientset/versioned/fake/clientset_generated.go new file mode 100644 index 0000000000..bab13eb4c2 --- /dev/null +++ b/pkg/generated/clientset/versioned/fake/clientset_generated.go @@ -0,0 +1,66 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + clientset "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" + machineconfigurationv1 "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1" + fakemachineconfigurationv1 "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/watch" + "k8s.io/client-go/discovery" + fakediscovery "k8s.io/client-go/discovery/fake" + "k8s.io/client-go/testing" +) + +// NewSimpleClientset returns a clientset that will respond with the provided objects. +// It's backed by a very simple object tracker that processes creates, updates and deletions as-is, +// without applying any validations and/or defaults. It shouldn't be considered a replacement +// for a real clientset and is mostly useful in simple unit tests. +func NewSimpleClientset(objects ...runtime.Object) *Clientset { + o := testing.NewObjectTracker(scheme, codecs.UniversalDecoder()) + for _, obj := range objects { + if err := o.Add(obj); err != nil { + panic(err) + } + } + + cs := &Clientset{} + cs.discovery = &fakediscovery.FakeDiscovery{Fake: &cs.Fake} + cs.AddReactor("*", "*", testing.ObjectReaction(o)) + cs.AddWatchReactor("*", func(action testing.Action) (handled bool, ret watch.Interface, err error) { + gvr := action.GetResource() + ns := action.GetNamespace() + watch, err := o.Watch(gvr, ns) + if err != nil { + return false, nil, err + } + return true, watch, nil + }) + + return cs +} + +// Clientset implements clientset.Interface. Meant to be embedded into a +// struct to get a default implementation. This makes faking out just the method +// you want to test easier. +type Clientset struct { + testing.Fake + discovery *fakediscovery.FakeDiscovery +} + +func (c *Clientset) Discovery() discovery.DiscoveryInterface { + return c.discovery +} + +var _ clientset.Interface = &Clientset{} + +// MachineconfigurationV1 retrieves the MachineconfigurationV1Client +func (c *Clientset) MachineconfigurationV1() machineconfigurationv1.MachineconfigurationV1Interface { + return &fakemachineconfigurationv1.FakeMachineconfigurationV1{Fake: &c.Fake} +} + +// Machineconfiguration retrieves the MachineconfigurationV1Client +func (c *Clientset) Machineconfiguration() machineconfigurationv1.MachineconfigurationV1Interface { + return &fakemachineconfigurationv1.FakeMachineconfigurationV1{Fake: &c.Fake} +} diff --git a/pkg/generated/clientset/versioned/fake/doc.go b/pkg/generated/clientset/versioned/fake/doc.go new file mode 100644 index 0000000000..3630ed1cd1 --- /dev/null +++ b/pkg/generated/clientset/versioned/fake/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated fake clientset. +package fake diff --git a/pkg/generated/clientset/versioned/fake/register.go b/pkg/generated/clientset/versioned/fake/register.go new file mode 100644 index 0000000000..bf937ddd03 --- /dev/null +++ b/pkg/generated/clientset/versioned/fake/register.go @@ -0,0 +1,38 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + machineconfigurationv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var scheme = runtime.NewScheme() +var codecs = serializer.NewCodecFactory(scheme) +var parameterCodec = runtime.NewParameterCodec(scheme) + +func init() { + v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + machineconfigurationv1.AddToScheme(scheme) +} diff --git a/pkg/generated/clientset/versioned/scheme/doc.go b/pkg/generated/clientset/versioned/scheme/doc.go new file mode 100644 index 0000000000..14db57a58f --- /dev/null +++ b/pkg/generated/clientset/versioned/scheme/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package contains the scheme of the automatically generated clientset. +package scheme diff --git a/pkg/generated/clientset/versioned/scheme/register.go b/pkg/generated/clientset/versioned/scheme/register.go new file mode 100644 index 0000000000..8ff9863960 --- /dev/null +++ b/pkg/generated/clientset/versioned/scheme/register.go @@ -0,0 +1,38 @@ +// Code generated by client-gen. DO NOT EDIT. + +package scheme + +import ( + machineconfigurationv1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" +) + +var Scheme = runtime.NewScheme() +var Codecs = serializer.NewCodecFactory(Scheme) +var ParameterCodec = runtime.NewParameterCodec(Scheme) + +func init() { + v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) + AddToScheme(Scheme) +} + +// AddToScheme adds all types of this clientset into the given scheme. This allows composition +// of clientsets, like in: +// +// import ( +// "k8s.io/client-go/kubernetes" +// clientsetscheme "k8s.io/client-go/kubernetes/scheme" +// aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" +// ) +// +// kclientset, _ := kubernetes.NewForConfig(c) +// aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) +// +// After this, RawExtensions in Kubernetes types will serialize kube-aggregator types +// correctly. +func AddToScheme(scheme *runtime.Scheme) { + machineconfigurationv1.AddToScheme(scheme) +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/controllerconfig.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/controllerconfig.go new file mode 100644 index 0000000000..406de35b9d --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/controllerconfig.go @@ -0,0 +1,141 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + scheme "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// ControllerConfigsGetter has a method to return a ControllerConfigInterface. +// A group's client should implement this interface. +type ControllerConfigsGetter interface { + ControllerConfigs(namespace string) ControllerConfigInterface +} + +// ControllerConfigInterface has methods to work with ControllerConfig resources. +type ControllerConfigInterface interface { + Create(*v1.ControllerConfig) (*v1.ControllerConfig, error) + Update(*v1.ControllerConfig) (*v1.ControllerConfig, error) + Delete(name string, options *metav1.DeleteOptions) error + DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error + Get(name string, options metav1.GetOptions) (*v1.ControllerConfig, error) + List(opts metav1.ListOptions) (*v1.ControllerConfigList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ControllerConfig, err error) + ControllerConfigExpansion +} + +// controllerConfigs implements ControllerConfigInterface +type controllerConfigs struct { + client rest.Interface + ns string +} + +// newControllerConfigs returns a ControllerConfigs +func newControllerConfigs(c *MachineconfigurationV1Client, namespace string) *controllerConfigs { + return &controllerConfigs{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the controllerConfig, and returns the corresponding controllerConfig object, and an error if there is any. +func (c *controllerConfigs) Get(name string, options metav1.GetOptions) (result *v1.ControllerConfig, err error) { + result = &v1.ControllerConfig{} + err = c.client.Get(). + Namespace(c.ns). + Resource("controllerconfigs"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ControllerConfigs that match those selectors. +func (c *controllerConfigs) List(opts metav1.ListOptions) (result *v1.ControllerConfigList, err error) { + result = &v1.ControllerConfigList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("controllerconfigs"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested controllerConfigs. +func (c *controllerConfigs) Watch(opts metav1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("controllerconfigs"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a controllerConfig and creates it. Returns the server's representation of the controllerConfig, and an error, if there is any. +func (c *controllerConfigs) Create(controllerConfig *v1.ControllerConfig) (result *v1.ControllerConfig, err error) { + result = &v1.ControllerConfig{} + err = c.client.Post(). + Namespace(c.ns). + Resource("controllerconfigs"). + Body(controllerConfig). + Do(). + Into(result) + return +} + +// Update takes the representation of a controllerConfig and updates it. Returns the server's representation of the controllerConfig, and an error, if there is any. +func (c *controllerConfigs) Update(controllerConfig *v1.ControllerConfig) (result *v1.ControllerConfig, err error) { + result = &v1.ControllerConfig{} + err = c.client.Put(). + Namespace(c.ns). + Resource("controllerconfigs"). + Name(controllerConfig.Name). + Body(controllerConfig). + Do(). + Into(result) + return +} + +// Delete takes name of the controllerConfig and deletes it. Returns an error if one occurs. +func (c *controllerConfigs) Delete(name string, options *metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("controllerconfigs"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *controllerConfigs) DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("controllerconfigs"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched controllerConfig. +func (c *controllerConfigs) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.ControllerConfig, err error) { + result = &v1.ControllerConfig{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("controllerconfigs"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/doc.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/doc.go new file mode 100644 index 0000000000..225e6b2be3 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// This package has the automatically generated typed clients. +package v1 diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/doc.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/doc.go new file mode 100644 index 0000000000..2b5ba4c8e4 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/doc.go @@ -0,0 +1,4 @@ +// Code generated by client-gen. DO NOT EDIT. + +// Package fake has the automatically generated clients. +package fake diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_controllerconfig.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_controllerconfig.go new file mode 100644 index 0000000000..4d40836ccd --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_controllerconfig.go @@ -0,0 +1,112 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + machineconfigurationopenshiftiov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeControllerConfigs implements ControllerConfigInterface +type FakeControllerConfigs struct { + Fake *FakeMachineconfigurationV1 + ns string +} + +var controllerconfigsResource = schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "controllerconfigs"} + +var controllerconfigsKind = schema.GroupVersionKind{Group: "machineconfiguration.openshift.io", Version: "v1", Kind: "ControllerConfig"} + +// Get takes name of the controllerConfig, and returns the corresponding controllerConfig object, and an error if there is any. +func (c *FakeControllerConfigs) Get(name string, options v1.GetOptions) (result *machineconfigurationopenshiftiov1.ControllerConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(controllerconfigsResource, c.ns, name), &machineconfigurationopenshiftiov1.ControllerConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.ControllerConfig), err +} + +// List takes label and field selectors, and returns the list of ControllerConfigs that match those selectors. +func (c *FakeControllerConfigs) List(opts v1.ListOptions) (result *machineconfigurationopenshiftiov1.ControllerConfigList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(controllerconfigsResource, controllerconfigsKind, c.ns, opts), &machineconfigurationopenshiftiov1.ControllerConfigList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &machineconfigurationopenshiftiov1.ControllerConfigList{ListMeta: obj.(*machineconfigurationopenshiftiov1.ControllerConfigList).ListMeta} + for _, item := range obj.(*machineconfigurationopenshiftiov1.ControllerConfigList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested controllerConfigs. +func (c *FakeControllerConfigs) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(controllerconfigsResource, c.ns, opts)) + +} + +// Create takes the representation of a controllerConfig and creates it. Returns the server's representation of the controllerConfig, and an error, if there is any. +func (c *FakeControllerConfigs) Create(controllerConfig *machineconfigurationopenshiftiov1.ControllerConfig) (result *machineconfigurationopenshiftiov1.ControllerConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(controllerconfigsResource, c.ns, controllerConfig), &machineconfigurationopenshiftiov1.ControllerConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.ControllerConfig), err +} + +// Update takes the representation of a controllerConfig and updates it. Returns the server's representation of the controllerConfig, and an error, if there is any. +func (c *FakeControllerConfigs) Update(controllerConfig *machineconfigurationopenshiftiov1.ControllerConfig) (result *machineconfigurationopenshiftiov1.ControllerConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(controllerconfigsResource, c.ns, controllerConfig), &machineconfigurationopenshiftiov1.ControllerConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.ControllerConfig), err +} + +// Delete takes name of the controllerConfig and deletes it. Returns an error if one occurs. +func (c *FakeControllerConfigs) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(controllerconfigsResource, c.ns, name), &machineconfigurationopenshiftiov1.ControllerConfig{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeControllerConfigs) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(controllerconfigsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &machineconfigurationopenshiftiov1.ControllerConfigList{}) + return err +} + +// Patch applies the patch and returns the patched controllerConfig. +func (c *FakeControllerConfigs) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *machineconfigurationopenshiftiov1.ControllerConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(controllerconfigsResource, c.ns, name, data, subresources...), &machineconfigurationopenshiftiov1.ControllerConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.ControllerConfig), err +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfig.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfig.go new file mode 100644 index 0000000000..ceec945008 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfig.go @@ -0,0 +1,112 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + machineconfigurationopenshiftiov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeMachineConfigs implements MachineConfigInterface +type FakeMachineConfigs struct { + Fake *FakeMachineconfigurationV1 + ns string +} + +var machineconfigsResource = schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigs"} + +var machineconfigsKind = schema.GroupVersionKind{Group: "machineconfiguration.openshift.io", Version: "v1", Kind: "MachineConfig"} + +// Get takes name of the machineConfig, and returns the corresponding machineConfig object, and an error if there is any. +func (c *FakeMachineConfigs) Get(name string, options v1.GetOptions) (result *machineconfigurationopenshiftiov1.MachineConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(machineconfigsResource, c.ns, name), &machineconfigurationopenshiftiov1.MachineConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfig), err +} + +// List takes label and field selectors, and returns the list of MachineConfigs that match those selectors. +func (c *FakeMachineConfigs) List(opts v1.ListOptions) (result *machineconfigurationopenshiftiov1.MachineConfigList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(machineconfigsResource, machineconfigsKind, c.ns, opts), &machineconfigurationopenshiftiov1.MachineConfigList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &machineconfigurationopenshiftiov1.MachineConfigList{ListMeta: obj.(*machineconfigurationopenshiftiov1.MachineConfigList).ListMeta} + for _, item := range obj.(*machineconfigurationopenshiftiov1.MachineConfigList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested machineConfigs. +func (c *FakeMachineConfigs) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(machineconfigsResource, c.ns, opts)) + +} + +// Create takes the representation of a machineConfig and creates it. Returns the server's representation of the machineConfig, and an error, if there is any. +func (c *FakeMachineConfigs) Create(machineConfig *machineconfigurationopenshiftiov1.MachineConfig) (result *machineconfigurationopenshiftiov1.MachineConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(machineconfigsResource, c.ns, machineConfig), &machineconfigurationopenshiftiov1.MachineConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfig), err +} + +// Update takes the representation of a machineConfig and updates it. Returns the server's representation of the machineConfig, and an error, if there is any. +func (c *FakeMachineConfigs) Update(machineConfig *machineconfigurationopenshiftiov1.MachineConfig) (result *machineconfigurationopenshiftiov1.MachineConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(machineconfigsResource, c.ns, machineConfig), &machineconfigurationopenshiftiov1.MachineConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfig), err +} + +// Delete takes name of the machineConfig and deletes it. Returns an error if one occurs. +func (c *FakeMachineConfigs) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(machineconfigsResource, c.ns, name), &machineconfigurationopenshiftiov1.MachineConfig{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeMachineConfigs) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(machineconfigsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &machineconfigurationopenshiftiov1.MachineConfigList{}) + return err +} + +// Patch applies the patch and returns the patched machineConfig. +func (c *FakeMachineConfigs) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *machineconfigurationopenshiftiov1.MachineConfig, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(machineconfigsResource, c.ns, name, data, subresources...), &machineconfigurationopenshiftiov1.MachineConfig{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfig), err +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfigpool.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfigpool.go new file mode 100644 index 0000000000..68ad3db203 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfigpool.go @@ -0,0 +1,124 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + machineconfigurationopenshiftiov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeMachineConfigPools implements MachineConfigPoolInterface +type FakeMachineConfigPools struct { + Fake *FakeMachineconfigurationV1 + ns string +} + +var machineconfigpoolsResource = schema.GroupVersionResource{Group: "machineconfiguration.openshift.io", Version: "v1", Resource: "machineconfigpools"} + +var machineconfigpoolsKind = schema.GroupVersionKind{Group: "machineconfiguration.openshift.io", Version: "v1", Kind: "MachineConfigPool"} + +// Get takes name of the machineConfigPool, and returns the corresponding machineConfigPool object, and an error if there is any. +func (c *FakeMachineConfigPools) Get(name string, options v1.GetOptions) (result *machineconfigurationopenshiftiov1.MachineConfigPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(machineconfigpoolsResource, c.ns, name), &machineconfigurationopenshiftiov1.MachineConfigPool{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfigPool), err +} + +// List takes label and field selectors, and returns the list of MachineConfigPools that match those selectors. +func (c *FakeMachineConfigPools) List(opts v1.ListOptions) (result *machineconfigurationopenshiftiov1.MachineConfigPoolList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(machineconfigpoolsResource, machineconfigpoolsKind, c.ns, opts), &machineconfigurationopenshiftiov1.MachineConfigPoolList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &machineconfigurationopenshiftiov1.MachineConfigPoolList{ListMeta: obj.(*machineconfigurationopenshiftiov1.MachineConfigPoolList).ListMeta} + for _, item := range obj.(*machineconfigurationopenshiftiov1.MachineConfigPoolList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested machineConfigPools. +func (c *FakeMachineConfigPools) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(machineconfigpoolsResource, c.ns, opts)) + +} + +// Create takes the representation of a machineConfigPool and creates it. Returns the server's representation of the machineConfigPool, and an error, if there is any. +func (c *FakeMachineConfigPools) Create(machineConfigPool *machineconfigurationopenshiftiov1.MachineConfigPool) (result *machineconfigurationopenshiftiov1.MachineConfigPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(machineconfigpoolsResource, c.ns, machineConfigPool), &machineconfigurationopenshiftiov1.MachineConfigPool{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfigPool), err +} + +// Update takes the representation of a machineConfigPool and updates it. Returns the server's representation of the machineConfigPool, and an error, if there is any. +func (c *FakeMachineConfigPools) Update(machineConfigPool *machineconfigurationopenshiftiov1.MachineConfigPool) (result *machineconfigurationopenshiftiov1.MachineConfigPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(machineconfigpoolsResource, c.ns, machineConfigPool), &machineconfigurationopenshiftiov1.MachineConfigPool{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfigPool), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeMachineConfigPools) UpdateStatus(machineConfigPool *machineconfigurationopenshiftiov1.MachineConfigPool) (*machineconfigurationopenshiftiov1.MachineConfigPool, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(machineconfigpoolsResource, "status", c.ns, machineConfigPool), &machineconfigurationopenshiftiov1.MachineConfigPool{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfigPool), err +} + +// Delete takes name of the machineConfigPool and deletes it. Returns an error if one occurs. +func (c *FakeMachineConfigPools) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(machineconfigpoolsResource, c.ns, name), &machineconfigurationopenshiftiov1.MachineConfigPool{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeMachineConfigPools) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(machineconfigpoolsResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &machineconfigurationopenshiftiov1.MachineConfigPoolList{}) + return err +} + +// Patch applies the patch and returns the patched machineConfigPool. +func (c *FakeMachineConfigPools) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *machineconfigurationopenshiftiov1.MachineConfigPool, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(machineconfigpoolsResource, c.ns, name, data, subresources...), &machineconfigurationopenshiftiov1.MachineConfigPool{}) + + if obj == nil { + return nil, err + } + return obj.(*machineconfigurationopenshiftiov1.MachineConfigPool), err +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfiguration.openshift.io_client.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfiguration.openshift.io_client.go new file mode 100644 index 0000000000..0765dcd45a --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/fake/fake_machineconfiguration.openshift.io_client.go @@ -0,0 +1,32 @@ +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeMachineconfigurationV1 struct { + *testing.Fake +} + +func (c *FakeMachineconfigurationV1) ControllerConfigs(namespace string) v1.ControllerConfigInterface { + return &FakeControllerConfigs{c, namespace} +} + +func (c *FakeMachineconfigurationV1) MachineConfigs(namespace string) v1.MachineConfigInterface { + return &FakeMachineConfigs{c, namespace} +} + +func (c *FakeMachineconfigurationV1) MachineConfigPools(namespace string) v1.MachineConfigPoolInterface { + return &FakeMachineConfigPools{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeMachineconfigurationV1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/generated_expansion.go new file mode 100644 index 0000000000..ca08477821 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/generated_expansion.go @@ -0,0 +1,9 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +type ControllerConfigExpansion interface{} + +type MachineConfigExpansion interface{} + +type MachineConfigPoolExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfig.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfig.go new file mode 100644 index 0000000000..ffbe0c8d52 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfig.go @@ -0,0 +1,141 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + scheme "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// MachineConfigsGetter has a method to return a MachineConfigInterface. +// A group's client should implement this interface. +type MachineConfigsGetter interface { + MachineConfigs(namespace string) MachineConfigInterface +} + +// MachineConfigInterface has methods to work with MachineConfig resources. +type MachineConfigInterface interface { + Create(*v1.MachineConfig) (*v1.MachineConfig, error) + Update(*v1.MachineConfig) (*v1.MachineConfig, error) + Delete(name string, options *metav1.DeleteOptions) error + DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error + Get(name string, options metav1.GetOptions) (*v1.MachineConfig, error) + List(opts metav1.ListOptions) (*v1.MachineConfigList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MachineConfig, err error) + MachineConfigExpansion +} + +// machineConfigs implements MachineConfigInterface +type machineConfigs struct { + client rest.Interface + ns string +} + +// newMachineConfigs returns a MachineConfigs +func newMachineConfigs(c *MachineconfigurationV1Client, namespace string) *machineConfigs { + return &machineConfigs{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the machineConfig, and returns the corresponding machineConfig object, and an error if there is any. +func (c *machineConfigs) Get(name string, options metav1.GetOptions) (result *v1.MachineConfig, err error) { + result = &v1.MachineConfig{} + err = c.client.Get(). + Namespace(c.ns). + Resource("machineconfigs"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of MachineConfigs that match those selectors. +func (c *machineConfigs) List(opts metav1.ListOptions) (result *v1.MachineConfigList, err error) { + result = &v1.MachineConfigList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("machineconfigs"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested machineConfigs. +func (c *machineConfigs) Watch(opts metav1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("machineconfigs"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a machineConfig and creates it. Returns the server's representation of the machineConfig, and an error, if there is any. +func (c *machineConfigs) Create(machineConfig *v1.MachineConfig) (result *v1.MachineConfig, err error) { + result = &v1.MachineConfig{} + err = c.client.Post(). + Namespace(c.ns). + Resource("machineconfigs"). + Body(machineConfig). + Do(). + Into(result) + return +} + +// Update takes the representation of a machineConfig and updates it. Returns the server's representation of the machineConfig, and an error, if there is any. +func (c *machineConfigs) Update(machineConfig *v1.MachineConfig) (result *v1.MachineConfig, err error) { + result = &v1.MachineConfig{} + err = c.client.Put(). + Namespace(c.ns). + Resource("machineconfigs"). + Name(machineConfig.Name). + Body(machineConfig). + Do(). + Into(result) + return +} + +// Delete takes name of the machineConfig and deletes it. Returns an error if one occurs. +func (c *machineConfigs) Delete(name string, options *metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("machineconfigs"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *machineConfigs) DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("machineconfigs"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched machineConfig. +func (c *machineConfigs) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MachineConfig, err error) { + result = &v1.MachineConfig{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("machineconfigs"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfigpool.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfigpool.go new file mode 100644 index 0000000000..05c63c91f5 --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfigpool.go @@ -0,0 +1,158 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + scheme "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// MachineConfigPoolsGetter has a method to return a MachineConfigPoolInterface. +// A group's client should implement this interface. +type MachineConfigPoolsGetter interface { + MachineConfigPools(namespace string) MachineConfigPoolInterface +} + +// MachineConfigPoolInterface has methods to work with MachineConfigPool resources. +type MachineConfigPoolInterface interface { + Create(*v1.MachineConfigPool) (*v1.MachineConfigPool, error) + Update(*v1.MachineConfigPool) (*v1.MachineConfigPool, error) + UpdateStatus(*v1.MachineConfigPool) (*v1.MachineConfigPool, error) + Delete(name string, options *metav1.DeleteOptions) error + DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error + Get(name string, options metav1.GetOptions) (*v1.MachineConfigPool, error) + List(opts metav1.ListOptions) (*v1.MachineConfigPoolList, error) + Watch(opts metav1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MachineConfigPool, err error) + MachineConfigPoolExpansion +} + +// machineConfigPools implements MachineConfigPoolInterface +type machineConfigPools struct { + client rest.Interface + ns string +} + +// newMachineConfigPools returns a MachineConfigPools +func newMachineConfigPools(c *MachineconfigurationV1Client, namespace string) *machineConfigPools { + return &machineConfigPools{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the machineConfigPool, and returns the corresponding machineConfigPool object, and an error if there is any. +func (c *machineConfigPools) Get(name string, options metav1.GetOptions) (result *v1.MachineConfigPool, err error) { + result = &v1.MachineConfigPool{} + err = c.client.Get(). + Namespace(c.ns). + Resource("machineconfigpools"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of MachineConfigPools that match those selectors. +func (c *machineConfigPools) List(opts metav1.ListOptions) (result *v1.MachineConfigPoolList, err error) { + result = &v1.MachineConfigPoolList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("machineconfigpools"). + VersionedParams(&opts, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested machineConfigPools. +func (c *machineConfigPools) Watch(opts metav1.ListOptions) (watch.Interface, error) { + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("machineconfigpools"). + VersionedParams(&opts, scheme.ParameterCodec). + Watch() +} + +// Create takes the representation of a machineConfigPool and creates it. Returns the server's representation of the machineConfigPool, and an error, if there is any. +func (c *machineConfigPools) Create(machineConfigPool *v1.MachineConfigPool) (result *v1.MachineConfigPool, err error) { + result = &v1.MachineConfigPool{} + err = c.client.Post(). + Namespace(c.ns). + Resource("machineconfigpools"). + Body(machineConfigPool). + Do(). + Into(result) + return +} + +// Update takes the representation of a machineConfigPool and updates it. Returns the server's representation of the machineConfigPool, and an error, if there is any. +func (c *machineConfigPools) Update(machineConfigPool *v1.MachineConfigPool) (result *v1.MachineConfigPool, err error) { + result = &v1.MachineConfigPool{} + err = c.client.Put(). + Namespace(c.ns). + Resource("machineconfigpools"). + Name(machineConfigPool.Name). + Body(machineConfigPool). + Do(). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). + +func (c *machineConfigPools) UpdateStatus(machineConfigPool *v1.MachineConfigPool) (result *v1.MachineConfigPool, err error) { + result = &v1.MachineConfigPool{} + err = c.client.Put(). + Namespace(c.ns). + Resource("machineconfigpools"). + Name(machineConfigPool.Name). + SubResource("status"). + Body(machineConfigPool). + Do(). + Into(result) + return +} + +// Delete takes name of the machineConfigPool and deletes it. Returns an error if one occurs. +func (c *machineConfigPools) Delete(name string, options *metav1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("machineconfigpools"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *machineConfigPools) DeleteCollection(options *metav1.DeleteOptions, listOptions metav1.ListOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("machineconfigpools"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched machineConfigPool. +func (c *machineConfigPools) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1.MachineConfigPool, err error) { + result = &v1.MachineConfigPool{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("machineconfigpools"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfiguration.openshift.io_client.go b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfiguration.openshift.io_client.go new file mode 100644 index 0000000000..34babe651a --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/machineconfiguration.openshift.io/v1/machineconfiguration.openshift.io_client.go @@ -0,0 +1,84 @@ +// Code generated by client-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned/scheme" + serializer "k8s.io/apimachinery/pkg/runtime/serializer" + rest "k8s.io/client-go/rest" +) + +type MachineconfigurationV1Interface interface { + RESTClient() rest.Interface + ControllerConfigsGetter + MachineConfigsGetter + MachineConfigPoolsGetter +} + +// MachineconfigurationV1Client is used to interact with features provided by the machineconfiguration.openshift.io group. +type MachineconfigurationV1Client struct { + restClient rest.Interface +} + +func (c *MachineconfigurationV1Client) ControllerConfigs(namespace string) ControllerConfigInterface { + return newControllerConfigs(c, namespace) +} + +func (c *MachineconfigurationV1Client) MachineConfigs(namespace string) MachineConfigInterface { + return newMachineConfigs(c, namespace) +} + +func (c *MachineconfigurationV1Client) MachineConfigPools(namespace string) MachineConfigPoolInterface { + return newMachineConfigPools(c, namespace) +} + +// NewForConfig creates a new MachineconfigurationV1Client for the given config. +func NewForConfig(c *rest.Config) (*MachineconfigurationV1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &MachineconfigurationV1Client{client}, nil +} + +// NewForConfigOrDie creates a new MachineconfigurationV1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *MachineconfigurationV1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new MachineconfigurationV1Client for the given RESTClient. +func New(c rest.Interface) *MachineconfigurationV1Client { + return &MachineconfigurationV1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = serializer.DirectCodecFactory{CodecFactory: scheme.Codecs} + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *MachineconfigurationV1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/generated/informers/externalversions/factory.go b/pkg/generated/informers/externalversions/factory.go new file mode 100644 index 0000000000..0f35d0e98f --- /dev/null +++ b/pkg/generated/informers/externalversions/factory.go @@ -0,0 +1,164 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" + internalinterfaces "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/internalinterfaces" + machineconfigurationopenshiftio "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/machineconfiguration.openshift.io" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Machineconfiguration() machineconfigurationopenshiftio.Interface +} + +func (f *sharedInformerFactory) Machineconfiguration() machineconfigurationopenshiftio.Interface { + return machineconfigurationopenshiftio.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go new file mode 100644 index 0000000000..3e931c7f51 --- /dev/null +++ b/pkg/generated/informers/externalversions/generic.go @@ -0,0 +1,50 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package externalversions + +import ( + "fmt" + + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=machineconfiguration.openshift.io, Version=v1 + case v1.SchemeGroupVersion.WithResource("controllerconfigs"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Machineconfiguration().V1().ControllerConfigs().Informer()}, nil + case v1.SchemeGroupVersion.WithResource("machineconfigs"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Machineconfiguration().V1().MachineConfigs().Informer()}, nil + case v1.SchemeGroupVersion.WithResource("machineconfigpools"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Machineconfiguration().V1().MachineConfigPools().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 0000000000..0b5dc9b130 --- /dev/null +++ b/pkg/generated/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,22 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package internalinterfaces + +import ( + time "time" + + versioned "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/interface.go b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/interface.go new file mode 100644 index 0000000000..78b6ef212d --- /dev/null +++ b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/interface.go @@ -0,0 +1,30 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package machineconfiguration + +import ( + internalinterfaces "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/internalinterfaces" + v1 "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1 provides access to shared informers for resources in V1. + V1() v1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1 returns a new v1.Interface. +func (g *group) V1() v1.Interface { + return v1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/controllerconfig.go b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/controllerconfig.go new file mode 100644 index 0000000000..afb5ed005f --- /dev/null +++ b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/controllerconfig.go @@ -0,0 +1,73 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + time "time" + + machineconfigurationopenshiftiov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + versioned "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" + internalinterfaces "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/internalinterfaces" + v1 "github.com/openshift/machine-config-operator/pkg/generated/listers/machineconfiguration.openshift.io/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// ControllerConfigInformer provides access to a shared informer and lister for +// ControllerConfigs. +type ControllerConfigInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.ControllerConfigLister +} + +type controllerConfigInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewControllerConfigInformer constructs a new informer for ControllerConfig type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewControllerConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredControllerConfigInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredControllerConfigInformer constructs a new informer for ControllerConfig type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredControllerConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.MachineconfigurationV1().ControllerConfigs(namespace).List(options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.MachineconfigurationV1().ControllerConfigs(namespace).Watch(options) + }, + }, + &machineconfigurationopenshiftiov1.ControllerConfig{}, + resyncPeriod, + indexers, + ) +} + +func (f *controllerConfigInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredControllerConfigInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *controllerConfigInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&machineconfigurationopenshiftiov1.ControllerConfig{}, f.defaultInformer) +} + +func (f *controllerConfigInformer) Lister() v1.ControllerConfigLister { + return v1.NewControllerConfigLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/interface.go b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/interface.go new file mode 100644 index 0000000000..c98f56c49f --- /dev/null +++ b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/interface.go @@ -0,0 +1,43 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + internalinterfaces "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ControllerConfigs returns a ControllerConfigInformer. + ControllerConfigs() ControllerConfigInformer + // MachineConfigs returns a MachineConfigInformer. + MachineConfigs() MachineConfigInformer + // MachineConfigPools returns a MachineConfigPoolInformer. + MachineConfigPools() MachineConfigPoolInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// ControllerConfigs returns a ControllerConfigInformer. +func (v *version) ControllerConfigs() ControllerConfigInformer { + return &controllerConfigInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// MachineConfigs returns a MachineConfigInformer. +func (v *version) MachineConfigs() MachineConfigInformer { + return &machineConfigInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + +// MachineConfigPools returns a MachineConfigPoolInformer. +func (v *version) MachineConfigPools() MachineConfigPoolInformer { + return &machineConfigPoolInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/machineconfig.go b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/machineconfig.go new file mode 100644 index 0000000000..fc36a8677a --- /dev/null +++ b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/machineconfig.go @@ -0,0 +1,73 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + time "time" + + machineconfigurationopenshiftiov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + versioned "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" + internalinterfaces "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/internalinterfaces" + v1 "github.com/openshift/machine-config-operator/pkg/generated/listers/machineconfiguration.openshift.io/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MachineConfigInformer provides access to a shared informer and lister for +// MachineConfigs. +type MachineConfigInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.MachineConfigLister +} + +type machineConfigInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewMachineConfigInformer constructs a new informer for MachineConfig type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewMachineConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredMachineConfigInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredMachineConfigInformer constructs a new informer for MachineConfig type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredMachineConfigInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.MachineconfigurationV1().MachineConfigs(namespace).List(options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.MachineconfigurationV1().MachineConfigs(namespace).Watch(options) + }, + }, + &machineconfigurationopenshiftiov1.MachineConfig{}, + resyncPeriod, + indexers, + ) +} + +func (f *machineConfigInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredMachineConfigInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *machineConfigInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&machineconfigurationopenshiftiov1.MachineConfig{}, f.defaultInformer) +} + +func (f *machineConfigInformer) Lister() v1.MachineConfigLister { + return v1.NewMachineConfigLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/machineconfigpool.go b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/machineconfigpool.go new file mode 100644 index 0000000000..ce2c0aa3eb --- /dev/null +++ b/pkg/generated/informers/externalversions/machineconfiguration.openshift.io/v1/machineconfigpool.go @@ -0,0 +1,73 @@ +// Code generated by informer-gen. DO NOT EDIT. + +package v1 + +import ( + time "time" + + machineconfigurationopenshiftiov1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + versioned "github.com/openshift/machine-config-operator/pkg/generated/clientset/versioned" + internalinterfaces "github.com/openshift/machine-config-operator/pkg/generated/informers/externalversions/internalinterfaces" + v1 "github.com/openshift/machine-config-operator/pkg/generated/listers/machineconfiguration.openshift.io/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// MachineConfigPoolInformer provides access to a shared informer and lister for +// MachineConfigPools. +type MachineConfigPoolInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1.MachineConfigPoolLister +} + +type machineConfigPoolInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewMachineConfigPoolInformer constructs a new informer for MachineConfigPool type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewMachineConfigPoolInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredMachineConfigPoolInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredMachineConfigPoolInformer constructs a new informer for MachineConfigPool type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredMachineConfigPoolInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options metav1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.MachineconfigurationV1().MachineConfigPools(namespace).List(options) + }, + WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.MachineconfigurationV1().MachineConfigPools(namespace).Watch(options) + }, + }, + &machineconfigurationopenshiftiov1.MachineConfigPool{}, + resyncPeriod, + indexers, + ) +} + +func (f *machineConfigPoolInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredMachineConfigPoolInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *machineConfigPoolInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&machineconfigurationopenshiftiov1.MachineConfigPool{}, f.defaultInformer) +} + +func (f *machineConfigPoolInformer) Lister() v1.MachineConfigPoolLister { + return v1.NewMachineConfigPoolLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/listers/machineconfiguration.openshift.io/v1/controllerconfig.go b/pkg/generated/listers/machineconfiguration.openshift.io/v1/controllerconfig.go new file mode 100644 index 0000000000..2d786eae6f --- /dev/null +++ b/pkg/generated/listers/machineconfiguration.openshift.io/v1/controllerconfig.go @@ -0,0 +1,78 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ControllerConfigLister helps list ControllerConfigs. +type ControllerConfigLister interface { + // List lists all ControllerConfigs in the indexer. + List(selector labels.Selector) (ret []*v1.ControllerConfig, err error) + // ControllerConfigs returns an object that can list and get ControllerConfigs. + ControllerConfigs(namespace string) ControllerConfigNamespaceLister + ControllerConfigListerExpansion +} + +// controllerConfigLister implements the ControllerConfigLister interface. +type controllerConfigLister struct { + indexer cache.Indexer +} + +// NewControllerConfigLister returns a new ControllerConfigLister. +func NewControllerConfigLister(indexer cache.Indexer) ControllerConfigLister { + return &controllerConfigLister{indexer: indexer} +} + +// List lists all ControllerConfigs in the indexer. +func (s *controllerConfigLister) List(selector labels.Selector) (ret []*v1.ControllerConfig, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.ControllerConfig)) + }) + return ret, err +} + +// ControllerConfigs returns an object that can list and get ControllerConfigs. +func (s *controllerConfigLister) ControllerConfigs(namespace string) ControllerConfigNamespaceLister { + return controllerConfigNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ControllerConfigNamespaceLister helps list and get ControllerConfigs. +type ControllerConfigNamespaceLister interface { + // List lists all ControllerConfigs in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1.ControllerConfig, err error) + // Get retrieves the ControllerConfig from the indexer for a given namespace and name. + Get(name string) (*v1.ControllerConfig, error) + ControllerConfigNamespaceListerExpansion +} + +// controllerConfigNamespaceLister implements the ControllerConfigNamespaceLister +// interface. +type controllerConfigNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all ControllerConfigs in the indexer for a given namespace. +func (s controllerConfigNamespaceLister) List(selector labels.Selector) (ret []*v1.ControllerConfig, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.ControllerConfig)) + }) + return ret, err +} + +// Get retrieves the ControllerConfig from the indexer for a given namespace and name. +func (s controllerConfigNamespaceLister) Get(name string) (*v1.ControllerConfig, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("controllerconfig"), name) + } + return obj.(*v1.ControllerConfig), nil +} diff --git a/pkg/generated/listers/machineconfiguration.openshift.io/v1/expansion_generated.go b/pkg/generated/listers/machineconfiguration.openshift.io/v1/expansion_generated.go new file mode 100644 index 0000000000..1ede024512 --- /dev/null +++ b/pkg/generated/listers/machineconfiguration.openshift.io/v1/expansion_generated.go @@ -0,0 +1,27 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +// ControllerConfigListerExpansion allows custom methods to be added to +// ControllerConfigLister. +type ControllerConfigListerExpansion interface{} + +// ControllerConfigNamespaceListerExpansion allows custom methods to be added to +// ControllerConfigNamespaceLister. +type ControllerConfigNamespaceListerExpansion interface{} + +// MachineConfigListerExpansion allows custom methods to be added to +// MachineConfigLister. +type MachineConfigListerExpansion interface{} + +// MachineConfigNamespaceListerExpansion allows custom methods to be added to +// MachineConfigNamespaceLister. +type MachineConfigNamespaceListerExpansion interface{} + +// MachineConfigPoolListerExpansion allows custom methods to be added to +// MachineConfigPoolLister. +type MachineConfigPoolListerExpansion interface{} + +// MachineConfigPoolNamespaceListerExpansion allows custom methods to be added to +// MachineConfigPoolNamespaceLister. +type MachineConfigPoolNamespaceListerExpansion interface{} diff --git a/pkg/generated/listers/machineconfiguration.openshift.io/v1/machineconfig.go b/pkg/generated/listers/machineconfiguration.openshift.io/v1/machineconfig.go new file mode 100644 index 0000000000..6e0831b1c6 --- /dev/null +++ b/pkg/generated/listers/machineconfiguration.openshift.io/v1/machineconfig.go @@ -0,0 +1,78 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// MachineConfigLister helps list MachineConfigs. +type MachineConfigLister interface { + // List lists all MachineConfigs in the indexer. + List(selector labels.Selector) (ret []*v1.MachineConfig, err error) + // MachineConfigs returns an object that can list and get MachineConfigs. + MachineConfigs(namespace string) MachineConfigNamespaceLister + MachineConfigListerExpansion +} + +// machineConfigLister implements the MachineConfigLister interface. +type machineConfigLister struct { + indexer cache.Indexer +} + +// NewMachineConfigLister returns a new MachineConfigLister. +func NewMachineConfigLister(indexer cache.Indexer) MachineConfigLister { + return &machineConfigLister{indexer: indexer} +} + +// List lists all MachineConfigs in the indexer. +func (s *machineConfigLister) List(selector labels.Selector) (ret []*v1.MachineConfig, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.MachineConfig)) + }) + return ret, err +} + +// MachineConfigs returns an object that can list and get MachineConfigs. +func (s *machineConfigLister) MachineConfigs(namespace string) MachineConfigNamespaceLister { + return machineConfigNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// MachineConfigNamespaceLister helps list and get MachineConfigs. +type MachineConfigNamespaceLister interface { + // List lists all MachineConfigs in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1.MachineConfig, err error) + // Get retrieves the MachineConfig from the indexer for a given namespace and name. + Get(name string) (*v1.MachineConfig, error) + MachineConfigNamespaceListerExpansion +} + +// machineConfigNamespaceLister implements the MachineConfigNamespaceLister +// interface. +type machineConfigNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all MachineConfigs in the indexer for a given namespace. +func (s machineConfigNamespaceLister) List(selector labels.Selector) (ret []*v1.MachineConfig, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.MachineConfig)) + }) + return ret, err +} + +// Get retrieves the MachineConfig from the indexer for a given namespace and name. +func (s machineConfigNamespaceLister) Get(name string) (*v1.MachineConfig, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("machineconfig"), name) + } + return obj.(*v1.MachineConfig), nil +} diff --git a/pkg/generated/listers/machineconfiguration.openshift.io/v1/machineconfigpool.go b/pkg/generated/listers/machineconfiguration.openshift.io/v1/machineconfigpool.go new file mode 100644 index 0000000000..1816451751 --- /dev/null +++ b/pkg/generated/listers/machineconfiguration.openshift.io/v1/machineconfigpool.go @@ -0,0 +1,78 @@ +// Code generated by lister-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "github.com/openshift/machine-config-operator/pkg/apis/machineconfiguration.openshift.io/v1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// MachineConfigPoolLister helps list MachineConfigPools. +type MachineConfigPoolLister interface { + // List lists all MachineConfigPools in the indexer. + List(selector labels.Selector) (ret []*v1.MachineConfigPool, err error) + // MachineConfigPools returns an object that can list and get MachineConfigPools. + MachineConfigPools(namespace string) MachineConfigPoolNamespaceLister + MachineConfigPoolListerExpansion +} + +// machineConfigPoolLister implements the MachineConfigPoolLister interface. +type machineConfigPoolLister struct { + indexer cache.Indexer +} + +// NewMachineConfigPoolLister returns a new MachineConfigPoolLister. +func NewMachineConfigPoolLister(indexer cache.Indexer) MachineConfigPoolLister { + return &machineConfigPoolLister{indexer: indexer} +} + +// List lists all MachineConfigPools in the indexer. +func (s *machineConfigPoolLister) List(selector labels.Selector) (ret []*v1.MachineConfigPool, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1.MachineConfigPool)) + }) + return ret, err +} + +// MachineConfigPools returns an object that can list and get MachineConfigPools. +func (s *machineConfigPoolLister) MachineConfigPools(namespace string) MachineConfigPoolNamespaceLister { + return machineConfigPoolNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// MachineConfigPoolNamespaceLister helps list and get MachineConfigPools. +type MachineConfigPoolNamespaceLister interface { + // List lists all MachineConfigPools in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1.MachineConfigPool, err error) + // Get retrieves the MachineConfigPool from the indexer for a given namespace and name. + Get(name string) (*v1.MachineConfigPool, error) + MachineConfigPoolNamespaceListerExpansion +} + +// machineConfigPoolNamespaceLister implements the MachineConfigPoolNamespaceLister +// interface. +type machineConfigPoolNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all MachineConfigPools in the indexer for a given namespace. +func (s machineConfigPoolNamespaceLister) List(selector labels.Selector) (ret []*v1.MachineConfigPool, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1.MachineConfigPool)) + }) + return ret, err +} + +// Get retrieves the MachineConfigPool from the indexer for a given namespace and name. +func (s machineConfigPoolNamespaceLister) Get(name string) (*v1.MachineConfigPool, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1.Resource("machineconfigpool"), name) + } + return obj.(*v1.MachineConfigPool), nil +} diff --git a/vendor/github.com/ajeddeloh/go-json/decode.go b/vendor/github.com/ajeddeloh/go-json/decode.go new file mode 100644 index 0000000000..1dc2fdf0d4 --- /dev/null +++ b/vendor/github.com/ajeddeloh/go-json/decode.go @@ -0,0 +1,1226 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Represents JSON data structure using native Go types: booleans, floats, +// strings, arrays, and maps. + +package json + +import ( + "bytes" + "encoding" + "encoding/base64" + "errors" + "fmt" + "reflect" + "runtime" + "strconv" + "unicode" + "unicode/utf16" + "unicode/utf8" +) + +// Unmarshal parses the JSON-encoded data and stores the result +// in the value pointed to by v. +// +// Unmarshal uses the inverse of the encodings that +// Marshal uses, allocating maps, slices, and pointers as necessary, +// with the following additional rules: +// +// To unmarshal JSON into a pointer, Unmarshal first handles the case of +// the JSON being the JSON literal null. In that case, Unmarshal sets +// the pointer to nil. Otherwise, Unmarshal unmarshals the JSON into +// the value pointed at by the pointer. If the pointer is nil, Unmarshal +// allocates a new value for it to point to. +// +// To unmarshal JSON into a struct, Unmarshal matches incoming object +// keys to the keys used by Marshal (either the struct field name or its tag), +// preferring an exact match but also accepting a case-insensitive match. +// +// To unmarshal JSON into an interface value, +// Unmarshal stores one of these in the interface value: +// +// bool, for JSON booleans +// float64, for JSON numbers +// string, for JSON strings +// []interface{}, for JSON arrays +// map[string]interface{}, for JSON objects +// nil for JSON null +// +// To unmarshal a JSON array into a slice, Unmarshal resets the slice to nil +// and then appends each element to the slice. +// +// To unmarshal a JSON object into a map, Unmarshal replaces the map +// with an empty map and then adds key-value pairs from the object to +// the map. +// +// If a JSON value is not appropriate for a given target type, +// or if a JSON number overflows the target type, Unmarshal +// skips that field and completes the unmarshalling as best it can. +// If no more serious errors are encountered, Unmarshal returns +// an UnmarshalTypeError describing the earliest such error. +// +// The JSON null value unmarshals into an interface, map, pointer, or slice +// by setting that Go value to nil. Because null is often used in JSON to mean +// ``not present,'' unmarshaling a JSON null into any other Go type has no effect +// on the value and produces no error. +// +// When unmarshaling quoted strings, invalid UTF-8 or +// invalid UTF-16 surrogate pairs are not treated as an error. +// Instead, they are replaced by the Unicode replacement +// character U+FFFD. +// +func Unmarshal(data []byte, v interface{}) error { + // Check for well-formedness. + // Avoids filling out half a data structure + // before discovering a JSON syntax error. + var d decodeState + err := checkValid(data, &d.scan) + if err != nil { + return err + } + + d.init(data) + return d.unmarshal(v) +} + +// Unmarshaler is the interface implemented by objects +// that can unmarshal a JSON description of themselves. +// The input can be assumed to be a valid encoding of +// a JSON value. UnmarshalJSON must copy the JSON data +// if it wishes to retain the data after returning. +type Unmarshaler interface { + UnmarshalJSON([]byte) error +} + +// An UnmarshalTypeError describes a JSON value that was +// not appropriate for a value of a specific Go type. +type UnmarshalTypeError struct { + Value string // description of JSON value - "bool", "array", "number -5" + Type reflect.Type // type of Go value it could not be assigned to + Offset int64 // error occurred after reading Offset bytes +} + +func (e *UnmarshalTypeError) Error() string { + return "json: cannot unmarshal " + e.Value + " into Go value of type " + e.Type.String() +} + +// An UnmarshalFieldError describes a JSON object key that +// led to an unexported (and therefore unwritable) struct field. +// (No longer used; kept for compatibility.) +type UnmarshalFieldError struct { + Key string + Type reflect.Type + Field reflect.StructField +} + +func (e *UnmarshalFieldError) Error() string { + return "json: cannot unmarshal object key " + strconv.Quote(e.Key) + " into unexported field " + e.Field.Name + " of type " + e.Type.String() +} + +// An InvalidUnmarshalError describes an invalid argument passed to Unmarshal. +// (The argument to Unmarshal must be a non-nil pointer.) +type InvalidUnmarshalError struct { + Type reflect.Type +} + +type Node struct { + Start int + End int + KeyStart int // Only value if a member of a struct + KeyEnd int + Value interface{} +} + +func (e *InvalidUnmarshalError) Error() string { + if e.Type == nil { + return "json: Unmarshal(nil)" + } + + if e.Type.Kind() != reflect.Ptr { + return "json: Unmarshal(non-pointer " + e.Type.String() + ")" + } + return "json: Unmarshal(nil " + e.Type.String() + ")" +} + +func (d *decodeState) unmarshal(v interface{}) (err error) { + defer func() { + if r := recover(); r != nil { + if _, ok := r.(runtime.Error); ok { + panic(r) + } + err = r.(error) + } + }() + + rv := reflect.ValueOf(v) + if rv.Kind() != reflect.Ptr || rv.IsNil() { + return &InvalidUnmarshalError{reflect.TypeOf(v)} + } + + d.scan.reset() + // We decode rv not rv.Elem because the Unmarshaler interface + // test must be applied at the top level of the value. + d.value(rv) + return d.savedError +} + +// A Number represents a JSON number literal. +type Number string + +// String returns the literal text of the number. +func (n Number) String() string { return string(n) } + +// Float64 returns the number as a float64. +func (n Number) Float64() (float64, error) { + return strconv.ParseFloat(string(n), 64) +} + +// Int64 returns the number as an int64. +func (n Number) Int64() (int64, error) { + return strconv.ParseInt(string(n), 10, 64) +} + +// decodeState represents the state while decoding a JSON value. +type decodeState struct { + data []byte + off int // read offset in data + scan scanner + nextscan scanner // for calls to nextValue + savedError error + useNumber bool +} + +// errPhase is used for errors that should not happen unless +// there is a bug in the JSON decoder or something is editing +// the data slice while the decoder executes. +var errPhase = errors.New("JSON decoder out of sync - data changing underfoot?") + +func (d *decodeState) init(data []byte) *decodeState { + d.data = data + d.off = 0 + d.savedError = nil + return d +} + +// error aborts the decoding by panicking with err. +func (d *decodeState) error(err error) { + panic(err) +} + +// saveError saves the first err it is called with, +// for reporting at the end of the unmarshal. +func (d *decodeState) saveError(err error) { + if d.savedError == nil { + d.savedError = err + } +} + +// next cuts off and returns the next full JSON value in d.data[d.off:]. +// The next value is known to be an object or array, not a literal. +func (d *decodeState) next() []byte { + c := d.data[d.off] + item, rest, err := nextValue(d.data[d.off:], &d.nextscan) + if err != nil { + d.error(err) + } + d.off = len(d.data) - len(rest) + + // Our scanner has seen the opening brace/bracket + // and thinks we're still in the middle of the object. + // invent a closing brace/bracket to get it out. + if c == '{' { + d.scan.step(&d.scan, '}') + } else { + d.scan.step(&d.scan, ']') + } + + return item +} + +// scanWhile processes bytes in d.data[d.off:] until it +// receives a scan code not equal to op. +// It updates d.off and returns the new scan code. +func (d *decodeState) scanWhile(op int) int { + var newOp int + for { + if d.off >= len(d.data) { + newOp = d.scan.eof() + d.off = len(d.data) + 1 // mark processed EOF with len+1 + } else { + c := int(d.data[d.off]) + d.off++ + newOp = d.scan.step(&d.scan, c) + } + if newOp != op { + break + } + } + return newOp +} + +// value decodes a JSON value from d.data[d.off:] into the value. +// it updates d.off to point past the decoded value. +func (d *decodeState) value(v reflect.Value) { + if !v.IsValid() { + _, rest, err := nextValue(d.data[d.off:], &d.nextscan) + if err != nil { + d.error(err) + } + d.off = len(d.data) - len(rest) + + // d.scan thinks we're still at the beginning of the item. + // Feed in an empty string - the shortest, simplest value - + // so that it knows we got to the end of the value. + if d.scan.redo { + // rewind. + d.scan.redo = false + d.scan.step = stateBeginValue + } + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '"') + + n := len(d.scan.parseState) + if n > 0 && d.scan.parseState[n-1] == parseObjectKey { + // d.scan thinks we just read an object key; finish the object + d.scan.step(&d.scan, ':') + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '"') + d.scan.step(&d.scan, '}') + } + + return + } + + switch op := d.scanWhile(scanSkipSpace); op { + default: + d.error(errPhase) + + case scanBeginArray: + d.array(v) + + case scanBeginObject: + d.object(v) + + case scanBeginLiteral: + d.literal(v) + } +} + +type unquotedValue struct{} + +// valueQuoted is like value but decodes a +// quoted string literal or literal null into an interface value. +// If it finds anything other than a quoted string literal or null, +// valueQuoted returns unquotedValue{}. +func (d *decodeState) valueQuoted() interface{} { + switch op := d.scanWhile(scanSkipSpace); op { + default: + d.error(errPhase) + + case scanBeginArray: + d.array(reflect.Value{}) + + case scanBeginObject: + d.object(reflect.Value{}) + + case scanBeginLiteral: + switch v := d.literalInterface().(type) { + case nil, string: + return v + } + } + return unquotedValue{} +} + +// indirect walks down v allocating pointers as needed, +// until it gets to a non-pointer. +// if it encounters an Unmarshaler, indirect stops and returns that. +// if decodingNull is true, indirect stops at the last pointer so it can be set to nil. +func (d *decodeState) indirect(v reflect.Value, decodingNull bool) (Unmarshaler, encoding.TextUnmarshaler, reflect.Value) { + // If v is a named type and is addressable, + // start with its address, so that if the type has pointer methods, + // we find them. + if v.Kind() != reflect.Ptr && v.Type().Name() != "" && v.CanAddr() { + v = v.Addr() + } + for { + // Load value from interface, but only if the result will be + // usefully addressable. + if v.Kind() == reflect.Interface && !v.IsNil() { + e := v.Elem() + if e.Kind() == reflect.Ptr && !e.IsNil() && (!decodingNull || e.Elem().Kind() == reflect.Ptr) { + v = e + continue + } + } + + if v.Kind() != reflect.Ptr { + break + } + + if v.Elem().Kind() != reflect.Ptr && decodingNull && v.CanSet() { + break + } + if v.IsNil() { + v.Set(reflect.New(v.Type().Elem())) + } + if v.Type().NumMethod() > 0 { + if u, ok := v.Interface().(Unmarshaler); ok { + return u, nil, reflect.Value{} + } + if u, ok := v.Interface().(encoding.TextUnmarshaler); ok { + return nil, u, reflect.Value{} + } + } + v = v.Elem() + } + return nil, nil, v +} + +// array consumes an array from d.data[d.off-1:], decoding into the value v. +// the first byte of the array ('[') has been read already. +func (d *decodeState) array(v reflect.Value) { + // Check for unmarshaler. + u, ut, pv := d.indirect(v, false) + if u != nil { + d.off-- + err := u.UnmarshalJSON(d.next()) + if err != nil { + d.error(err) + } + return + } + if ut != nil { + d.saveError(&UnmarshalTypeError{"array", v.Type(), int64(d.off)}) + d.off-- + d.next() + return + } + + v = pv + + // Check type of target. + switch v.Kind() { + case reflect.Interface: + if v.NumMethod() == 0 { + // Decoding into nil interface? Switch to non-reflect code. + v.Set(reflect.ValueOf(d.arrayInterface())) + return + } + // Otherwise it's invalid. + fallthrough + default: + if v.Type() == reflect.TypeOf(Node{}) { + // Decoding to Node? Switch to that code + v.Set(reflect.ValueOf(d.arrayNode())) + return + } + d.saveError(&UnmarshalTypeError{"array", v.Type(), int64(d.off)}) + d.off-- + d.next() + return + case reflect.Array: + case reflect.Slice: + break + } + + i := 0 + for { + // Look ahead for ] - can only happen on first iteration. + op := d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + + // Back up so d.value can have the byte we just read. + d.off-- + d.scan.undo(op) + + // Get element of array, growing if necessary. + if v.Kind() == reflect.Slice { + // Grow slice if necessary + if i >= v.Cap() { + newcap := v.Cap() + v.Cap()/2 + if newcap < 4 { + newcap = 4 + } + newv := reflect.MakeSlice(v.Type(), v.Len(), newcap) + reflect.Copy(newv, v) + v.Set(newv) + } + if i >= v.Len() { + v.SetLen(i + 1) + } + } + + if i < v.Len() { + // Decode into element. + d.value(v.Index(i)) + } else { + // Ran out of fixed array: skip. + d.value(reflect.Value{}) + } + i++ + + // Next token must be , or ]. + op = d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + if op != scanArrayValue { + d.error(errPhase) + } + } + + if i < v.Len() { + if v.Kind() == reflect.Array { + // Array. Zero the rest. + z := reflect.Zero(v.Type().Elem()) + for ; i < v.Len(); i++ { + v.Index(i).Set(z) + } + } else { + v.SetLen(i) + } + } + if i == 0 && v.Kind() == reflect.Slice { + v.Set(reflect.MakeSlice(v.Type(), 0, 0)) + } +} + +var nullLiteral = []byte("null") + +// object consumes an object from d.data[d.off-1:], decoding into the value v. +// the first byte ('{') of the object has been read already. +func (d *decodeState) object(v reflect.Value) { + // Check for unmarshaler. + u, ut, pv := d.indirect(v, false) + if u != nil { + d.off-- + err := u.UnmarshalJSON(d.next()) + if err != nil { + d.error(err) + } + return + } + if ut != nil { + d.saveError(&UnmarshalTypeError{"object", v.Type(), int64(d.off)}) + d.off-- + d.next() // skip over { } in input + return + } + v = pv + + // Decoding into nil interface? Switch to non-reflect code. + if v.Kind() == reflect.Interface && v.NumMethod() == 0 { + v.Set(reflect.ValueOf(d.objectInterface())) + return + } else if v.Type() == reflect.TypeOf(Node{}) { + // Decoding to Node? Switch to that code + v.Set(reflect.ValueOf(d.objectNode())) + return + } + + // Check type of target: struct or map[string]T + switch v.Kind() { + case reflect.Map: + // map must have string kind + t := v.Type() + if t.Key().Kind() != reflect.String { + d.saveError(&UnmarshalTypeError{"object", v.Type(), int64(d.off)}) + d.off-- + d.next() // skip over { } in input + return + } + if v.IsNil() { + v.Set(reflect.MakeMap(t)) + } + case reflect.Struct: + + default: + d.saveError(&UnmarshalTypeError{"object", v.Type(), int64(d.off)}) + d.off-- + d.next() // skip over { } in input + return + } + + var mapElem reflect.Value + + for { + // Read opening " of string key or closing }. + op := d.scanWhile(scanSkipSpace) + if op == scanEndObject { + // closing } - can only happen on first iteration. + break + } + if op != scanBeginLiteral { + d.error(errPhase) + } + + // Read key. + start := d.off - 1 + op = d.scanWhile(scanContinue) + item := d.data[start : d.off-1] + key, ok := unquoteBytes(item) + if !ok { + d.error(errPhase) + } + + // Figure out field corresponding to key. + var subv reflect.Value + destring := false // whether the value is wrapped in a string to be decoded first + + if v.Kind() == reflect.Map { + elemType := v.Type().Elem() + if !mapElem.IsValid() { + mapElem = reflect.New(elemType).Elem() + } else { + mapElem.Set(reflect.Zero(elemType)) + } + subv = mapElem + } else { + var f *field + fields := cachedTypeFields(v.Type()) + for i := range fields { + ff := &fields[i] + if bytes.Equal(ff.nameBytes, key) { + f = ff + break + } + if f == nil && ff.equalFold(ff.nameBytes, key) { + f = ff + } + } + if f != nil { + subv = v + destring = f.quoted + for _, i := range f.index { + if subv.Kind() == reflect.Ptr { + if subv.IsNil() { + subv.Set(reflect.New(subv.Type().Elem())) + } + subv = subv.Elem() + } + subv = subv.Field(i) + } + } + } + + // Read : before value. + if op == scanSkipSpace { + op = d.scanWhile(scanSkipSpace) + } + if op != scanObjectKey { + d.error(errPhase) + } + + // Read value. + if destring { + switch qv := d.valueQuoted().(type) { + case nil: + d.literalStore(nullLiteral, subv, false) + case string: + d.literalStore([]byte(qv), subv, true) + default: + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal unquoted value into %v", subv.Type())) + } + } else { + d.value(subv) + } + + // Write value back to map; + // if using struct, subv points into struct already. + if v.Kind() == reflect.Map { + kv := reflect.ValueOf(key).Convert(v.Type().Key()) + v.SetMapIndex(kv, subv) + } + + // Next token must be , or }. + op = d.scanWhile(scanSkipSpace) + if op == scanEndObject { + break + } + if op != scanObjectValue { + d.error(errPhase) + } + } +} + +// literal consumes a literal from d.data[d.off-1:], decoding into the value v. +// The first byte of the literal has been read already +// (that's how the caller knows it's a literal). +func (d *decodeState) literal(v reflect.Value) { + // All bytes inside literal return scanContinue op code. + start := d.off - 1 + op := d.scanWhile(scanContinue) + + // Scan read one byte too far; back up. + d.off-- + d.scan.undo(op) + + d.literalStore(d.data[start:d.off], v, false) +} + +// convertNumber converts the number literal s to a float64 or a Number +// depending on the setting of d.useNumber. +func (d *decodeState) convertNumber(s string) (interface{}, error) { + if d.useNumber { + return Number(s), nil + } + f, err := strconv.ParseFloat(s, 64) + if err != nil { + return nil, &UnmarshalTypeError{"number " + s, reflect.TypeOf(0.0), int64(d.off)} + } + return f, nil +} + +var numberType = reflect.TypeOf(Number("")) + +// literalStore decodes a literal stored in item into v. +// +// fromQuoted indicates whether this literal came from unwrapping a +// string from the ",string" struct tag option. this is used only to +// produce more helpful error messages. +func (d *decodeState) literalStore(item []byte, v reflect.Value, fromQuoted bool) { + // Check for unmarshaler. + if len(item) == 0 { + //Empty string given + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + return + } + wantptr := item[0] == 'n' // null + u, ut, pv := d.indirect(v, wantptr) + if u != nil { + err := u.UnmarshalJSON(item) + if err != nil { + d.error(err) + } + return + } + if ut != nil { + if item[0] != '"' { + if fromQuoted { + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + } + return + } + s, ok := unquoteBytes(item) + if !ok { + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } + } + err := ut.UnmarshalText(s) + if err != nil { + d.error(err) + } + return + } + + v = pv + + switch c := item[0]; c { + case 'n': // null + switch v.Kind() { + case reflect.Interface, reflect.Ptr, reflect.Map, reflect.Slice: + v.Set(reflect.Zero(v.Type())) + // otherwise, ignore null for primitives/string + } + case 't', 'f': // true, false + value := c == 't' + switch v.Kind() { + default: + if fromQuoted { + d.saveError(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.saveError(&UnmarshalTypeError{"bool", v.Type(), int64(d.off)}) + } + case reflect.Bool: + v.SetBool(value) + case reflect.Interface: + if v.NumMethod() == 0 { + v.Set(reflect.ValueOf(value)) + } else { + d.saveError(&UnmarshalTypeError{"bool", v.Type(), int64(d.off)}) + } + } + + case '"': // string + s, ok := unquoteBytes(item) + if !ok { + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } + } + switch v.Kind() { + default: + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + case reflect.Slice: + if v.Type().Elem().Kind() != reflect.Uint8 { + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + break + } + b := make([]byte, base64.StdEncoding.DecodedLen(len(s))) + n, err := base64.StdEncoding.Decode(b, s) + if err != nil { + d.saveError(err) + break + } + v.Set(reflect.ValueOf(b[0:n])) + case reflect.String: + v.SetString(string(s)) + case reflect.Interface: + if v.NumMethod() == 0 { + v.Set(reflect.ValueOf(string(s))) + } else { + d.saveError(&UnmarshalTypeError{"string", v.Type(), int64(d.off)}) + } + } + + default: // number + if c != '-' && (c < '0' || c > '9') { + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(errPhase) + } + } + s := string(item) + switch v.Kind() { + default: + if v.Kind() == reflect.String && v.Type() == numberType { + v.SetString(s) + break + } + if fromQuoted { + d.error(fmt.Errorf("json: invalid use of ,string struct tag, trying to unmarshal %q into %v", item, v.Type())) + } else { + d.error(&UnmarshalTypeError{"number", v.Type(), int64(d.off)}) + } + case reflect.Interface: + n, err := d.convertNumber(s) + if err != nil { + d.saveError(err) + break + } + if v.NumMethod() != 0 { + d.saveError(&UnmarshalTypeError{"number", v.Type(), int64(d.off)}) + break + } + v.Set(reflect.ValueOf(n)) + + case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: + n, err := strconv.ParseInt(s, 10, 64) + if err != nil || v.OverflowInt(n) { + d.saveError(&UnmarshalTypeError{"number " + s, v.Type(), int64(d.off)}) + break + } + v.SetInt(n) + + case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr: + n, err := strconv.ParseUint(s, 10, 64) + if err != nil || v.OverflowUint(n) { + d.saveError(&UnmarshalTypeError{"number " + s, v.Type(), int64(d.off)}) + break + } + v.SetUint(n) + + case reflect.Float32, reflect.Float64: + n, err := strconv.ParseFloat(s, v.Type().Bits()) + if err != nil || v.OverflowFloat(n) { + d.saveError(&UnmarshalTypeError{"number " + s, v.Type(), int64(d.off)}) + break + } + v.SetFloat(n) + } + } +} + +// The xxxInterface routines build up a value to be stored +// in an empty interface. They are not strictly necessary, +// but they avoid the weight of reflection in this common case. + +// valueInterface is like value but returns interface{} +func (d *decodeState) valueInterface() interface{} { + switch d.scanWhile(scanSkipSpace) { + default: + d.error(errPhase) + panic("unreachable") + case scanBeginArray: + return d.arrayInterface() + case scanBeginObject: + return d.objectInterface() + case scanBeginLiteral: + return d.literalInterface() + } +} + +// valueNode is like valueInterface but returns a wrapped version that +// contains metadata about where it decoded from +func (d *decodeState) valueNode() Node { + switch d.scanWhile(scanSkipSpace) { + default: + d.error(errPhase) + panic("unreachable") + case scanBeginArray: + return d.arrayNode() + case scanBeginObject: + return d.objectNode() + case scanBeginLiteral: + return d.literalNode() + } +} + +// arrayInterface is like array but returns []interface{}. +func (d *decodeState) arrayInterface() []interface{} { + var v = make([]interface{}, 0) + for { + // Look ahead for ] - can only happen on first iteration. + op := d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + + // Back up so d.value can have the byte we just read. + d.off-- + d.scan.undo(op) + + v = append(v, d.valueInterface()) + + // Next token must be , or ]. + op = d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + if op != scanArrayValue { + d.error(errPhase) + } + } + return v +} + +// arrayNode is like arrayInterface but returns Node. +func (d *decodeState) arrayNode() Node { + var v = make([]Node, 0) + node := Node{ + Start: d.off, + Value: v, + } + for { + // Look ahead for ] - can only happen on first iteration. + op := d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + + // Back up so d.value can have the byte we just read. + d.off-- + d.scan.undo(op) + + v = append(v, d.valueNode()) + + // Next token must be , or ]. + op = d.scanWhile(scanSkipSpace) + if op == scanEndArray { + break + } + if op != scanArrayValue { + d.error(errPhase) + } + } + node.Value = v + node.End = d.off - 1 + return node +} + +// objectInterface is like object but returns map[string]interface{}. +func (d *decodeState) objectInterface() map[string]interface{} { + m := make(map[string]interface{}) + for { + // Read opening " of string key or closing }. + op := d.scanWhile(scanSkipSpace) + if op == scanEndObject { + // closing } - can only happen on first iteration. + break + } + if op != scanBeginLiteral { + d.error(errPhase) + } + + // Read string key. + start := d.off - 1 + op = d.scanWhile(scanContinue) + item := d.data[start : d.off-1] + key, ok := unquote(item) + if !ok { + d.error(errPhase) + } + + // Read : before value. + if op == scanSkipSpace { + op = d.scanWhile(scanSkipSpace) + } + if op != scanObjectKey { + d.error(errPhase) + } + + // Read value. + m[key] = d.valueInterface() + + // Next token must be , or }. + op = d.scanWhile(scanSkipSpace) + if op == scanEndObject { + break + } + if op != scanObjectValue { + d.error(errPhase) + } + } + return m +} + +// objectNode is like object but returns Node. +func (d *decodeState) objectNode() Node { + m := make(map[string]Node) + node := Node{ + Start: d.off, + } + for { + // Read opening " of string key or closing }. + op := d.scanWhile(scanSkipSpace) + if op == scanEndObject { + // closing } - can only happen on first iteration. + break + } + if op != scanBeginLiteral { + d.error(errPhase) + } + + // Read string key. + start := d.off - 1 + op = d.scanWhile(scanContinue) + item := d.data[start : d.off-1] + keyEnd := d.off - 1 + key, ok := unquote(item) + if !ok { + d.error(errPhase) + } + + // Read : before value. + if op == scanSkipSpace { + op = d.scanWhile(scanSkipSpace) + } + if op != scanObjectKey { + d.error(errPhase) + } + + // Read value. + val := d.valueNode() + val.KeyStart = start + val.KeyEnd = keyEnd + m[key] = val + + // Next token must be , or }. + op = d.scanWhile(scanSkipSpace) + if op == scanEndObject { + break + } + if op != scanObjectValue { + d.error(errPhase) + } + } + node.Value = m + node.End = d.off - 1 + return node +} + +// literalInterface is like literal but returns an interface value. +func (d *decodeState) literalInterface() interface{} { + // All bytes inside literal return scanContinue op code. + start := d.off - 1 + op := d.scanWhile(scanContinue) + + // Scan read one byte too far; back up. + d.off-- + d.scan.undo(op) + item := d.data[start:d.off] + + switch c := item[0]; c { + case 'n': // null + return nil + + case 't', 'f': // true, false + return c == 't' + + case '"': // string + s, ok := unquote(item) + if !ok { + d.error(errPhase) + } + return s + + default: // number + if c != '-' && (c < '0' || c > '9') { + d.error(errPhase) + } + n, err := d.convertNumber(string(item)) + if err != nil { + d.saveError(err) + } + return n + } +} + +func (d *decodeState) literalNode() Node { + start := d.off - 1 + // Can just use the interface version since this has no children + node := Node{ + Start: start, + Value: d.literalInterface(), + } + node.End = d.off - 1 + return node +} + +// getu4 decodes \uXXXX from the beginning of s, returning the hex value, +// or it returns -1. +func getu4(s []byte) rune { + if len(s) < 6 || s[0] != '\\' || s[1] != 'u' { + return -1 + } + r, err := strconv.ParseUint(string(s[2:6]), 16, 64) + if err != nil { + return -1 + } + return rune(r) +} + +// unquote converts a quoted JSON string literal s into an actual string t. +// The rules are different than for Go, so cannot use strconv.Unquote. +func unquote(s []byte) (t string, ok bool) { + s, ok = unquoteBytes(s) + t = string(s) + return +} + +func unquoteBytes(s []byte) (t []byte, ok bool) { + if len(s) < 2 || s[0] != '"' || s[len(s)-1] != '"' { + return + } + s = s[1 : len(s)-1] + + // Check for unusual characters. If there are none, + // then no unquoting is needed, so return a slice of the + // original bytes. + r := 0 + for r < len(s) { + c := s[r] + if c == '\\' || c == '"' || c < ' ' { + break + } + if c < utf8.RuneSelf { + r++ + continue + } + rr, size := utf8.DecodeRune(s[r:]) + if rr == utf8.RuneError && size == 1 { + break + } + r += size + } + if r == len(s) { + return s, true + } + + b := make([]byte, len(s)+2*utf8.UTFMax) + w := copy(b, s[0:r]) + for r < len(s) { + // Out of room? Can only happen if s is full of + // malformed UTF-8 and we're replacing each + // byte with RuneError. + if w >= len(b)-2*utf8.UTFMax { + nb := make([]byte, (len(b)+utf8.UTFMax)*2) + copy(nb, b[0:w]) + b = nb + } + switch c := s[r]; { + case c == '\\': + r++ + if r >= len(s) { + return + } + switch s[r] { + default: + return + case '"', '\\', '/', '\'': + b[w] = s[r] + r++ + w++ + case 'b': + b[w] = '\b' + r++ + w++ + case 'f': + b[w] = '\f' + r++ + w++ + case 'n': + b[w] = '\n' + r++ + w++ + case 'r': + b[w] = '\r' + r++ + w++ + case 't': + b[w] = '\t' + r++ + w++ + case 'u': + r-- + rr := getu4(s[r:]) + if rr < 0 { + return + } + r += 6 + if utf16.IsSurrogate(rr) { + rr1 := getu4(s[r:]) + if dec := utf16.DecodeRune(rr, rr1); dec != unicode.ReplacementChar { + // A valid pair; consume. + r += 6 + w += utf8.EncodeRune(b[w:], dec) + break + } + // Invalid surrogate; fall back to replacement rune. + rr = unicode.ReplacementChar + } + w += utf8.EncodeRune(b[w:], rr) + } + + // Quote, control characters are invalid. + case c == '"', c < ' ': + return + + // ASCII + case c < utf8.RuneSelf: + b[w] = c + r++ + w++ + + // Coerce to well-formed UTF-8. + default: + rr, size := utf8.DecodeRune(s[r:]) + r += size + w += utf8.EncodeRune(b[w:], rr) + } + } + return b[0:w], true +} diff --git a/vendor/github.com/ajeddeloh/go-json/encode.go b/vendor/github.com/ajeddeloh/go-json/encode.go new file mode 100644 index 0000000000..90782deb70 --- /dev/null +++ b/vendor/github.com/ajeddeloh/go-json/encode.go @@ -0,0 +1,1194 @@ +// Copyright 2010 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package json implements encoding and decoding of JSON objects as defined in +// RFC 4627. The mapping between JSON objects and Go values is described +// in the documentation for the Marshal and Unmarshal functions. +// +// See "JSON and Go" for an introduction to this package: +// https://golang.org/doc/articles/json_and_go.html +package json + +import ( + "bytes" + "encoding" + "encoding/base64" + "math" + "reflect" + "runtime" + "sort" + "strconv" + "strings" + "sync" + "unicode" + "unicode/utf8" +) + +// Marshal returns the JSON encoding of v. +// +// Marshal traverses the value v recursively. +// If an encountered value implements the Marshaler interface +// and is not a nil pointer, Marshal calls its MarshalJSON method +// to produce JSON. The nil pointer exception is not strictly necessary +// but mimics a similar, necessary exception in the behavior of +// UnmarshalJSON. +// +// Otherwise, Marshal uses the following type-dependent default encodings: +// +// Boolean values encode as JSON booleans. +// +// Floating point, integer, and Number values encode as JSON numbers. +// +// String values encode as JSON strings coerced to valid UTF-8, +// replacing invalid bytes with the Unicode replacement rune. +// The angle brackets "<" and ">" are escaped to "\u003c" and "\u003e" +// to keep some browsers from misinterpreting JSON output as HTML. +// Ampersand "&" is also escaped to "\u0026" for the same reason. +// +// Array and slice values encode as JSON arrays, except that +// []byte encodes as a base64-encoded string, and a nil slice +// encodes as the null JSON object. +// +// Struct values encode as JSON objects. Each exported struct field +// becomes a member of the object unless +// - the field's tag is "-", or +// - the field is empty and its tag specifies the "omitempty" option. +// The empty values are false, 0, any +// nil pointer or interface value, and any array, slice, map, or string of +// length zero. The object's default key string is the struct field name +// but can be specified in the struct field's tag value. The "json" key in +// the struct field's tag value is the key name, followed by an optional comma +// and options. Examples: +// +// // Field is ignored by this package. +// Field int `json:"-"` +// +// // Field appears in JSON as key "myName". +// Field int `json:"myName"` +// +// // Field appears in JSON as key "myName" and +// // the field is omitted from the object if its value is empty, +// // as defined above. +// Field int `json:"myName,omitempty"` +// +// // Field appears in JSON as key "Field" (the default), but +// // the field is skipped if empty. +// // Note the leading comma. +// Field int `json:",omitempty"` +// +// The "string" option signals that a field is stored as JSON inside a +// JSON-encoded string. It applies only to fields of string, floating point, +// integer, or boolean types. This extra level of encoding is sometimes used +// when communicating with JavaScript programs: +// +// Int64String int64 `json:",string"` +// +// The key name will be used if it's a non-empty string consisting of +// only Unicode letters, digits, dollar signs, percent signs, hyphens, +// underscores and slashes. +// +// Anonymous struct fields are usually marshaled as if their inner exported fields +// were fields in the outer struct, subject to the usual Go visibility rules amended +// as described in the next paragraph. +// An anonymous struct field with a name given in its JSON tag is treated as +// having that name, rather than being anonymous. +// An anonymous struct field of interface type is treated the same as having +// that type as its name, rather than being anonymous. +// +// The Go visibility rules for struct fields are amended for JSON when +// deciding which field to marshal or unmarshal. If there are +// multiple fields at the same level, and that level is the least +// nested (and would therefore be the nesting level selected by the +// usual Go rules), the following extra rules apply: +// +// 1) Of those fields, if any are JSON-tagged, only tagged fields are considered, +// even if there are multiple untagged fields that would otherwise conflict. +// 2) If there is exactly one field (tagged or not according to the first rule), that is selected. +// 3) Otherwise there are multiple fields, and all are ignored; no error occurs. +// +// Handling of anonymous struct fields is new in Go 1.1. +// Prior to Go 1.1, anonymous struct fields were ignored. To force ignoring of +// an anonymous struct field in both current and earlier versions, give the field +// a JSON tag of "-". +// +// Map values encode as JSON objects. +// The map's key type must be string; the map keys are used as JSON object +// keys, subject to the UTF-8 coercion described for string values above. +// +// Pointer values encode as the value pointed to. +// A nil pointer encodes as the null JSON object. +// +// Interface values encode as the value contained in the interface. +// A nil interface value encodes as the null JSON object. +// +// Channel, complex, and function values cannot be encoded in JSON. +// Attempting to encode such a value causes Marshal to return +// an UnsupportedTypeError. +// +// JSON cannot represent cyclic data structures and Marshal does not +// handle them. Passing cyclic structures to Marshal will result in +// an infinite recursion. +// +func Marshal(v interface{}) ([]byte, error) { + e := &encodeState{} + err := e.marshal(v) + if err != nil { + return nil, err + } + return e.Bytes(), nil +} + +// MarshalIndent is like Marshal but applies Indent to format the output. +func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) { + b, err := Marshal(v) + if err != nil { + return nil, err + } + var buf bytes.Buffer + err = Indent(&buf, b, prefix, indent) + if err != nil { + return nil, err + } + return buf.Bytes(), nil +} + +// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029 +// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029 +// so that the JSON will be safe to embed inside HTML