├── .github └── PULL_REQUEST_TEMPLATE.md ├── CONTRIBUTING.md ├── LICENSE ├── OWNERS ├── README.md ├── SECURITY_CONTACTS ├── code-of-conduct.md ├── doc.go ├── go.mod ├── go.sum ├── pkg ├── OWNERS ├── api │ ├── apitesting │ │ ├── close.go │ │ ├── codec.go │ │ ├── fuzzer │ │ │ ├── fuzzer.go │ │ │ ├── valuefuzz.go │ │ │ └── valuefuzz_test.go │ │ ├── naming │ │ │ └── naming.go │ │ └── roundtrip │ │ │ ├── compatibility.go │ │ │ ├── construct.go │ │ │ ├── fuzz_norace.go │ │ │ ├── fuzz_race.go │ │ │ ├── roundtrip.go │ │ │ └── unstructured.go │ ├── equality │ │ └── semantic.go │ ├── errors │ │ ├── OWNERS │ │ ├── doc.go │ │ ├── errors.go │ │ └── errors_test.go │ ├── meta │ │ ├── OWNERS │ │ ├── conditions.go │ │ ├── conditions_test.go │ │ ├── doc.go │ │ ├── errors.go │ │ ├── errors_test.go │ │ ├── firsthit_restmapper.go │ │ ├── help.go │ │ ├── help_test.go │ │ ├── interfaces.go │ │ ├── lazy.go │ │ ├── meta.go │ │ ├── meta_test.go │ │ ├── multirestmapper.go │ │ ├── multirestmapper_test.go │ │ ├── priority.go │ │ ├── priority_test.go │ │ ├── restmapper.go │ │ ├── restmapper_test.go │ │ ├── table │ │ │ └── table.go │ │ └── testrestmapper │ │ │ └── test_restmapper.go │ ├── operation │ │ └── operation.go │ ├── resource │ │ ├── OWNERS │ │ ├── amount.go │ │ ├── amount_test.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── math.go │ │ ├── math_test.go │ │ ├── quantity.go │ │ ├── quantity_example_test.go │ │ ├── quantity_proto.go │ │ ├── quantity_proto_test.go │ │ ├── quantity_test.go │ │ ├── scale_int.go │ │ ├── scale_int_test.go │ │ ├── suffix.go │ │ └── zz_generated.deepcopy.go │ ├── safe │ │ └── safe.go │ ├── validate │ │ ├── README.md │ │ ├── common.go │ │ ├── constraints │ │ │ └── constraints.go │ │ ├── content │ │ │ └── errors.go │ │ ├── doc.go │ │ ├── each.go │ │ ├── each_test.go │ │ ├── immutable.go │ │ ├── immutable_test.go │ │ ├── limits.go │ │ ├── limits_test.go │ │ ├── required.go │ │ ├── required_test.go │ │ ├── subfield.go │ │ ├── testing.go │ │ ├── testing_test.go │ │ └── util_test.go │ └── validation │ │ ├── OWNERS │ │ ├── doc.go │ │ ├── generic.go │ │ ├── generic_test.go │ │ ├── objectmeta.go │ │ ├── objectmeta_test.go │ │ └── path │ │ ├── name.go │ │ └── name_test.go ├── apis │ ├── OWNERS │ ├── asn1 │ │ └── oid.go │ ├── meta │ │ ├── fuzzer │ │ │ └── fuzzer.go │ │ ├── internalversion │ │ │ ├── defaults.go │ │ │ ├── defaults_test.go │ │ │ ├── doc.go │ │ │ ├── register.go │ │ │ ├── scheme │ │ │ │ ├── doc.go │ │ │ │ ├── register.go │ │ │ │ ├── register_test.go │ │ │ │ └── roundtrip_test.go │ │ │ ├── types.go │ │ │ ├── validation │ │ │ │ ├── validation.go │ │ │ │ └── validation_test.go │ │ │ ├── zz_generated.conversion.go │ │ │ └── zz_generated.deepcopy.go │ │ ├── v1 │ │ │ ├── OWNERS │ │ │ ├── controller_ref.go │ │ │ ├── controller_ref_test.go │ │ │ ├── conversion.go │ │ │ ├── conversion_test.go │ │ │ ├── deepcopy.go │ │ │ ├── doc.go │ │ │ ├── duration.go │ │ │ ├── duration_test.go │ │ │ ├── generated.pb.go │ │ │ ├── generated.proto │ │ │ ├── group_version.go │ │ │ ├── group_version_test.go │ │ │ ├── helpers.go │ │ │ ├── helpers_test.go │ │ │ ├── labels.go │ │ │ ├── labels_test.go │ │ │ ├── meta.go │ │ │ ├── micro_time.go │ │ │ ├── micro_time_fuzz.go │ │ │ ├── micro_time_proto.go │ │ │ ├── micro_time_test.go │ │ │ ├── options_test.go │ │ │ ├── register.go │ │ │ ├── time.go │ │ │ ├── time_fuzz.go │ │ │ ├── time_proto.go │ │ │ ├── time_test.go │ │ │ ├── types.go │ │ │ ├── types_swagger_doc_generated.go │ │ │ ├── types_test.go │ │ │ ├── unstructured │ │ │ │ ├── helpers.go │ │ │ │ ├── helpers_test.go │ │ │ │ ├── unstructured.go │ │ │ │ ├── unstructured_conversion_test.go │ │ │ │ ├── unstructured_list.go │ │ │ │ ├── unstructured_list_test.go │ │ │ │ ├── unstructured_test.go │ │ │ │ ├── unstructuredscheme │ │ │ │ │ └── scheme.go │ │ │ │ └── zz_generated.deepcopy.go │ │ │ ├── validation │ │ │ │ ├── validation.go │ │ │ │ └── validation_test.go │ │ │ ├── watch.go │ │ │ ├── zz_generated.conversion.go │ │ │ ├── zz_generated.deepcopy.go │ │ │ └── zz_generated.defaults.go │ │ └── v1beta1 │ │ │ ├── conversion.go │ │ │ ├── deepcopy.go │ │ │ ├── doc.go │ │ │ ├── generated.pb.go │ │ │ ├── generated.proto │ │ │ ├── register.go │ │ │ ├── types.go │ │ │ ├── types_swagger_doc_generated.go │ │ │ ├── validation │ │ │ └── validation.go │ │ │ ├── zz_generated.deepcopy.go │ │ │ └── zz_generated.defaults.go │ └── testapigroup │ │ ├── doc.go │ │ ├── fuzzer │ │ └── fuzzer.go │ │ ├── install │ │ ├── install.go │ │ └── roundtrip_test.go │ │ ├── register.go │ │ ├── types.go │ │ ├── v1 │ │ ├── conversion.go │ │ ├── defaults.go │ │ ├── doc.go │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── register.go │ │ ├── types.go │ │ ├── zz_generated.conversion.go │ │ ├── zz_generated.deepcopy.go │ │ └── zz_generated.defaults.go │ │ └── zz_generated.deepcopy.go ├── conversion │ ├── converter.go │ ├── converter_test.go │ ├── deep_equal.go │ ├── doc.go │ ├── helper.go │ ├── helper_test.go │ └── queryparams │ │ ├── convert.go │ │ ├── convert_test.go │ │ └── doc.go ├── fields │ ├── doc.go │ ├── fields.go │ ├── fields_test.go │ ├── requirements.go │ ├── selector.go │ └── selector_test.go ├── labels │ ├── doc.go │ ├── labels.go │ ├── labels_test.go │ ├── selector.go │ ├── selector_test.go │ └── zz_generated.deepcopy.go ├── runtime │ ├── allocator.go │ ├── allocator_test.go │ ├── codec.go │ ├── codec_check.go │ ├── codec_test.go │ ├── conversion.go │ ├── converter.go │ ├── converter_test.go │ ├── converter_zero_test.go │ ├── doc.go │ ├── embedded.go │ ├── embedded_test.go │ ├── error.go │ ├── extension.go │ ├── extension_test.go │ ├── generated.pb.go │ ├── generated.proto │ ├── helper.go │ ├── interfaces.go │ ├── local_scheme_test.go │ ├── mapper.go │ ├── mapper_test.go │ ├── negotiate.go │ ├── register.go │ ├── schema │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── group_version.go │ │ ├── group_version_test.go │ │ └── interfaces.go │ ├── scheme.go │ ├── scheme_builder.go │ ├── scheme_test.go │ ├── serializer │ │ ├── cbor │ │ │ ├── cbor.go │ │ │ ├── cbor_test.go │ │ │ ├── direct │ │ │ │ ├── direct.go │ │ │ │ └── direct_test.go │ │ │ ├── framer.go │ │ │ ├── framer_test.go │ │ │ ├── internal │ │ │ │ └── modes │ │ │ │ │ ├── appendixa_test.go │ │ │ │ │ ├── buffers.go │ │ │ │ │ ├── buffers_test.go │ │ │ │ │ ├── custom.go │ │ │ │ │ ├── custom_test.go │ │ │ │ │ ├── decode.go │ │ │ │ │ ├── decode_test.go │ │ │ │ │ ├── diagnostic.go │ │ │ │ │ ├── encode.go │ │ │ │ │ ├── encode_test.go │ │ │ │ │ ├── modes_test.go │ │ │ │ │ └── roundtrip_test.go │ │ │ ├── raw.go │ │ │ └── raw_test.go │ │ ├── codec_factory.go │ │ ├── codec_test.go │ │ ├── encoder_with_allocator_test.go │ │ ├── json │ │ │ ├── collections.go │ │ │ ├── collections_test.go │ │ │ ├── json.go │ │ │ ├── json_limit_test.go │ │ │ ├── json_test.go │ │ │ ├── meta.go │ │ │ └── meta_test.go │ │ ├── negotiated_codec.go │ │ ├── protobuf │ │ │ ├── collections.go │ │ │ ├── collections_test.go │ │ │ ├── doc.go │ │ │ ├── protobuf.go │ │ │ └── protobuf_test.go │ │ ├── recognizer │ │ │ ├── recognizer.go │ │ │ └── testing │ │ │ │ └── recognizer_test.go │ │ ├── sparse_test.go │ │ ├── streaming │ │ │ ├── streaming.go │ │ │ └── streaming_test.go │ │ ├── versioning │ │ │ ├── versioning.go │ │ │ ├── versioning_test.go │ │ │ └── versioning_unstructured_test.go │ │ └── yaml │ │ │ ├── meta.go │ │ │ ├── meta_test.go │ │ │ ├── yaml.go │ │ │ └── yaml_test.go │ ├── splice.go │ ├── splice_test.go │ ├── swagger_doc_generator.go │ ├── swagger_doc_generator_test.go │ ├── testing │ │ ├── cacheable_object.go │ │ ├── conversion.go │ │ ├── doc.go │ │ ├── types.go │ │ ├── v1 │ │ │ ├── doc.go │ │ │ ├── types.go │ │ │ └── zz_generated.deepcopy.go │ │ ├── validation.go │ │ └── zz_generated.deepcopy.go │ ├── types.go │ ├── types_proto.go │ ├── types_proto_test.go │ └── zz_generated.deepcopy.go ├── selection │ └── operator.go ├── test │ ├── api_meta_help_test.go │ ├── api_meta_meta_test.go │ ├── apis_meta_v1_unstructed_unstructure_test.go │ ├── runtime_helper_test.go │ ├── runtime_serializer_protobuf_protobuf_test.go │ ├── runtime_unversioned_test.go │ ├── util.go │ └── zz_generated.deepcopy.go ├── types │ ├── doc.go │ ├── namespacedname.go │ ├── nodename.go │ ├── patch.go │ └── uid.go ├── util │ ├── OWNERS │ ├── cache │ │ ├── expiring.go │ │ ├── expiring_test.go │ │ ├── lruexpirecache.go │ │ └── lruexpirecache_test.go │ ├── diff │ │ └── diff.go │ ├── dump │ │ ├── dump.go │ │ └── dump_test.go │ ├── duration │ │ ├── duration.go │ │ └── duration_test.go │ ├── errors │ │ ├── doc.go │ │ ├── errors.go │ │ └── errors_test.go │ ├── framer │ │ ├── framer.go │ │ └── framer_test.go │ ├── httpstream │ │ ├── doc.go │ │ ├── httpstream.go │ │ ├── httpstream_test.go │ │ ├── spdy │ │ │ ├── connection.go │ │ │ ├── connection_test.go │ │ │ ├── roundtripper.go │ │ │ ├── roundtripper_test.go │ │ │ ├── upgrade.go │ │ │ └── upgrade_test.go │ │ └── wsstream │ │ │ ├── conn.go │ │ │ ├── conn_test.go │ │ │ ├── doc.go │ │ │ ├── stream.go │ │ │ └── stream_test.go │ ├── intstr │ │ ├── generated.pb.go │ │ ├── generated.proto │ │ ├── instr_fuzz.go │ │ ├── intstr.go │ │ └── intstr_test.go │ ├── json │ │ ├── json.go │ │ └── json_test.go │ ├── jsonmergepatch │ │ ├── patch.go │ │ └── patch_test.go │ ├── managedfields │ │ ├── endpoints.yaml │ │ ├── extract.go │ │ ├── extract_test.go │ │ ├── fieldmanager.go │ │ ├── fieldmanager_test.go │ │ ├── gvkparser.go │ │ ├── internal │ │ │ ├── atmostevery.go │ │ │ ├── atmostevery_test.go │ │ │ ├── buildmanagerinfo.go │ │ │ ├── capmanagers.go │ │ │ ├── capmanagers_test.go │ │ │ ├── conflict.go │ │ │ ├── conflict_test.go │ │ │ ├── fieldmanager.go │ │ │ ├── fieldmanager_test.go │ │ │ ├── fields.go │ │ │ ├── fields_test.go │ │ │ ├── lastapplied.go │ │ │ ├── lastappliedmanager.go │ │ │ ├── lastappliedmanager_test.go │ │ │ ├── lastappliedupdater.go │ │ │ ├── lastappliedupdater_test.go │ │ │ ├── managedfields.go │ │ │ ├── managedfields_test.go │ │ │ ├── managedfieldsupdater.go │ │ │ ├── managedfieldsupdater_test.go │ │ │ ├── manager.go │ │ │ ├── pathelement.go │ │ │ ├── pathelement_test.go │ │ │ ├── runtimetypeconverter.go │ │ │ ├── skipnonapplied.go │ │ │ ├── skipnonapplied_test.go │ │ │ ├── stripmeta.go │ │ │ ├── structuredmerge.go │ │ │ ├── testdata │ │ │ │ └── swagger.json │ │ │ ├── testing │ │ │ │ └── testfieldmanager.go │ │ │ ├── typeconverter.go │ │ │ ├── typeconverter_test.go │ │ │ ├── versioncheck.go │ │ │ ├── versionconverter.go │ │ │ └── versionconverter_test.go │ │ ├── managedfieldstest │ │ │ └── testfieldmanager.go │ │ ├── node.yaml │ │ ├── pod.yaml │ │ ├── scalehandler.go │ │ ├── scalehandler_test.go │ │ └── typeconverter.go │ ├── mergepatch │ │ ├── OWNERS │ │ ├── errors.go │ │ ├── util.go │ │ └── util_test.go │ ├── naming │ │ ├── from_stack.go │ │ └── from_stack_test.go │ ├── net │ │ ├── http.go │ │ ├── http_test.go │ │ ├── interface.go │ │ ├── interface_test.go │ │ ├── port_range.go │ │ ├── port_range_test.go │ │ ├── port_split.go │ │ ├── port_split_test.go │ │ ├── testing │ │ │ ├── http.go │ │ │ └── socket.go │ │ ├── util.go │ │ └── util_test.go │ ├── portforward │ │ └── constants.go │ ├── proxy │ │ ├── dial.go │ │ ├── dial_test.go │ │ ├── doc.go │ │ ├── transport.go │ │ ├── transport_test.go │ │ ├── upgradeaware.go │ │ └── upgradeaware_test.go │ ├── rand │ │ ├── rand.go │ │ └── rand_test.go │ ├── remotecommand │ │ └── constants.go │ ├── runtime │ │ ├── runtime.go │ │ ├── runtime_stack_test.go │ │ └── runtime_test.go │ ├── sets │ │ ├── byte.go │ │ ├── doc.go │ │ ├── empty.go │ │ ├── int.go │ │ ├── int32.go │ │ ├── int64.go │ │ ├── set.go │ │ ├── set_generic_test.go │ │ ├── set_test.go │ │ └── string.go │ ├── strategicpatch │ │ ├── OWNERS │ │ ├── errors.go │ │ ├── meta.go │ │ ├── patch.go │ │ ├── patch_test.go │ │ ├── testdata │ │ │ ├── swagger-merge-item-v3.json │ │ │ ├── swagger-merge-item.json │ │ │ ├── swagger-precision-item-v3.json │ │ │ └── swagger-precision-item.json │ │ ├── testing │ │ │ ├── openapi.go │ │ │ └── openapi3.go │ │ └── types.go │ ├── uuid │ │ └── uuid.go │ ├── validation │ │ ├── OWNERS │ │ ├── field │ │ │ ├── error_matcher.go │ │ │ ├── errors.go │ │ │ ├── errors_test.go │ │ │ ├── path.go │ │ │ └── path_test.go │ │ ├── ip.go │ │ ├── ip_test.go │ │ ├── validation.go │ │ └── validation_test.go │ ├── version │ │ ├── doc.go │ │ ├── version.go │ │ └── version_test.go │ ├── wait │ │ ├── backoff.go │ │ ├── delay.go │ │ ├── doc.go │ │ ├── error.go │ │ ├── error_test.go │ │ ├── loop.go │ │ ├── loop_test.go │ │ ├── poll.go │ │ ├── timer.go │ │ ├── wait.go │ │ └── wait_test.go │ ├── waitgroup │ │ ├── doc.go │ │ ├── ratelimited_waitgroup.go │ │ ├── ratelimited_waitgroup_test.go │ │ ├── waitgroup.go │ │ └── waitgroup_test.go │ └── yaml │ │ ├── decoder.go │ │ ├── decoder_test.go │ │ ├── stream_reader.go │ │ └── stream_reader_test.go ├── version │ ├── doc.go │ ├── helpers.go │ ├── helpers_test.go │ └── types.go └── watch │ ├── doc.go │ ├── filter.go │ ├── filter_test.go │ ├── mux.go │ ├── mux_test.go │ ├── streamwatcher.go │ ├── streamwatcher_test.go │ ├── watch.go │ ├── watch_test.go │ └── zz_generated.deepcopy.go └── third_party └── forked └── golang ├── LICENSE ├── PATENTS ├── json ├── OWNERS ├── fields.go └── fields_test.go ├── netutil └── addr.go └── reflect ├── deep_equal.go └── deep_equal_test.go /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Sorry, we do not accept changes directly against this repository. Please see 2 | CONTRIBUTING.md for information on where and how to contribute instead. 3 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | Do not open pull requests directly against this repository, they will be ignored. Instead, please open pull requests against [kubernetes/kubernetes](https://git.k8s.io/kubernetes/). Please follow the same [contributing guide](https://git.k8s.io/kubernetes/CONTRIBUTING.md) you would follow for any other pull request made to kubernetes/kubernetes. 4 | 5 | This repository is published from [kubernetes/kubernetes/staging/src/k8s.io/apimachinery](https://git.k8s.io/kubernetes/staging/src/k8s.io/apimachinery) by the [kubernetes publishing-bot](https://git.k8s.io/publishing-bot). 6 | 7 | Please see [Staging Directory and Publishing](https://git.k8s.io/community/contributors/devel/sig-architecture/staging.md) for more information 8 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - smarterclayton 5 | - deads2k 6 | - sttts 7 | - liggitt 8 | - caesarxuchao 9 | - jpbetz 10 | reviewers: 11 | - apelisse 12 | - thockin 13 | - smarterclayton 14 | - wojtek-t 15 | - deads2k 16 | - derekwaynecarr 17 | - caesarxuchao 18 | - cheftako 19 | - mikedanese 20 | - liggitt 21 | - sttts 22 | - logicalhan 23 | - jpbetz 24 | labels: 25 | - sig/api-machinery 26 | emeritus_approvers: 27 | - lavalamp 28 | emeritus_reviewers: 29 | - ncdc 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # apimachinery 2 | 3 | Scheme, typing, encoding, decoding, and conversion packages for Kubernetes and Kubernetes-like API objects. 4 | 5 | 6 | ## Purpose 7 | 8 | This library is a shared dependency for servers and clients to work with Kubernetes API infrastructure without direct 9 | type dependencies. Its first consumers are `k8s.io/kubernetes`, `k8s.io/client-go`, and `k8s.io/apiserver`. 10 | 11 | 12 | ## Compatibility 13 | 14 | There are *NO compatibility guarantees* for this repository. It is in direct support of Kubernetes, so branches 15 | will track Kubernetes and be compatible with that repo. As we more cleanly separate the layers, we will review the 16 | compatibility guarantee. 17 | 18 | 19 | ## Where does it come from? 20 | 21 | `apimachinery` is synced from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/apimachinery. 22 | Code changes are made in that location, merged into `k8s.io/kubernetes` and later synced here. 23 | 24 | 25 | ## Things you should *NOT* do 26 | 27 | 1. Add API types to this repo. This is for the machinery, not for the types. 28 | 2. Directly modify any files under `pkg` in this repo. Those are driven from `k8s.io/kubernetes/staging/src/k8s.io/apimachinery`. 29 | 3. Expect compatibility. This repo is direct support of Kubernetes and the API isn't yet stable enough for API guarantees. 30 | 31 | -------------------------------------------------------------------------------- /SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Committee to reach out 4 | # to for triaging and handling of incoming issues. 5 | # 6 | # The below names agree to abide by the 7 | # [Embargo Policy](https://git.k8s.io/security/private-distributors-list.md#embargo-policy) 8 | # and will be removed and replaced if they violate that agreement. 9 | # 10 | # DO NOT REPORT SECURITY VULNERABILITIES DIRECTLY TO THESE NAMES, FOLLOW THE 11 | # INSTRUCTIONS AT https://kubernetes.io/security/ 12 | 13 | cheftako 14 | deads2k 15 | lavalamp 16 | sttts 17 | -------------------------------------------------------------------------------- /code-of-conduct.md: -------------------------------------------------------------------------------- 1 | # Kubernetes Community Code of Conduct 2 | 3 | Please refer to our [Kubernetes Community Code of Conduct](https://git.k8s.io/community/code-of-conduct.md) 4 | -------------------------------------------------------------------------------- /doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package apimachinery 18 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | // This is a generated file. Do not edit directly. 2 | 3 | module k8s.io/apimachinery 4 | 5 | go 1.24.0 6 | 7 | godebug default=go1.24 8 | 9 | require ( 10 | github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 11 | github.com/davecgh/go-spew v1.1.1 12 | github.com/fxamacker/cbor/v2 v2.8.0 13 | github.com/gogo/protobuf v1.3.2 14 | github.com/google/gnostic-models v0.6.9 15 | github.com/google/go-cmp v0.7.0 16 | github.com/google/uuid v1.6.0 17 | github.com/moby/spdystream v0.5.0 18 | github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f 19 | github.com/spf13/pflag v1.0.6 20 | github.com/stretchr/testify v1.10.0 21 | golang.org/x/net v0.38.0 22 | golang.org/x/time v0.9.0 23 | gopkg.in/evanphx/json-patch.v4 v4.12.0 24 | gopkg.in/inf.v0 v0.9.1 25 | k8s.io/klog/v2 v2.130.1 26 | k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff 27 | k8s.io/utils v0.0.0-20250502105355-0f33e8f1c979 28 | sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 29 | sigs.k8s.io/randfill v1.0.0 30 | sigs.k8s.io/structured-merge-diff/v4 v4.7.0 31 | sigs.k8s.io/yaml v1.4.0 32 | ) 33 | 34 | require ( 35 | github.com/go-logr/logr v1.4.2 // indirect 36 | github.com/go-openapi/jsonpointer v0.21.0 // indirect 37 | github.com/go-openapi/jsonreference v0.20.2 // indirect 38 | github.com/go-openapi/swag v0.23.0 // indirect 39 | github.com/josharian/intern v1.0.0 // indirect 40 | github.com/json-iterator/go v1.1.12 // indirect 41 | github.com/mailru/easyjson v0.7.7 // indirect 42 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect 43 | github.com/modern-go/reflect2 v1.0.2 // indirect 44 | github.com/onsi/ginkgo/v2 v2.21.0 // indirect 45 | github.com/onsi/gomega v1.35.1 // indirect 46 | github.com/pkg/errors v0.9.1 // indirect 47 | github.com/pmezard/go-difflib v1.0.0 // indirect 48 | github.com/rogpeppe/go-internal v1.13.1 // indirect 49 | github.com/x448/float16 v0.8.4 // indirect 50 | golang.org/x/text v0.23.0 // indirect 51 | google.golang.org/protobuf v1.36.5 // indirect 52 | gopkg.in/yaml.v3 v3.0.1 // indirect 53 | ) 54 | -------------------------------------------------------------------------------- /pkg/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - caesarxuchao 5 | - deads2k 6 | - smarterclayton 7 | - liggitt 8 | emeritus_approvers: 9 | - lavalamp 10 | -------------------------------------------------------------------------------- /pkg/api/apitesting/close.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package apitesting 18 | 19 | import ( 20 | "io" 21 | "testing" 22 | ) 23 | 24 | // Close and fail the test if it returns an error. 25 | func Close(t TestingT, c io.Closer) { 26 | t.Helper() 27 | assertNoError(t, c.Close()) 28 | } 29 | 30 | // CloseNoOp does nothing. Use as a replacement for Close when you 31 | // need to disable a defer. 32 | func CloseNoOp(TestingT, io.Closer) {} 33 | 34 | // TestingT simulates assert.TestingT and assert.tHelper without adding 35 | // testify as a non-test dependency. 36 | type TestingT interface { 37 | Errorf(format string, args ...interface{}) 38 | Helper() 39 | } 40 | 41 | // Ensure that testing T & B satisfy the TestingT interface 42 | var _ TestingT = &testing.T{} 43 | var _ TestingT = &testing.B{} 44 | 45 | // assertNoError simulates assert.NoError without adding testify as a 46 | // non-test dependency. 47 | // 48 | // In test files, use github.com/stretchr/testify/assert instead. 49 | func assertNoError(t TestingT, err error) { 50 | t.Helper() 51 | if err != nil { 52 | t.Errorf("Received unexpected error:\n%+v", err) 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /pkg/api/apitesting/fuzzer/valuefuzz_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fuzzer 18 | 19 | import "testing" 20 | 21 | func TestValueFuzz(t *testing.T) { 22 | type ( 23 | Y struct { 24 | I int 25 | B bool 26 | F float32 27 | U uint 28 | } 29 | X struct { 30 | Ptr *X 31 | Y Y 32 | Map map[string]int 33 | Slice []int 34 | } 35 | ) 36 | 37 | x := X{ 38 | Ptr: &X{}, 39 | Map: map[string]int{"foo": 42}, 40 | Slice: []int{1, 2, 3}, 41 | } 42 | 43 | p := x.Ptr 44 | m := x.Map 45 | s := x.Slice 46 | 47 | ValueFuzz(x) 48 | 49 | if x.Ptr.Y.I == 0 { 50 | t.Errorf("x.Ptr.Y.I should have changed") 51 | } 52 | 53 | if x.Map["foo"] == 42 { 54 | t.Errorf("x.Map[foo] should have changed") 55 | } 56 | 57 | if x.Slice[0] == 1 { 58 | t.Errorf("x.Slice[0] should have changed") 59 | } 60 | 61 | if x.Ptr != p { 62 | t.Errorf("x.Ptr changed") 63 | } 64 | 65 | m["foo"] = 7 66 | if x.Map["foo"] != m["foo"] { 67 | t.Errorf("x.Map changed") 68 | } 69 | s[0] = 7 70 | if x.Slice[0] != s[0] { 71 | t.Errorf("x.Slice changed") 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /pkg/api/apitesting/roundtrip/fuzz_norace.go: -------------------------------------------------------------------------------- 1 | //go:build !race 2 | // +build !race 3 | 4 | /* 5 | Copyright 2021 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package roundtrip 21 | 22 | // in non-race-detection mode, a higher number of iterations is reasonable 23 | const defaultFuzzIters = 20 24 | -------------------------------------------------------------------------------- /pkg/api/apitesting/roundtrip/fuzz_race.go: -------------------------------------------------------------------------------- 1 | //go:build race 2 | // +build race 3 | 4 | /* 5 | Copyright 2021 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package roundtrip 21 | 22 | // in race-detection mode, lower the number of iterations to keep reasonable runtimes in CI 23 | const defaultFuzzIters = 5 24 | -------------------------------------------------------------------------------- /pkg/api/equality/semantic.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package equality 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/api/resource" 21 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 22 | "k8s.io/apimachinery/pkg/conversion" 23 | "k8s.io/apimachinery/pkg/fields" 24 | "k8s.io/apimachinery/pkg/labels" 25 | ) 26 | 27 | // Semantic can do semantic deep equality checks for api objects. 28 | // Example: apiequality.Semantic.DeepEqual(aPod, aPodWithNonNilButEmptyMaps) == true 29 | var Semantic = conversion.EqualitiesOrDie( 30 | func(a, b resource.Quantity) bool { 31 | // Ignore formatting, only care that numeric value stayed the same. 32 | // TODO: if we decide it's important, it should be safe to start comparing the format. 33 | // 34 | // Uninitialized quantities are equivalent to 0 quantities. 35 | return a.Cmp(b) == 0 36 | }, 37 | func(a, b metav1.MicroTime) bool { 38 | return a.UTC() == b.UTC() 39 | }, 40 | func(a, b metav1.Time) bool { 41 | return a.UTC() == b.UTC() 42 | }, 43 | func(a, b labels.Selector) bool { 44 | return a.String() == b.String() 45 | }, 46 | func(a, b fields.Selector) bool { 47 | return a.String() == b.String() 48 | }, 49 | ) 50 | -------------------------------------------------------------------------------- /pkg/api/errors/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | reviewers: 4 | - thockin 5 | - smarterclayton 6 | - wojtek-t 7 | - deads2k 8 | - derekwaynecarr 9 | - caesarxuchao 10 | - mikedanese 11 | - liggitt 12 | - saad-ali 13 | - janetkuo 14 | - tallclair 15 | - dims 16 | - cjcullen 17 | -------------------------------------------------------------------------------- /pkg/api/errors/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package errors provides detailed error types for api field validation. 18 | package errors 19 | -------------------------------------------------------------------------------- /pkg/api/meta/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | reviewers: 4 | - thockin 5 | - smarterclayton 6 | - wojtek-t 7 | - deads2k 8 | - derekwaynecarr 9 | - caesarxuchao 10 | - mikedanese 11 | - liggitt 12 | - janetkuo 13 | - dims 14 | emeritus_reviewers: 15 | - ncdc 16 | -------------------------------------------------------------------------------- /pkg/api/meta/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package meta provides functions for retrieving API metadata from objects 18 | // belonging to the Kubernetes API 19 | package meta 20 | -------------------------------------------------------------------------------- /pkg/api/meta/meta_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package meta 18 | 19 | import ( 20 | "math/rand" 21 | "reflect" 22 | "testing" 23 | 24 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | metav1beta1 "k8s.io/apimachinery/pkg/apis/meta/v1beta1" 26 | 27 | "github.com/google/go-cmp/cmp" 28 | "sigs.k8s.io/randfill" 29 | ) 30 | 31 | func TestAsPartialObjectMetadata(t *testing.T) { 32 | f := randfill.New().NilChance(.5).NumElements(0, 1).RandSource(rand.NewSource(1)) 33 | 34 | for i := 0; i < 100; i++ { 35 | m := &metav1.ObjectMeta{} 36 | f.Fill(m) 37 | partial := AsPartialObjectMetadata(m) 38 | if !reflect.DeepEqual(&partial.ObjectMeta, m) { 39 | t.Fatalf("incomplete partial object metadata: %s", cmp.Diff(&partial.ObjectMeta, m)) 40 | } 41 | } 42 | 43 | for i := 0; i < 100; i++ { 44 | m := &metav1beta1.PartialObjectMetadata{} 45 | f.Fill(&m.ObjectMeta) 46 | partial := AsPartialObjectMetadata(m) 47 | if !reflect.DeepEqual(&partial.ObjectMeta, &m.ObjectMeta) { 48 | t.Fatalf("incomplete partial object metadata: %s", cmp.Diff(&partial.ObjectMeta, &m.ObjectMeta)) 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkg/api/meta/table/table.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package table 18 | 19 | import ( 20 | "time" 21 | 22 | "k8s.io/apimachinery/pkg/api/meta" 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | "k8s.io/apimachinery/pkg/util/duration" 26 | ) 27 | 28 | // MetaToTableRow converts a list or object into one or more table rows. The provided rowFn is invoked for 29 | // each accessed item, with name and age being passed to each. 30 | func MetaToTableRow(obj runtime.Object, rowFn func(obj runtime.Object, m metav1.Object, name, age string) ([]interface{}, error)) ([]metav1.TableRow, error) { 31 | if meta.IsListType(obj) { 32 | rows := make([]metav1.TableRow, 0, 16) 33 | err := meta.EachListItem(obj, func(obj runtime.Object) error { 34 | nestedRows, err := MetaToTableRow(obj, rowFn) 35 | if err != nil { 36 | return err 37 | } 38 | rows = append(rows, nestedRows...) 39 | return nil 40 | }) 41 | if err != nil { 42 | return nil, err 43 | } 44 | return rows, nil 45 | } 46 | 47 | rows := make([]metav1.TableRow, 0, 1) 48 | m, err := meta.Accessor(obj) 49 | if err != nil { 50 | return nil, err 51 | } 52 | row := metav1.TableRow{ 53 | Object: runtime.RawExtension{Object: obj}, 54 | } 55 | row.Cells, err = rowFn(obj, m, m.GetName(), ConvertToHumanReadableDateType(m.GetCreationTimestamp())) 56 | if err != nil { 57 | return nil, err 58 | } 59 | rows = append(rows, row) 60 | return rows, nil 61 | } 62 | 63 | // ConvertToHumanReadableDateType returns the elapsed time since timestamp in 64 | // human-readable approximation. 65 | func ConvertToHumanReadableDateType(timestamp metav1.Time) string { 66 | if timestamp.IsZero() { 67 | return "" 68 | } 69 | return duration.HumanDuration(time.Since(timestamp.Time)) 70 | } 71 | -------------------------------------------------------------------------------- /pkg/api/resource/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | reviewers: 4 | - thockin 5 | - smarterclayton 6 | - wojtek-t 7 | - derekwaynecarr 8 | - mikedanese 9 | - saad-ali 10 | - janetkuo 11 | -------------------------------------------------------------------------------- /pkg/api/resource/quantity_example_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package resource_test 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/api/resource" 23 | ) 24 | 25 | func ExampleFormat() { 26 | memorySize := resource.NewQuantity(5*1024*1024*1024, resource.BinarySI) 27 | fmt.Printf("memorySize = %v\n", memorySize) 28 | 29 | diskSize := resource.NewQuantity(5*1000*1000*1000, resource.DecimalSI) 30 | fmt.Printf("diskSize = %v\n", diskSize) 31 | 32 | cores := resource.NewMilliQuantity(5300, resource.DecimalSI) 33 | fmt.Printf("cores = %v\n", cores) 34 | 35 | // Output: 36 | // memorySize = 5Gi 37 | // diskSize = 5G 38 | // cores = 5300m 39 | } 40 | 41 | func ExampleMustParse() { 42 | memorySize := resource.MustParse("5Gi") 43 | fmt.Printf("memorySize = %v (%v)\n", memorySize.Value(), memorySize.Format) 44 | 45 | diskSize := resource.MustParse("5G") 46 | fmt.Printf("diskSize = %v (%v)\n", diskSize.Value(), diskSize.Format) 47 | 48 | cores := resource.MustParse("5300m") 49 | fmt.Printf("milliCores = %v (%v)\n", cores.MilliValue(), cores.Format) 50 | 51 | cores2 := resource.MustParse("5.4") 52 | fmt.Printf("milliCores = %v (%v)\n", cores2.MilliValue(), cores2.Format) 53 | 54 | // Output: 55 | // memorySize = 5368709120 (BinarySI) 56 | // diskSize = 5000000000 (DecimalSI) 57 | // milliCores = 5300 (DecimalSI) 58 | // milliCores = 5400 (DecimalSI) 59 | } 60 | -------------------------------------------------------------------------------- /pkg/api/resource/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package resource 23 | 24 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 25 | func (in *Quantity) DeepCopyInto(out *Quantity) { 26 | *out = in.DeepCopy() 27 | return 28 | } 29 | 30 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 31 | func (in *QuantityValue) DeepCopyInto(out *QuantityValue) { 32 | *out = *in 33 | out.Quantity = in.Quantity.DeepCopy() 34 | return 35 | } 36 | 37 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new QuantityValue. 38 | func (in *QuantityValue) DeepCopy() *QuantityValue { 39 | if in == nil { 40 | return nil 41 | } 42 | out := new(QuantityValue) 43 | in.DeepCopyInto(out) 44 | return out 45 | } 46 | -------------------------------------------------------------------------------- /pkg/api/safe/safe.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package safe 18 | 19 | // Field takes a pointer to any value (which may or may not be nil) and 20 | // a function that traverses to a target type R (a typical use case is to dereference a field), 21 | // and returns the result of the traversal, or the zero value of the target type. 22 | // This is roughly equivalent to "value != nil ? fn(value) : zero-value" in languages that support the ternary operator. 23 | func Field[V any, R any](value *V, fn func(*V) R) R { 24 | if value == nil { 25 | var zero R 26 | return zero 27 | } 28 | o := fn(value) 29 | return o 30 | } 31 | 32 | // Cast takes any value, attempts to cast it to T, and returns the T value if 33 | // the cast is successful, or else the zero value of T. 34 | func Cast[T any](value any) T { 35 | result, _ := value.(T) 36 | return result 37 | } 38 | -------------------------------------------------------------------------------- /pkg/api/validate/common.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validate 18 | 19 | import ( 20 | "context" 21 | 22 | "k8s.io/apimachinery/pkg/api/operation" 23 | "k8s.io/apimachinery/pkg/util/validation/field" 24 | ) 25 | 26 | // ValidateFunc is a function that validates a value, possibly considering the 27 | // old value (if any). 28 | type ValidateFunc[T any] func(ctx context.Context, op operation.Operation, fldPath *field.Path, newValue, oldValue T) field.ErrorList 29 | -------------------------------------------------------------------------------- /pkg/api/validate/constraints/constraints.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package constraints 18 | 19 | // Signed is a constraint that permits any signed integer type. 20 | type Signed interface { 21 | ~int | ~int8 | ~int16 | ~int32 | ~int64 22 | } 23 | 24 | // Unsigned is a constraint that permits any unsigned integer type. 25 | type Unsigned interface { 26 | ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr 27 | } 28 | 29 | // Integer is a constraint that permits any integer type. 30 | type Integer interface { 31 | Signed | Unsigned 32 | } 33 | -------------------------------------------------------------------------------- /pkg/api/validate/content/errors.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package content 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/api/validate/constraints" 23 | ) 24 | 25 | // MinError returns a string explanation of a "must be greater than or equal" 26 | // validation failure. 27 | func MinError[T constraints.Integer](min T) string { 28 | return fmt.Sprintf("must be greater than or equal to %d", min) 29 | } 30 | -------------------------------------------------------------------------------- /pkg/api/validate/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package validate holds API validation functions which are designed for use 18 | // with the k8s.io/code-generator/cmd/validation-gen tool. Each validation 19 | // function has a similar fingerprint: 20 | // 21 | // func (ctx context.Context, 22 | // op operation.Operation, 23 | // fldPath *field.Path, 24 | // value, oldValue , 25 | // ) field.ErrorList 26 | // 27 | // The value and oldValue arguments will always be a nilable type. If the 28 | // original value was a string, these will be a *string. If the original value 29 | // was a slice or map, these will be the same slice or map type. 30 | // 31 | // For a CREATE operation, the oldValue will always be nil. For an UPDATE 32 | // operation, either value or oldValue may be nil, e.g. when adding or removing 33 | // a value in a list-map. Validators which care about UPDATE operations should 34 | // look at the opCtx argument to know which operation is being executed. 35 | // 36 | // Tightened validation (also known as ratcheting validation) is supported by 37 | // defining a new validation function. For example: 38 | // 39 | // func TightenedMaxLength(ctx context.Context, op operation.Operation, fldPath *field.Path, value, oldValue *string) field.ErrorList { 40 | // if oldValue != nil && len(MaxLength(ctx, op, fldPath, oldValue, nil)) > 0 { 41 | // // old value is not valid, so this value skips the tightened validation 42 | // return nil 43 | // } 44 | // return MaxLength(ctx, op, fldPath, value, nil) 45 | // } 46 | // 47 | // In general, we cannot distinguish a non-specified slice or map from one that 48 | // is specified but empty. Validators should not rely on nil values, but use 49 | // len() instead. 50 | package validate 51 | -------------------------------------------------------------------------------- /pkg/api/validate/limits.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validate 18 | 19 | import ( 20 | "context" 21 | 22 | "k8s.io/apimachinery/pkg/api/operation" 23 | "k8s.io/apimachinery/pkg/api/validate/constraints" 24 | "k8s.io/apimachinery/pkg/api/validate/content" 25 | "k8s.io/apimachinery/pkg/util/validation/field" 26 | ) 27 | 28 | // Minimum verifies that the specified value is greater than or equal to min. 29 | func Minimum[T constraints.Integer](_ context.Context, _ operation.Operation, fldPath *field.Path, value, _ *T, min T) field.ErrorList { 30 | if value == nil { 31 | return nil 32 | } 33 | if *value < min { 34 | return field.ErrorList{field.Invalid(fldPath, *value, content.MinError(min)).WithOrigin("minimum")} 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /pkg/api/validate/subfield.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validate 18 | 19 | import ( 20 | "context" 21 | 22 | "k8s.io/apimachinery/pkg/api/operation" 23 | "k8s.io/apimachinery/pkg/util/validation/field" 24 | ) 25 | 26 | // GetFieldFunc is a function that extracts a field from a type and returns a 27 | // nilable value. 28 | type GetFieldFunc[Tstruct any, Tfield any] func(*Tstruct) Tfield 29 | 30 | // Subfield validates a subfield of a struct against a validator function. 31 | func Subfield[Tstruct any, Tfield any](ctx context.Context, op operation.Operation, fldPath *field.Path, newStruct, oldStruct *Tstruct, 32 | fldName string, getField GetFieldFunc[Tstruct, Tfield], validator ValidateFunc[Tfield]) field.ErrorList { 33 | var errs field.ErrorList 34 | newVal := getField(newStruct) 35 | var oldVal Tfield 36 | if oldStruct != nil { 37 | oldVal = getField(oldStruct) 38 | } 39 | errs = append(errs, validator(ctx, op, fldPath.Child(fldName), newVal, oldVal)...) 40 | return errs 41 | } 42 | -------------------------------------------------------------------------------- /pkg/api/validate/testing.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validate 18 | 19 | import ( 20 | "context" 21 | 22 | "k8s.io/apimachinery/pkg/api/operation" 23 | "k8s.io/apimachinery/pkg/util/validation/field" 24 | ) 25 | 26 | // FixedResult asserts a fixed boolean result. This is mostly useful for 27 | // testing. 28 | func FixedResult[T any](_ context.Context, op operation.Operation, fldPath *field.Path, value, _ T, result bool, arg string) field.ErrorList { 29 | if result { 30 | return nil 31 | } 32 | return field.ErrorList{ 33 | field.Invalid(fldPath, value, "forced failure: "+arg).WithOrigin("validateFalse"), 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /pkg/api/validate/util_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validate 18 | 19 | import ( 20 | "bytes" 21 | "strconv" 22 | 23 | "k8s.io/apimachinery/pkg/util/validation/field" 24 | ) 25 | 26 | // fmtErrs is a helper for nicer test output. It will use multiple lines if 27 | // errs has more than 1 item. 28 | func fmtErrs(errs field.ErrorList) string { 29 | if len(errs) == 0 { 30 | return "" 31 | } 32 | if len(errs) == 1 { 33 | return strconv.Quote(errs[0].Error()) 34 | } 35 | buf := bytes.Buffer{} 36 | for _, e := range errs { 37 | buf.WriteString("\n") 38 | buf.WriteString(strconv.Quote(e.Error())) 39 | } 40 | return buf.String() 41 | } 42 | -------------------------------------------------------------------------------- /pkg/api/validation/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | # Disable inheritance as this is an api owners file 4 | options: 5 | no_parent_owners: true 6 | approvers: 7 | - api-approvers 8 | reviewers: 9 | - api-reviewers 10 | labels: 11 | - kind/api-change 12 | -------------------------------------------------------------------------------- /pkg/api/validation/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package validation contains generic api type validation functions. 18 | package validation 19 | -------------------------------------------------------------------------------- /pkg/api/validation/generic_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validation 18 | 19 | import "testing" 20 | 21 | func TestMaskTrailingDash(t *testing.T) { 22 | testCases := []struct { 23 | beforeMasking string 24 | expectedAfterMasking string 25 | description string 26 | }{ 27 | { 28 | beforeMasking: "", 29 | expectedAfterMasking: "", 30 | description: "empty string", 31 | }, 32 | { 33 | beforeMasking: "-", 34 | expectedAfterMasking: "-", 35 | description: "only a single dash", 36 | }, 37 | { 38 | beforeMasking: "-foo", 39 | expectedAfterMasking: "-foo", 40 | description: "has leading dash", 41 | }, 42 | { 43 | beforeMasking: "-foo-", 44 | expectedAfterMasking: "-foa", 45 | description: "has both leading and trailing dashes", 46 | }, 47 | { 48 | beforeMasking: "b-", 49 | expectedAfterMasking: "a", 50 | description: "has trailing dash", 51 | }, 52 | { 53 | beforeMasking: "ab", 54 | expectedAfterMasking: "ab", 55 | description: "has neither leading nor trailing dashes", 56 | }, 57 | } 58 | 59 | for _, tc := range testCases { 60 | afterMasking := maskTrailingDash(tc.beforeMasking) 61 | if afterMasking != tc.expectedAfterMasking { 62 | t.Errorf("error in test case: %s. expected: %s, actual: %s", tc.description, tc.expectedAfterMasking, afterMasking) 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /pkg/apis/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | # Disable inheritance as this is an api owners file 4 | options: 5 | no_parent_owners: true 6 | approvers: 7 | - api-approvers 8 | reviewers: 9 | - api-reviewers 10 | labels: 11 | - kind/api-change 12 | -------------------------------------------------------------------------------- /pkg/apis/asn1/oid.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package asn1 18 | 19 | import "encoding/asn1" 20 | 21 | // These constants store suffixes for use with the CNCF Private Enterprise Number allocated to Kubernetes: 22 | // https://www.iana.org/assignments/enterprise-numbers.txt 23 | // 24 | // Root: 1.3.6.1.4.1.57683 25 | // 26 | // Cloud Native Computing Foundation 27 | const ( 28 | // single-value, string value 29 | x509UIDSuffix = 2 30 | ) 31 | 32 | func makeOID(suffix int) asn1.ObjectIdentifier { 33 | return asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 57683, suffix} 34 | } 35 | 36 | // X509UID returns an OID (1.3.6.1.4.1.57683.2) for an element of an x509 distinguished name representing a user UID. 37 | // The UID is a unique value for a particular user that will change if the user is removed from the system 38 | // and another user is added with the same username. 39 | // 40 | // This element must not appear more than once in a distinguished name, and the value must be a string 41 | func X509UID() asn1.ObjectIdentifier { 42 | return makeOID(x509UIDSuffix) 43 | } 44 | -------------------------------------------------------------------------------- /pkg/apis/meta/internalversion/defaults.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internalversion 18 | 19 | import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 20 | 21 | // SetListOptionsDefaults sets defaults on the provided ListOptions if applicable. 22 | // 23 | // TODO(#115478): once the watch-list fg is always on we register this function in the scheme (via AddTypeDefaultingFunc). 24 | // TODO(#115478): when the function is registered in the scheme remove all callers of this method. 25 | func SetListOptionsDefaults(obj *ListOptions, isWatchListFeatureEnabled bool) { 26 | if !isWatchListFeatureEnabled { 27 | return 28 | } 29 | if obj.SendInitialEvents != nil || len(obj.ResourceVersionMatch) != 0 { 30 | return 31 | } 32 | legacy := obj.ResourceVersion == "" || obj.ResourceVersion == "0" 33 | if obj.Watch && legacy { 34 | turnOnInitialEvents := true 35 | obj.SendInitialEvents = &turnOnInitialEvents 36 | obj.ResourceVersionMatch = metav1.ResourceVersionMatchNotOlderThan 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pkg/apis/meta/internalversion/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:conversion-gen=k8s.io/apimachinery/pkg/apis/meta/v1 19 | 20 | package internalversion 21 | -------------------------------------------------------------------------------- /pkg/apis/meta/internalversion/scheme/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package scheme 18 | -------------------------------------------------------------------------------- /pkg/apis/meta/internalversion/scheme/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package scheme 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/apis/meta/internalversion" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/serializer" 23 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 24 | ) 25 | 26 | // Scheme is the registry for any type that adheres to the meta API spec. 27 | var Scheme = runtime.NewScheme() 28 | 29 | // Codecs provides access to encoding and decoding for the scheme. 30 | var Codecs = serializer.NewCodecFactory(Scheme) 31 | 32 | // ParameterCodec handles versioning of objects that are converted to query parameters. 33 | var ParameterCodec = runtime.NewParameterCodec(Scheme) 34 | 35 | // Unlike other API groups, meta internal knows about all meta external versions, but keeps 36 | // the logic for conversion private. 37 | func init() { 38 | utilruntime.Must(internalversion.AddToScheme(Scheme)) 39 | } 40 | -------------------------------------------------------------------------------- /pkg/apis/meta/internalversion/scheme/roundtrip_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package scheme 18 | 19 | import ( 20 | "testing" 21 | 22 | "k8s.io/apimachinery/pkg/api/apitesting/roundtrip" 23 | "k8s.io/apimachinery/pkg/apis/meta/fuzzer" 24 | ) 25 | 26 | func TestRoundTrip(t *testing.T) { 27 | roundtrip.RoundTripTestForScheme(t, Scheme, fuzzer.Funcs) 28 | } 29 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | reviewers: 4 | - thockin 5 | - smarterclayton 6 | - wojtek-t 7 | - deads2k 8 | - caesarxuchao 9 | - liggitt 10 | - sttts 11 | - luxas 12 | - janetkuo 13 | - justinsb 14 | - soltysh 15 | - dims 16 | emeritus_reviewers: 17 | - ncdc 18 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/controller_ref.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime/schema" 21 | "k8s.io/utils/ptr" 22 | ) 23 | 24 | // IsControlledBy checks if the object has a controllerRef set to the given owner 25 | func IsControlledBy(obj Object, owner Object) bool { 26 | ref := GetControllerOfNoCopy(obj) 27 | if ref == nil { 28 | return false 29 | } 30 | return ref.UID == owner.GetUID() 31 | } 32 | 33 | // GetControllerOf returns a pointer to a copy of the controllerRef if controllee has a controller 34 | func GetControllerOf(controllee Object) *OwnerReference { 35 | ref := GetControllerOfNoCopy(controllee) 36 | if ref == nil { 37 | return nil 38 | } 39 | cp := *ref 40 | cp.Controller = ptr.To(*ref.Controller) 41 | if ref.BlockOwnerDeletion != nil { 42 | cp.BlockOwnerDeletion = ptr.To(*ref.BlockOwnerDeletion) 43 | } 44 | return &cp 45 | } 46 | 47 | // GetControllerOfNoCopy returns a pointer to the controllerRef if controllee has a controller 48 | func GetControllerOfNoCopy(controllee Object) *OwnerReference { 49 | refs := controllee.GetOwnerReferences() 50 | for i := range refs { 51 | if refs[i].Controller != nil && *refs[i].Controller { 52 | return &refs[i] 53 | } 54 | } 55 | return nil 56 | } 57 | 58 | // NewControllerRef creates an OwnerReference pointing to the given owner. 59 | func NewControllerRef(owner Object, gvk schema.GroupVersionKind) *OwnerReference { 60 | return &OwnerReference{ 61 | APIVersion: gvk.GroupVersion().String(), 62 | Kind: gvk.Kind, 63 | Name: owner.GetName(), 64 | UID: owner.GetUID(), 65 | BlockOwnerDeletion: ptr.To(true), 66 | Controller: ptr.To(true), 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/deepcopy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | ) 22 | 23 | func (in *TableRow) DeepCopy() *TableRow { 24 | if in == nil { 25 | return nil 26 | } 27 | 28 | out := new(TableRow) 29 | 30 | if in.Cells != nil { 31 | out.Cells = make([]interface{}, len(in.Cells)) 32 | for i := range in.Cells { 33 | out.Cells[i] = runtime.DeepCopyJSONValue(in.Cells[i]) 34 | } 35 | } 36 | 37 | if in.Conditions != nil { 38 | out.Conditions = make([]TableRowCondition, len(in.Conditions)) 39 | for i := range in.Conditions { 40 | in.Conditions[i].DeepCopyInto(&out.Conditions[i]) 41 | } 42 | } 43 | 44 | in.Object.DeepCopyInto(&out.Object) 45 | return out 46 | } 47 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:conversion-gen=false 18 | // +k8s:deepcopy-gen=package 19 | // +k8s:openapi-gen=true 20 | // +k8s:defaulter-gen=TypeMeta 21 | 22 | // +groupName=meta.k8s.io 23 | 24 | package v1 25 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/duration.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "encoding/json" 21 | "time" 22 | ) 23 | 24 | // Duration is a wrapper around time.Duration which supports correct 25 | // marshaling to YAML and JSON. In particular, it marshals into strings, which 26 | // can be used as map keys in json. 27 | type Duration struct { 28 | time.Duration `protobuf:"varint,1,opt,name=duration,casttype=time.Duration"` 29 | } 30 | 31 | // UnmarshalJSON implements the json.Unmarshaller interface. 32 | func (d *Duration) UnmarshalJSON(b []byte) error { 33 | var str string 34 | err := json.Unmarshal(b, &str) 35 | if err != nil { 36 | return err 37 | } 38 | 39 | pd, err := time.ParseDuration(str) 40 | if err != nil { 41 | return err 42 | } 43 | d.Duration = pd 44 | return nil 45 | } 46 | 47 | // MarshalJSON implements the json.Marshaler interface. 48 | func (d Duration) MarshalJSON() ([]byte, error) { 49 | return json.Marshal(d.Duration.String()) 50 | } 51 | 52 | // ToUnstructured implements the value.UnstructuredConverter interface. 53 | func (d Duration) ToUnstructured() interface{} { 54 | return d.Duration.String() 55 | } 56 | 57 | // OpenAPISchemaType is used by the kube-openapi generator when constructing 58 | // the OpenAPI spec of this type. 59 | // 60 | // See: https://github.com/kubernetes/kube-openapi/tree/master/pkg/generators 61 | func (_ Duration) OpenAPISchemaType() []string { return []string{"string"} } 62 | 63 | // OpenAPISchemaFormat is used by the kube-openapi generator when constructing 64 | // the OpenAPI spec of this type. 65 | func (_ Duration) OpenAPISchemaFormat() string { return "" } 66 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/labels.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | // Clones the given selector and returns a new selector with the given key and value added. 20 | // Returns the given selector, if labelKey is empty. 21 | func CloneSelectorAndAddLabel(selector *LabelSelector, labelKey, labelValue string) *LabelSelector { 22 | if labelKey == "" { 23 | // Don't need to add a label. 24 | return selector 25 | } 26 | 27 | // Clone. 28 | newSelector := selector.DeepCopy() 29 | 30 | if newSelector.MatchLabels == nil { 31 | newSelector.MatchLabels = make(map[string]string) 32 | } 33 | 34 | newSelector.MatchLabels[labelKey] = labelValue 35 | 36 | return newSelector 37 | } 38 | 39 | // AddLabelToSelector returns a selector with the given key and value added to the given selector's MatchLabels. 40 | func AddLabelToSelector(selector *LabelSelector, labelKey, labelValue string) *LabelSelector { 41 | if labelKey == "" { 42 | // Don't need to add a label. 43 | return selector 44 | } 45 | if selector.MatchLabels == nil { 46 | selector.MatchLabels = make(map[string]string) 47 | } 48 | selector.MatchLabels[labelKey] = labelValue 49 | return selector 50 | } 51 | 52 | // SelectorHasLabel checks if the given selector contains the given label key in its MatchLabels 53 | func SelectorHasLabel(selector *LabelSelector, labelKey string) bool { 54 | return len(selector.MatchLabels[labelKey]) > 0 55 | } 56 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/micro_time_fuzz.go: -------------------------------------------------------------------------------- 1 | //go:build !notest 2 | // +build !notest 3 | 4 | /* 5 | Copyright 2020 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package v1 21 | 22 | import ( 23 | "math/rand" 24 | "time" 25 | 26 | "sigs.k8s.io/randfill" 27 | ) 28 | 29 | // Fuzz satisfies randfill.SimpleSelfFiller. 30 | func (t *MicroTime) RandFill(r *rand.Rand) { 31 | if t == nil { 32 | return 33 | } 34 | // Allow for about 1000 years of randomness. Accurate to a tenth of 35 | // micro second. Leave off nanoseconds because JSON doesn't 36 | // represent them so they can't round-trip properly. 37 | t.Time = time.Unix(r.Int63n(1000*365*24*60*60), 1000*r.Int63n(1000000)) 38 | } 39 | 40 | // ensure MicroTime implements randfill.Interface 41 | var _ randfill.SimpleSelfFiller = &MicroTime{} 42 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/options_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "encoding/json" 21 | "fmt" 22 | "reflect" 23 | "testing" 24 | 25 | "sigs.k8s.io/randfill" 26 | ) 27 | 28 | func TestPatchOptionsIsSuperSetOfUpdateOptions(t *testing.T) { 29 | f := randfill.New() 30 | for i := 0; i < 1000; i++ { 31 | t.Run(fmt.Sprintf("Run %d/1000", i), func(t *testing.T) { 32 | update := UpdateOptions{} 33 | f.Fill(&update) 34 | 35 | b, err := json.Marshal(update) 36 | if err != nil { 37 | t.Fatalf("failed to marshal UpdateOptions (%v): %v", err, update) 38 | } 39 | patch := PatchOptions{} 40 | err = json.Unmarshal(b, &patch) 41 | if err != nil { 42 | t.Fatalf("failed to unmarshal UpdateOptions into PatchOptions: %v", err) 43 | } 44 | 45 | b, err = json.Marshal(patch) 46 | if err != nil { 47 | t.Fatalf("failed to marshal PatchOptions (%v): %v", err, patch) 48 | } 49 | got := UpdateOptions{} 50 | err = json.Unmarshal(b, &got) 51 | if err != nil { 52 | t.Fatalf("failed to unmarshal UpdateOptions into UpdateOptions: %v", err) 53 | } 54 | 55 | if !reflect.DeepEqual(update, got) { 56 | t.Fatalf(`UpdateOptions -> PatchOptions -> UpdateOptions round-trip failed: 57 | got: %v 58 | want: %v`, got, update) 59 | } 60 | }) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/time_fuzz.go: -------------------------------------------------------------------------------- 1 | //go:build !notest 2 | // +build !notest 3 | 4 | /* 5 | Copyright 2020 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package v1 21 | 22 | import ( 23 | "math/rand" 24 | "time" 25 | 26 | "sigs.k8s.io/randfill" 27 | ) 28 | 29 | // Fuzz satisfies randfill.SimpleSelfFiller. 30 | func (t *Time) RandFill(r *rand.Rand) { 31 | if t == nil { 32 | return 33 | } 34 | // Allow for about 1000 years of randomness. Leave off nanoseconds 35 | // because JSON doesn't represent them so they can't round-trip 36 | // properly. 37 | t.Time = time.Unix(r.Int63n(1000*365*24*60*60), 0) 38 | } 39 | 40 | // ensure Time implements randfill.SimpleSelfFiller 41 | var _ randfill.SimpleSelfFiller = &Time{} 42 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/unstructured/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package unstructured 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 29 | func (in *Unstructured) DeepCopyInto(out *Unstructured) { 30 | clone := in.DeepCopy() 31 | *out = *clone 32 | return 33 | } 34 | 35 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 36 | func (in *Unstructured) DeepCopyObject() runtime.Object { 37 | if c := in.DeepCopy(); c != nil { 38 | return c 39 | } 40 | return nil 41 | } 42 | 43 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 44 | func (in *UnstructuredList) DeepCopyInto(out *UnstructuredList) { 45 | clone := in.DeepCopy() 46 | *out = *clone 47 | return 48 | } 49 | 50 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 51 | func (in *UnstructuredList) DeepCopyObject() runtime.Object { 52 | if c := in.DeepCopy(); c != nil { 53 | return c 54 | } 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1/zz_generated.defaults.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by defaulter-gen. DO NOT EDIT. 21 | 22 | package v1 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // RegisterDefaults adds defaulters functions to the given scheme. 29 | // Public to allow building arbitrary schemes. 30 | // All generated defaulters are covering - they call all nested defaulters. 31 | func RegisterDefaults(scheme *runtime.Scheme) error { 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/conversion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | import ( 20 | "unsafe" 21 | 22 | "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | "k8s.io/apimachinery/pkg/conversion" 24 | ) 25 | 26 | // Convert_Slice_string_To_v1beta1_IncludeObjectPolicy allows converting a URL query parameter value 27 | func Convert_Slice_string_To_v1beta1_IncludeObjectPolicy(in *[]string, out *IncludeObjectPolicy, s conversion.Scope) error { 28 | if len(*in) > 0 { 29 | *out = IncludeObjectPolicy((*in)[0]) 30 | } 31 | return nil 32 | } 33 | 34 | // Convert_v1beta1_PartialObjectMetadataList_To_v1_PartialObjectMetadataList allows converting PartialObjectMetadataList between versions 35 | func Convert_v1beta1_PartialObjectMetadataList_To_v1_PartialObjectMetadataList(in *PartialObjectMetadataList, out *v1.PartialObjectMetadataList, s conversion.Scope) error { 36 | out.ListMeta = in.ListMeta 37 | out.Items = *(*[]v1.PartialObjectMetadata)(unsafe.Pointer(&in.Items)) 38 | return nil 39 | } 40 | 41 | // Convert_v1_PartialObjectMetadataList_To_v1beta1_PartialObjectMetadataList allows converting PartialObjectMetadataList between versions 42 | func Convert_v1_PartialObjectMetadataList_To_v1beta1_PartialObjectMetadataList(in *v1.PartialObjectMetadataList, out *PartialObjectMetadataList, s conversion.Scope) error { 43 | out.ListMeta = in.ListMeta 44 | out.Items = *(*[]v1.PartialObjectMetadata)(unsafe.Pointer(&in.Items)) 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/deepcopy.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:openapi-gen=true 19 | // +k8s:defaulter-gen=TypeMeta 20 | 21 | // +groupName=meta.k8s.io 22 | 23 | package v1beta1 24 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.apimachinery.pkg.apis.meta.v1beta1; 23 | 24 | import "k8s.io/apimachinery/pkg/apis/meta/v1/generated.proto"; 25 | import "k8s.io/apimachinery/pkg/runtime/schema/generated.proto"; 26 | 27 | // Package-wide variables from generator "generated". 28 | option go_package = "k8s.io/apimachinery/pkg/apis/meta/v1beta1"; 29 | 30 | // PartialObjectMetadataList contains a list of objects containing only their metadata. 31 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 32 | message PartialObjectMetadataList { 33 | // Standard list metadata. 34 | // More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds 35 | // +optional 36 | optional .k8s.io.apimachinery.pkg.apis.meta.v1.ListMeta metadata = 2; 37 | 38 | // items contains each of the included items. 39 | repeated .k8s.io.apimachinery.pkg.apis.meta.v1.PartialObjectMetadata items = 1; 40 | } 41 | 42 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/types_swagger_doc_generated.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1beta1 18 | 19 | // This file contains a collection of methods that can be used from go-restful to 20 | // generate Swagger API documentation for its models. Please read this PR for more 21 | // information on the implementation: https://github.com/emicklei/go-restful/pull/215 22 | // 23 | // TODOs are ignored from the parser (e.g. TODO(andronat):... || TODO:...) if and only if 24 | // they are on one line! For multiple line or blocks that you want to ignore use ---. 25 | // Any context after a --- is ignored. 26 | // 27 | // Those methods can be generated by using hack/update-codegen.sh 28 | 29 | // AUTO-GENERATED FUNCTIONS START HERE. DO NOT EDIT. 30 | var map_PartialObjectMetadataList = map[string]string{ 31 | "": "PartialObjectMetadataList contains a list of objects containing only their metadata.", 32 | "metadata": "Standard list metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", 33 | "items": "items contains each of the included items.", 34 | } 35 | 36 | func (PartialObjectMetadataList) SwaggerDoc() map[string]string { 37 | return map_PartialObjectMetadataList 38 | } 39 | 40 | // AUTO-GENERATED FUNCTIONS END HERE 41 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/validation/validation.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package validation 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/util/validation/field" 22 | ) 23 | 24 | // ValidateTableOptions returns any invalid flags on TableOptions. 25 | func ValidateTableOptions(opts *metav1.TableOptions) field.ErrorList { 26 | var allErrs field.ErrorList 27 | switch opts.IncludeObject { 28 | case metav1.IncludeMetadata, metav1.IncludeNone, metav1.IncludeObject, "": 29 | default: 30 | allErrs = append(allErrs, field.Invalid(field.NewPath("includeObject"), opts.IncludeObject, "must be 'Metadata', 'Object', 'None', or empty")) 31 | } 32 | return allErrs 33 | } 34 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1beta1 23 | 24 | import ( 25 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 | runtime "k8s.io/apimachinery/pkg/runtime" 27 | ) 28 | 29 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 30 | func (in *PartialObjectMetadataList) DeepCopyInto(out *PartialObjectMetadataList) { 31 | *out = *in 32 | out.TypeMeta = in.TypeMeta 33 | in.ListMeta.DeepCopyInto(&out.ListMeta) 34 | if in.Items != nil { 35 | in, out := &in.Items, &out.Items 36 | *out = make([]v1.PartialObjectMetadata, len(*in)) 37 | for i := range *in { 38 | (*in)[i].DeepCopyInto(&(*out)[i]) 39 | } 40 | } 41 | return 42 | } 43 | 44 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PartialObjectMetadataList. 45 | func (in *PartialObjectMetadataList) DeepCopy() *PartialObjectMetadataList { 46 | if in == nil { 47 | return nil 48 | } 49 | out := new(PartialObjectMetadataList) 50 | in.DeepCopyInto(out) 51 | return out 52 | } 53 | 54 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 55 | func (in *PartialObjectMetadataList) DeepCopyObject() runtime.Object { 56 | if c := in.DeepCopy(); c != nil { 57 | return c 58 | } 59 | return nil 60 | } 61 | -------------------------------------------------------------------------------- /pkg/apis/meta/v1beta1/zz_generated.defaults.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by defaulter-gen. DO NOT EDIT. 21 | 22 | package v1beta1 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // RegisterDefaults adds defaulters functions to the given scheme. 29 | // Public to allow building arbitrary schemes. 30 | // All generated defaulters are covering - they call all nested defaulters. 31 | func RegisterDefaults(scheme *runtime.Scheme) error { 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +groupName=testapigroup.apimachinery.k8s.io 19 | // 20 | // package testapigroup contains an testapigroup API used to demonstrate how to create api groups. Moreover, this is 21 | // used within tests. 22 | package testapigroup 23 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/install/install.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package install installs the certificates API group, making it available as 18 | // an option to all of the API encoding/decoding machinery. 19 | package install 20 | 21 | import ( 22 | "k8s.io/apimachinery/pkg/apis/testapigroup" 23 | "k8s.io/apimachinery/pkg/apis/testapigroup/v1" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 26 | ) 27 | 28 | // Install registers the API group and adds types to a scheme 29 | func Install(scheme *runtime.Scheme) { 30 | utilruntime.Must(testapigroup.AddToScheme(scheme)) 31 | utilruntime.Must(v1.AddToScheme(scheme)) 32 | utilruntime.Must(scheme.SetVersionPriority(v1.SchemeGroupVersion)) 33 | } 34 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/install/roundtrip_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package install 18 | 19 | import ( 20 | "testing" 21 | 22 | "k8s.io/apimachinery/pkg/api/apitesting/roundtrip" 23 | testapigroupfuzzer "k8s.io/apimachinery/pkg/apis/testapigroup/fuzzer" 24 | ) 25 | 26 | func TestRoundTrip(t *testing.T) { 27 | roundtrip.RoundTripTestForAPIGroup(t, Install, testapigroupfuzzer.Funcs) 28 | roundtrip.RoundTripProtobufTestForAPIGroup(t, Install, testapigroupfuzzer.Funcs) 29 | } 30 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package testapigroup 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | ) 23 | 24 | var ( 25 | SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) 26 | AddToScheme = SchemeBuilder.AddToScheme 27 | ) 28 | 29 | // GroupName is the group name use in this package 30 | const GroupName = "testapigroup.apimachinery.k8s.io" 31 | 32 | // SchemeGroupVersion is group version used to register these objects 33 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: runtime.APIVersionInternal} 34 | 35 | // Kind takes an unqualified kind and returns a Group qualified GroupKind 36 | func Kind(kind string) schema.GroupKind { 37 | return SchemeGroupVersion.WithKind(kind).GroupKind() 38 | } 39 | 40 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 41 | func Resource(resource string) schema.GroupResource { 42 | return SchemeGroupVersion.WithResource(resource).GroupResource() 43 | } 44 | 45 | // Adds the list of known types to the given scheme. 46 | func addKnownTypes(scheme *runtime.Scheme) error { 47 | scheme.AddKnownTypes(SchemeGroupVersion, 48 | &Carp{}, 49 | ) 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/v1/conversion.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | ) 22 | 23 | func addConversionFuncs(scheme *runtime.Scheme) error { 24 | // Add non-generated conversion functions here. Currently there are none. 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/v1/defaults.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | ) 22 | 23 | func addDefaultingFuncs(scheme *runtime.Scheme) error { 24 | // return RegisterDefaults(scheme) 25 | return nil 26 | } 27 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/v1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | // +k8s:conversion-gen=k8s.io/apimachinery/pkg/apis/testapigroup 19 | // +k8s:openapi-gen=false 20 | // +k8s:defaulter-gen=TypeMeta 21 | 22 | // +groupName=testapigroup.apimachinery.k8s.io 23 | 24 | package v1 25 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/v1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | // GroupName is the group name use in this package 26 | const GroupName = "testapigroup.apimachinery.k8s.io" 27 | 28 | // SchemeGroupVersion is group version used to register these objects 29 | var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1"} 30 | 31 | // Kind takes an unqualified kind and returns a Group qualified GroupKind 32 | func Kind(kind string) schema.GroupKind { 33 | return SchemeGroupVersion.WithKind(kind).GroupKind() 34 | } 35 | 36 | // Resource takes an unqualified resource and returns a Group qualified GroupResource 37 | func Resource(resource string) schema.GroupResource { 38 | return SchemeGroupVersion.WithResource(resource).GroupResource() 39 | } 40 | 41 | var ( 42 | // TODO: move SchemeBuilder with zz_generated.deepcopy.go to k8s.io/api. 43 | // localSchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. 44 | SchemeBuilder runtime.SchemeBuilder 45 | localSchemeBuilder = &SchemeBuilder 46 | AddToScheme = localSchemeBuilder.AddToScheme 47 | ) 48 | 49 | func init() { 50 | // We only register manually written functions here. The registration of the 51 | // generated functions takes place in the generated files. The separation 52 | // makes the code compile even when the generated files are missing. 53 | localSchemeBuilder.Register(addKnownTypes, addConversionFuncs, addDefaultingFuncs) 54 | } 55 | 56 | // Adds the list of known types to the given scheme. 57 | func addKnownTypes(scheme *runtime.Scheme) error { 58 | scheme.AddKnownTypes(SchemeGroupVersion, 59 | &Carp{}, 60 | ) 61 | metav1.AddToGroupVersion(scheme, SchemeGroupVersion) 62 | return nil 63 | } 64 | -------------------------------------------------------------------------------- /pkg/apis/testapigroup/v1/zz_generated.defaults.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by defaulter-gen. DO NOT EDIT. 21 | 22 | package v1 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // RegisterDefaults adds defaulters functions to the given scheme. 29 | // Public to allow building arbitrary schemes. 30 | // All generated defaulters are covering - they call all nested defaulters. 31 | func RegisterDefaults(scheme *runtime.Scheme) error { 32 | return nil 33 | } 34 | -------------------------------------------------------------------------------- /pkg/conversion/deep_equal.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package conversion 18 | 19 | import ( 20 | "k8s.io/apimachinery/third_party/forked/golang/reflect" 21 | ) 22 | 23 | // The code for this type must be located in third_party, since it forks from 24 | // go std lib. But for convenience, we expose the type here, too. 25 | type Equalities struct { 26 | reflect.Equalities 27 | } 28 | 29 | // For convenience, panics on errors 30 | func EqualitiesOrDie(funcs ...interface{}) Equalities { 31 | e := Equalities{reflect.Equalities{}} 32 | if err := e.AddFuncs(funcs...); err != nil { 33 | panic(err) 34 | } 35 | return e 36 | } 37 | 38 | // Performs a shallow copy of the equalities map 39 | func (e Equalities) Copy() Equalities { 40 | result := Equalities{reflect.Equalities{}} 41 | 42 | for key, value := range e.Equalities { 43 | result.Equalities[key] = value 44 | } 45 | 46 | return result 47 | } 48 | -------------------------------------------------------------------------------- /pkg/conversion/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package conversion provides go object versioning. 18 | // 19 | // Specifically, conversion provides a way for you to define multiple versions 20 | // of the same object. You may write functions which implement conversion logic, 21 | // but for the fields which did not change, copying is automated. This makes it 22 | // easy to modify the structures you use in memory without affecting the format 23 | // you store on disk or respond to in your external API calls. 24 | package conversion 25 | -------------------------------------------------------------------------------- /pkg/conversion/helper.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package conversion 18 | 19 | import ( 20 | "fmt" 21 | "reflect" 22 | ) 23 | 24 | // EnforcePtr ensures that obj is a pointer of some sort. Returns a reflect.Value 25 | // of the dereferenced pointer, ensuring that it is settable/addressable. 26 | // Returns an error if this is not possible. 27 | func EnforcePtr(obj interface{}) (reflect.Value, error) { 28 | v := reflect.ValueOf(obj) 29 | if v.Kind() != reflect.Pointer { 30 | if v.Kind() == reflect.Invalid { 31 | return reflect.Value{}, fmt.Errorf("expected pointer, but got invalid kind") 32 | } 33 | return reflect.Value{}, fmt.Errorf("expected pointer, but got %v type", v.Type()) 34 | } 35 | if v.IsNil() { 36 | return reflect.Value{}, fmt.Errorf("expected pointer, but got nil") 37 | } 38 | return v.Elem(), nil 39 | } 40 | -------------------------------------------------------------------------------- /pkg/conversion/helper_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package conversion 18 | 19 | import "testing" 20 | 21 | func TestInvalidPtrValueKind(t *testing.T) { 22 | var simple interface{} 23 | switch obj := simple.(type) { 24 | default: 25 | _, err := EnforcePtr(obj) 26 | if err == nil { 27 | t.Errorf("Expected error on invalid kind") 28 | } 29 | } 30 | } 31 | 32 | func TestEnforceNilPtr(t *testing.T) { 33 | var nilPtr *struct{} 34 | _, err := EnforcePtr(nilPtr) 35 | if err == nil { 36 | t.Errorf("Expected error on nil pointer") 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /pkg/conversion/queryparams/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package queryparams provides conversion from versioned 18 | // runtime objects to URL query values 19 | package queryparams 20 | -------------------------------------------------------------------------------- /pkg/fields/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package fields implements a simple field system, parsing and matching 18 | // selectors with sets of fields. 19 | package fields 20 | -------------------------------------------------------------------------------- /pkg/fields/fields.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fields 18 | 19 | import ( 20 | "sort" 21 | "strings" 22 | ) 23 | 24 | // Fields allows you to present fields independently from their storage. 25 | type Fields interface { 26 | // Has returns whether the provided field exists. 27 | Has(field string) (exists bool) 28 | 29 | // Get returns the value for the provided field. 30 | Get(field string) (value string) 31 | } 32 | 33 | // Set is a map of field:value. It implements Fields. 34 | type Set map[string]string 35 | 36 | // String returns all fields listed as a human readable string. 37 | // Conveniently, exactly the format that ParseSelector takes. 38 | func (ls Set) String() string { 39 | selector := make([]string, 0, len(ls)) 40 | for key, value := range ls { 41 | selector = append(selector, key+"="+value) 42 | } 43 | // Sort for determinism. 44 | sort.StringSlice(selector).Sort() 45 | return strings.Join(selector, ",") 46 | } 47 | 48 | // Has returns whether the provided field exists in the map. 49 | func (ls Set) Has(field string) bool { 50 | _, exists := ls[field] 51 | return exists 52 | } 53 | 54 | // Get returns the value in the map for the provided field. 55 | func (ls Set) Get(field string) string { 56 | return ls[field] 57 | } 58 | 59 | // AsSelector converts fields into a selectors. 60 | func (ls Set) AsSelector() Selector { 61 | return SelectorFromSet(ls) 62 | } 63 | -------------------------------------------------------------------------------- /pkg/fields/fields_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fields 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func matches(t *testing.T, ls Set, want string) { 24 | if ls.String() != want { 25 | t.Errorf("Expected '%s', but got '%s'", want, ls.String()) 26 | } 27 | } 28 | 29 | func TestSetString(t *testing.T) { 30 | matches(t, Set{"x": "y"}, "x=y") 31 | matches(t, Set{"foo": "bar"}, "foo=bar") 32 | matches(t, Set{"foo": "bar", "baz": "qup"}, "baz=qup,foo=bar") 33 | } 34 | 35 | func TestFieldHas(t *testing.T) { 36 | fieldHasTests := []struct { 37 | Ls Fields 38 | Key string 39 | Has bool 40 | }{ 41 | {Set{"x": "y"}, "x", true}, 42 | {Set{"x": ""}, "x", true}, 43 | {Set{"x": "y"}, "foo", false}, 44 | } 45 | for _, lh := range fieldHasTests { 46 | if has := lh.Ls.Has(lh.Key); has != lh.Has { 47 | t.Errorf("%#v.Has(%#v) => %v, expected %v", lh.Ls, lh.Key, has, lh.Has) 48 | } 49 | } 50 | } 51 | 52 | func TestFieldGet(t *testing.T) { 53 | ls := Set{"x": "y"} 54 | if ls.Get("x") != "y" { 55 | t.Errorf("Set.Get is broken") 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /pkg/fields/requirements.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package fields 18 | 19 | import "k8s.io/apimachinery/pkg/selection" 20 | 21 | // Requirements is AND of all requirements. 22 | type Requirements []Requirement 23 | 24 | // Requirement contains a field, a value, and an operator that relates the field and value. 25 | // This is currently for reading internal selection information of field selector. 26 | type Requirement struct { 27 | Operator selection.Operator 28 | Field string 29 | Value string 30 | } 31 | -------------------------------------------------------------------------------- /pkg/labels/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package labels implements a simple label system, parsing and matching 18 | // selectors with sets of labels. 19 | package labels 20 | -------------------------------------------------------------------------------- /pkg/labels/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package labels 23 | 24 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 25 | func (in *Requirement) DeepCopyInto(out *Requirement) { 26 | *out = *in 27 | if in.strValues != nil { 28 | in, out := &in.strValues, &out.strValues 29 | *out = make([]string, len(*in)) 30 | copy(*out, *in) 31 | } 32 | return 33 | } 34 | 35 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Requirement. 36 | func (in *Requirement) DeepCopy() *Requirement { 37 | if in == nil { 38 | return nil 39 | } 40 | out := new(Requirement) 41 | in.DeepCopyInto(out) 42 | return out 43 | } 44 | -------------------------------------------------------------------------------- /pkg/runtime/codec_check.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | import ( 20 | "fmt" 21 | "reflect" 22 | 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "k8s.io/apimachinery/pkg/util/json" 25 | ) 26 | 27 | // CheckCodec makes sure that the codec can encode objects like internalType, 28 | // decode all of the external types listed, and also decode them into the given 29 | // object. (Will modify internalObject.) (Assumes JSON serialization.) 30 | // TODO: verify that the correct external version is chosen on encode... 31 | func CheckCodec(c Codec, internalType Object, externalTypes ...schema.GroupVersionKind) error { 32 | if _, err := Encode(c, internalType); err != nil { 33 | return fmt.Errorf("internal type not encodable: %v", err) 34 | } 35 | for _, et := range externalTypes { 36 | typeMeta := TypeMeta{ 37 | Kind: et.Kind, 38 | APIVersion: et.GroupVersion().String(), 39 | } 40 | exBytes, err := json.Marshal(&typeMeta) 41 | if err != nil { 42 | return err 43 | } 44 | obj, err := Decode(c, exBytes) 45 | if err != nil { 46 | return fmt.Errorf("external type %s not interpretable: %v", et, err) 47 | } 48 | if reflect.TypeOf(obj) != reflect.TypeOf(internalType) { 49 | return fmt.Errorf("decode of external type %s produced: %#v", et, obj) 50 | } 51 | if err = DecodeInto(c, exBytes, internalType); err != nil { 52 | return fmt.Errorf("external type %s not convertible to internal type: %v", et, err) 53 | } 54 | } 55 | return nil 56 | } 57 | -------------------------------------------------------------------------------- /pkg/runtime/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package runtime includes helper functions for working with API objects 18 | // that follow the kubernetes API object conventions, which are: 19 | // 20 | // 0. Your API objects have a common metadata struct member, TypeMeta. 21 | // 22 | // 1. Your code refers to an internal set of API objects. 23 | // 24 | // 2. In a separate package, you have an external set of API objects. 25 | // 26 | // 3. The external set is considered to be versioned, and no breaking 27 | // changes are ever made to it (fields may be added but not changed 28 | // or removed). 29 | // 30 | // 4. As your api evolves, you'll make an additional versioned package 31 | // with every major change. 32 | // 33 | // 5. Versioned packages have conversion functions which convert to 34 | // and from the internal version. 35 | // 36 | // 6. You'll continue to support older versions according to your 37 | // deprecation policy, and you can easily provide a program/library 38 | // to update old versions into new versions because of 5. 39 | // 40 | // 7. All of your serializations and deserializations are handled in a 41 | // centralized place. 42 | // 43 | // Package runtime provides a conversion helper to make 5 easy, and the 44 | // Encode/Decode/DecodeInto trio to accomplish 7. You can also register 45 | // additional "codecs" which use a version of your choice. It's 46 | // recommended that you register your types with runtime in your 47 | // package's init function. 48 | // 49 | // As a bonus, a few common types useful from all api objects and versions 50 | // are provided in types.go. 51 | package runtime 52 | -------------------------------------------------------------------------------- /pkg/runtime/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | import "k8s.io/apimachinery/pkg/runtime/schema" 20 | 21 | // SetGroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta 22 | func (obj *TypeMeta) SetGroupVersionKind(gvk schema.GroupVersionKind) { 23 | obj.APIVersion, obj.Kind = gvk.ToAPIVersionAndKind() 24 | } 25 | 26 | // GroupVersionKind satisfies the ObjectKind interface for all objects that embed TypeMeta 27 | func (obj *TypeMeta) GroupVersionKind() schema.GroupVersionKind { 28 | return schema.FromAPIVersionAndKind(obj.APIVersion, obj.Kind) 29 | } 30 | 31 | func (obj *TypeMeta) GetObjectKind() schema.ObjectKind { return obj } 32 | -------------------------------------------------------------------------------- /pkg/runtime/schema/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.apimachinery.pkg.runtime.schema; 23 | 24 | // Package-wide variables from generator "generated". 25 | option go_package = "k8s.io/apimachinery/pkg/runtime/schema"; 26 | 27 | -------------------------------------------------------------------------------- /pkg/runtime/schema/interfaces.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package schema 18 | 19 | // All objects that are serialized from a Scheme encode their type information. This interface is used 20 | // by serialization to set type information from the Scheme onto the serialized version of an object. 21 | // For objects that cannot be serialized or have unique requirements, this interface may be a no-op. 22 | type ObjectKind interface { 23 | // SetGroupVersionKind sets or clears the intended serialized kind of an object. Passing kind nil 24 | // should clear the current setting. 25 | SetGroupVersionKind(kind GroupVersionKind) 26 | // GroupVersionKind returns the stored group, version, and kind of an object, or an empty struct 27 | // if the object does not expose or provide these fields. 28 | GroupVersionKind() GroupVersionKind 29 | } 30 | 31 | // EmptyObjectKind implements the ObjectKind interface as a noop 32 | var EmptyObjectKind = emptyObjectKind{} 33 | 34 | type emptyObjectKind struct{} 35 | 36 | // SetGroupVersionKind implements the ObjectKind interface 37 | func (emptyObjectKind) SetGroupVersionKind(gvk GroupVersionKind) {} 38 | 39 | // GroupVersionKind implements the ObjectKind interface 40 | func (emptyObjectKind) GroupVersionKind() GroupVersionKind { return GroupVersionKind{} } 41 | -------------------------------------------------------------------------------- /pkg/runtime/scheme_builder.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | // SchemeBuilder collects functions that add things to a scheme. It's to allow 20 | // code to compile without explicitly referencing generated types. You should 21 | // declare one in each package that will have generated deep copy or conversion 22 | // functions. 23 | type SchemeBuilder []func(*Scheme) error 24 | 25 | // AddToScheme applies all the stored functions to the scheme. A non-nil error 26 | // indicates that one function failed and the attempt was abandoned. 27 | func (sb *SchemeBuilder) AddToScheme(s *Scheme) error { 28 | for _, f := range *sb { 29 | if err := f(s); err != nil { 30 | return err 31 | } 32 | } 33 | return nil 34 | } 35 | 36 | // Register adds a scheme setup function to the list. 37 | func (sb *SchemeBuilder) Register(funcs ...func(*Scheme) error) { 38 | for _, f := range funcs { 39 | *sb = append(*sb, f) 40 | } 41 | } 42 | 43 | // NewSchemeBuilder calls Register for you. 44 | func NewSchemeBuilder(funcs ...func(*Scheme) error) SchemeBuilder { 45 | var sb SchemeBuilder 46 | sb.Register(funcs...) 47 | return sb 48 | } 49 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/cbor/internal/modes/buffers.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package modes 18 | 19 | import ( 20 | "bytes" 21 | "sync" 22 | ) 23 | 24 | var buffers = BufferProvider{p: new(sync.Pool)} 25 | 26 | type buffer struct { 27 | bytes.Buffer 28 | } 29 | 30 | type pool interface { 31 | Get() interface{} 32 | Put(interface{}) 33 | } 34 | 35 | type BufferProvider struct { 36 | p pool 37 | } 38 | 39 | func (b *BufferProvider) Get() *buffer { 40 | if buf, ok := b.p.Get().(*buffer); ok { 41 | return buf 42 | } 43 | return &buffer{} 44 | } 45 | 46 | func (b *BufferProvider) Put(buf *buffer) { 47 | if buf.Cap() > 3*1024*1024 /* Default MaxRequestBodyBytes */ { 48 | // Objects in a sync.Pool are assumed to be fungible. This is not a good assumption 49 | // for pools of *bytes.Buffer because a *bytes.Buffer's underlying array grows as 50 | // needed to accommodate writes. In Kubernetes, apiservers tend to encode "small" 51 | // objects very frequently and much larger objects (especially large lists) only 52 | // occasionally. Under steady load, pooled buffers tend to be borrowed frequently 53 | // enough to prevent them from being released. Over time, each buffer is used to 54 | // encode a large object and its capacity increases accordingly. The result is that 55 | // practically all buffers in the pool retain much more capacity than needed to 56 | // encode most objects. 57 | 58 | // As a basic mitigation for the worst case, buffers with more capacity than the 59 | // default max request body size are never returned to the pool. 60 | // TODO: Optimize for higher buffer utilization. 61 | return 62 | } 63 | buf.Reset() 64 | b.p.Put(buf) 65 | } 66 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/cbor/internal/modes/buffers_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package modes 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | type mockPool struct { 24 | v interface{} 25 | } 26 | 27 | func (*mockPool) Get() interface{} { 28 | return nil 29 | } 30 | 31 | func (p *mockPool) Put(v interface{}) { 32 | p.v = v 33 | } 34 | 35 | func TestBufferProviderPut(t *testing.T) { 36 | { 37 | p := new(mockPool) 38 | bp := &BufferProvider{p: p} 39 | small := new(buffer) 40 | small.Grow(3 * 1024 * 1024) 41 | small.WriteString("hello world") 42 | bp.Put(small) 43 | if p.v != small { 44 | t.Errorf("expected buf with capacity %d to be returned to pool", small.Cap()) 45 | } 46 | if small.Len() != 0 { 47 | t.Errorf("expected buf to be reset before returning to pool") 48 | } 49 | } 50 | 51 | { 52 | p := new(mockPool) 53 | bp := &BufferProvider{p: p} 54 | big := new(buffer) 55 | big.Grow(3*1024*1024 + 1) 56 | bp.Put(big) 57 | if p.v != nil { 58 | t.Errorf("expected buf with capacity %d not to be returned to pool", big.Cap()) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/cbor/internal/modes/diagnostic.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package modes 18 | 19 | import ( 20 | "github.com/fxamacker/cbor/v2" 21 | ) 22 | 23 | var Diagnostic cbor.DiagMode = func() cbor.DiagMode { 24 | opts := Decode.DecOptions() 25 | diagnostic, err := cbor.DiagOptions{ 26 | ByteStringText: true, 27 | 28 | MaxNestedLevels: opts.MaxNestedLevels, 29 | MaxArrayElements: opts.MaxArrayElements, 30 | MaxMapPairs: opts.MaxMapPairs, 31 | }.DiagMode() 32 | if err != nil { 33 | panic(err) 34 | } 35 | return diagnostic 36 | }() 37 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/cbor/internal/modes/modes_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2024 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package modes_test 18 | 19 | import ( 20 | "errors" 21 | "testing" 22 | 23 | "github.com/fxamacker/cbor/v2" 24 | "github.com/google/go-cmp/cmp" 25 | "k8s.io/apimachinery/pkg/runtime/serializer/cbor/internal/modes" 26 | ) 27 | 28 | var encModeNames = map[modes.EncMode]string{ 29 | modes.Encode: "Encode", 30 | modes.EncodeNondeterministic: "EncodeNondeterministic", 31 | } 32 | 33 | var allEncModes = []modes.EncMode{ 34 | modes.Encode, 35 | modes.EncodeNondeterministic, 36 | } 37 | 38 | var decModeNames = map[cbor.DecMode]string{ 39 | modes.Decode: "Decode", 40 | modes.DecodeLax: "DecodeLax", 41 | } 42 | 43 | var allDecModes = []cbor.DecMode{ 44 | modes.Decode, 45 | modes.DecodeLax, 46 | } 47 | 48 | func assertNilError(t *testing.T, e error) { 49 | if e != nil { 50 | t.Errorf("expected nil error, got: %v", e) 51 | } 52 | } 53 | 54 | func assertOnConcreteError[E error](fn func(*testing.T, E)) func(t *testing.T, e error) { 55 | return func(t *testing.T, ei error) { 56 | var ec E 57 | if !errors.As(ei, &ec) { 58 | t.Errorf("expected concrete error type %T, got %T: %v", ec, ei, ei) 59 | return 60 | } 61 | fn(t, ec) 62 | } 63 | } 64 | 65 | func assertErrorMessage(want string) func(*testing.T, error) { 66 | return func(t *testing.T, got error) { 67 | if got == nil { 68 | t.Error("expected non-nil error") 69 | return 70 | } 71 | if got.Error() != want { 72 | t.Errorf("got error %q, want %q", got.Error(), want) 73 | } 74 | } 75 | } 76 | 77 | func assertIdenticalError[E error](expected E) func(*testing.T, error) { 78 | return assertOnConcreteError(func(t *testing.T, actual E) { 79 | if diff := cmp.Diff(expected, actual); diff != "" { 80 | t.Errorf("diff between actual error and expected error:\n%s", diff) 81 | } 82 | }) 83 | } 84 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/json/meta_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package json 18 | 19 | import "testing" 20 | 21 | func TestSimpleMetaFactoryInterpret(t *testing.T) { 22 | factory := SimpleMetaFactory{} 23 | gvk, err := factory.Interpret([]byte(`{"apiVersion":"1","kind":"object"}`)) 24 | if err != nil { 25 | t.Fatalf("unexpected error: %v", err) 26 | } 27 | if gvk.Version != "1" || gvk.Kind != "object" { 28 | t.Errorf("unexpected interpret: %#v", gvk) 29 | } 30 | 31 | // no kind or version 32 | gvk, err = factory.Interpret([]byte(`{}`)) 33 | if err != nil { 34 | t.Fatalf("unexpected error: %v", err) 35 | } 36 | if gvk.Version != "" || gvk.Kind != "" { 37 | t.Errorf("unexpected interpret: %#v", gvk) 38 | } 39 | 40 | // unparsable 41 | _, err = factory.Interpret([]byte(`{`)) 42 | if err == nil { 43 | t.Errorf("unexpected non-error") 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/negotiated_codec.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package serializer 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | ) 22 | 23 | // TODO: We should split negotiated serializers that we can change versions on from those we can change 24 | // serialization formats on 25 | type negotiatedSerializerWrapper struct { 26 | info runtime.SerializerInfo 27 | } 28 | 29 | func NegotiatedSerializerWrapper(info runtime.SerializerInfo) runtime.NegotiatedSerializer { 30 | return &negotiatedSerializerWrapper{info} 31 | } 32 | 33 | func (n *negotiatedSerializerWrapper) SupportedMediaTypes() []runtime.SerializerInfo { 34 | return []runtime.SerializerInfo{n.info} 35 | } 36 | 37 | func (n *negotiatedSerializerWrapper) EncoderForVersion(e runtime.Encoder, _ runtime.GroupVersioner) runtime.Encoder { 38 | return e 39 | } 40 | 41 | func (n *negotiatedSerializerWrapper) DecoderToVersion(d runtime.Decoder, _gv runtime.GroupVersioner) runtime.Decoder { 42 | return d 43 | } 44 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/protobuf/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package protobuf provides a Kubernetes serializer for the protobuf format. 18 | package protobuf 19 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/recognizer/testing/recognizer_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package testing 18 | 19 | import ( 20 | "testing" 21 | 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "k8s.io/apimachinery/pkg/runtime/serializer/json" 25 | "k8s.io/apimachinery/pkg/runtime/serializer/recognizer" 26 | ) 27 | 28 | type A struct{} 29 | 30 | func (A) GetObjectKind() schema.ObjectKind { return schema.EmptyObjectKind } 31 | func (a A) DeepCopyObject() runtime.Object { 32 | return a 33 | } 34 | 35 | func TestRecognizer(t *testing.T) { 36 | s := runtime.NewScheme() 37 | s.AddKnownTypes(schema.GroupVersion{Version: "v1"}, &A{}) 38 | d := recognizer.NewDecoder( 39 | json.NewSerializerWithOptions(json.DefaultMetaFactory, s, s, json.SerializerOptions{}), 40 | json.NewSerializerWithOptions(json.DefaultMetaFactory, s, s, json.SerializerOptions{Yaml: true}), 41 | ) 42 | out, _, err := d.Decode([]byte(` 43 | kind: A 44 | apiVersion: v1 45 | `), nil, nil) 46 | if err != nil { 47 | t.Fatal(err) 48 | } 49 | t.Logf("%#v", out) 50 | 51 | out, _, err = d.Decode([]byte(` 52 | { 53 | "kind":"A", 54 | "apiVersion":"v1" 55 | } 56 | `), nil, nil) 57 | if err != nil { 58 | t.Fatal(err) 59 | } 60 | t.Logf("%#v", out) 61 | } 62 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/yaml/meta.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package yaml 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "k8s.io/apimachinery/pkg/runtime/schema" 24 | "sigs.k8s.io/yaml" 25 | ) 26 | 27 | // DefaultMetaFactory is a default factory for versioning objects in JSON or 28 | // YAML. The object in memory and in the default serialization will use the 29 | // "kind" and "apiVersion" fields. 30 | var DefaultMetaFactory = SimpleMetaFactory{} 31 | 32 | // SimpleMetaFactory provides default methods for retrieving the type and version of objects 33 | // that are identified with an "apiVersion" and "kind" fields in their JSON 34 | // serialization. It may be parameterized with the names of the fields in memory, or an 35 | // optional list of base structs to search for those fields in memory. 36 | type SimpleMetaFactory struct{} 37 | 38 | // Interpret will return the APIVersion and Kind of the JSON wire-format 39 | // encoding of an object, or an error. 40 | func (SimpleMetaFactory) Interpret(data []byte) (*schema.GroupVersionKind, error) { 41 | gvk := runtime.TypeMeta{} 42 | if err := yaml.Unmarshal(data, &gvk); err != nil { 43 | return nil, fmt.Errorf("could not interpret GroupVersionKind; unmarshal error: %v", err) 44 | } 45 | gv, err := schema.ParseGroupVersion(gvk.APIVersion) 46 | if err != nil { 47 | return nil, err 48 | } 49 | return &schema.GroupVersionKind{Group: gv.Group, Version: gv.Version, Kind: gvk.Kind}, nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/runtime/serializer/yaml/yaml.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package yaml 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | "k8s.io/apimachinery/pkg/runtime/schema" 22 | "k8s.io/apimachinery/pkg/util/yaml" 23 | ) 24 | 25 | // yamlSerializer converts YAML passed to the Decoder methods to JSON. 26 | type yamlSerializer struct { 27 | // the nested serializer 28 | runtime.Serializer 29 | } 30 | 31 | // yamlSerializer implements Serializer 32 | var _ runtime.Serializer = yamlSerializer{} 33 | 34 | // NewDecodingSerializer adds YAML decoding support to a serializer that supports JSON. 35 | func NewDecodingSerializer(jsonSerializer runtime.Serializer) runtime.Serializer { 36 | return &yamlSerializer{jsonSerializer} 37 | } 38 | 39 | func (c yamlSerializer) Decode(data []byte, gvk *schema.GroupVersionKind, into runtime.Object) (runtime.Object, *schema.GroupVersionKind, error) { 40 | out, err := yaml.ToJSON(data) 41 | if err != nil { 42 | return nil, nil, err 43 | } 44 | data = out 45 | return c.Serializer.Decode(data, gvk, into) 46 | } 47 | -------------------------------------------------------------------------------- /pkg/runtime/splice.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | import ( 20 | "bytes" 21 | "io" 22 | ) 23 | 24 | // Splice is the interface that wraps the Splice method. 25 | // 26 | // Splice moves data from given slice without copying the underlying data for 27 | // efficiency purpose. Therefore, the caller should make sure the underlying 28 | // data is not changed later. 29 | type Splice interface { 30 | Splice([]byte) 31 | io.Writer 32 | Reset() 33 | Bytes() []byte 34 | } 35 | 36 | // A spliceBuffer implements Splice and io.Writer interfaces. 37 | type spliceBuffer struct { 38 | raw []byte 39 | buf *bytes.Buffer 40 | } 41 | 42 | func NewSpliceBuffer() Splice { 43 | return &spliceBuffer{} 44 | } 45 | 46 | // Splice implements the Splice interface. 47 | func (sb *spliceBuffer) Splice(raw []byte) { 48 | sb.raw = raw 49 | } 50 | 51 | // Write implements the io.Writer interface. 52 | func (sb *spliceBuffer) Write(p []byte) (n int, err error) { 53 | if sb.buf == nil { 54 | sb.buf = &bytes.Buffer{} 55 | } 56 | return sb.buf.Write(p) 57 | } 58 | 59 | // Reset resets the buffer to be empty. 60 | func (sb *spliceBuffer) Reset() { 61 | if sb.buf != nil { 62 | sb.buf.Reset() 63 | } 64 | sb.raw = nil 65 | } 66 | 67 | // Bytes returns the data held by the buffer. 68 | func (sb *spliceBuffer) Bytes() []byte { 69 | if sb.buf != nil && len(sb.buf.Bytes()) > 0 { 70 | return sb.buf.Bytes() 71 | } 72 | if sb.raw != nil { 73 | return sb.raw 74 | } 75 | return []byte{} 76 | } 77 | -------------------------------------------------------------------------------- /pkg/runtime/swagger_doc_generator_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | import ( 20 | "testing" 21 | ) 22 | 23 | func TestFmtRawDoc(t *testing.T) { 24 | tests := []struct { 25 | t, expected string 26 | }{ 27 | {"aaa\n --- asd\n TODO: tooooodo\n toooodoooooo\n", "aaa"}, 28 | {"aaa\nasd\n TODO: tooooodo\nbbbb\n --- toooodoooooo\n", "aaa asd bbbb"}, 29 | {" TODO: tooooodo\n", ""}, 30 | {"Par1\n\nPar2\n\n", "Par1\\n\\nPar2"}, 31 | {"", ""}, 32 | {" ", ""}, 33 | {" \n", ""}, 34 | {" \n\n ", ""}, 35 | {"Example:\n\tl1\n\t\tl2\n", "Example:\\n\\tl1\\n\\t\\tl2"}, 36 | } 37 | 38 | for _, test := range tests { 39 | if o := fmtRawDoc(test.t); o != test.expected { 40 | t.Fatalf("Expected: %q, got %q", test.expected, o) 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /pkg/runtime/testing/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | 19 | package testing 20 | -------------------------------------------------------------------------------- /pkg/runtime/testing/v1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:deepcopy-gen=package 18 | 19 | package v1 20 | -------------------------------------------------------------------------------- /pkg/runtime/testing/v1/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package v1 18 | 19 | import ( 20 | "k8s.io/apimachinery/pkg/runtime" 21 | ) 22 | 23 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 24 | type ExternalSimple struct { 25 | runtime.TypeMeta `json:",inline"` 26 | TestString string `json:"testString"` 27 | } 28 | -------------------------------------------------------------------------------- /pkg/runtime/testing/v1/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package v1 23 | 24 | import ( 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 29 | func (in *ExternalSimple) DeepCopyInto(out *ExternalSimple) { 30 | *out = *in 31 | out.TypeMeta = in.TypeMeta 32 | return 33 | } 34 | 35 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalSimple. 36 | func (in *ExternalSimple) DeepCopy() *ExternalSimple { 37 | if in == nil { 38 | return nil 39 | } 40 | out := new(ExternalSimple) 41 | in.DeepCopyInto(out) 42 | return out 43 | } 44 | 45 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. 46 | func (in *ExternalSimple) DeepCopyObject() runtime.Object { 47 | if c := in.DeepCopy(); c != nil { 48 | return c 49 | } 50 | return nil 51 | } 52 | -------------------------------------------------------------------------------- /pkg/runtime/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package runtime 23 | 24 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 25 | func (in *RawExtension) DeepCopyInto(out *RawExtension) { 26 | *out = *in 27 | if in.Raw != nil { 28 | in, out := &in.Raw, &out.Raw 29 | *out = make([]byte, len(*in)) 30 | copy(*out, *in) 31 | } 32 | if in.Object != nil { 33 | out.Object = in.Object.DeepCopyObject() 34 | } 35 | return 36 | } 37 | 38 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new RawExtension. 39 | func (in *RawExtension) DeepCopy() *RawExtension { 40 | if in == nil { 41 | return nil 42 | } 43 | out := new(RawExtension) 44 | in.DeepCopyInto(out) 45 | return out 46 | } 47 | 48 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 49 | func (in *Unknown) DeepCopyInto(out *Unknown) { 50 | *out = *in 51 | out.TypeMeta = in.TypeMeta 52 | if in.Raw != nil { 53 | in, out := &in.Raw, &out.Raw 54 | *out = make([]byte, len(*in)) 55 | copy(*out, *in) 56 | } 57 | return 58 | } 59 | 60 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Unknown. 61 | func (in *Unknown) DeepCopy() *Unknown { 62 | if in == nil { 63 | return nil 64 | } 65 | out := new(Unknown) 66 | in.DeepCopyInto(out) 67 | return out 68 | } 69 | 70 | // DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new Object. 71 | func (in *Unknown) DeepCopyObject() Object { 72 | if c := in.DeepCopy(); c != nil { 73 | return c 74 | } 75 | return nil 76 | } 77 | -------------------------------------------------------------------------------- /pkg/selection/operator.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package selection 18 | 19 | // Operator represents a key/field's relationship to value(s). 20 | // See labels.Requirement and fields.Requirement for more details. 21 | type Operator string 22 | 23 | const ( 24 | DoesNotExist Operator = "!" 25 | Equals Operator = "=" 26 | DoubleEquals Operator = "==" 27 | In Operator = "in" 28 | NotEquals Operator = "!=" 29 | NotIn Operator = "notin" 30 | Exists Operator = "exists" 31 | GreaterThan Operator = "gt" 32 | LessThan Operator = "lt" 33 | ) 34 | -------------------------------------------------------------------------------- /pkg/test/runtime_helper_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package test 18 | 19 | import ( 20 | "testing" 21 | 22 | apitesting "k8s.io/apimachinery/pkg/api/apitesting" 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/apimachinery/pkg/apis/testapigroup" 25 | "k8s.io/apimachinery/pkg/runtime" 26 | ) 27 | 28 | func TestDecodeList(t *testing.T) { 29 | pl := List{ 30 | Items: []runtime.Object{ 31 | &testapigroup.Carp{ObjectMeta: metav1.ObjectMeta{Name: "1"}}, 32 | &runtime.Unknown{ 33 | TypeMeta: runtime.TypeMeta{Kind: "Carp", APIVersion: "v1"}, 34 | Raw: []byte(`{"kind":"Carp","apiVersion":"` + "v1" + `","metadata":{"name":"test"}}`), 35 | ContentType: runtime.ContentTypeJSON, 36 | }, 37 | }, 38 | } 39 | 40 | _, codecs := TestScheme() 41 | Codec := apitesting.TestCodec(codecs, testapigroup.SchemeGroupVersion) 42 | 43 | if errs := runtime.DecodeList(pl.Items, Codec); len(errs) != 0 { 44 | t.Fatalf("unexpected error %v", errs) 45 | } 46 | if pod, ok := pl.Items[1].(*testapigroup.Carp); !ok || pod.Name != "test" { 47 | t.Errorf("object not converted: %#v", pl.Items[1]) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /pkg/test/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package test 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/apis/testapigroup" 22 | "k8s.io/apimachinery/pkg/apis/testapigroup/v1" 23 | "k8s.io/apimachinery/pkg/runtime" 24 | "k8s.io/apimachinery/pkg/runtime/schema" 25 | apiserializer "k8s.io/apimachinery/pkg/runtime/serializer" 26 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 27 | ) 28 | 29 | // List and ListV1 should be kept in sync with k8s.io/kubernetes/pkg/api#List 30 | // and k8s.io/api/core/v1#List. 31 | // 32 | // +k8s:deepcopy-gen=true 33 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 34 | type List struct { 35 | metav1.TypeMeta 36 | metav1.ListMeta 37 | 38 | Items []runtime.Object 39 | } 40 | 41 | // +k8s:deepcopy-gen=true 42 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 43 | type ListV1 struct { 44 | metav1.TypeMeta `json:",inline"` 45 | metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` 46 | 47 | Items []runtime.RawExtension `json:"items" protobuf:"bytes,2,rep,name=items"` 48 | } 49 | 50 | func TestScheme() (*runtime.Scheme, apiserializer.CodecFactory) { 51 | internalGV := schema.GroupVersion{Group: "", Version: runtime.APIVersionInternal} 52 | externalGV := schema.GroupVersion{Group: "", Version: "v1"} 53 | scheme := runtime.NewScheme() 54 | 55 | scheme.AddKnownTypes(internalGV, 56 | &testapigroup.Carp{}, 57 | &testapigroup.CarpList{}, 58 | &List{}, 59 | ) 60 | scheme.AddKnownTypes(externalGV, 61 | &v1.Carp{}, 62 | &v1.CarpList{}, 63 | &List{}, 64 | ) 65 | utilruntime.Must(testapigroup.AddToScheme(scheme)) 66 | utilruntime.Must(v1.AddToScheme(scheme)) 67 | 68 | codecs := apiserializer.NewCodecFactory(scheme) 69 | return scheme, codecs 70 | } 71 | -------------------------------------------------------------------------------- /pkg/types/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package types implements various generic types used throughout kubernetes. 18 | package types 19 | -------------------------------------------------------------------------------- /pkg/types/namespacedname.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package types 18 | 19 | // NamespacedName comprises a resource name, with a mandatory namespace, 20 | // rendered as "/". Being a type captures intent and 21 | // helps make sure that UIDs, namespaced names and non-namespaced names 22 | // do not get conflated in code. For most use cases, namespace and name 23 | // will already have been format validated at the API entry point, so we 24 | // don't do that here. Where that's not the case (e.g. in testing), 25 | // consider using NamespacedNameOrDie() in testing.go in this package. 26 | 27 | type NamespacedName struct { 28 | Namespace string 29 | Name string 30 | } 31 | 32 | const ( 33 | Separator = '/' 34 | ) 35 | 36 | // String returns the general purpose string representation 37 | func (n NamespacedName) String() string { 38 | return n.Namespace + string(Separator) + n.Name 39 | } 40 | 41 | // MarshalLog emits a struct containing required key/value pair 42 | func (n NamespacedName) MarshalLog() interface{} { 43 | return struct { 44 | Name string `json:"name"` 45 | Namespace string `json:"namespace,omitempty"` 46 | }{ 47 | Name: n.Name, 48 | Namespace: n.Namespace, 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /pkg/types/nodename.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package types 18 | 19 | // NodeName is a type that holds a api.Node's Name identifier. 20 | // Being a type captures intent and helps make sure that the node name 21 | // is not confused with similar concepts (the hostname, the cloud provider id, 22 | // the cloud provider name etc) 23 | // 24 | // To clarify the various types: 25 | // 26 | // - Node.Name is the Name field of the Node in the API. This should be stored in a NodeName. 27 | // Unfortunately, because Name is part of ObjectMeta, we can't store it as a NodeName at the API level. 28 | // 29 | // - Hostname is the hostname of the local machine (from uname -n). 30 | // However, some components allow the user to pass in a --hostname-override flag, 31 | // which will override this in most places. In the absence of anything more meaningful, 32 | // kubelet will use Hostname as the Node.Name when it creates the Node. 33 | // 34 | // * The cloudproviders have the own names: GCE has InstanceName, AWS has InstanceId. 35 | // 36 | // For GCE, InstanceName is the Name of an Instance object in the GCE API. On GCE, Instance.Name becomes the 37 | // Hostname, and thus it makes sense also to use it as the Node.Name. But that is GCE specific, and it is up 38 | // to the cloudprovider how to do this mapping. 39 | // 40 | // For AWS, the InstanceID is not yet suitable for use as a Node.Name, so we actually use the 41 | // PrivateDnsName for the Node.Name. And this is _not_ always the same as the hostname: if 42 | // we are using a custom DHCP domain it won't be. 43 | type NodeName string 44 | -------------------------------------------------------------------------------- /pkg/types/patch.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package types 18 | 19 | // Similarly to above, these are constants to support HTTP PATCH utilized by 20 | // both the client and server that didn't make sense for a whole package to be 21 | // dedicated to. 22 | type PatchType string 23 | 24 | const ( 25 | JSONPatchType PatchType = "application/json-patch+json" 26 | MergePatchType PatchType = "application/merge-patch+json" 27 | StrategicMergePatchType PatchType = "application/strategic-merge-patch+json" 28 | ApplyPatchType PatchType = ApplyYAMLPatchType 29 | ApplyYAMLPatchType PatchType = "application/apply-patch+yaml" 30 | ApplyCBORPatchType PatchType = "application/apply-patch+cbor" 31 | ) 32 | -------------------------------------------------------------------------------- /pkg/types/uid.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package types 18 | 19 | // UID is a type that holds unique ID values, including UUIDs. Because we 20 | // don't ONLY use UUIDs, this is an alias to string. Being a type captures 21 | // intent and helps make sure that UIDs and names do not get conflated. 22 | type UID string 23 | -------------------------------------------------------------------------------- /pkg/util/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - apelisse 5 | -------------------------------------------------------------------------------- /pkg/util/dump/dump.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package dump 18 | 19 | import ( 20 | "github.com/davecgh/go-spew/spew" 21 | ) 22 | 23 | var prettyPrintConfig = &spew.ConfigState{ 24 | Indent: " ", 25 | DisableMethods: true, 26 | DisablePointerAddresses: true, 27 | DisableCapacities: true, 28 | } 29 | 30 | // The config MUST NOT be changed because that could change the result of a hash operation 31 | var prettyPrintConfigForHash = &spew.ConfigState{ 32 | Indent: " ", 33 | SortKeys: true, 34 | DisableMethods: true, 35 | SpewKeys: true, 36 | DisablePointerAddresses: true, 37 | DisableCapacities: true, 38 | } 39 | 40 | // Pretty wrap the spew.Sdump with Indent, and disabled methods like error() and String() 41 | // The output may change over time, so for guaranteed output please take more direct control 42 | func Pretty(a interface{}) string { 43 | return prettyPrintConfig.Sdump(a) 44 | } 45 | 46 | // ForHash keeps the original Spew.Sprintf format to ensure the same checksum 47 | func ForHash(a interface{}) string { 48 | return prettyPrintConfigForHash.Sprintf("%#v", a) 49 | } 50 | 51 | // OneLine outputs the object in one line 52 | func OneLine(a interface{}) string { 53 | return prettyPrintConfig.Sprintf("%#v", a) 54 | } 55 | -------------------------------------------------------------------------------- /pkg/util/errors/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package errors implements various utility functions and types around errors. 18 | package errors 19 | -------------------------------------------------------------------------------- /pkg/util/httpstream/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package httpstream adds multiplexed streaming support to HTTP requests and 18 | // responses via connection upgrades. 19 | package httpstream 20 | -------------------------------------------------------------------------------- /pkg/util/intstr/generated.proto: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | 18 | // This file was autogenerated by go-to-protobuf. Do not edit it manually! 19 | 20 | syntax = "proto2"; 21 | 22 | package k8s.io.apimachinery.pkg.util.intstr; 23 | 24 | // Package-wide variables from generator "generated". 25 | option go_package = "k8s.io/apimachinery/pkg/util/intstr"; 26 | 27 | // IntOrString is a type that can hold an int32 or a string. When used in 28 | // JSON or YAML marshalling and unmarshalling, it produces or consumes the 29 | // inner type. This allows you to have, for example, a JSON field that can 30 | // accept a name or number. 31 | // TODO: Rename to Int32OrString 32 | // 33 | // +protobuf=true 34 | // +protobuf.options.(gogoproto.goproto_stringer)=false 35 | // +k8s:openapi-gen=true 36 | message IntOrString { 37 | optional int64 type = 1; 38 | 39 | optional int32 intVal = 2; 40 | 41 | optional string strVal = 3; 42 | } 43 | 44 | -------------------------------------------------------------------------------- /pkg/util/intstr/instr_fuzz.go: -------------------------------------------------------------------------------- 1 | //go:build !notest 2 | // +build !notest 3 | 4 | /* 5 | Copyright 2020 The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | package intstr 21 | 22 | import ( 23 | "sigs.k8s.io/randfill" 24 | ) 25 | 26 | // RandFill satisfies randfill.NativeSelfFiller 27 | func (intstr *IntOrString) RandFill(c randfill.Continue) { 28 | if intstr == nil { 29 | return 30 | } 31 | if c.Bool() { 32 | intstr.Type = Int 33 | c.Fill(&intstr.IntVal) 34 | intstr.StrVal = "" 35 | } else { 36 | intstr.Type = String 37 | intstr.IntVal = 0 38 | c.Fill(&intstr.StrVal) 39 | } 40 | } 41 | 42 | // ensure IntOrString implements fuzz.Interface 43 | var _ randfill.NativeSelfFiller = &IntOrString{} 44 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/atmostevery.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import ( 20 | "sync" 21 | "time" 22 | ) 23 | 24 | // AtMostEvery will never run the method more than once every specified 25 | // duration. 26 | type AtMostEvery struct { 27 | delay time.Duration 28 | lastCall time.Time 29 | mutex sync.Mutex 30 | } 31 | 32 | // NewAtMostEvery creates a new AtMostEvery, that will run the method at 33 | // most every given duration. 34 | func NewAtMostEvery(delay time.Duration) *AtMostEvery { 35 | return &AtMostEvery{ 36 | delay: delay, 37 | } 38 | } 39 | 40 | // updateLastCall returns true if the lastCall time has been updated, 41 | // false if it was too early. 42 | func (s *AtMostEvery) updateLastCall() bool { 43 | s.mutex.Lock() 44 | defer s.mutex.Unlock() 45 | if time.Since(s.lastCall) < s.delay { 46 | return false 47 | } 48 | s.lastCall = time.Now() 49 | return true 50 | } 51 | 52 | // Do will run the method if enough time has passed, and return true. 53 | // Otherwise, it does nothing and returns false. 54 | func (s *AtMostEvery) Do(fn func()) bool { 55 | if !s.updateLastCall() { 56 | return false 57 | } 58 | fn() 59 | return true 60 | } 61 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/atmostevery_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal_test 18 | 19 | import ( 20 | "testing" 21 | "time" 22 | 23 | "k8s.io/apimachinery/pkg/util/managedfields/internal" 24 | ) 25 | 26 | func TestAtMostEvery(t *testing.T) { 27 | duration := time.Second 28 | delay := 179 * time.Millisecond 29 | atMostEvery := internal.NewAtMostEvery(delay) 30 | count := 0 31 | exit := time.NewTicker(duration) 32 | tick := time.NewTicker(2 * time.Millisecond) 33 | defer exit.Stop() 34 | defer tick.Stop() 35 | 36 | done := false 37 | for !done { 38 | select { 39 | case <-exit.C: 40 | done = true 41 | case <-tick.C: 42 | atMostEvery.Do(func() { 43 | count++ 44 | }) 45 | } 46 | } 47 | 48 | if expected := int(duration/delay) + 1; count > expected { 49 | t.Fatalf("Function called %d times, should have been called less than or equal to %d times", count, expected) 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/fieldmanager_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal_test 18 | 19 | import ( 20 | "encoding/json" 21 | "os" 22 | "path/filepath" 23 | "strings" 24 | 25 | "k8s.io/apimachinery/pkg/util/managedfields/internal" 26 | "k8s.io/kube-openapi/pkg/validation/spec" 27 | ) 28 | 29 | var fakeTypeConverter = func() internal.TypeConverter { 30 | data, err := os.ReadFile(filepath.Join( 31 | strings.Repeat(".."+string(filepath.Separator), 8), 32 | "api", "openapi-spec", "swagger.json")) 33 | if err != nil { 34 | panic(err) 35 | } 36 | convertedDefs := map[string]*spec.Schema{} 37 | spec := spec.Swagger{} 38 | if err := json.Unmarshal(data, &spec); err != nil { 39 | panic(err) 40 | } 41 | 42 | for k, v := range spec.Definitions { 43 | vCopy := v 44 | convertedDefs[k] = &vCopy 45 | } 46 | 47 | typeConverter, err := internal.NewTypeConverter(convertedDefs, false) 48 | if err != nil { 49 | panic(err) 50 | } 51 | return typeConverter 52 | }() 53 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/fields.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import ( 20 | "bytes" 21 | 22 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | 24 | "sigs.k8s.io/structured-merge-diff/v4/fieldpath" 25 | ) 26 | 27 | // EmptyFields represents a set with no paths 28 | // It looks like metav1.Fields{Raw: []byte("{}")} 29 | var EmptyFields = func() metav1.FieldsV1 { 30 | f, err := SetToFields(*fieldpath.NewSet()) 31 | if err != nil { 32 | panic("should never happen") 33 | } 34 | return f 35 | }() 36 | 37 | // FieldsToSet creates a set paths from an input trie of fields 38 | func FieldsToSet(f metav1.FieldsV1) (s fieldpath.Set, err error) { 39 | err = s.FromJSON(bytes.NewReader(f.Raw)) 40 | return s, err 41 | } 42 | 43 | // SetToFields creates a trie of fields from an input set of paths 44 | func SetToFields(s fieldpath.Set) (f metav1.FieldsV1, err error) { 45 | f.Raw, err = s.ToJSON() 46 | return f, err 47 | } 48 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/lastapplied.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/api/meta" 23 | apimachineryvalidation "k8s.io/apimachinery/pkg/api/validation" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | ) 26 | 27 | // LastAppliedConfigAnnotation is the annotation used to store the previous 28 | // configuration of a resource for use in a three way diff by UpdateApplyAnnotation. 29 | // 30 | // This is a copy of the corev1 annotation since we don't want to depend on the whole package. 31 | const LastAppliedConfigAnnotation = "kubectl.kubernetes.io/last-applied-configuration" 32 | 33 | // SetLastApplied sets the last-applied annotation the given value in 34 | // the object. 35 | func SetLastApplied(obj runtime.Object, value string) error { 36 | accessor, err := meta.Accessor(obj) 37 | if err != nil { 38 | panic(fmt.Sprintf("couldn't get accessor: %v", err)) 39 | } 40 | var annotations = accessor.GetAnnotations() 41 | if annotations == nil { 42 | annotations = map[string]string{} 43 | } 44 | annotations[LastAppliedConfigAnnotation] = value 45 | if err := apimachineryvalidation.ValidateAnnotationsSize(annotations); err != nil { 46 | delete(annotations, LastAppliedConfigAnnotation) 47 | } 48 | accessor.SetAnnotations(annotations) 49 | return nil 50 | } 51 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/manager.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import ( 20 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "sigs.k8s.io/structured-merge-diff/v4/fieldpath" 23 | ) 24 | 25 | // Managed groups a fieldpath.ManagedFields together with the timestamps associated with each operation. 26 | type Managed interface { 27 | // Fields gets the fieldpath.ManagedFields. 28 | Fields() fieldpath.ManagedFields 29 | 30 | // Times gets the timestamps associated with each operation. 31 | Times() map[string]*metav1.Time 32 | } 33 | 34 | // Manager updates the managed fields and merges applied configurations. 35 | type Manager interface { 36 | // Update is used when the object has already been merged (non-apply 37 | // use-case), and simply updates the managed fields in the output 38 | // object. 39 | // * `liveObj` is not mutated by this function 40 | // * `newObj` may be mutated by this function 41 | // Returns the new object with managedFields removed, and the object's new 42 | // proposed managedFields separately. 43 | Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) 44 | 45 | // Apply is used when server-side apply is called, as it merges the 46 | // object and updates the managed fields. 47 | // * `liveObj` is not mutated by this function 48 | // * `newObj` may be mutated by this function 49 | // Returns the new object with managedFields removed, and the object's new 50 | // proposed managedFields separately. 51 | Apply(liveObj, appliedObj runtime.Object, managed Managed, fieldManager string, force bool) (runtime.Object, Managed, error) 52 | } 53 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/pathelement_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import "testing" 20 | 21 | func TestPathElementRoundTrip(t *testing.T) { 22 | tests := []string{ 23 | `i:0`, 24 | `i:1234`, 25 | `f:`, 26 | `f:spec`, 27 | `f:more-complicated-string`, 28 | `k:{"name":"my-container"}`, 29 | `k:{"port":"8080","protocol":"TCP"}`, 30 | `k:{"optionalField":null}`, 31 | `k:{"jsonField":{"A":1,"B":null,"C":"D","E":{"F":"G"}}}`, 32 | `k:{"listField":["1","2","3"]}`, 33 | `v:null`, 34 | `v:"some-string"`, 35 | `v:1234`, 36 | `v:{"some":"json"}`, 37 | } 38 | 39 | for _, test := range tests { 40 | t.Run(test, func(t *testing.T) { 41 | pe, err := NewPathElement(test) 42 | if err != nil { 43 | t.Fatalf("Failed to create path element: %v", err) 44 | } 45 | output, err := PathElementString(pe) 46 | if err != nil { 47 | t.Fatalf("Failed to create string from path element: %v", err) 48 | } 49 | if test != output { 50 | t.Fatalf("Expected round-trip:\ninput: %v\noutput: %v", test, output) 51 | } 52 | }) 53 | } 54 | } 55 | 56 | func TestPathElementIgnoreUnknown(t *testing.T) { 57 | _, err := NewPathElement("r:Hello") 58 | if err != nil { 59 | t.Fatalf("Unknown qualifiers should be ignored") 60 | } 61 | } 62 | 63 | func TestNewPathElementError(t *testing.T) { 64 | tests := []string{ 65 | ``, 66 | `no-colon`, 67 | `i:index is not a number`, 68 | `i:1.23`, 69 | `i:`, 70 | `v:invalid json`, 71 | `v:`, 72 | `k:invalid json`, 73 | `k:{"name":invalid}`, 74 | } 75 | 76 | for _, test := range tests { 77 | t.Run(test, func(t *testing.T) { 78 | _, err := NewPathElement(test) 79 | if err == nil { 80 | t.Fatalf("Expected error, no error found") 81 | } 82 | }) 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/runtimetypeconverter.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import ( 20 | "fmt" 21 | "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "sigs.k8s.io/structured-merge-diff/v4/typed" 24 | ) 25 | 26 | type schemeTypeConverter struct { 27 | scheme *runtime.Scheme 28 | parser *typed.Parser 29 | } 30 | 31 | var _ TypeConverter = &schemeTypeConverter{} 32 | 33 | // NewSchemeTypeConverter creates a TypeConverter that uses the provided scheme to 34 | // convert between runtime.Objects and TypedValues. 35 | func NewSchemeTypeConverter(scheme *runtime.Scheme, parser *typed.Parser) TypeConverter { 36 | return &schemeTypeConverter{scheme: scheme, parser: parser} 37 | } 38 | 39 | func (tc schemeTypeConverter) ObjectToTyped(obj runtime.Object, opts ...typed.ValidationOptions) (*typed.TypedValue, error) { 40 | gvk := obj.GetObjectKind().GroupVersionKind() 41 | name, err := tc.scheme.ToOpenAPIDefinitionName(gvk) 42 | if err != nil { 43 | return nil, err 44 | } 45 | t := tc.parser.Type(name) 46 | switch o := obj.(type) { 47 | case *unstructured.Unstructured: 48 | return t.FromUnstructured(o.UnstructuredContent(), opts...) 49 | default: 50 | return t.FromStructured(obj, opts...) 51 | } 52 | } 53 | 54 | func (tc schemeTypeConverter) TypedToObject(value *typed.TypedValue) (runtime.Object, error) { 55 | vu := value.AsValue().Unstructured() 56 | switch o := vu.(type) { 57 | case map[string]interface{}: 58 | return &unstructured.Unstructured{Object: o}, nil 59 | default: 60 | return nil, fmt.Errorf("failed to convert value to unstructured for type %T", vu) 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /pkg/util/managedfields/internal/versioncheck.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package internal 18 | 19 | import ( 20 | "fmt" 21 | 22 | "k8s.io/apimachinery/pkg/api/errors" 23 | "k8s.io/apimachinery/pkg/runtime" 24 | "k8s.io/apimachinery/pkg/runtime/schema" 25 | ) 26 | 27 | type versionCheckManager struct { 28 | fieldManager Manager 29 | gvk schema.GroupVersionKind 30 | } 31 | 32 | var _ Manager = &versionCheckManager{} 33 | 34 | // NewVersionCheckManager creates a manager that makes sure that the 35 | // applied object is in the proper version. 36 | func NewVersionCheckManager(fieldManager Manager, gvk schema.GroupVersionKind) Manager { 37 | return &versionCheckManager{fieldManager: fieldManager, gvk: gvk} 38 | } 39 | 40 | // Update implements Manager. 41 | func (f *versionCheckManager) Update(liveObj, newObj runtime.Object, managed Managed, manager string) (runtime.Object, Managed, error) { 42 | // Nothing to do for updates, this is checked in many other places. 43 | return f.fieldManager.Update(liveObj, newObj, managed, manager) 44 | } 45 | 46 | // Apply implements Manager. 47 | func (f *versionCheckManager) Apply(liveObj, appliedObj runtime.Object, managed Managed, fieldManager string, force bool) (runtime.Object, Managed, error) { 48 | if gvk := appliedObj.GetObjectKind().GroupVersionKind(); gvk != f.gvk { 49 | return nil, nil, errors.NewBadRequest(fmt.Sprintf("invalid object type: %v", gvk)) 50 | } 51 | return f.fieldManager.Apply(liveObj, appliedObj, managed, fieldManager, force) 52 | } 53 | -------------------------------------------------------------------------------- /pkg/util/mergepatch/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - pwittrock 5 | reviewers: 6 | - apelisse 7 | -------------------------------------------------------------------------------- /pkg/util/naming/from_stack_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package naming 18 | 19 | import ( 20 | "strings" 21 | "testing" 22 | ) 23 | 24 | func TestGetNameFromCallsite(t *testing.T) { 25 | tests := []struct { 26 | name string 27 | ignoredPackages []string 28 | expected string 29 | }{ 30 | { 31 | name: "simple", 32 | expected: "k8s.io/apimachinery/pkg/util/naming/from_stack_test.go:", 33 | }, 34 | { 35 | name: "ignore-package", 36 | ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming"}, 37 | expected: "testing/testing.go:", 38 | }, 39 | { 40 | name: "ignore-file", 41 | ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming/from_stack_test.go"}, 42 | expected: "testing/testing.go:", 43 | }, 44 | { 45 | name: "ignore-multiple", 46 | ignoredPackages: []string{"k8s.io/apimachinery/pkg/util/naming/from_stack_test.go", "testing/testing.go"}, 47 | expected: "????", 48 | }, 49 | } 50 | 51 | for _, tc := range tests { 52 | t.Run(tc.name, func(t *testing.T) { 53 | actual := GetNameFromCallsite(tc.ignoredPackages...) 54 | if !strings.HasPrefix(actual, tc.expected) { 55 | t.Fatalf("expected string with prefix %q, got %q", tc.expected, actual) 56 | } 57 | }) 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /pkg/util/net/port_range_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2015 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package net 18 | 19 | import ( 20 | "testing" 21 | 22 | flag "github.com/spf13/pflag" 23 | ) 24 | 25 | func TestPortRange(t *testing.T) { 26 | testCases := []struct { 27 | input string 28 | success bool 29 | expected string 30 | included int 31 | excluded int 32 | }{ 33 | {"100-200", true, "100-200", 200, 201}, 34 | {" 100-200 ", true, "100-200", 200, 201}, 35 | {"0-0", true, "0-0", 0, 1}, 36 | {"", true, "", -1, 0}, 37 | {"100", true, "100-100", 100, 101}, 38 | {"100 - 200", false, "", -1, -1}, 39 | {"-100", false, "", -1, -1}, 40 | {"100-", false, "", -1, -1}, 41 | {"200-100", false, "", -1, -1}, 42 | {"60000-70000", false, "", -1, -1}, 43 | {"70000-80000", false, "", -1, -1}, 44 | {"70000+80000", false, "", -1, -1}, 45 | {"1+0", true, "1-1", 1, 2}, 46 | {"0+0", true, "0-0", 0, 1}, 47 | {"1+-1", false, "", -1, -1}, 48 | {"1-+1", false, "", -1, -1}, 49 | {"100+200", true, "100-300", 300, 301}, 50 | {"1+65535", false, "", -1, -1}, 51 | {"0+65535", true, "0-65535", 65535, 65536}, 52 | } 53 | 54 | for i := range testCases { 55 | tc := &testCases[i] 56 | pr := &PortRange{} 57 | var f flag.Value = pr 58 | err := f.Set(tc.input) 59 | if err != nil && tc.success { 60 | t.Errorf("expected success, got %q", err) 61 | continue 62 | } else if err == nil && !tc.success { 63 | t.Errorf("expected failure %#v", testCases[i]) 64 | continue 65 | } else if tc.success { 66 | if f.String() != tc.expected { 67 | t.Errorf("expected %q, got %q", tc.expected, f.String()) 68 | } 69 | if tc.included >= 0 && !pr.Contains(tc.included) { 70 | t.Errorf("expected %q to include %d", f.String(), tc.included) 71 | } 72 | if tc.excluded >= 0 && pr.Contains(tc.excluded) { 73 | t.Errorf("expected %q to exclude %d", f.String(), tc.excluded) 74 | } 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /pkg/util/net/testing/socket.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2025 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package nettesting contains utilities for testing networking functionality. 18 | // Don't use these utilities in production code. They have not been security 19 | // reviewed. 20 | package nettesting 21 | 22 | import ( 23 | "os" 24 | goruntime "runtime" 25 | "testing" 26 | ) 27 | 28 | // MakeSocketNameForTest returns a socket name to use for the duration of a test. 29 | // On Operating systems that support abstract sockets, it the name is prefixed with `@` to make it an abstract socket. 30 | // On Operating systems that do not support abstract sockets, the name is treated as a filename and a cleanup hook is 31 | // registered to delete the socket at the end of the test. 32 | func MakeSocketNameForTest(t testing.TB, name string) string { 33 | var sockname = name 34 | switch goruntime.GOOS { 35 | case "darwin", "windows": 36 | t.Cleanup(func() { _ = os.Remove(sockname) }) 37 | default: 38 | sockname = "@" + name 39 | } 40 | return sockname 41 | } 42 | -------------------------------------------------------------------------------- /pkg/util/net/util.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package net 18 | 19 | import ( 20 | "errors" 21 | "net" 22 | "reflect" 23 | "strings" 24 | "syscall" 25 | ) 26 | 27 | // IPNetEqual checks if the two input IPNets are representing the same subnet. 28 | // For example, 29 | // 30 | // 10.0.0.1/24 and 10.0.0.0/24 are the same subnet. 31 | // 10.0.0.1/24 and 10.0.0.0/25 are not the same subnet. 32 | func IPNetEqual(ipnet1, ipnet2 *net.IPNet) bool { 33 | if ipnet1 == nil || ipnet2 == nil { 34 | return false 35 | } 36 | if reflect.DeepEqual(ipnet1.Mask, ipnet2.Mask) && ipnet1.Contains(ipnet2.IP) && ipnet2.Contains(ipnet1.IP) { 37 | return true 38 | } 39 | return false 40 | } 41 | 42 | // Returns if the given err is "connection reset by peer" error. 43 | func IsConnectionReset(err error) bool { 44 | var errno syscall.Errno 45 | if errors.As(err, &errno) { 46 | return errno == syscall.ECONNRESET 47 | } 48 | return false 49 | } 50 | 51 | // Returns if the given err is "http2: client connection lost" error. 52 | func IsHTTP2ConnectionLost(err error) bool { 53 | return err != nil && strings.Contains(err.Error(), "http2: client connection lost") 54 | } 55 | 56 | // Returns if the given err is "connection refused" error 57 | func IsConnectionRefused(err error) bool { 58 | var errno syscall.Errno 59 | if errors.As(err, &errno) { 60 | return errno == syscall.ECONNREFUSED 61 | } 62 | return false 63 | } 64 | -------------------------------------------------------------------------------- /pkg/util/portforward/constants.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package portforward 18 | 19 | const ( 20 | PortForwardV1Name = "portforward.k8s.io" 21 | WebsocketsSPDYTunnelingPrefix = "SPDY/3.1+" 22 | KubernetesSuffix = ".k8s.io" 23 | WebsocketsSPDYTunnelingPortForwardV1 = WebsocketsSPDYTunnelingPrefix + PortForwardV1Name 24 | ) 25 | -------------------------------------------------------------------------------- /pkg/util/proxy/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package proxy provides transport and upgrade support for proxies. 18 | package proxy 19 | -------------------------------------------------------------------------------- /pkg/util/runtime/runtime_stack_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package runtime 18 | 19 | import ( 20 | "bytes" 21 | "context" 22 | "errors" 23 | "flag" 24 | "fmt" 25 | "regexp" 26 | 27 | "k8s.io/klog/v2" 28 | ) 29 | 30 | //nolint:logcheck // Several functions are normally not okay in a package. 31 | func ExampleHandleErrorWithContext() { 32 | state := klog.CaptureState() 33 | defer state.Restore() 34 | var fs flag.FlagSet 35 | klog.InitFlags(&fs) 36 | for flag, value := range map[string]string{ 37 | "one_output": "true", 38 | "logtostderr": "false", 39 | } { 40 | if err := fs.Set(flag, value); err != nil { 41 | fmt.Printf("Unexpected error configuring klog: %v", err) 42 | return 43 | } 44 | } 45 | var buffer bytes.Buffer 46 | klog.SetOutput(&buffer) 47 | 48 | logger := klog.Background() 49 | logger = klog.LoggerWithValues(logger, "request", 42) 50 | ctx := klog.NewContext(context.Background(), logger) 51 | 52 | // The line number of the next call must be at line 60. Here are some 53 | // blank lines that can be removed to keep the line unchanged. 54 | // 55 | // 56 | // 57 | // 58 | // 59 | // 60 | HandleErrorWithContext(ctx, errors.New("fake error"), "test") 61 | 62 | klog.Flush() 63 | // Strip varying header. Code location should be constant and something 64 | // that needs to be tested. 65 | output := buffer.String() 66 | output = regexp.MustCompile(`^.* ([^[:space:]]*.go:[[:digit:]]*)\] `).ReplaceAllString(output, `xxx $1] `) 67 | fmt.Print(output) 68 | 69 | // Output: 70 | // xxx runtime_stack_test.go:60] "test" err="fake error" logger="UnhandledError" request=42 71 | } 72 | -------------------------------------------------------------------------------- /pkg/util/sets/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package sets has generic set and specified sets. Generic set will 18 | // replace specified ones over time. And specific ones are deprecated. 19 | package sets 20 | -------------------------------------------------------------------------------- /pkg/util/sets/empty.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package sets 18 | 19 | // Empty is public since it is used by some internal API objects for conversions between external 20 | // string arrays and internal sets, and conversion logic requires public types today. 21 | type Empty struct{} 22 | -------------------------------------------------------------------------------- /pkg/util/strategicpatch/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - apelisse 5 | - pwittrock 6 | reviewers: 7 | - apelisse 8 | emeritus_approvers: 9 | - mengqiy 10 | -------------------------------------------------------------------------------- /pkg/util/strategicpatch/errors.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package strategicpatch 18 | 19 | import ( 20 | "fmt" 21 | ) 22 | 23 | type LookupPatchMetaError struct { 24 | Path string 25 | Err error 26 | } 27 | 28 | func (e LookupPatchMetaError) Error() string { 29 | return fmt.Sprintf("LookupPatchMetaError(%s): %v", e.Path, e.Err) 30 | } 31 | 32 | type FieldNotFoundError struct { 33 | Path string 34 | Field string 35 | } 36 | 37 | func (e FieldNotFoundError) Error() string { 38 | return fmt.Sprintf("unable to find api field %q in %s", e.Field, e.Path) 39 | } 40 | 41 | type InvalidTypeError struct { 42 | Path string 43 | Expected string 44 | Actual string 45 | } 46 | 47 | func (e InvalidTypeError) Error() string { 48 | return fmt.Sprintf("invalid type for %s: got %q, expected %q", e.Path, e.Actual, e.Expected) 49 | } 50 | -------------------------------------------------------------------------------- /pkg/util/strategicpatch/testdata/swagger-precision-item-v3.json: -------------------------------------------------------------------------------- 1 | { 2 | "openapi": "3.0", 3 | "info": { 4 | "title": "StrategicMergePatchTestingPrecisionItem", 5 | "version": "v1.9.0" 6 | }, 7 | "paths": {}, 8 | "components": { 9 | "schemas": { 10 | "precisionItem": { 11 | "description": "PrecisionItem is type definition for testing strategic merge.", 12 | "required": [], 13 | "properties": { 14 | "name": { 15 | "description": "Name field.", 16 | "type": "string" 17 | }, 18 | "int32": { 19 | "description": "Int32 field.", 20 | "type": "integer", 21 | "format": "int32" 22 | }, 23 | "int64": { 24 | "description": "Int64 field.", 25 | "type": "integer", 26 | "format": "int64" 27 | }, 28 | "float32": { 29 | "description": "Float32 field.", 30 | "type": "number", 31 | "format": "float32" 32 | }, 33 | "float64": { 34 | "description": "Float64 field.", 35 | "type": "number", 36 | "format": "float64" 37 | } 38 | }, 39 | "x-kubernetes-group-version-kind": [ 40 | { 41 | "group": "fake-group", 42 | "kind": "precisionItem", 43 | "version": "some-version" 44 | } 45 | ] 46 | } 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /pkg/util/strategicpatch/testdata/swagger-precision-item.json: -------------------------------------------------------------------------------- 1 | { 2 | "swagger": "2.0", 3 | "info": { 4 | "title": "StrategicMergePatchTestingPrecisionItem", 5 | "version": "v1.9.0" 6 | }, 7 | "paths": {}, 8 | "definitions": { 9 | "precisionItem": { 10 | "description": "PrecisionItem is type definition for testing strategic merge.", 11 | "required": [], 12 | "properties": { 13 | "name": { 14 | "description": "Name field.", 15 | "type": "string" 16 | }, 17 | "int32": { 18 | "description": "Int32 field.", 19 | "type": "integer", 20 | "format": "int32" 21 | }, 22 | "int64": { 23 | "description": "Int64 field.", 24 | "type": "integer", 25 | "format": "int64" 26 | }, 27 | "float32": { 28 | "description": "Float32 field.", 29 | "type": "number", 30 | "format": "float32" 31 | }, 32 | "float64": { 33 | "description": "Float64 field.", 34 | "type": "number", 35 | "format": "float64" 36 | } 37 | }, 38 | "x-kubernetes-group-version-kind": [ 39 | { 40 | "group": "fake-group", 41 | "kind": "precisionItem", 42 | "version": "some-version" 43 | } 44 | ] 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /pkg/util/strategicpatch/testing/openapi.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package testing 18 | 19 | import ( 20 | "os" 21 | "sync" 22 | 23 | openapi_v2 "github.com/google/gnostic-models/openapiv2" 24 | openapi "k8s.io/kube-openapi/pkg/util/proto" 25 | ) 26 | 27 | // Fake opens and returns a openapi swagger from a file Path. It will 28 | // parse only once and then return the same copy everytime. 29 | type Fake struct { 30 | Path string 31 | 32 | once sync.Once 33 | document *openapi_v2.Document 34 | err error 35 | } 36 | 37 | // OpenAPISchema returns the openapi document and a potential error. 38 | func (f *Fake) OpenAPISchema() (*openapi_v2.Document, error) { 39 | f.once.Do(func() { 40 | _, err := os.Stat(f.Path) 41 | if err != nil { 42 | f.err = err 43 | return 44 | } 45 | spec, err := os.ReadFile(f.Path) 46 | if err != nil { 47 | f.err = err 48 | return 49 | } 50 | f.document, f.err = openapi_v2.ParseDocument(spec) 51 | }) 52 | return f.document, f.err 53 | } 54 | 55 | func getSchema(f *Fake, model string) (openapi.Schema, error) { 56 | s, err := f.OpenAPISchema() 57 | if err != nil { 58 | return nil, err 59 | } 60 | m, err := openapi.NewOpenAPIData(s) 61 | if err != nil { 62 | return nil, err 63 | } 64 | return m.LookupModel(model), nil 65 | } 66 | 67 | // GetSchemaOrDie returns the openapi schema. 68 | func GetSchemaOrDie(f *Fake, model string) openapi.Schema { 69 | s, err := getSchema(f, model) 70 | if err != nil { 71 | panic(err) 72 | } 73 | return s 74 | } 75 | -------------------------------------------------------------------------------- /pkg/util/strategicpatch/testing/openapi3.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package testing 18 | 19 | import ( 20 | "os" 21 | "sync" 22 | 23 | "k8s.io/kube-openapi/pkg/spec3" 24 | ) 25 | 26 | type OpenAPIV3Getter struct { 27 | Path string 28 | once sync.Once 29 | bytes []byte 30 | openapiv3 spec3.OpenAPI 31 | } 32 | 33 | func (f *OpenAPIV3Getter) SchemaBytesOrDie() []byte { 34 | f.once.Do(func() { 35 | _, err := os.Stat(f.Path) 36 | if err != nil { 37 | panic(err) 38 | } 39 | spec, err := os.ReadFile(f.Path) 40 | if err != nil { 41 | panic(err) 42 | } 43 | f.bytes = spec 44 | }) 45 | return f.bytes 46 | } 47 | 48 | func (f *OpenAPIV3Getter) SchemaOrDie() *spec3.OpenAPI { 49 | f.once.Do(func() { 50 | _, err := os.Stat(f.Path) 51 | if err != nil { 52 | panic(err) 53 | } 54 | spec, err := os.ReadFile(f.Path) 55 | if err != nil { 56 | panic(err) 57 | } 58 | 59 | err = f.openapiv3.UnmarshalJSON(spec) 60 | if err != nil { 61 | panic(err) 62 | } 63 | }) 64 | return &f.openapiv3 65 | } 66 | -------------------------------------------------------------------------------- /pkg/util/uuid/uuid.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package uuid 18 | 19 | import ( 20 | "github.com/google/uuid" 21 | 22 | "k8s.io/apimachinery/pkg/types" 23 | ) 24 | 25 | func NewUUID() types.UID { 26 | return types.UID(uuid.New().String()) 27 | } 28 | -------------------------------------------------------------------------------- /pkg/util/validation/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | # Disable inheritance as this is an api owners file 4 | options: 5 | no_parent_owners: true 6 | approvers: 7 | - api-approvers 8 | reviewers: 9 | - api-reviewers 10 | labels: 11 | - kind/api-change 12 | -------------------------------------------------------------------------------- /pkg/util/version/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2016 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package version provides utilities for version number comparisons 18 | package version 19 | -------------------------------------------------------------------------------- /pkg/util/wait/delay.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2023 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package wait 18 | 19 | import ( 20 | "context" 21 | "sync" 22 | "time" 23 | 24 | "k8s.io/utils/clock" 25 | ) 26 | 27 | // DelayFunc returns the next time interval to wait. 28 | type DelayFunc func() time.Duration 29 | 30 | // Timer takes an arbitrary delay function and returns a timer that can handle arbitrary interval changes. 31 | // Use Backoff{...}.Timer() for simple delays and more efficient timers. 32 | func (fn DelayFunc) Timer(c clock.Clock) Timer { 33 | return &variableTimer{fn: fn, new: c.NewTimer} 34 | } 35 | 36 | // Until takes an arbitrary delay function and runs until cancelled or the condition indicates exit. This 37 | // offers all of the functionality of the methods in this package. 38 | func (fn DelayFunc) Until(ctx context.Context, immediate, sliding bool, condition ConditionWithContextFunc) error { 39 | return loopConditionUntilContext(ctx, &variableTimer{fn: fn, new: internalClock.NewTimer}, immediate, sliding, condition) 40 | } 41 | 42 | // Concurrent returns a version of this DelayFunc that is safe for use by multiple goroutines that 43 | // wish to share a single delay timer. 44 | func (fn DelayFunc) Concurrent() DelayFunc { 45 | var lock sync.Mutex 46 | return func() time.Duration { 47 | lock.Lock() 48 | defer lock.Unlock() 49 | return fn() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /pkg/util/wait/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package wait provides tools for polling or listening for changes 18 | // to a condition. 19 | package wait 20 | -------------------------------------------------------------------------------- /pkg/util/waitgroup/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package waitgroup implements SafeWaitGroup wrap of sync.WaitGroup. 18 | // Add with positive delta when waiting will fail, to prevent sync.WaitGroup race issue. 19 | package waitgroup 20 | -------------------------------------------------------------------------------- /pkg/util/waitgroup/waitgroup.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package waitgroup 18 | 19 | import ( 20 | "fmt" 21 | "sync" 22 | ) 23 | 24 | // SafeWaitGroup must not be copied after first use. 25 | type SafeWaitGroup struct { 26 | wg sync.WaitGroup 27 | mu sync.RWMutex 28 | // wait indicate whether Wait is called, if true, 29 | // then any Add with positive delta will return error. 30 | wait bool 31 | } 32 | 33 | // Add adds delta, which may be negative, similar to sync.WaitGroup. 34 | // If Add with a positive delta happens after Wait, it will return error, 35 | // which prevent unsafe Add. 36 | func (wg *SafeWaitGroup) Add(delta int) error { 37 | wg.mu.RLock() 38 | defer wg.mu.RUnlock() 39 | if wg.wait && delta > 0 { 40 | return fmt.Errorf("add with positive delta after Wait is forbidden") 41 | } 42 | wg.wg.Add(delta) 43 | return nil 44 | } 45 | 46 | // Done decrements the WaitGroup counter. 47 | func (wg *SafeWaitGroup) Done() { 48 | wg.wg.Done() 49 | } 50 | 51 | // Wait blocks until the WaitGroup counter is zero. 52 | func (wg *SafeWaitGroup) Wait() { 53 | wg.mu.Lock() 54 | wg.wait = true 55 | wg.mu.Unlock() 56 | wg.wg.Wait() 57 | } 58 | -------------------------------------------------------------------------------- /pkg/util/waitgroup/waitgroup_test.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package waitgroup test cases reference golang sync.WaitGroup https://golang.org/src/sync/waitgroup_test.go. 18 | package waitgroup 19 | 20 | import ( 21 | "testing" 22 | ) 23 | 24 | func TestWaitGroup(t *testing.T) { 25 | wg1 := &SafeWaitGroup{} 26 | wg2 := &SafeWaitGroup{} 27 | n := 16 28 | wg1.Add(n) 29 | wg2.Add(n) 30 | exited := make(chan bool, n) 31 | for i := 0; i != n; i++ { 32 | go func(i int) { 33 | wg1.Done() 34 | wg2.Wait() 35 | exited <- true 36 | }(i) 37 | } 38 | wg1.Wait() 39 | for i := 0; i != n; i++ { 40 | select { 41 | case <-exited: 42 | t.Fatal("SafeWaitGroup released group too soon") 43 | default: 44 | } 45 | wg2.Done() 46 | } 47 | for i := 0; i != n; i++ { 48 | <-exited // Will block if barrier fails to unlock someone. 49 | } 50 | } 51 | 52 | func TestWaitGroupAddFail(t *testing.T) { 53 | wg := &SafeWaitGroup{} 54 | wg.Add(1) 55 | wg.Done() 56 | wg.Wait() 57 | if err := wg.Add(1); err == nil { 58 | t.Errorf("Should return error when add positive after Wait") 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pkg/version/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // +k8s:openapi-gen=true 18 | 19 | // Package version supplies the type for version information. 20 | package version 21 | -------------------------------------------------------------------------------- /pkg/version/types.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | package version 18 | 19 | // Info contains versioning information. 20 | // TODO: Add []string of api versions supported? It's still unclear 21 | // how we'll want to distribute that information. 22 | type Info struct { 23 | // Major is the major version of the binary version 24 | Major string `json:"major"` 25 | // Minor is the minor version of the binary version 26 | Minor string `json:"minor"` 27 | // EmulationMajor is the major version of the emulation version 28 | EmulationMajor string `json:"emulationMajor,omitempty"` 29 | // EmulationMinor is the minor version of the emulation version 30 | EmulationMinor string `json:"emulationMinor,omitempty"` 31 | // MinCompatibilityMajor is the major version of the minimum compatibility version 32 | MinCompatibilityMajor string `json:"minCompatibilityMajor,omitempty"` 33 | // MinCompatibilityMinor is the minor version of the minimum compatibility version 34 | MinCompatibilityMinor string `json:"minCompatibilityMinor,omitempty"` 35 | GitVersion string `json:"gitVersion"` 36 | GitCommit string `json:"gitCommit"` 37 | GitTreeState string `json:"gitTreeState"` 38 | BuildDate string `json:"buildDate"` 39 | GoVersion string `json:"goVersion"` 40 | Compiler string `json:"compiler"` 41 | Platform string `json:"platform"` 42 | } 43 | 44 | // String returns info as a human-friendly version string. 45 | func (info Info) String() string { 46 | return info.GitVersion 47 | } 48 | -------------------------------------------------------------------------------- /pkg/watch/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2014 The Kubernetes Authors. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | */ 16 | 17 | // Package watch contains a generic watchable interface, and a fake for 18 | // testing code that uses the watch interface. 19 | package watch 20 | -------------------------------------------------------------------------------- /pkg/watch/zz_generated.deepcopy.go: -------------------------------------------------------------------------------- 1 | //go:build !ignore_autogenerated 2 | // +build !ignore_autogenerated 3 | 4 | /* 5 | Copyright The Kubernetes Authors. 6 | 7 | Licensed under the Apache License, Version 2.0 (the "License"); 8 | you may not use this file except in compliance with the License. 9 | You may obtain a copy of the License at 10 | 11 | http://www.apache.org/licenses/LICENSE-2.0 12 | 13 | Unless required by applicable law or agreed to in writing, software 14 | distributed under the License is distributed on an "AS IS" BASIS, 15 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 | See the License for the specific language governing permissions and 17 | limitations under the License. 18 | */ 19 | 20 | // Code generated by deepcopy-gen. DO NOT EDIT. 21 | 22 | package watch 23 | 24 | // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. 25 | func (in *Event) DeepCopyInto(out *Event) { 26 | *out = *in 27 | if in.Object != nil { 28 | out.Object = in.Object.DeepCopyObject() 29 | } 30 | return 31 | } 32 | 33 | // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Event. 34 | func (in *Event) DeepCopy() *Event { 35 | if in == nil { 36 | return nil 37 | } 38 | out := new(Event) 39 | in.DeepCopyInto(out) 40 | return out 41 | } 42 | -------------------------------------------------------------------------------- /third_party/forked/golang/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /third_party/forked/golang/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /third_party/forked/golang/json/OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | approvers: 4 | - pwittrock 5 | reviewers: 6 | - apelisse 7 | -------------------------------------------------------------------------------- /third_party/forked/golang/json/fields_test.go: -------------------------------------------------------------------------------- 1 | package json 2 | 3 | import ( 4 | "reflect" 5 | "testing" 6 | ) 7 | 8 | func TestLookupPtrToStruct(t *testing.T) { 9 | type Elem struct { 10 | Key string 11 | Value string 12 | } 13 | type Outer struct { 14 | Inner []Elem `json:"inner" patchStrategy:"merge" patchMergeKey:"key"` 15 | } 16 | outer := &Outer{} 17 | elemType, patchStrategies, patchMergeKey, err := LookupPatchMetadataForStruct(reflect.TypeOf(outer), "inner") 18 | if err != nil { 19 | t.Fatal(err) 20 | } 21 | if elemType != reflect.TypeOf([]Elem{}) { 22 | t.Errorf("elemType = %v, want: %v", elemType, reflect.TypeOf([]Elem{})) 23 | } 24 | if !reflect.DeepEqual(patchStrategies, []string{"merge"}) { 25 | t.Errorf("patchStrategies = %v, want: %v", patchStrategies, []string{"merge"}) 26 | } 27 | if patchMergeKey != "key" { 28 | t.Errorf("patchMergeKey = %v, want: %v", patchMergeKey, "key") 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /third_party/forked/golang/netutil/addr.go: -------------------------------------------------------------------------------- 1 | package netutil 2 | 3 | import ( 4 | "net/url" 5 | "strings" 6 | ) 7 | 8 | // FROM: http://golang.org/src/net/http/client.go 9 | // Given a string of the form "host", "host:port", or "[ipv6::address]:port", 10 | // return true if the string includes a port. 11 | func hasPort(s string) bool { return strings.LastIndex(s, ":") > strings.LastIndex(s, "]") } 12 | 13 | // FROM: http://golang.org/src/net/http/transport.go 14 | var portMap = map[string]string{ 15 | "http": "80", 16 | "https": "443", 17 | "socks5": "1080", 18 | } 19 | 20 | // FROM: http://golang.org/src/net/http/transport.go 21 | // canonicalAddr returns url.Host but always with a ":port" suffix 22 | func CanonicalAddr(url *url.URL) string { 23 | addr := url.Host 24 | if !hasPort(addr) { 25 | return addr + ":" + portMap[url.Scheme] 26 | } 27 | return addr 28 | } 29 | --------------------------------------------------------------------------------