3.8 KiB
PLEASE NOTE: This document applies to the HEAD of the source tree
If you are using a released version of Kubernetes, you should refer to the docs that go with that version.
The latest 1.0.x release of this document can be found [here](http://releases.k8s.io/release-1.0/docs/devel/adding-an-APIGroup.md).Documentation for other releases can be found at releases.k8s.io.
Adding an API Group
This document includes the steps to add an API group. You may also want to take a look at PR #16621 and PR #13146, which add API groups.
Please also read about API conventions and API changes before adding an API group.
Your core group package:
-
creaet a folder in pkg/apis to hold you group. Create types.go in pkg/apis/<group>/ and pkg/apis/<group>/<version>/ to define API objects in your group.
-
create pkg/apis/<group>/{register.go, <version>/register.go} to register this group's API objects to the scheme;
-
add a pkg/apis/<group>/install/install.go, which is responsible for adding the group to the
latestpackage, so that other packages can access the group's meta throughlatest.Group. You need to import thisinstallpackage in {pkg/master, pkg/client/unversioned, cmd/kube-version-change}/import_known_versions.go, if you want to make your group accessible to other packages in the kube-apiserver binary, binaries that uses the client package, or the kube-version-change tool.
Scripts changes and auto-generated code:
-
Generate conversions and deep-copies:
- add your "group/" or "group/version" into hack/after-build/{update-generated-conversions.sh, update-generated-deep-copies.sh, verify-generated-conversions.sh, verify-generated-deep-copies.sh};
- run hack/update-generated-conversions.sh, hack/update-generated-deep-copies.sh.
-
Generate files for Ugorji codec:
- touch types.generated.go in pkg/apis/<group>{/, <version>}, and run hack/update-codecgen.sh.
Client (optional):
We are overhauling pkg/client, so this section might be outdated. Currently, to add your group to the client package, you need to
-
create pkg/client/unversioned/<group>.go, define a group client interface and implement the client. You can take pkg/client/unversioned/extensions.go as a reference.
-
add the group client interface to the
Interfacein pkg/client/unversioned/client.go and add method to fetch the interface. Again, you can take how we add the Extensions group there as an example. -
if you need to support the group in kubectl, you'll also need to modify pkg/kubectl/cmd/util/factory.go.
Make the group/version selectable in unit tests (optional):
-
add your group in pkg/api/testapi/testapi.go, then you can access the group in tests through testapi.<group>;
-
add your "group/version" to
KUBE_API_VERSIONSandKUBE_TEST_API_VERSIONSin hack/test-go.sh.