├── .github └── workflows │ ├── build.yml │ └── release.yml ├── .gitignore ├── CONTRIBUTING.md ├── LICENSE ├── Makefile ├── Makefile.test ├── OWNERS ├── README.md ├── SECURITY_CONTACTS ├── cmd └── apiserver-boot │ └── main.go ├── code-of-conduct.md ├── docs ├── adding_custom_rest.md ├── adding_defaulting.md ├── adding_non_namespaced_resources.md ├── adding_resources.md ├── adding_subresources.md ├── adding_validation.md ├── building_docs.md ├── compare_with_kubebuilder.md ├── concepts │ ├── README.md │ ├── aggregation.md │ ├── api_building_overview.md │ ├── auth.md │ ├── extensionserver.jpg │ ├── gvk.jpg │ ├── reconciliation.jpg │ ├── storage.jpg │ ├── store_reconcile.jpg │ └── store_reconcile_example.jpg ├── creating_an_api_server.md ├── installing.md ├── libraries_user_guide.md ├── migrating_controller_runtime.md ├── protobuf_serialization.md ├── running_in_cluster.md ├── running_locally.md ├── static_includes │ └── demo.gif ├── tools_user_guide.md ├── using_minikube.md └── watching_kubernetes_resources.md ├── example ├── basic │ ├── .gitignore │ ├── Makefile │ ├── PROJECT │ ├── boilerplate.go.txt │ ├── cmd │ │ ├── apiserver │ │ │ └── main.go │ │ └── manager │ │ │ └── main.go │ ├── config │ │ ├── aggregated-apiserver.yaml │ │ ├── apiservice.yaml │ │ ├── certificates │ │ │ ├── apiserver.crt │ │ │ ├── apiserver.key │ │ │ ├── apiserver_ca.crt │ │ │ └── apiserver_ca.key │ │ ├── controller-manager.yaml │ │ ├── etcd.yaml │ │ └── rbac.yaml │ ├── docs │ │ └── examples │ │ │ └── poseidon │ │ │ └── poseidon.yaml │ ├── go.mod │ ├── go.sum │ ├── pkg │ │ ├── apis │ │ │ ├── doc.go │ │ │ ├── innsmouth │ │ │ │ ├── common │ │ │ │ │ └── constants.go │ │ │ │ └── v1 │ │ │ │ │ ├── deepone_types.go │ │ │ │ │ ├── doc.go │ │ │ │ │ └── register.go │ │ │ ├── kingsport │ │ │ │ └── v1 │ │ │ │ │ ├── doc.go │ │ │ │ │ ├── festival_types.go │ │ │ │ │ └── register.go │ │ │ ├── miskatonic │ │ │ │ └── v1beta1 │ │ │ │ │ ├── doc.go │ │ │ │ │ ├── register.go │ │ │ │ │ ├── student_storage.go │ │ │ │ │ ├── student_types.go │ │ │ │ │ ├── university_campus.go │ │ │ │ │ ├── university_scale.go │ │ │ │ │ └── university_types.go │ │ │ └── olympus │ │ │ │ └── v1beta1 │ │ │ │ ├── doc.go │ │ │ │ ├── poseidon_types.go │ │ │ │ └── register.go │ │ ├── controller │ │ │ ├── controller.go │ │ │ ├── doc.go │ │ │ ├── festival │ │ │ │ └── festival_controller.go │ │ │ └── poseidon │ │ │ │ └── poseidon_controller.go │ │ ├── doc.go │ │ ├── openapi │ │ │ └── doc.go │ │ └── webhook │ │ │ └── webhook.go │ ├── sample │ │ ├── festival.yaml │ │ ├── poseidon.yaml │ │ ├── university.yaml │ │ └── university_scale.json │ └── sampleconfig │ │ └── university.yaml ├── kine │ ├── .gitignore │ ├── PROJECT │ ├── boilerplate.go.txt │ ├── cmd │ │ ├── apiserver │ │ │ └── main.go │ │ └── manager │ │ │ └── main.go │ ├── config │ │ ├── apiserver.yaml │ │ ├── certificates │ │ │ ├── apiserver.crt │ │ │ ├── apiserver.key │ │ │ ├── apiserver_ca.crt │ │ │ └── apiserver_ca.key │ │ └── mysql.yml │ ├── docs │ │ └── examples │ │ │ ├── tiger │ │ │ └── tiger.yaml │ │ │ └── tik │ │ │ └── tik.yaml │ ├── go.mod │ ├── go.sum │ ├── pkg │ │ ├── apis │ │ │ ├── doc.go │ │ │ └── mysql │ │ │ │ ├── doc.go │ │ │ │ └── v1 │ │ │ │ ├── doc.go │ │ │ │ └── tiger_types.go │ │ ├── controller │ │ │ └── tiger │ │ │ │ └── tiger_controller.go │ │ ├── doc.go │ │ ├── openapi │ │ │ └── doc.go │ │ └── webhook │ │ │ └── webhook.go │ └── sample │ │ ├── tiger.yaml │ │ └── tik.yaml ├── non-etcd │ ├── .gitignore │ ├── PROJECT │ ├── boilerplate.go.txt │ ├── cmd │ │ └── apiserver │ │ │ └── main.go │ ├── docs │ │ └── examples │ │ │ └── burger │ │ │ └── burger.yaml │ ├── go.mod │ ├── go.sum │ ├── pkg │ │ ├── apis │ │ │ ├── doc.go │ │ │ └── filepath │ │ │ │ ├── doc.go │ │ │ │ └── v1 │ │ │ │ ├── burger_types.go │ │ │ │ └── doc.go │ │ └── doc.go │ └── sample │ │ └── burger.yaml ├── podexec │ ├── .gitignore │ ├── Makefile │ ├── PROJECT │ ├── boilerplate.go.txt │ ├── cmd │ │ └── apiserver │ │ │ └── main.go │ ├── docs │ │ └── examples │ │ │ └── pod │ │ │ └── pod.yaml │ ├── go.mod │ ├── go.sum │ ├── pkg │ │ ├── apis │ │ │ ├── doc.go │ │ │ └── podexec │ │ │ │ └── v1 │ │ │ │ ├── doc.go │ │ │ │ ├── pod_exec.go │ │ │ │ └── pod_types.go │ │ ├── doc.go │ │ └── kubelet │ │ │ └── kubelet_client.go │ └── sample │ │ └── pod.yaml └── podlogs │ ├── .gitignore │ ├── PROJECT │ ├── boilerplate.go.txt │ ├── cmd │ ├── apiserver │ │ └── main.go │ └── manager │ │ └── main.go │ ├── docs │ └── examples │ │ └── pod │ │ └── pod.yaml │ ├── go.mod │ ├── go.sum │ ├── pkg │ ├── apis │ │ ├── doc.go │ │ ├── podlogs │ │ │ ├── doc.go │ │ │ ├── install │ │ │ │ ├── doc.go │ │ │ │ └── zz_generated.api.register.go │ │ │ ├── logs_pod_rest.go │ │ │ ├── pod_strategy.go │ │ │ ├── v1 │ │ │ │ ├── doc.go │ │ │ │ ├── logs_pod_types.go │ │ │ │ ├── pod_types.go │ │ │ │ ├── pod_types_test.go │ │ │ │ ├── v1_suite_test.go │ │ │ │ ├── zz_generated.api.register.go │ │ │ │ ├── zz_generated.conversion.go │ │ │ │ └── zz_generated.defaults.go │ │ │ ├── zz_generated.api.register.go │ │ │ ├── zz_generated.deepcopy.go │ │ │ └── zz_generated.defaults.go │ │ └── zz_generated.api.register.go │ ├── client │ │ ├── clientset_generated │ │ │ └── clientset │ │ │ │ ├── clientset.go │ │ │ │ ├── doc.go │ │ │ │ ├── fake │ │ │ │ ├── clientset_generated.go │ │ │ │ ├── doc.go │ │ │ │ └── register.go │ │ │ │ ├── scheme │ │ │ │ ├── doc.go │ │ │ │ └── register.go │ │ │ │ └── typed │ │ │ │ └── podlogs │ │ │ │ └── v1 │ │ │ │ ├── doc.go │ │ │ │ ├── fake │ │ │ │ ├── doc.go │ │ │ │ ├── fake_pod.go │ │ │ │ ├── fake_podlogs.go │ │ │ │ └── fake_podlogs_client.go │ │ │ │ ├── generated_expansion.go │ │ │ │ ├── pod.go │ │ │ │ ├── podlogs.go │ │ │ │ └── podlogs_client.go │ │ ├── informers_generated │ │ │ └── externalversions │ │ │ │ ├── factory.go │ │ │ │ ├── generic.go │ │ │ │ ├── internalinterfaces │ │ │ │ └── factory_interfaces.go │ │ │ │ └── podlogs │ │ │ │ ├── interface.go │ │ │ │ └── v1 │ │ │ │ ├── interface.go │ │ │ │ ├── pod.go │ │ │ │ └── podlogs.go │ │ └── listers_generated │ │ │ └── podlogs │ │ │ └── v1 │ │ │ ├── expansion_generated.go │ │ │ ├── pod.go │ │ │ └── podlogs.go │ ├── controller │ │ └── doc.go │ ├── doc.go │ ├── kubelet │ │ └── kubelet_client.go │ ├── openapi │ │ ├── doc.go │ │ └── openapi_generated.go │ └── webhook │ │ └── webhook.go │ ├── plugin │ └── admission │ │ └── install │ │ └── zz_generated.api.register.go │ └── sample │ └── pod.yaml ├── go.mod ├── go.sum ├── pkg ├── boot │ ├── build │ │ ├── build.go │ │ ├── build_container.go │ │ ├── build_executables.go │ │ ├── build_resource_config.go │ │ ├── docs.go │ │ └── util.go │ ├── create │ │ ├── create.go │ │ ├── group.go │ │ ├── resource.go │ │ ├── subresource.go │ │ ├── util.go │ │ └── version.go │ ├── init_repo │ │ ├── init.go │ │ ├── repo.go │ │ ├── template.go │ │ └── templates │ │ │ ├── api.doc.tpl │ │ │ ├── apiserver.tpl │ │ │ ├── go.mod.tpl │ │ │ └── package.doc.tpl │ ├── run │ │ ├── in_cluster.go │ │ ├── local.go │ │ └── run.go │ ├── show │ │ ├── cmd.go │ │ ├── cmd_apiserver.go │ │ └── cmd_resource.go │ ├── util │ │ ├── repo.go │ │ ├── untar.go │ │ ├── util.go │ │ └── x509.go │ └── version │ │ └── version.go └── utils │ ├── portforward.go │ └── prefixwriter.go ├── scripts └── print-workspace-status.sh └── test └── golden ├── .dockerignore ├── .gitignore ├── Dockerfile ├── Makefile ├── cmd ├── apiserver │ └── main.go └── manager │ └── main.go ├── controllers └── storage │ ├── snapshot_controller.go │ ├── snapshotclaim_controller.go │ ├── volume_controller.go │ └── volumeclaim_controller.go ├── go.mod ├── go.sum ├── hack └── boilerplate.go.txt ├── main.go └── pkg └── apis ├── doc.go └── storage ├── doc.go └── v1 ├── doc.go ├── register.go ├── snapshot_bar.go ├── snapshot_foo.go ├── snapshot_scale.go ├── snapshot_types.go ├── snapshotclaim_types.go ├── volume_types.go ├── volumeclaim_types.go └── zz_generated.deepcopy.go /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: GoRelease 2 | 3 | on: 4 | push: 5 | tags: 6 | - 'v*.*.*' 7 | env: 8 | # Common versions 9 | GO_VERSION: '1.17' 10 | GO_REQUIRED_MIN_VERSION: '' 11 | GITHUB_REF: ${{ github.ref }} 12 | 13 | jobs: 14 | release: 15 | name: release 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: checkout code 19 | uses: actions/checkout@v2 20 | - name: get release version 21 | run: | 22 | echo "RELEASE_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV 23 | - name: get major release version 24 | run: | 25 | echo "MAJOR_RELEASE_VERSION=${RELEASE_VERSION%.*}" >> $GITHUB_ENV 26 | echo "TRIMED_RELEASE_VERSION=${RELEASE_VERSION#v}" >> $GITHUB_ENV 27 | - name: install Go 28 | uses: actions/setup-go@v2 29 | with: 30 | go-version: ${{ env.GO_VERSION }} 31 | - name: binary 32 | run: | 33 | GOOS=linux make release-binary 34 | GOOS=darwin make release-binary 35 | GOOS=windows make release-binary 36 | - name: publish release 37 | uses: ncipollo/release-action@v1 38 | with: 39 | tag: ${{ env.RELEASE_VERSION }} 40 | artifacts: "*.tar.gz" 41 | token: ${{ secrets.GITHUB_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bazel-* 2 | .idea/*** 3 | example/violations.report 4 | db/** 5 | test/bin/** 6 | vendor/** 7 | bin/** 8 | *.tar.gz 9 | release/** 10 | default.etcd/** -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Welcome to Kubernetes. We are excited about the prospect of you joining our [community](https://github.com/kubernetes/community)! The Kubernetes community abides by the CNCF [code of conduct](code-of-conduct.md). Here is an excerpt: 4 | 5 | _As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities._ 6 | 7 | ## Getting Started 8 | 9 | apiserver-builder is deprecated and has been replaced with [kubebuilder](https://github.com/kubernetes-sigs/kubebuilder). Please send Pull Requests to the kubebuilder repository. 10 | 11 | We have full documentation on how to get started contributing here: 12 | 13 | - [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests 14 | - [Kubernetes Contributor Guide](http://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](http://git.k8s.io/community/contributors/guide#contributing) 15 | - [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet/README.md) - Common resources for existing developers 16 | 17 | ## Mentorship 18 | 19 | - [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers! 20 | 21 | ## Contact Information 22 | 23 | - [Slack channel](https://kubernetes.slack.com/messages/kubebuilder) 24 | - [Mailing list](https://groups.google.com/forum/#!forum/kubebuilder) 25 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Kubernetes Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | NAME=apiserver-builder-alpha 16 | VENDOR=kubernetes-sigs 17 | VERSION=$(shell git describe --always --tags HEAD) 18 | COMMIT=$(shell git rev-parse --short HEAD) 19 | KUBE_VERSION?=v0.23.5 20 | DESCRIPTION=apiserver-builder implements libraries and tools to quickly and easily build Kubernetes apiservers to support custom resource types. 21 | MAINTAINER=The Kubernetes Authors 22 | URL=https://github.com/$(VENDOR)/$(NAME) 23 | LICENSE=Apache-2.0 24 | GOOS?=$(shell go env GOOS) 25 | GOARCH?=$(shell go env GOARCH) 26 | GOPATH?=$(shell go env GOPATH) 27 | 28 | .PHONY: default 29 | default: install 30 | 31 | .PHONY: test 32 | test: 33 | go test ./cmd/... ./pkg/... 34 | 35 | .PHONY: install 36 | install: build 37 | @echo "Installing apiserver-builder suite tools..." 38 | @echo "GOOS: $(GOOS)" 39 | @echo "GOARCH: $(GOARCH)" 40 | @echo "ARCH: $(ARCH)" 41 | go install ./cmd/apiserver-boot 42 | 43 | .PHONY: clean 44 | clean: 45 | rm -rf *.deb *.rpm *.tar.gz ./release bin/* 46 | 47 | .PHONY: build 48 | build: clean ## Create release artefacts for darwin:amd64, linux:amd64 and windows:amd64. Requires etcd, glide, hg. 49 | mkdir -p bin 50 | go build -o bin/apiserver-boot ./cmd/apiserver-boot 51 | 52 | release-binary: 53 | mkdir -p bin 54 | go build \ 55 | -ldflags=" \ 56 | -X 'sigs.k8s.io/apiserver-builder-alpha/cmd/apiserver-boot/boot/version.goos=${GOOS}' \ 57 | -X 'sigs.k8s.io/apiserver-builder-alpha/cmd/apiserver-boot/boot/version.goarch=${GOARCH}' \ 58 | -X 'sigs.k8s.io/apiserver-builder-alpha/cmd/apiserver-boot/boot/version.kubernetesVendorVersion=${KUBE_VERSION}' \ 59 | -X 'sigs.k8s.io/apiserver-builder-alpha/cmd/apiserver-boot/boot/version.apiserverBuilderVersion=${VERSION}' \ 60 | -X 'sigs.k8s.io/apiserver-builder-alpha/cmd/apiserver-boot/boot/version.gitCommit=${COMMIT}' \ 61 | " \ 62 | -o bin/apiserver-boot ./cmd/apiserver-boot 63 | tar czvf apiserver-boot-${GOOS}-${GOARCH}.tar.gz bin/apiserver-boot 64 | 65 | -------------------------------------------------------------------------------- /Makefile.test: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Kubernetes Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | .PHONY: all test build generate docs cmds clean cleangenerated cleandocs skeleton 16 | 17 | TESTDIR?=$(shell mktemp -d) 18 | 19 | all: test 20 | 21 | NON_INTERACTIVE_FLAG=--skip-resource=false --skip-controller=false --with-status-subresource=true 22 | 23 | test: 24 | cd ${TESTDIR} && \ 25 | pwd && \ 26 | apiserver-boot init repo --domain sample.kubernetes.io --module-name=example.io && \ 27 | apiserver-boot create group version resource --group storage --version v1 --kind VolumeClaim $(NON_INTERACTIVE_FLAG) && \ 28 | apiserver-boot create group version resource --group storage --version v1 --kind SnapshotClaim $(NON_INTERACTIVE_FLAG) && \ 29 | apiserver-boot create group version resource --group storage --version v1 --kind Volume --non-namespaced $(NON_INTERACTIVE_FLAG) && \ 30 | apiserver-boot create group version resource --group storage --version v1 --kind Snapshot --non-namespaced $(NON_INTERACTIVE_FLAG) && \ 31 | apiserver-boot create subresource --group storage --version v1 --kind Snapshot --subresource scale --type scale && \ 32 | apiserver-boot create subresource --group storage --version v1 --kind Snapshot --subresource foo --type arbitrary && \ 33 | apiserver-boot create subresource --group storage --version v1 --kind Snapshot --subresource bar --type connector && \ 34 | make controller-gen && \ 35 | go mod tidy && \ 36 | make generate && \ 37 | go mod tidy && \ 38 | go vet $$(go list ./... | grep -vE '(clientset|listers|informers)_generated') && \ 39 | go test ./pkg/... && \ 40 | bash -c "find pkg/apis/ -name apiserver.local.config | xargs rm -rf" 41 | 42 | 43 | mod-tidy: 44 | go mod tidy 45 | 46 | 47 | # Build docs 48 | docs: cleandocs build 49 | apiserver-boot build docs --server bin/apiserver 50 | 51 | # Clean up functions 52 | clean: cleangenerated cleandocs 53 | 54 | cleangenerated: cmds 55 | apiserver-boot build generated clean 56 | 57 | cleandocs: cmds 58 | apiserver-boot build docs clean 59 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # See the OWNERS docs at https://go.k8s.io/owners 2 | 3 | reviewers: 4 | - pwittrock 5 | - yue9944882 6 | approvers: 7 | - pwittrock 8 | - yue9944882 9 | -------------------------------------------------------------------------------- /SECURITY_CONTACTS: -------------------------------------------------------------------------------- 1 | # Defined below are the security contacts for this repo. 2 | # 3 | # They are the contact point for the Product Security Team 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://github.com/kubernetes/sig-release/blob/master/security-release-process-documentation/security-release-process.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 | pwittrock 14 | directxman12 15 | yue9944882 -------------------------------------------------------------------------------- /cmd/apiserver-boot/main.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 main 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | "k8s.io/klog/v2" 22 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/build" 23 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/create" 24 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/init_repo" 25 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/run" 26 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/show" 27 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/version" 28 | ) 29 | 30 | func main() { 31 | 32 | init_repo.AddInit(cmd) 33 | create.AddCreate(cmd) 34 | build.AddBuild(cmd) 35 | run.AddRun(cmd) 36 | version.AddVersion(cmd) 37 | show.AddShow(cmd) 38 | 39 | if err := cmd.Execute(); err != nil { 40 | klog.Fatal(err) 41 | } 42 | } 43 | 44 | var cmd = &cobra.Command{ 45 | Use: "apiserver-boot", 46 | Short: "apiserver-boot development kit for building Kubernetes extensions in go.", 47 | Long: `apiserver-boot development kit for building Kubernetes extensions in go.`, 48 | Example: `# Initialize your repository with scaffolding directories and go files. Specify --module-name if the project works outside GOPATH. 49 | apiserver-boot init repo --domain example.com 50 | 51 | # Create new resource "Bee" in the "insect" group with version "v1beta1" 52 | apiserver-boot create group version resource --group insect --version v1beta1 --kind Bee 53 | 54 | # Build the generated code, apiserver and controller-manager so they be run locally. 55 | apiserver-boot build executables 56 | 57 | # Run the tests that were created for your resources 58 | # Requires generated code was already built by "build executables" or "build generated" 59 | go test ./pkg/... 60 | 61 | # Run locally by starting a local etcd, apiserver and controller-manager 62 | # Produces a kubeconfig to talk to the local server 63 | apiserver-boot run local 64 | 65 | # Check the api versions of the locally running server 66 | kubectl --kubeconfig kubeconfig api-versions 67 | 68 | # Build an image and run in a cluster in the default namespace 69 | # Note: after running this you should clear the discovery service 70 | # cache before running kubectl with "rm -rf ~/.kube/cache/discovery/" 71 | apiserver-boot run in-cluster --name creatures --namespace default --image repo/name:tag`, 72 | Run: RunMain, 73 | } 74 | 75 | func RunMain(cmd *cobra.Command, args []string) { 76 | cmd.Help() 77 | } 78 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /docs/adding_custom_rest.md: -------------------------------------------------------------------------------- 1 | # Adding resources 2 | 3 | **Important:** Read [this doc](https://sigs.k8s.io/apiserver-builder-alpha/docs/adding_resources.md) 4 | first to understand how resources are added. 5 | 6 | ## Create a resource with custom rest 7 | 8 | You can implement your own REST implementation instead of using the 9 | standard storage by any one of `Getter`, `Lister`, `Creator`, `Updater` 10 | from `sigs.k8s.io/apiserver-runtime/pkg/builder/resource/resourcerest` 11 | package. 12 | 13 | ```go 14 | // +genclient=true 15 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 16 | 17 | // +resource:path=foos,rest=FooREST 18 | // +k8s:openapi-gen=true 19 | // Foo defines some thing 20 | type Foo struct { 21 | // Your resource definition here 22 | } 23 | 24 | // Foo resource supports "get", "create", "update" verbs. Hence you can't invoke 25 | // "list" upon Foo resource. 26 | var _ resourcerest.Getter = &Foo{} 27 | var _ resourcerest.Creator = &Foo{} 28 | var _ resourcerest.Updater = &Foo{} 29 | 30 | // Your rest.Storage implementation below 31 | // ... 32 | ``` 33 | -------------------------------------------------------------------------------- /docs/adding_defaulting.md: -------------------------------------------------------------------------------- 1 | # Adding a value defaulting to a resources schema 2 | 3 | To add server side field value defaulting for your resource implement 4 | the interface `var _ resourcestrategy.Defaulter = &{}` 5 | in the type definition file. Specifically the defaulter interface lies 6 | in the package `sigs.k8s.io/apiserver-runtime/pkg/builder/resource/resourcestrategy`. 7 | 8 | Example: 9 | 10 | File: `pkg/apis///_types.go` 11 | 12 | ```go 13 | var _ resourcestrategy.Defaulter = &Foo{} 14 | 15 | func (in *Foo) Default() { 16 | if in.Spec.Field == nil { 17 | f := "value" 18 | in.Spec.Field = &f 19 | } 20 | } 21 | ``` 22 | 23 | ## Anatomy of defaulting 24 | 25 | By default, the apiserver-boot won't generate defaulter related codes for 26 | you. You're supposed to manually add the interface assertion and implementation. 27 | 28 | --- 29 | 30 | Update set values for fields with nil values. 31 | 32 | ```go 33 | if in.Spec.Field == nil { 34 | f := "value" 35 | in.Spec.Field = &f 36 | } 37 | ``` -------------------------------------------------------------------------------- /docs/adding_non_namespaced_resources.md: -------------------------------------------------------------------------------- 1 | # Adding non-namespaced resources 2 | 3 | This document covers how to create a non-namespaced resource using 4 | `apiserver-boot`. 5 | 6 | ## Prerequisites 7 | 8 | - [adding resources](adding_resources.md) 9 | 10 | ## Creating a non-namespaced resource with apiserver-boot 11 | 12 | Use the `--non-namespaced=true` flag when creating a resource: 13 | 14 | `apiserver-boot create group version resource --non-namespaced=true --group --version --kind ` 15 | 16 | ## Non-namespaced resources 17 | 18 | Non-namespaced resources have the following differences from namespaced resources: 19 | 20 | - nonNamespaced comment directive above the type in `pkg/apis/{group}/{version}/{Kind}_types.go` 21 | - `// +genclient:nonNamespaced` comment under `// +genclient` 22 | - Strategy and StatusStrategy override NamespacedScoped to false in `pkg/apis/{group}/{version}/{Kind}_types.go` 23 | ``` 24 | func (in *VolumeClaim) NamespaceScoped() bool { 25 | return false 26 | } 27 | ``` 28 | - Do not provide namespace when creating the client from a clientset 29 | 30 | Example: 31 | 32 | File : `pkg/apis/{group}/{version}/{Kind}_types.go` 33 | ```go 34 | // +genclient=true 35 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 36 | // +genclient:nonNamespaced 37 | 38 | // +resource:path=foos 39 | // +k8s:openapi-gen=true 40 | // Foo defines some thing 41 | type Foo struct { 42 | ... 43 | } 44 | ``` 45 | 46 | ```go 47 | ... 48 | func (in *Foo) NamespaceScoped() bool { 49 | return false 50 | } 51 | ``` 52 | -------------------------------------------------------------------------------- /docs/adding_validation.md: -------------------------------------------------------------------------------- 1 | # Adding a validation to a resources schema 2 | 3 | **Note:** By default, when creating a resource with `apiserver-boot create group version resource` a validation 4 | function will be created in the versioned `_types.go` file. 5 | 6 | ```go 7 | func (in *Foo) Validate(ctx context.Context) field.ErrorList { 8 | // TODO(user): Modify it, adding your API validation here. 9 | return nil 10 | } 11 | ``` 12 | 13 | To add server side validation for your resource fill the `Validate` function with 14 | your implementation. 15 | 16 | Example: 17 | 18 | File: `pkg/apis///foo_types.go` 19 | 20 | ```go 21 | // Resource Validation 22 | func (in *Foo) Validate(ctx request.Context) field.ErrorList { 23 | foo := in.(*Foo) 24 | errors := field.ErrorList{} 25 | if ... { 26 | errors = append(errors, field.Invalid( 27 | field.NewPath("spec", "Field"), 28 | *foo.Spec.Field, 29 | "Error message")) 30 | } 31 | return errors 32 | } 33 | ``` 34 | 35 | ## Anatomy of validation 36 | 37 | Use the field.Invalid function to specify errors scoped to fields in the object. 38 | 39 | ```go 40 | field.Invalid(field.NewPath("spec", "Field"), *bar.Spec.Field, "Error message") 41 | ``` 42 | -------------------------------------------------------------------------------- /docs/concepts/README.md: -------------------------------------------------------------------------------- 1 | API Server Concepts 2 | =================== 3 | 4 | In this directory, you will find documentation on how addon API servers 5 | function, and how they interact with the main Kubernetes API server. 6 | 7 | Currently, the following topics are available: 8 | 9 | - [Authentication, Authorization, and Certificates](./auth.md) 10 | - [Aggregation](./aggregation.md) 11 | - [Api building concept guide](./api_building_overview.md) 12 | -------------------------------------------------------------------------------- /docs/concepts/extensionserver.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/concepts/extensionserver.jpg -------------------------------------------------------------------------------- /docs/concepts/gvk.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/concepts/gvk.jpg -------------------------------------------------------------------------------- /docs/concepts/reconciliation.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/concepts/reconciliation.jpg -------------------------------------------------------------------------------- /docs/concepts/storage.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/concepts/storage.jpg -------------------------------------------------------------------------------- /docs/concepts/store_reconcile.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/concepts/store_reconcile.jpg -------------------------------------------------------------------------------- /docs/concepts/store_reconcile_example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/concepts/store_reconcile_example.jpg -------------------------------------------------------------------------------- /docs/creating_an_api_server.md: -------------------------------------------------------------------------------- 1 | # Creating an API Server 2 | 3 | **Note:** This document explains how to manually create the files generated 4 | by `apiserver-boot`. It is recommended to automatically create these files 5 | instead. 6 | 7 | ## Create the apiserver command 8 | 9 | Create a file called `main.go` under `cmd/apiserver` in your project. This 10 | file bootstraps the apiserver by invoking the apiserver start function 11 | with the generated API code. 12 | 13 | ```go 14 | 15 | package main 16 | 17 | import ( 18 | "k8s.io/klog" 19 | "sigs.k8s.io/apiserver-runtime/pkg/builder" 20 | 21 | // +kubebuilder:scaffold:resource-imports 22 | storagev1 "example.io/kimmin/pkg/apis/storage/v1" 23 | ) 24 | 25 | const storagePath = "/registry/YOUR.DOMAIN" // Change this 26 | 27 | func main() { 28 | err := builder.APIServer. 29 | // +kubebuilder:scaffold:resource-register 30 | WithResource(&storagev1.VolumeClaim{}). 31 | SetDelegateAuthOptional(). 32 | WithLocalDebugExtension(). 33 | WithOptionsFns(func(options *builder.ServerOptions) *builder.ServerOptions { 34 | options.RecommendedOptions.CoreAPI = nil 35 | options.RecommendedOptions.Admission = nil 36 | options.RecommendedOptions.Authorization = nil 37 | return options 38 | }). 39 | Execute() 40 | if err != nil { 41 | klog.Fatal(err) 42 | } 43 | } 44 | ``` 45 | 46 | ## Create the API root package 47 | 48 | Create your API root under `pkg/apis` 49 | 50 | *Location:* `GOPATH/src/YOUR/GO/PACKAGE/pkg/apis/doc.go` 51 | 52 | - Change `YOUR.DOMAIN` to the domain you want your API groups to appear under. 53 | 54 | ```go 55 | // +domain=YOUR.DOMAIN 56 | 57 | package apis 58 | ``` 59 | 60 | ## Create an API group 61 | 62 | Create your API group under `pkg/apis/GROUP` 63 | 64 | *Location:* `GOPATH/src/YOUR/GO/PACKAGE/pkg/apis/GROUP/doc.go` 65 | 66 | - Change GROUP to be the group name. 67 | - Change YOUR.DOMAIN to be your domain. 68 | 69 | ```go 70 | // +k8s:deepcopy-gen=package,register 71 | // +groupName=GROUP.YOUR.DOMAIN 72 | 73 | // Package api is the internal version of the API. 74 | package GROUP 75 | ``` 76 | 77 | ## Create an API version 78 | 79 | Create your API group under `pkg/apis/GROUP/VERSION` 80 | 81 | *Location:* `GOPATH/src/YOUR/GO/PACKAGE/pkg/apis/GROUP/VERSION/doc.go` 82 | 83 | - Change GROUP to be the group name. 84 | - Change VERSION to the be the api version name. 85 | - Change YOUR/GO/PACKAGE to be the go package of you project. 86 | 87 | ```go 88 | // +k8s:openapi-gen=true 89 | // +k8s:deepcopy-gen=package,register 90 | // +k8s:conversion-gen=YOUR/GO/PACKAGE/pkg/apis/GROUP 91 | // +k8s:defaulter-gen=TypeMeta 92 | 93 | // +groupName=GROUP.VERSION 94 | package VERSION // import "YOUR/GO/PACKAGE/pkg/apis/GROUP/VERSION" 95 | ``` 96 | 97 | ## Create the API type definitions 98 | 99 | ## Generate the code 100 | 101 | ## Create an integration test 102 | 103 | ## Start the server locally -------------------------------------------------------------------------------- /docs/installing.md: -------------------------------------------------------------------------------- 1 | # Manually Installing the apiserver build tools 2 | 3 | 4 | Requires the following to already be installed: 5 | - kubectl 6 | - go 7 | - docker 8 | - openssl 9 | - base64 10 | - tar 11 | - cp 12 | 13 | Installing by Go Get 14 | 15 | ```go 16 | GO111MODULE=on go get sigs.k8s.io/apiserver-builder-alpha/cmd/apiserver-boot 17 | ``` 18 | 19 | Alternative Manual Installation instructions: 20 | 21 | - Download the latest [release](https://github.com/kubernetes-sigs/apiserver-builder-alpha/releases) 22 | - Extract to `/usr/local/apiserver-builder/` 23 | - Create this directory if it does not already exist 24 | - Add `/usr/local/apiserver-builder/bin` to your path 25 | `export PATH=$PATH:/usr/local/apiserver-builder/bin` 26 | - Test things are working by running `apiserver-boot -h`. -------------------------------------------------------------------------------- /docs/libraries_user_guide.md: -------------------------------------------------------------------------------- 1 | # Libraries user guide 2 | 3 | This document covers how to use the apiserver-builder libraries to 4 | implement your APIs. 5 | 6 | ## Topics 7 | 8 | - [Adding a resource](adding_resources.md) 9 | - [Adding a non-namespaced resource](adding_non_namespaced_resources.md) 10 | - [Adding validation to a resource](adding_validation.md) 11 | - [Adding field defaulting to a resource](adding_defaulting.md) 12 | - [(WIP) Adding subresources to a resource](adding_subresources.md) 13 | - [Defining custom rest handlers for a resource](adding_custom_rest.md) 14 | - [Managing Kubernetes API resources (e.g. Deployment/Pod) from your resource](watching_kubernetes_resources.md) -------------------------------------------------------------------------------- /docs/running_in_cluster.md: -------------------------------------------------------------------------------- 1 | # Running an apiserver and controller-manager in-cluster 2 | 3 | This document describes how to run an apiserver and controller-manager 4 | in cluster using API aggregation. 5 | 6 | For details on the underlying concepts applied by the commands, 7 | see the [auth concept page](concepts/auth.md). 8 | 9 | ## TL;DR version 10 | 11 | Running the following command will automatically invoke each of the commands 12 | covered in the [long version](#long-version) 13 | 14 | `apiserver-boot build config --name --namespace --image ` 15 | 16 | ## Long version 17 | 18 | ### Build the container image 19 | 20 | **Note:** If your apiserver and controller-manager were not created 21 | with the apiserver-builder framework, you made need to manually build 22 | your container image. 23 | 24 | `apiserver-boot build container --image ` 25 | 26 | This will generate code, build the apiserver and controller-manager 27 | binaries and then build a container image. 28 | 29 | Push the image with: 30 | 31 | `docker push ` 32 | 33 | ### Build the config 34 | 35 | `apiserver-boot build config --name --namespace --image ` 36 | 37 | This will perform the following: 38 | 39 | - create a CA + certificate for the service to use 40 | - under config/certificates 41 | - locate each API group/version based on the directory structure 42 | - create config for the APIServices, Deployment, Service, and Secret 43 | - in config/*.yaml 44 | 45 | **Note:** This relies on the container have the binaries `apiserver` and `controller-manager` 46 | present and runnable from "./". You may need to manually edit the config if your 47 | container looks differently. 48 | 49 | You can also provide optional flags: 50 | - `image-pull-secrets` secrets that will be used by k8s cluster if your image is stored in private registry 51 | - `service-account` service account name that will be used by deployment, can be used to provide additional rights for running container 52 | 53 | ### Run the apiserver 54 | 55 | `kubectl apply -f config/` 56 | 57 | Clear the discovery cache: 58 | 59 | `rm -rf ~/.kube/cache/discovery/` 60 | 61 | Look for your API: 62 | 63 | `kubectl api-versions` 64 | 65 | ## Create an instance of your resource 66 | 67 | `kubectl apply -f sample/.yaml` -------------------------------------------------------------------------------- /docs/running_locally.md: -------------------------------------------------------------------------------- 1 | # Running an apiserver and controller-manager locally 2 | 3 | This document describes how to run an apiserver and controller-manager 4 | locally. 5 | 6 | ## Build the executables 7 | 8 | `apiserver-boot build executables` 9 | 10 | This will build the apiserver and controller-manager using 11 | go build and put the binaries under `bin/`. The commands 12 | used to build the binaries are printed to the terminal. 13 | 14 | ## Run the executables and etcd 15 | 16 | `apiserver-boot run local` 17 | 18 | This will start the apiserver and controller-manager binaries 19 | under `bin/` and send the output of both to the terminal. 20 | The commands used to start the binaries are printed 21 | to the terminal. 22 | 23 | **Note:** The location of the binaries can be controlled with `--apiserver` and `--controller-manager`. -------------------------------------------------------------------------------- /docs/static_includes/demo.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kubernetes-sigs/apiserver-builder-alpha/ba22a63c6f739eef533979e20427bd470de1909f/docs/static_includes/demo.gif -------------------------------------------------------------------------------- /docs/using_minikube.md: -------------------------------------------------------------------------------- 1 | # THIS DOC HAS BEEN DEPRECATED 2 | 3 | `apiserver-boot` now supports running in minikube using `run local-minikube` 4 | See [Running in minikube](running_in_minikube.md) instead 5 | 6 | 7 | # Running the apiserver with delegated auth against minikube 8 | 9 | - start [minikube](https://github.com/kubernetes/minikube) 10 | - `minikube start` 11 | - copy `~/.kube/config` to `~/.kube/auth_config` 12 | - `kubectl config use-context minikube` 13 | - `cp ~/.kube/config ~/.kube/auth_config` 14 | - add a `~/.kube/config` entry for your apiserver, using the minikube user 15 | - `kubectl config set-cluster mycluster --server=https://localhost:9443 --certificate-authority=/var/run/kubernetes/apiserver.crt` // Use the cluster you created and the minikube user 16 | - `kubectl config set-context mycluster --user=minikube --cluster=mycluster` 17 | - `kubectl config use-context mycluster` 18 | - make the directory `/var/run/kubernetes` if it doesn't exist 19 | - `sudo mkdir /var/run/kubernetes` 20 | - `sudo chown $(whoami) /var/run/kubernetes` 21 | - run the server with ` ./main --authentication-kubeconfig ~/.kube/auth_config --authorization-kubeconfig ~/.kube/auth_config --client-ca-file /var/run/kubernetes/apiserver.crt --requestheader-client-ca-file /var/run/kubernetes/apiserver.crt --requestheader-username-headers=X-Remote-User --requestheader-group-headers=X-Remote-Group --requestheader-extra-headers-prefix=X-Remote-Extra- --etcd-servers=http://localhost:2379 --secure-port=9443 --tls-ca-file /var/run/kubernetes/apiserver.crt --print-bearer-token` 22 | - This will have the server use minikube for delegated auth -------------------------------------------------------------------------------- /docs/watching_kubernetes_resources.md: -------------------------------------------------------------------------------- 1 | # Watching Kubernetes resources 2 | 3 | go to [here](https://book.kubebuilder.io/cronjob-tutorial/controller-implementation.html) -------------------------------------------------------------------------------- /example/basic/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | default.etcd/ 3 | kubeconfig 4 | apiserver.local.config/ 5 | zz_generated* 6 | pkg/client/*_generated 7 | pkg/openapi/openapi_generated.go 8 | .crt 9 | .key 10 | vendor/** 11 | Gopkg.* 12 | violations.report 13 | kubernetes/* 14 | -------------------------------------------------------------------------------- /example/basic/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2017 The Kubernetes Authors. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | .PHONY: all test build generate docs cmds clean cleangenerated cleandocs 16 | 17 | all: test 18 | 19 | test: build check 20 | go test ./pkg/... 21 | bash -c "find pkg/apis/ -name apiserver.local.config | xargs rm -rf" 22 | 23 | check: 24 | go vet $$(go list ./... | grep -vE '(clientset|listers|informers)_generated') 25 | 26 | build: 27 | GO111MODULE=off apiserver-boot build executables --vendor-dir=../../vendor/ 28 | 29 | # Build docs 30 | docs: cleandocs build 31 | apiserver-boot build docs --server bin/apiserver 32 | 33 | 34 | # Clean up functions 35 | clean: cleangenerated cleandocs 36 | 37 | cleangenerated: cmds 38 | apiserver-boot build generated clean 39 | 40 | cleandocs: cmds 41 | apiserver-boot build docs clean 42 | 43 | generate: 44 | controller-gen object:headerFile="boilerplate.go.txt" paths="./..." -------------------------------------------------------------------------------- /example/basic/PROJECT: -------------------------------------------------------------------------------- 1 | version: "1" 2 | domain: k8s.io 3 | repo: sigs.k8s.io/apiserver-builder-alpha/example 4 | -------------------------------------------------------------------------------- /example/basic/boilerplate.go.txt: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 | -------------------------------------------------------------------------------- /example/basic/cmd/apiserver/main.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 main 18 | 19 | import ( 20 | "k8s.io/klog/v2" 21 | "sigs.k8s.io/apiserver-runtime/pkg/builder" 22 | 23 | innsmouthv1 "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/innsmouth/v1" 24 | kingsportv1 "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/kingsport/v1" 25 | miskatonicv1beta1 "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/miskatonic/v1beta1" 26 | olympusv1beta1 "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/olympus/v1beta1" 27 | ) 28 | 29 | func main() { 30 | err := builder.APIServer. 31 | WithResource(&innsmouthv1.DeepOne{}). // namespaced resource 32 | WithResource(&kingsportv1.Festival{}). // cluster-scoped resource 33 | WithResource(&miskatonicv1beta1.Student{}). // resource with arbitrary subresource and custom storage 34 | WithResource(&miskatonicv1beta1.University{}). // resource with arbitrary subresource 35 | WithResource(&olympusv1beta1.Poseidon{}). // resource with custom storage indexers 36 | WithLocalDebugExtension(). 37 | DisableAuthorization(). 38 | WithOptionsFns(func(options *builder.ServerOptions) *builder.ServerOptions { 39 | options.RecommendedOptions.CoreAPI = nil 40 | options.RecommendedOptions.Admission = nil 41 | return options 42 | }). 43 | Execute() 44 | 45 | if err != nil { 46 | klog.Fatal(err) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example/basic/config/certificates/apiserver.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYzCCAkugAwIBAgIIH/fHVGzvwrswDQYJKoZIhvcNAQELBQAwZTELMAkGA1UE 3 | BhMCdW4xCzAJBgNVBAgMAnN0MQowCAYDVQQHDAFsMQowCAYDVQQKDAFvMQswCQYD 4 | VQQLDAJvdTEkMCIGA1UEAwwbYmFzaWMtY2VydGlmaWNhdGUtYXV0aG9yaXR5MB4X 5 | DTIyMDMzMTA5MTc1M1oXDTMyMDMyODA5MTc1NFowHDEaMBgGA1UEAxMRYmFzaWMu 6 | ZGVmYXVsdC5zdmMwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCtMKtx 7 | cstcvO+t5Lk6QBDAgx5jFB/auu+UopCGfzV+ZEnhnWih/11VvzN8r8ftfnRFFMVz 8 | bjbUaIsC8W5xbC5sisekvuAX9iju32QrlE4E4uS3XDGUfHFHXLqlAEOQrU/G44Dh 9 | kB7j2Np4snOHrAth07M+ompfVIaI9dBgXcxlPNPFCMjiNoUpyS8ysaktPEqce0ik 10 | f40XTDf7V0zAEzR4BA8c8toNT1SgIqHWLnxDJrvQzjCi5E7cL6JfNhed491EMZQ0 11 | egnEymwzwRrkpXNFxDrsIzNfhGzPzDbKvaHPxy5L/3xwrVwTyenIZ9Q1+KczkBJK 12 | EvHiUJ/PL/EXfIhjAgMBAAGjYDBeMA4GA1UdDwEB/wQEAwIFoDAdBgNVHSUEFjAU 13 | BggrBgEFBQcDAQYIKwYBBQUHAwIwLQYDVR0RBCYwJIIJbG9jYWxob3N0ghFiYXNp 14 | Yy5kZWZhdWx0LnN2Y4cEfwAAATANBgkqhkiG9w0BAQsFAAOCAQEADkXllfLNZsX1 15 | bjuoHxEuTZ+Z89LYLOP0L3GG0X0uWdg2Eqv5nfMDuQVbHFkyuZ7d9CcMPbMv17CZ 16 | 1dl0BMFA2dNBs+uuQqHPXwFB8HWOH8AsZL2v/louOx6uMPBOnYHnCzEcmEAvhGgK 17 | JW03dwd06ROyGKOojJIENTgwLgCWYK+OZb3BIr1BjKMvCgG7zIT1TQSgkxF7SF75 18 | bNAhGNkCV0ekJsWAi5PhsU/HukateGPcLKxbkDFtzRWkQ6gJQxdfen9PJN5IT+xE 19 | Er/0aI+8S9cQORy4U3CHThvig8argqnraV1Ov9vMMlsgzgaw7J7ZxkdYl+JC2YG/ 20 | 2kQ8UwR3Bw== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /example/basic/config/certificates/apiserver.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEowIBAAKCAQEArTCrcXLLXLzvreS5OkAQwIMeYxQf2rrvlKKQhn81fmRJ4Z1o 3 | of9dVb8zfK/H7X50RRTFc2421GiLAvFucWwubIrHpL7gF/Yo7t9kK5ROBOLkt1wx 4 | lHxxR1y6pQBDkK1PxuOA4ZAe49jaeLJzh6wLYdOzPqJqX1SGiPXQYF3MZTzTxQjI 5 | 4jaFKckvMrGpLTxKnHtIpH+NF0w3+1dMwBM0eAQPHPLaDU9UoCKh1i58Qya70M4w 6 | ouRO3C+iXzYXnePdRDGUNHoJxMpsM8Ea5KVzRcQ67CMzX4Rsz8w2yr2hz8cuS/98 7 | cK1cE8npyGfUNfinM5ASShLx4lCfzy/xF3yIYwIDAQABAoIBABVYMzj3KeMTEgL/ 8 | dmicbrQbNMqHN2nQsihCZMd+tAwQth5NNREKFOm1d9X9IAnAFPpSlgck5TMGc2N4 9 | d+EYsRwFepduQtYRK3hNJd5NF9R4VjHW9fFT6O4fmo0tXCZfhb6AWWjzRytTlZFc 10 | hOqKpJh469VjVPLMywvkJ7tItCEhyxoKtUXprn9IpK6sTkNu91f1P8s2Ml7uFUjc 11 | IthLorg0F2StZxBfT2FhTXhVqFTIKZfk1FntimL2ZT+EvsBZgdv0kfuChEtNcEmO 12 | tYsgJOq1May3gtvY7T0zZDmM2+9ZJCBKro2Wb1tl4DsgicdGB6JXgN/5jIR13fl5 13 | 14IwXskCgYEAzkPoS+NJ4BBdGtXznmeeaDQPUU4vAuGv2Semj4wDmJEpzh7h1iPd 14 | kUlfb71gULni4H5dTYrTZp8ITivo3p5mCkWyEWOp2lxUFh3rgUcz5ktEHdz9un3h 15 | qX5RiMid3F7udH87ja7IV/fPAFJykzd+XsZdanOKO+U/WKvzM+HQ3Q8CgYEA1vMj 16 | viwvqq3AAkEi7de9LKPMnKSyTOAtt3KgjWTK5NZAGjyjhHlDn4BzjRKnCZO1cIIg 17 | 4ZyuW4+RPyhd+xAno5h1Xt7/Kc3Eimnr0KSFfEeskcNDR2TsSt+ca9zhQOLRtMdB 18 | q99fCxZk+ZfpHiK2B+JGTLMuRQcKCaN7FWJNB20CgYBasi9llwZ32Jon36XkpCla 19 | JnIJzTgMq1IYSUAK5IT8Q/A+6wNglpqpdLrbNkkwldv13HqISx/TguAzB0m5Aata 20 | nvTCgrFAC9MJepSAXt+qRrQn8XE73HgqgBm37IbFTJTLctqr3QvI6nUB7j7lDsSp 21 | Rc3zreQ9m/rzsYAZ8xRU7wKBgQCBXN88Cre9TshqEu2EmvxdK09vTqeIILsi1rfN 22 | oMWDJ3Z409nNVnXePp5MXtdsqhreVVKYtYUx0ZummRLGkJhqmsy4hhim/hG1A75K 23 | WVmEzFYNe6i4BQM4pI8tU0e1l0yCMhFR8SLwN1AZ7tT7sARBhmqsqoHERVJDLsJa 24 | wkh9mQKBgCXGlhg68iS32WfIemaAQ12i4TTRME5jiLYtfY2DBS00VWsqcIu8ATZm 25 | TuhdpQTof+17/1rSG2bqZXP6/HwjMx95HuiWn5JJ07E7n9EBP9dA64+IGuiowHyD 26 | 6kx7UXnMKSawbWbqgRFe1NdGKnHtdNF8lgtGcw+qQ97bB+yqkys1 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /example/basic/config/certificates/apiserver_ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDYzCCAkugAwIBAgIJAKJcANgxmHmSMA0GCSqGSIb3DQEBCwUAMGUxCzAJBgNV 3 | BAYTAnVuMQswCQYDVQQIDAJzdDEKMAgGA1UEBwwBbDEKMAgGA1UECgwBbzELMAkG 4 | A1UECwwCb3UxJDAiBgNVBAMMG2Jhc2ljLWNlcnRpZmljYXRlLWF1dGhvcml0eTAe 5 | Fw0yMjAzMzEwOTE3NTNaFw0yMzAzMzEwOTE3NTNaMGUxCzAJBgNVBAYTAnVuMQsw 6 | CQYDVQQIDAJzdDEKMAgGA1UEBwwBbDEKMAgGA1UECgwBbzELMAkGA1UECwwCb3Ux 7 | JDAiBgNVBAMMG2Jhc2ljLWNlcnRpZmljYXRlLWF1dGhvcml0eTCCASIwDQYJKoZI 8 | hvcNAQEBBQADggEPADCCAQoCggEBAMBp0ta5OvW/UqYlGTLfuljoGbApVpx1mBmL 9 | GGG9HNfbdUlhCQm1SX+uzvYrCNDdBQ1gAaeDkYq9cLnsxaOvGnixruZYTWX2iOfi 10 | cE6qEEQNm92lQFponpgyr6tW7t8d0dMpEU59XRT3utFdhGERTb/xrTtsTiiJxVMc 11 | lEK8wj6c/+N6+G4vDqPrvAypPIiBmnHpTOmnhNv8RyuWsuWTBpoBS1Ecm85VV70E 12 | Paia+7l73/0+Zasq0GzIBvLxKFbTuXdxvkDDcS9sAnO+Upx5aLan8+GnTMgz74zV 13 | wX4nHU5nQqbFRH/SC5WxcXs2W/BMfYAEI6rHgQ0J62b10RfM/BcCAwEAAaMWMBQw 14 | EgYDVR0TAQH/BAgwBgEB/wIBATANBgkqhkiG9w0BAQsFAAOCAQEAqQs9yGljPEqH 15 | TqzDJDkoCmySZd4KuUHJOr65Bhfbji+0lH/QnOftwiwQoj8pHYgz5fdfIkrLLU5+ 16 | p38tq+9BYl8SnuwzSa3CeiaIgpu//Nqh+bx4ZwYb4RfVvfINMuFIiHKPPIRmPFiD 17 | 6IB9tXSkJcfjxGwSKFhKHk3aODnk15IrL04SN4KFDGWgrr4ZBh/TXOnWVdi0tA7y 18 | OifFJQukujxMT4TSvmrkcenTnO8TFS2M7HeOd4KbmxABEGvshftWkWPhtemHaRWc 19 | U8HvHo1KS8pgraWq1Nc21+trhA/nhdmidCmmC8vRCS0SW1dOtCvIG8iUJHx5J2IF 20 | xcPkwhv+7Q== 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /example/basic/config/certificates/apiserver_ca.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDAadLWuTr1v1Km 3 | JRky37pY6BmwKVacdZgZixhhvRzX23VJYQkJtUl/rs72KwjQ3QUNYAGng5GKvXC5 4 | 7MWjrxp4sa7mWE1l9ojn4nBOqhBEDZvdpUBaaJ6YMq+rVu7fHdHTKRFOfV0U97rR 5 | XYRhEU2/8a07bE4oicVTHJRCvMI+nP/jevhuLw6j67wMqTyIgZpx6Uzpp4Tb/Ecr 6 | lrLlkwaaAUtRHJvOVVe9BD2omvu5e9/9PmWrKtBsyAby8ShW07l3cb5Aw3EvbAJz 7 | vlKceWi2p/Php0zIM++M1cF+Jx1OZ0KmxUR/0guVsXF7NlvwTH2ABCOqx4ENCetm 8 | 9dEXzPwXAgMBAAECggEAKSc5GgXaD2+RPMnYfuINGDDkNaJRzPr1whjW6Siqf5yH 9 | lF81sKbehnmb+Fix9QIgr4CmOe7Q9SyZbJqwlta/waq3LrsaKsG0/GuY+6ox+mwy 10 | txA+GFgh+4lzuyDHzF6zXwd8lR4JB5AIm/j1dFFgILqPA5Ohj9gPpTwKlc+LeBp7 11 | Ou7YM7CoPvl4UQSIpRFUuUlRKu4iZJ7jeC3btYQ4uhdLPh2Y8F41jOObQY8xa2zE 12 | sF2NZaMVAdZPiXmSUFPFpVybEUjL9UsCFd+BlU88pDTMWukh/NnkdSxwSDnGjHeb 13 | I77Io8PHiS2mkKojWXTZT1f+atimX4CLRufP73TvqQKBgQDmc5SZ9BhalrZ94Dck 14 | SMG3anqq1g1CzwzeF8ntKEtA8QJswv2urJ16Gr4nCCtKpgnODgWHWyY6UqTAVs7Y 15 | ZLR4qmsFNV1JtdOrpyQxDqbrQ7N/Lnt22H95tDQedMQWkWJ4z2rvgyxn8dBH64Ih 16 | 5TNikC0i4k0TaG1geuRu3miWawKBgQDVvq/6T1YY5CzMv4ZRkTlAeOcb/9qq5+2Z 17 | yPMuxCFlXnrfZ/PzgZ4K6EsXBoVxp1ccalBgv06iGkvea5sXyYn3q9Y5rTdp0yRN 18 | zCcnXXtftTmqFurye4higQE898eblO1rFWU/HYzeTawX27Q5+kq/8cUupVHXu64L 19 | DQguiJEkBQKBgDGlvuL4AnMpuwEdV+PaRNml9+1sFglJoAUM7PTJ1ISWJ6aUz6Bd 20 | EcQnlMXF7cW0RbJ9tNU3XuH7wgCp8wANmg/Q7yN9Hq7tnD+Dz7k95doTiM0ij3jI 21 | JZZrqzrQfxo5khRi4y/ce6mdH/kOlMeGoG5gj0jPpjlDKyU49JOqGLAnAoGBAK5w 22 | 99IDWbLq1Z0sWgTLzrvNcGAriVyd+A3gMIfkTZUbbJBTmIcNK9yfBFmAWvwMpE1u 23 | frbWquglKfIWQ/c/5jeZqDZeJbFaPnC3wuSfqIbNsogcOBc5tm8d9dK6Lc/N1Y3l 24 | YkIGbecn4OF/zzDaEpNgT5roFUlJxJsEQb8oebu5AoGAZifb4DdobdkcCBPrmtM6 25 | VIaPeEY2+uRrmRufyKTWpRPxiXRC2myNX+UJq9YSBE8L2Oyc34k6gAi7UaIwb5t/ 26 | wUpC4EDcVD4fkbExxkh8wN4Wds+10Q0nz4ag4MPGSprYInsQK1HCNLLfjdugdkM0 27 | QTLIND/xuvImOz3h2k5s3yY= 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /example/basic/config/controller-manager.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: Deployment 4 | metadata: 5 | name: basic-example-controller 6 | namespace: default 7 | labels: 8 | api: basic-example 9 | controller: "true" 10 | spec: 11 | selector: 12 | matchLabels: 13 | api: basic-example 14 | controller: "true" 15 | replicas: 1 16 | template: 17 | metadata: 18 | labels: 19 | api: basic-example 20 | controller: "true" 21 | spec: 22 | containers: 23 | - name: controller 24 | image: example.io/basic 25 | imagePullPolicy: IfNotPresent 26 | command: 27 | - "./controller-manager" 28 | args: 29 | resources: 30 | requests: 31 | cpu: 100m 32 | memory: 200Mi 33 | limits: 34 | cpu: 100m 35 | memory: 300Mi 36 | volumes: 37 | - name: apiserver-certs 38 | secret: 39 | secretName: basic-example 40 | -------------------------------------------------------------------------------- /example/basic/config/etcd.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: apps/v1 3 | kind: StatefulSet 4 | metadata: 5 | name: etcd 6 | namespace: default 7 | spec: 8 | selector: 9 | matchLabels: 10 | app: etcd 11 | serviceName: "etcd" 12 | replicas: 1 13 | template: 14 | metadata: 15 | labels: 16 | app: etcd 17 | spec: 18 | terminationGracePeriodSeconds: 10 19 | containers: 20 | - name: etcd 21 | image: quay.io/coreos/etcd:latest 22 | imagePullPolicy: Always 23 | resources: 24 | requests: 25 | cpu: 100m 26 | memory: 20Mi 27 | limits: 28 | cpu: 100m 29 | memory: 30Mi 30 | env: 31 | - name: ETCD_DATA_DIR 32 | value: /etcd-data-dir 33 | command: 34 | - /usr/local/bin/etcd 35 | - --listen-client-urls 36 | - http://0.0.0.0:2379 37 | - --advertise-client-urls 38 | - http://localhost:2379 39 | ports: 40 | - containerPort: 2379 41 | volumeMounts: 42 | - name: etcd-data-dir 43 | mountPath: /etcd-data-dir 44 | readinessProbe: 45 | httpGet: 46 | port: 2379 47 | path: /health 48 | failureThreshold: 1 49 | initialDelaySeconds: 10 50 | periodSeconds: 10 51 | successThreshold: 1 52 | timeoutSeconds: 2 53 | livenessProbe: 54 | httpGet: 55 | port: 2379 56 | path: /health 57 | failureThreshold: 3 58 | initialDelaySeconds: 10 59 | periodSeconds: 10 60 | successThreshold: 1 61 | timeoutSeconds: 2 62 | volumeClaimTemplates: 63 | - metadata: 64 | name: etcd-data-dir 65 | annotations: 66 | volume.beta.kubernetes.io/storage-class: standard 67 | spec: 68 | accessModes: [ "ReadWriteOnce" ] 69 | resources: 70 | requests: 71 | storage: 10Gi 72 | --- 73 | apiVersion: v1 74 | kind: Service 75 | metadata: 76 | name: etcd-svc 77 | namespace: default 78 | labels: 79 | app: etcd 80 | spec: 81 | ports: 82 | - port: 2379 83 | name: etcd 84 | targetPort: 2379 85 | selector: 86 | app: etcd 87 | -------------------------------------------------------------------------------- /example/basic/config/rbac.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | apiVersion: rbac.authorization.k8s.io/v1 3 | kind: ClusterRole 4 | metadata: 5 | name: basic-example-apiserver-auth-reader 6 | rules: 7 | - apiGroups: 8 | - "" 9 | resourceNames: 10 | - extension-apiserver-authentication 11 | resources: 12 | - configmaps 13 | verbs: 14 | - get 15 | - list 16 | --- 17 | apiVersion: rbac.authorization.k8s.io/v1 18 | kind: ClusterRoleBinding 19 | metadata: 20 | name: basic-example-apiserver-auth-reader 21 | namespace: kube-system 22 | roleRef: 23 | apiGroup: rbac.authorization.k8s.io 24 | kind: ClusterRole 25 | name: basic-example-apiserver-auth-reader 26 | subjects: 27 | - kind: ServiceAccount 28 | namespace: default 29 | name: default 30 | --- 31 | apiVersion: rbac.authorization.k8s.io/v1 32 | kind: ClusterRoleBinding 33 | metadata: 34 | name: basic-example-apiserver-auth-delegator 35 | roleRef: 36 | apiGroup: rbac.authorization.k8s.io 37 | kind: ClusterRole 38 | name: system:auth-delegator 39 | subjects: 40 | - kind: ServiceAccount 41 | namespace: default 42 | name: default 43 | --- 44 | apiVersion: rbac.authorization.k8s.io/v1 45 | kind: ClusterRole 46 | metadata: 47 | name: basic-example-controller 48 | namespace: default 49 | rules: 50 | - apiGroups: 51 | - 'innsmouth.k8s.io' 52 | - 'kingsport.k8s.io' 53 | - 'miskatonic.k8s.io' 54 | - 'olympus.k8s.io' 55 | resources: 56 | - '*' 57 | verbs: 58 | - '*' 59 | - apiGroups: 60 | - '' 61 | resources: 62 | - 'configmaps' 63 | - 'namespaces' 64 | verbs: 65 | - 'get' 66 | - 'list' 67 | - 'watch' 68 | - apiGroups: 69 | - 'admissionregistration.k8s.io' 70 | resources: 71 | - '*' 72 | verbs: 73 | - 'list' 74 | - 'watch' 75 | - nonResourceURLs: 76 | - '*' 77 | verbs: 78 | - '*' 79 | 80 | --- 81 | apiVersion: rbac.authorization.k8s.io/v1 82 | kind: ClusterRoleBinding 83 | metadata: 84 | name: basic-example-controller 85 | namespace: default 86 | roleRef: 87 | apiGroup: rbac.authorization.k8s.io 88 | kind: ClusterRole 89 | name: basic-example-controller 90 | subjects: 91 | - kind: ServiceAccount 92 | namespace: default 93 | name: default 94 | -------------------------------------------------------------------------------- /example/basic/docs/examples/poseidon/poseidon.yaml: -------------------------------------------------------------------------------- 1 | note: Poseidon Example 2 | sample: | 3 | apiVersion: olympus.k8s.io/v1beta1 4 | kind: Poseidon 5 | metadata: 6 | name: poseidon-example 7 | spec: 8 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/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 | //go:generate apiregister-gen --input-dirs ./... -h ../../boilerplate.go.txt 18 | //go:generate controller-gen +object +paths=./pkg/apis/... 19 | 20 | // +domain=k8s.io 21 | 22 | package apis 23 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/innsmouth/common/constants.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 common 18 | 19 | // Constants aren't automatically generated for unversioned packages. 20 | // Instead share the same constant for both packages 21 | type CustomType string 22 | 23 | const ( 24 | CUSTOM1 CustomType = "test1" 25 | CUSTOM2 CustomType = "test2" 26 | ) 27 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/innsmouth/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 | // Api versions allow the api contract for a resource to be changed while keeping 18 | // backward compatibility by support multiple concurrent versions 19 | // of the same resource 20 | 21 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../../boilerplate.go.txt 22 | 23 | // +k8s:openapi-gen=true 24 | // +k8s:deepcopy-gen=package,register 25 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/innsmouth 26 | // +k8s:defaulter-gen=TypeMeta 27 | 28 | // +groupName=innsmouth.k8s.io 29 | package v1 // import "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/innsmouth/v1" 30 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/innsmouth/v1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 | var AddToScheme = func(scheme *runtime.Scheme) error { 26 | metav1.AddToGroupVersion(scheme, schema.GroupVersion{ 27 | Group: "innsmouth.k8s.io", 28 | Version: "v1", 29 | }) 30 | // +kubebuilder:scaffold:install 31 | scheme.AddKnownTypes(schema.GroupVersion{ 32 | Group: "innsmouth.k8s.io", 33 | Version: "v1", 34 | }, &DeepOne{}, &DeepOneList{}) 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/kingsport/v1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 | // Api versions allow the api contract for a resource to be changed while keeping 18 | // backward compatibility by support multiple concurrent versions 19 | // of the same resource 20 | 21 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../../boilerplate.go.txt 22 | 23 | // +k8s:openapi-gen=true 24 | // +k8s:deepcopy-gen=package,register 25 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/kingsport 26 | // +k8s:defaulter-gen=TypeMeta 27 | // +groupName=kingsport.k8s.io 28 | package v1 // import "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/kingsport/v1" 29 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/kingsport/v1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 | var AddToScheme = func(scheme *runtime.Scheme) error { 26 | metav1.AddToGroupVersion(scheme, schema.GroupVersion{ 27 | Group: "kingsport.k8s.io", 28 | Version: "v1", 29 | }) 30 | // +kubebuilder:scaffold:install 31 | scheme.AddKnownTypes(schema.GroupVersion{ 32 | Group: "kingsport.k8s.io", 33 | Version: "v1", 34 | }, &Festival{}, &FestivalList{}) 35 | return nil 36 | } 37 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/miskatonic/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 | // Api versions allow the api contract for a resource to be changed while keeping 18 | // backward compatibility by support multiple concurrent versions 19 | // of the same resource 20 | 21 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../../boilerplate.go.txt 22 | 23 | // +k8s:openapi-gen=true 24 | // +k8s:deepcopy-gen=package,register 25 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/miskatonic 26 | // +k8s:defaulter-gen=TypeMeta 27 | // +groupName=miskatonic.k8s.io 28 | package v1beta1 // import "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/miskatonic/v1beta1" 29 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/miskatonic/v1beta1/register.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | ) 24 | 25 | var AddToScheme = func(scheme *runtime.Scheme) error { 26 | metav1.AddToGroupVersion(scheme, schema.GroupVersion{ 27 | Group: "miskatonic.k8s.io", 28 | Version: "v1beta1", 29 | }) 30 | // +kubebuilder:scaffold:install 31 | scheme.AddKnownTypes(schema.GroupVersion{ 32 | Group: "miskatonic.k8s.io", 33 | Version: "v1beta1", 34 | }, &Student{}, &StudentList{}) 35 | scheme.AddKnownTypes(schema.GroupVersion{ 36 | Group: "miskatonic.k8s.io", 37 | Version: "v1beta1", 38 | }, &University{}, &UniversityList{}) 39 | return nil 40 | } 41 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/miskatonic/v1beta1/student_storage.go: -------------------------------------------------------------------------------- 1 | package v1beta1 2 | 3 | import ( 4 | "context" 5 | 6 | "k8s.io/apimachinery/pkg/runtime" 7 | "k8s.io/apiserver/pkg/registry/rest" 8 | 9 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 10 | "sigs.k8s.io/apiserver-runtime/pkg/builder/resource/resourcerest" 11 | ) 12 | 13 | var _ resourcerest.Getter = &Student{} 14 | var _ resourcerest.Creator = &Student{} 15 | var _ resourcerest.Updater = &Student{} 16 | 17 | func (in *Student) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) { 18 | s := obj.(*Student) 19 | s.Spec.ID = s.Spec.ID + 1 20 | return s, nil 21 | } 22 | 23 | // Get retrieves the object from the storage. It is required to support Patch. 24 | func (in *Student) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { 25 | return &Student{}, nil 26 | } 27 | 28 | // Update alters the status subset of an object. 29 | func (in *Student) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { 30 | return nil, false, nil 31 | } 32 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/miskatonic/v1beta1/university_campus.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 | "context" 21 | "fmt" 22 | 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | "k8s.io/apiserver/pkg/registry/rest" 26 | "sigs.k8s.io/apiserver-runtime/pkg/builder/resource" 27 | contextutil "sigs.k8s.io/apiserver-runtime/pkg/util/context" 28 | ) 29 | 30 | var _ resource.GetterUpdaterSubResource = &UniversityCampus{} 31 | 32 | var _ resource.ObjectWithArbitrarySubResource = &University{} 33 | 34 | func (in *University) GetArbitrarySubResources() []resource.ArbitrarySubResource { 35 | return []resource.ArbitrarySubResource{ 36 | &UniversityCampus{}, 37 | } 38 | } 39 | 40 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 41 | type UniversityCampus struct { 42 | metav1.TypeMeta `json:",inline"` 43 | Faculty int `json:"faculty,omitempty"` 44 | } 45 | 46 | func (in *UniversityCampus) Get(ctx context.Context, name string, options *metav1.GetOptions) (runtime.Object, error) { 47 | parentStorage, ok := contextutil.GetParentStorage(ctx) 48 | if !ok { 49 | return nil, fmt.Errorf("no parent storage found in the context") 50 | } 51 | university, err := parentStorage.Get(ctx, name, options) 52 | if err != nil { 53 | return nil, err 54 | } 55 | return &UniversityCampus{ 56 | Faculty: university.(*University).Spec.FacultySize, 57 | }, nil 58 | } 59 | 60 | func (in *UniversityCampus) Update(ctx context.Context, name string, objInfo rest.UpdatedObjectInfo, createValidation rest.ValidateObjectFunc, updateValidation rest.ValidateObjectUpdateFunc, forceAllowCreate bool, options *metav1.UpdateOptions) (runtime.Object, bool, error) { 61 | parentStorage, ok := contextutil.GetParentStorage(ctx) 62 | if !ok { 63 | return nil, false, fmt.Errorf("no parent storage found in the context") 64 | } 65 | return parentStorage.Update(ctx, name, objInfo, createValidation, updateValidation, forceAllowCreate, options) 66 | } 67 | 68 | func (in *UniversityCampus) New() runtime.Object { 69 | return &UniversityCampus{} 70 | } 71 | 72 | func (in *UniversityCampus) SubResourceName() string { 73 | return "campus" 74 | } 75 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/miskatonic/v1beta1/university_scale.go: -------------------------------------------------------------------------------- 1 | package v1beta1 2 | 3 | import ( 4 | v1 "k8s.io/api/autoscaling/v1" 5 | "sigs.k8s.io/apiserver-runtime/pkg/builder/resource" 6 | ) 7 | 8 | var _ resource.ObjectWithScaleSubResource = &University{} 9 | 10 | func (in *University) SetScale(scaleSubResource *v1.Scale) { 11 | in.Spec.FacultySize = int(scaleSubResource.Spec.Replicas) 12 | } 13 | 14 | func (in *University) GetScale() (scaleSubResource *v1.Scale) { 15 | return &v1.Scale{ 16 | Spec: v1.ScaleSpec{ 17 | Replicas: int32(in.Spec.FacultySize), 18 | }, 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/olympus/v1beta1/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 | // Api versions allow the api contract for a resource to be changed while keeping 18 | // backward compatibility by support multiple concurrent versions 19 | // of the same resource 20 | 21 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../../boilerplate.go.txt 22 | //go:generate defaulter-gen -O zz_generated.defaults -i . -h ../../../../boilerplate.go.txt 23 | //go:generate conversion-gen -O zz_generated.conversion -i . -h ../../../../boilerplate.go.txt 24 | 25 | // +k8s:openapi-gen=true 26 | // +k8s:deepcopy-gen=package,register 27 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/olympus 28 | // +k8s:defaulter-gen=TypeMeta 29 | // +groupName=olympus.k8s.io 30 | package v1beta1 // import "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/olympus/v1beta1" 31 | -------------------------------------------------------------------------------- /example/basic/pkg/apis/olympus/v1beta1/register.go: -------------------------------------------------------------------------------- 1 | package v1beta1 2 | 3 | import ( 4 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 5 | "k8s.io/apimachinery/pkg/runtime" 6 | "k8s.io/apimachinery/pkg/runtime/schema" 7 | ) 8 | 9 | //import ( 10 | // "fmt" 11 | // "sigs.k8s.io/apiserver-builder-alpha/pkg/builders" 12 | //) 13 | // 14 | //func init() { 15 | // builders.Scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Poseidon"), PoseidonFieldSelectorConversion) 16 | //} 17 | // 18 | //// All field selector fields must appear in this function 19 | //func PoseidonFieldSelectorConversion(label, value string) (string, string, error) { 20 | // switch label { 21 | // case "metadata.name": 22 | // return label, value, nil 23 | // case "metadata.namespace": 24 | // return label, value, nil 25 | // case "spec.deployment.name": 26 | // return label, value, nil 27 | // default: 28 | // return "", "", fmt.Errorf("%q is not a known field selector: only %q, %q, %q", label, "metadata.name", "metadata.namespace", "spec.deployment.name") 29 | // } 30 | //} 31 | 32 | var AddToScheme = func(scheme *runtime.Scheme) error { 33 | metav1.AddToGroupVersion(scheme, schema.GroupVersion{ 34 | Group: "olympus.k8s.io", 35 | Version: "v1beta1", 36 | }) 37 | // +kubebuilder:scaffold:install 38 | scheme.AddKnownTypes(schema.GroupVersion{ 39 | Group: "olympus.k8s.io", 40 | Version: "v1beta1", 41 | }, &Poseidon{}, &PoseidonList{}) 42 | return nil 43 | } 44 | -------------------------------------------------------------------------------- /example/basic/pkg/controller/controller.go: -------------------------------------------------------------------------------- 1 | package controller 2 | 3 | import ( 4 | "sigs.k8s.io/controller-runtime/pkg/manager" 5 | ) 6 | 7 | // AddToManagerFuncs is a list of functions to add all Controllers to the Manager 8 | var AddToManagerFuncs []func(manager.Manager) error 9 | 10 | // AddToManager adds all Controllers to the Manager 11 | func AddToManager(m manager.Manager) error { 12 | for _, f := range AddToManagerFuncs { 13 | if err := f(m); err != nil { 14 | return err 15 | } 16 | } 17 | return nil 18 | } 19 | -------------------------------------------------------------------------------- /example/basic/pkg/controller/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 controller 18 | -------------------------------------------------------------------------------- /example/basic/pkg/controller/festival/festival_controller.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 festival 18 | 19 | import ( 20 | "context" 21 | "github.com/go-logr/logr" 22 | 23 | "k8s.io/apimachinery/pkg/api/errors" 24 | "k8s.io/apimachinery/pkg/runtime" 25 | kingsportv1 "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/kingsport/v1" 26 | ctrl "sigs.k8s.io/controller-runtime" 27 | "sigs.k8s.io/controller-runtime/pkg/client" 28 | "sigs.k8s.io/controller-runtime/pkg/reconcile" 29 | ) 30 | 31 | var _ reconcile.Reconciler = &ReconcileFestival{} 32 | 33 | // ReconcileFestival reconciles a Festival object 34 | type ReconcileFestival struct { 35 | client.Client 36 | Log logr.Logger 37 | Scheme *runtime.Scheme 38 | } 39 | 40 | // Reconcile reads that state of the cluster for a Festival object and makes changes based on the state read 41 | // and what is in the Festival.Spec 42 | // TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes 43 | // a Deployment as an example 44 | // +kubebuilder:rbac:groups=kingsport.k8s.io,resources=festivals,verbs=get;list;watch;create;update;patch;delete 45 | // +kubebuilder:rbac:groups=kingsport.k8s.io,resources=festivals/status,verbs=get;update;patch 46 | func (r *ReconcileFestival) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { 47 | // Fetch the Festival instance 48 | instance := &kingsportv1.Festival{} 49 | err := r.Get(ctx, request.NamespacedName, instance) 50 | if err != nil { 51 | if errors.IsNotFound(err) { 52 | // Object not found, return. Created objects are automatically garbage collected. 53 | // For additional cleanup logic use finalizers. 54 | return reconcile.Result{}, nil 55 | } 56 | // Error reading the object - requeue the request. 57 | return reconcile.Result{}, err 58 | } 59 | 60 | instance.Spec.Invited = 1 61 | 62 | if err := r.Update(ctx, instance); err != nil { 63 | return reconcile.Result{}, err 64 | } 65 | 66 | return reconcile.Result{}, nil 67 | } 68 | 69 | func (r *ReconcileFestival) SetupWithManager(mgr ctrl.Manager) error { 70 | return ctrl.NewControllerManagedBy(mgr). 71 | For(&kingsportv1.Festival{}). 72 | Complete(r) 73 | } 74 | -------------------------------------------------------------------------------- /example/basic/pkg/controller/poseidon/poseidon_controller.go: -------------------------------------------------------------------------------- 1 | package poseidon 2 | 3 | import ( 4 | "context" 5 | 6 | "github.com/go-logr/logr" 7 | ctrl "sigs.k8s.io/controller-runtime" 8 | 9 | "k8s.io/apimachinery/pkg/api/errors" 10 | "k8s.io/apimachinery/pkg/runtime" 11 | olympusv1beta1 "sigs.k8s.io/apiserver-builder-alpha/example/basic/pkg/apis/olympus/v1beta1" 12 | "sigs.k8s.io/controller-runtime/pkg/client" 13 | "sigs.k8s.io/controller-runtime/pkg/reconcile" 14 | ) 15 | 16 | var _ reconcile.Reconciler = &ReconcilePoseidon{} 17 | 18 | // ReconcilePoseidon reconciles a Poseidon object 19 | type ReconcilePoseidon struct { 20 | client.Client 21 | Log logr.Logger 22 | Scheme *runtime.Scheme 23 | } 24 | 25 | // Reconcile reads that state of the cluster for a Poseidon object and makes changes based on the state read 26 | // and what is in the Poseidon.Spec 27 | // TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes 28 | // a Deployment as an example 29 | // +kubebuilder:rbac:groups=olympus.k8s.io,resources=poseidons,verbs=get;list;watch;create;update;patch;delete 30 | // +kubebuilder:rbac:groups=olympus.k8s.io,resources=poseidons/status,verbs=get;update;patch 31 | func (r *ReconcilePoseidon) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { 32 | // Fetch the Poseidon instance 33 | instance := &olympusv1beta1.Poseidon{} 34 | err := r.Get(ctx, request.NamespacedName, instance) 35 | if err != nil { 36 | if errors.IsNotFound(err) { 37 | // Object not found, return. Created objects are automatically garbage collected. 38 | // For additional cleanup logic use finalizers. 39 | return reconcile.Result{}, nil 40 | } 41 | // Error reading the object - requeue the request. 42 | return reconcile.Result{}, err 43 | } 44 | 45 | return reconcile.Result{}, nil 46 | } 47 | 48 | func (r *ReconcilePoseidon) SetupWithManager(mgr ctrl.Manager) error { 49 | return ctrl.NewControllerManagedBy(mgr). 50 | For(&olympusv1beta1.Poseidon{}). 51 | Complete(r) 52 | } 53 | -------------------------------------------------------------------------------- /example/basic/pkg/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 pkg 18 | -------------------------------------------------------------------------------- /example/basic/pkg/openapi/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2017 The Kubernetes Authors. 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | http://www.apache.org/licenses/LICENSE-2.0 7 | Unless required by applicable law or agreed to in writing, software 8 | distributed under the License is distributed on an "AS IS" BASIS, 9 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 10 | See the License for the specific language governing permissions and 11 | limitations under the License. 12 | */ 13 | 14 | //go:generate openapi-gen -o . --output-package ../../pkg/openapi --report-filename violations.report -i ../../pkg/apis/...,../../vendor/k8s.io/api/core/v1,../../vendor/k8s.io/api/apps/v1,../../vendor/k8s.io/apimachinery/pkg/... -h ../../boilerplate.go.txt 15 | 16 | // Package openapi exists to hold generated openapi code 17 | package openapi 18 | -------------------------------------------------------------------------------- /example/basic/pkg/webhook/webhook.go: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright YEAR 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 webhook 18 | 19 | import ( 20 | "sigs.k8s.io/controller-runtime/pkg/manager" 21 | ) 22 | 23 | // AddToManagerFuncs is a list of functions to add all Controllers to the Manager 24 | var AddToManagerFuncs []func(manager.Manager) error 25 | 26 | // AddToManager adds all Controllers to the Manager 27 | // +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;create;update;patch;delete 28 | // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete 29 | // +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete 30 | func AddToManager(m manager.Manager) error { 31 | for _, f := range AddToManagerFuncs { 32 | if err := f(m); err != nil { 33 | return err 34 | } 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /example/basic/sample/festival.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: kingsport.k8s.io/v1 2 | kind: Festival 3 | metadata: 4 | name: festival-example 5 | spec: 6 | year: 2020 7 | -------------------------------------------------------------------------------- /example/basic/sample/poseidon.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: olympus.k8s.io/v1beta1 2 | kind: Poseidon 3 | metadata: 4 | name: poseidon-example 5 | spec: 6 | -------------------------------------------------------------------------------- /example/basic/sample/university.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: miskatonic.k8s.io/v1beta1 2 | kind: University 3 | metadata: 4 | name: university-example 5 | spec: 6 | facultySize: 1 -------------------------------------------------------------------------------- /example/basic/sample/university_scale.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiVersion":"autoscaling\/v1", 3 | "kind":"Scale", 4 | "metadata":{ 5 | "name":"university-example" 6 | }, 7 | "spec":{ 8 | "replicas":2 9 | } 10 | } -------------------------------------------------------------------------------- /example/basic/sampleconfig/university.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: miskatonic.k8s.io/v1beta1 2 | kind: University 3 | metadata: 4 | name: u2 5 | spec: 6 | -------------------------------------------------------------------------------- /example/kine/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | default.etcd/ 3 | kubeconfig 4 | apiserver.local.config/ 5 | zz_generated* 6 | pkg/client/*_generated 7 | pkg/openapi/openapi_generated.go 8 | .crt 9 | .key 10 | vendor/** 11 | Gopkg.* 12 | violations.report 13 | -------------------------------------------------------------------------------- /example/kine/PROJECT: -------------------------------------------------------------------------------- 1 | 2 | version: "1" 3 | domain: example.com 4 | repo: sigs.k8s.io/apiserver-builder-alpha/example/kine 5 | -------------------------------------------------------------------------------- /example/kine/boilerplate.go.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /example/kine/cmd/apiserver/main.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 main 18 | 19 | import ( 20 | "os" 21 | "strconv" 22 | 23 | "k8s.io/klog/v2" 24 | mysqlv1 "sigs.k8s.io/apiserver-builder-alpha/example/kine/pkg/apis/mysql/v1" 25 | "sigs.k8s.io/apiserver-runtime/pkg/builder" 26 | "sigs.k8s.io/apiserver-runtime/pkg/experimental/storage/mysql" 27 | ) 28 | 29 | func main() { 30 | mysqlHost := os.Getenv("MYSQL_HOST") 31 | mysqlPort, _ := strconv.Atoi(os.Getenv("MYSQL_PORT")) 32 | mysqlUser := os.Getenv("MYSQL_USERNAME") 33 | mysqlPasswd := os.Getenv("MYSQL_PASSWORD") 34 | mysqlDatabase := os.Getenv("MYSQL_DATABASE") 35 | err := builder.APIServer. 36 | WithResourceAndStorage(&mysqlv1.Tiger{}, mysql.NewMysqlStorageProvider( 37 | mysqlHost, 38 | int32(mysqlPort), 39 | mysqlUser, 40 | mysqlPasswd, 41 | mysqlDatabase, 42 | )). // namespaced resource 43 | WithoutEtcd(). 44 | WithLocalDebugExtension(). 45 | Execute() 46 | if err != nil { 47 | klog.Fatal(err) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /example/kine/config/certificates/apiserver.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDljCCAn6gAwIBAgIIauu9yyQOIt4wDQYJKoZIhvcNAQELBQAwdjELMAkGA1UE 3 | BhMCdW4xCzAJBgNVBAgMAnN0MQowCAYDVQQHDAFsMQowCAYDVQQKDAFvMQswCQYD 4 | VQQLDAJvdTE1MDMGA1UEAwwsa2luZS1leGFtcGxlLWFwaXNlcnZlci1jZXJ0aWZp 5 | Y2F0ZS1hdXRob3JpdHkwHhcNMjIwMzMxMDkyNzQzWhcNMzIwMzI4MDkyNzQzWjAt 6 | MSswKQYDVQQDEyJraW5lLWV4YW1wbGUtYXBpc2VydmVyLmRlZmF1bHQuc3ZjMIIB 7 | IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA301T4LJK2qspgFY/RpEvYkwq 8 | G/6NBGfuCj6AJrCA8zfI3xlJ+q/xX62lAdkwjzCnvrdkdDrt4vQ6EpmSndkibyWn 9 | ubH6jfntkWILkPPDYW1uG46M/kqjhztmBje+7reQG1lhd5+d56mb9f9+EZX3m5T/ 10 | VWVVLTYTFVu2XIN/9gK9bnMr+e3zcGlSWAPukXVk4MEfJkIqqs/J7gxruJn7hjr0 11 | ua4mOHakI07i8c2psrTnZQUaoNmGSQ9skbXxloz9a2urkHNa5AGGoUS9suUpnMLu 12 | goMuwOWc24/auzuJZrYGxxuAA7steulRTigFFgfUsYV2n/3v/1hQBdWX0upmFQID 13 | AQABo3EwbzAOBgNVHQ8BAf8EBAMCBaAwHQYDVR0lBBYwFAYIKwYBBQUHAwEGCCsG 14 | AQUFBwMCMD4GA1UdEQQ3MDWCCWxvY2FsaG9zdIIia2luZS1leGFtcGxlLWFwaXNl 15 | cnZlci5kZWZhdWx0LnN2Y4cEfwAAATANBgkqhkiG9w0BAQsFAAOCAQEA3EpXOcSv 16 | zSdg8KI8BmQqeacMo3Ae2gFL0eCRnNwo2FB9bYz23xoDvCyw8B7jK0yrCCtoeuIY 17 | bYSXOrjf5a3NlqDt8hYveFUWsOwPToOJDIGADMquJD1gTct2LK4zmWaSXMVU0t3K 18 | 63Ibht310SZ4PIXOx7W2j96K3OxPrmORFMNtKexZk8/Vg1TzE70+7LVjPDUGEZ6z 19 | NeH/B+rnV7ZRHd2WCDXxltnh4lJb3JRp+9IY7Muq1DeS8pboHvu1Pz/6+W4/5NnR 20 | 3aVqZEEQ7eYnSlsjCi7Dvqk+Xr4hQxsCjmM1a5v4zVYj2eER+SDzKG156GIT0qGw 21 | DIYIcdSLPix5Wg== 22 | -----END CERTIFICATE----- 23 | -------------------------------------------------------------------------------- /example/kine/config/certificates/apiserver.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | MIIEpAIBAAKCAQEA301T4LJK2qspgFY/RpEvYkwqG/6NBGfuCj6AJrCA8zfI3xlJ 3 | +q/xX62lAdkwjzCnvrdkdDrt4vQ6EpmSndkibyWnubH6jfntkWILkPPDYW1uG46M 4 | /kqjhztmBje+7reQG1lhd5+d56mb9f9+EZX3m5T/VWVVLTYTFVu2XIN/9gK9bnMr 5 | +e3zcGlSWAPukXVk4MEfJkIqqs/J7gxruJn7hjr0ua4mOHakI07i8c2psrTnZQUa 6 | oNmGSQ9skbXxloz9a2urkHNa5AGGoUS9suUpnMLugoMuwOWc24/auzuJZrYGxxuA 7 | A7steulRTigFFgfUsYV2n/3v/1hQBdWX0upmFQIDAQABAoIBAQCKooegyRCQEhQC 8 | CYnfVeQFMyQxnSgPxDaVRZhqbMqiNdAQMrMrYHCK5lO7ggwT2jFKxrEnOC7Y6Kfl 9 | RFMyjMxEFSy8rTLRUomb6TMlGzICGt5xXV9LwSslmksNMS7pJi3hzOwmSILQgQzC 10 | /YxXfrPrc+XSLsdi+l9+syHU7g9Tu9bLQr9+Xg6D08c9HoKKtwI5hoizdrbB4VwE 11 | VJntwtLyVGxY9mbbk8gFX5o1fTa4sOdai+8SbeFtA829QWoRQ6oJatfE9r7TmeLn 12 | YLM/XcoMscrCVoApjweor4sAYwXV5gAhbhoHwjzhaGEUpYn7NuO/d7pKrVU+R/sO 13 | YMGZ8HdBAoGBAOnMG4S7mmCI9dhtK43CIM9sQPpXeyuYSjMsMJ+p2yONhcUAQkaq 14 | GcTdeyfd4ZFOFQIaxNtN7OYzugPbqifQhJZSiBtZEq8zHdXFbry01I46frAeupov 15 | djJJOQdrxXPkhPY82IgHSYQyMzVq7Xjt7eidlsSHIhqbL5ODHXoltPs3AoGBAPSC 16 | EYU14r57UZT91d0T01g+ygU8Tu9qJyzRdVPYNB40qOnGsTwonuNXsrbRVWsa/Om/ 17 | glN3ycUPkAf2RyLy8fuzyXuUmyKdtSQdwEsVg5ygZ7uYbNsJIpk7uAxKCZ/45/D7 18 | 7W3VAWL+lhSof1ANhPB3n2h+SNupCKo/5tOEbMcTAoGAYFzkKr04T/mjeuTkQrV0 19 | 2ImB7q0H81v9mUHpeKWF0Q2PyTbmGkIaBO5UyIXHZyCLwCZQZSOlNOy1CsoLRAXJ 20 | 4Dt8Jel8rgGflnCdx+Gwij7J4MWJm+tcCDXt74UYCUBzHRrPFKIMRxR5ztaXsnQ+ 21 | ztXFQpOAFv9HiMFN8P6BrdkCgYEAz2PTwI2oObEXzaxQTiiWxu7bI/23ZlM/z0AK 22 | qIdmDYjVDRU/F6vMuUCVkYOVVDeb9hg+TtX4CnHc1SQLypUOs1QXvf6aZ44lKvEh 23 | PY6OB7f2xKPRESh6dEa3IZVa/Jl/AmRtSw+1EWannfYdpqUQ8XZFe7hBzC9f7igt 24 | fZOBQIkCgYBkgxkioK1FuKn60ABP5X4qIhkOgVD4ZWdVWhz4rIJ7yzmmnKWLgZZ0 25 | zSmczHqIvb8qW1cn6XxVnQ+aWHmOUowK4OJfXEkzB1cKccYIWfL3azHXCcRXYz0w 26 | xuRLJy6Ocpuxl/ZAs6bkMsI/XtU+sFSkYc6KD5Ir0Em5LVdHDLHtoA== 27 | -----END RSA PRIVATE KEY----- 28 | -------------------------------------------------------------------------------- /example/kine/config/certificates/apiserver_ca.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDhTCCAm2gAwIBAgIJAP0vVsn+VR9PMA0GCSqGSIb3DQEBCwUAMHYxCzAJBgNV 3 | BAYTAnVuMQswCQYDVQQIDAJzdDEKMAgGA1UEBwwBbDEKMAgGA1UECgwBbzELMAkG 4 | A1UECwwCb3UxNTAzBgNVBAMMLGtpbmUtZXhhbXBsZS1hcGlzZXJ2ZXItY2VydGlm 5 | aWNhdGUtYXV0aG9yaXR5MB4XDTIyMDMzMTA5Mjc0M1oXDTIzMDMzMTA5Mjc0M1ow 6 | djELMAkGA1UEBhMCdW4xCzAJBgNVBAgMAnN0MQowCAYDVQQHDAFsMQowCAYDVQQK 7 | DAFvMQswCQYDVQQLDAJvdTE1MDMGA1UEAwwsa2luZS1leGFtcGxlLWFwaXNlcnZl 8 | ci1jZXJ0aWZpY2F0ZS1hdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw 9 | ggEKAoIBAQDgluktsU7Hmba334q3LYtqRdF2NYG6Izdy6g7Qgx/vBDR15xRCV/1T 10 | Pg6etodEcZoYo9pZqkrlajHITn+I/8byksMQYTzGRYCrjCR1/bQhBRO9oSUuA3+N 11 | 1+MBZOa2GW1qoHd/FdLf5xOvVfIUOU3s0nvj80Toqs+iMpoHVEFYrPeDJMjGjK8V 12 | +F8dTe03XTsp71t7gaMt6Yk7lT7Huh2PVplD+84ABE8A43skZuMMFJLkrbQGBpkE 13 | X9ZU4Kx4ZNBR4hHtTtcKG5cVVmOImndN+4L8jpElV8BcNPXZX2ZsfU+UwQeH1jeD 14 | OD2yVgmoQ14GM5yBq1P42ZtdrnMcW0RnAgMBAAGjFjAUMBIGA1UdEwEB/wQIMAYB 15 | Af8CAQEwDQYJKoZIhvcNAQELBQADggEBAB4ihBsKmQivhtNs0bNAuXL+CWy/7lt/ 16 | dUwwoHgNyaviUJub/MTlYQepjRoNfjmm2V+VlACZDmvD0O6XN6/ec7Wpf3gYuB7I 17 | si55oz3MEfp++pWniBDDWg3JKVspzKtK967m1bGos5SoU+1whzo1BCOuG7ZovwRk 18 | 6x2lLihrCUp2QHo/aRfnI5O4AWsO5s/AVAM1E6DnM1ShxIpWADF1Y6NgrOLIyOCT 19 | WtEU0ZM59lAHpQM8NxTuQRuTQ8Cb45W/na9yCML77UaBCzZIL2iq8d600Y+cV99D 20 | H1EYsHsQWZvC3FZnWz5E7knpiBlpO0OxLA8TcEQWpJj4YiYo6NJXaKc= 21 | -----END CERTIFICATE----- 22 | -------------------------------------------------------------------------------- /example/kine/config/certificates/apiserver_ca.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDgluktsU7Hmba3 3 | 34q3LYtqRdF2NYG6Izdy6g7Qgx/vBDR15xRCV/1TPg6etodEcZoYo9pZqkrlajHI 4 | Tn+I/8byksMQYTzGRYCrjCR1/bQhBRO9oSUuA3+N1+MBZOa2GW1qoHd/FdLf5xOv 5 | VfIUOU3s0nvj80Toqs+iMpoHVEFYrPeDJMjGjK8V+F8dTe03XTsp71t7gaMt6Yk7 6 | lT7Huh2PVplD+84ABE8A43skZuMMFJLkrbQGBpkEX9ZU4Kx4ZNBR4hHtTtcKG5cV 7 | VmOImndN+4L8jpElV8BcNPXZX2ZsfU+UwQeH1jeDOD2yVgmoQ14GM5yBq1P42Ztd 8 | rnMcW0RnAgMBAAECggEAf7bRmt49Qlwy/5TrOQd5RFG3r1T2FHd6TKq1CfXG7xCh 9 | FHr3llKbB/8+KRr7CPzg+CoVPPAN7y/YZ2PcOnfZFpBGxMXG3akgZm0nPsGq8SwF 10 | 8cv1bJkoq+ycdmp+mAcVpZDi4y3x4Mly9D4Xj1CW85kuQo5QHU8lC8Niu9A56MZC 11 | tGJxS6ATJWi3ECgJfNah2L2YIOsS+HWq3s1sAao6pcOWXdvP3lofVqmb/z8lCvLi 12 | pIuRy4tZUgbHZdCEi+r97BFegJh3CqNYbOyKPCjyKkjzoftWISOr8T2HvAb+oYwn 13 | qYBoavNugUTrDh1mLdIrJwOy1f/0O/rStQeJrBBbwQKBgQDv1yFac6FSvtULm8yW 14 | T99zrdjfQCEnfAOTMhdZIy2kadGJp7Je+44gzzE6Zq3aPC8AzWd4oNXKud0cw+dq 15 | KV3Dixv3TLqIvIDeEozZv7xKjRV1fx9zgMdxusZ8uP7dCWfSO1XfpdumVjBg727L 16 | 9AtsL6uYS1z6uhjWAujbAxwNDwKBgQDvuLoqqYQxvcqu6iuEwbzR2QSJfGRiuMph 17 | DjAzhJP44rVrQz9dhwRcS2hurRr1kGYRa/E0Api3ctF2kvrkMrrRKJh5oMdcKFRj 18 | jn/aAvyTVEMTUoXIhFI63l1ZNyLxdwNKssy2U3xiYNsLsrdm86jk/4/Vp67b15Wr 19 | R74aF+oDKQKBgBrNk/Cj03eH1A9EDg0OSA6Jcx8f75SWC2A7zNgtUkB5gu07THfI 20 | 7Q1Fml7Ics1cxHP2gIW+k6XgN5GrYwU+MjhUJ3/vlzkIt+4ZbJw5DTXXpnpHBqDF 21 | 14QiN2Rg2DqjfnLEJsijpHRmVWm/2EX6s/wXJ7oRUgbDHVttX9B5/HyJAoGAFMxc 22 | KpNmisJCsYZTnEMK1NIVWLBYLVCHDoCiofWguPlCcDn3Z2/tauyH9QJD0oZitKQ+ 23 | 2xpWkaP+lGEQL3hPSRJSmErgwRgmqjSU1x9nNokbALQqM0l3sO/V/YWRHI4M1RBK 24 | Po9jvU1V89/flakSQDwECK9xtlUwARpKXg0xGnECgYAaHLwNa1b57zGFUMQ5CtjX 25 | q2Ux8+E/CQu8RQ9ZwMKt3Tsvuys33It96qfMiUxxoLChz38lEcVf+atIM1t5V/mn 26 | xhKK3MsppVQ7ooGqBQMB45w7mQTCaFTuYT1wSZix15g1IHt2JvK5ua9G882tg5VT 27 | GI1J/v6qzs8vgTNa4LOHgA== 28 | -----END PRIVATE KEY----- 29 | -------------------------------------------------------------------------------- /example/kine/config/mysql.yml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: mysql 5 | spec: 6 | selector: 7 | matchLabels: 8 | app: mysql 9 | strategy: 10 | type: Recreate 11 | template: 12 | metadata: 13 | labels: 14 | app: mysql 15 | spec: 16 | containers: 17 | - image: mysql:8.0 18 | name: mysql 19 | env: 20 | - name: MYSQL_ROOT_PASSWORD 21 | value: test-password 22 | ports: 23 | - containerPort: 3306 24 | name: mysql 25 | --- 26 | apiVersion: v1 27 | kind: Service 28 | metadata: 29 | name: mysql 30 | spec: 31 | ports: 32 | - port: 3306 33 | selector: 34 | app: mysql 35 | clusterIP: None -------------------------------------------------------------------------------- /example/kine/docs/examples/tiger/tiger.yaml: -------------------------------------------------------------------------------- 1 | note: Tiger Example 2 | sample: | 3 | apiVersion: mysql.example.com/v1 4 | kind: Tiger 5 | metadata: 6 | name: tiger-example 7 | spec: 8 | -------------------------------------------------------------------------------- /example/kine/docs/examples/tik/tik.yaml: -------------------------------------------------------------------------------- 1 | note: Tik Example 2 | sample: | 3 | apiVersion: sqlite.example.com/v1alpha1 4 | kind: Tik 5 | metadata: 6 | name: tik-example 7 | spec: 8 | -------------------------------------------------------------------------------- /example/kine/pkg/apis/doc.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 | // 18 | // +domain=example.com 19 | 20 | package apis 21 | -------------------------------------------------------------------------------- /example/kine/pkg/apis/mysql/doc.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 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../boilerplate.go.txt 18 | //go:generate defaulter-gen -O zz_generated.defaults -i . -h ../../../boilerplate.go.txt 19 | 20 | // +k8s:deepcopy-gen=package,register 21 | // +groupName=mysql.example.com 22 | 23 | // Package api is the internal version of the API. 24 | package mysql 25 | -------------------------------------------------------------------------------- /example/kine/pkg/apis/mysql/v1/doc.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 | // Api versions allow the api contract for a resource to be changed while keeping 18 | // backward compatibility by support multiple concurrent versions 19 | // of the same resource 20 | 21 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../../boilerplate.go.txt 22 | //go:generate defaulter-gen -O zz_generated.defaults -i . -h ../../../../boilerplate.go.txt 23 | //go:generate conversion-gen -O zz_generated.conversion -i . -h ../../../../boilerplate.go.txt 24 | 25 | // +k8s:openapi-gen=true 26 | // +k8s:deepcopy-gen=package,register 27 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/kine/pkg/apis/mysql 28 | // +k8s:defaulter-gen=TypeMeta 29 | // +groupName=mysql.example.com 30 | package v1 // import "sigs.k8s.io/apiserver-builder-alpha/example/kine/pkg/apis/mysql/v1" 31 | -------------------------------------------------------------------------------- /example/kine/pkg/controller/tiger/tiger_controller.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 tiger 18 | 19 | import ( 20 | "context" 21 | 22 | "github.com/go-logr/logr" 23 | ctrl "sigs.k8s.io/controller-runtime" 24 | 25 | "k8s.io/apimachinery/pkg/api/errors" 26 | "k8s.io/apimachinery/pkg/runtime" 27 | mysqlv1 "sigs.k8s.io/apiserver-builder-alpha/example/kine/pkg/apis/mysql/v1" 28 | "sigs.k8s.io/controller-runtime/pkg/client" 29 | "sigs.k8s.io/controller-runtime/pkg/reconcile" 30 | ) 31 | 32 | var _ reconcile.Reconciler = &ReconcileTiger{} 33 | 34 | // ReconcileTiger reconciles a Tiger object 35 | type ReconcileTiger struct { 36 | client.Client 37 | Log logr.Logger 38 | Scheme *runtime.Scheme 39 | } 40 | 41 | // Reconcile reads that state of the cluster for a Tiger object and makes changes based on the state read 42 | // and what is in the Tiger.Spec 43 | // TODO(user): Modify this Reconcile function to implement your Controller logic. The scaffolding writes 44 | // a Deployment as an example 45 | // +kubebuilder:rbac:groups=mysql.example.com,resources=tigers,verbs=get;list;watch;create;update;patch;delete 46 | // +kubebuilder:rbac:groups=mysql.example.com,resources=tigers/status,verbs=get;update;patch 47 | func (r *ReconcileTiger) Reconcile(ctx context.Context, request reconcile.Request) (reconcile.Result, error) { 48 | // Fetch the Tiger instance 49 | instance := &mysqlv1.Tiger{} 50 | err := r.Get(ctx, request.NamespacedName, instance) 51 | if err != nil { 52 | if errors.IsNotFound(err) { 53 | // Object not found, return. Created objects are automatically garbage collected. 54 | // For additional cleanup logic use finalizers. 55 | return reconcile.Result{}, nil 56 | } 57 | // Error reading the object - requeue the request. 58 | return reconcile.Result{}, err 59 | } 60 | 61 | instance.Status.Hungry = true 62 | if err := r.Status().Update(ctx, instance); err != nil { 63 | return reconcile.Result{}, err 64 | } 65 | 66 | return reconcile.Result{}, nil 67 | } 68 | 69 | func (r *ReconcileTiger) SetupWithManager(mgr ctrl.Manager) error { 70 | return ctrl.NewControllerManagedBy(mgr). 71 | For(&mysqlv1.Tiger{}). 72 | Complete(r) 73 | } 74 | -------------------------------------------------------------------------------- /example/kine/pkg/doc.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 pkg 18 | -------------------------------------------------------------------------------- /example/kine/pkg/openapi/doc.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 openapi 18 | -------------------------------------------------------------------------------- /example/kine/pkg/webhook/webhook.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 webhook 18 | 19 | import ( 20 | "sigs.k8s.io/controller-runtime/pkg/manager" 21 | ) 22 | 23 | // AddToManagerFuncs is a list of functions to add all Controllers to the Manager 24 | var AddToManagerFuncs []func(manager.Manager) error 25 | 26 | // AddToManager adds all Controllers to the Manager 27 | // +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;create;update;patch;delete 28 | // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete 29 | // +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete 30 | func AddToManager(m manager.Manager) error { 31 | for _, f := range AddToManagerFuncs { 32 | if err := f(m); err != nil { 33 | return err 34 | } 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /example/kine/sample/tiger.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: mysql.example.com/v1 2 | kind: Tiger 3 | metadata: 4 | name: tiger-example 5 | spec: 6 | -------------------------------------------------------------------------------- /example/kine/sample/tik.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: sqlite.example.com/v1alpha1 2 | kind: Tik 3 | metadata: 4 | name: tik-example 5 | spec: 6 | -------------------------------------------------------------------------------- /example/non-etcd/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | default.etcd/ 3 | kubeconfig 4 | apiserver.local.config/ 5 | zz_generated* 6 | pkg/client/*_generated 7 | pkg/openapi/openapi_generated.go 8 | .crt 9 | .key 10 | vendor/** 11 | Gopkg.* 12 | violations.report 13 | data/** 14 | -------------------------------------------------------------------------------- /example/non-etcd/PROJECT: -------------------------------------------------------------------------------- 1 | 2 | version: "1" 3 | domain: example.com 4 | repo: sigs.k8s.io/apiserver-builder-alpha/example/non-etcd 5 | -------------------------------------------------------------------------------- /example/non-etcd/boilerplate.go.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /example/non-etcd/cmd/apiserver/main.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 main 18 | 19 | import ( 20 | "k8s.io/klog/v2" 21 | "sigs.k8s.io/apiserver-runtime/pkg/builder" 22 | "sigs.k8s.io/apiserver-runtime/pkg/experimental/storage/filepath" 23 | 24 | filepathv1 "sigs.k8s.io/apiserver-builder-alpha/example/non-etcd/pkg/apis/filepath/v1" 25 | ) 26 | 27 | func main() { 28 | err := builder.APIServer. 29 | // writes burger resources as static files under the "data" folder in the working directory. 30 | WithResourceAndHandler(&filepathv1.Burger{}, filepath.NewJSONFilepathStorageProvider(&filepathv1.Burger{}, "data")). 31 | WithLocalDebugExtension(). 32 | WithoutEtcd(). 33 | Execute() 34 | if err != nil { 35 | klog.Fatal(err) 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /example/non-etcd/docs/examples/burger/burger.yaml: -------------------------------------------------------------------------------- 1 | note: Burger Example 2 | sample: | 3 | apiVersion: filepath.example.com/v1 4 | kind: Burger 5 | metadata: 6 | name: burger-example 7 | spec: 8 | -------------------------------------------------------------------------------- /example/non-etcd/pkg/apis/doc.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 | //go:generate apiregister-gen --input-dirs ./... -h ../../boilerplate.go.txt 18 | 19 | // 20 | // +domain=example.com 21 | 22 | package apis 23 | -------------------------------------------------------------------------------- /example/non-etcd/pkg/apis/filepath/doc.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 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../boilerplate.go.txt 18 | //go:generate defaulter-gen -O zz_generated.defaults -i . -h ../../../boilerplate.go.txt 19 | 20 | // +k8s:deepcopy-gen=package,register 21 | // +groupName=filepath.example.com 22 | 23 | // Package api is the internal version of the API. 24 | package filepath 25 | -------------------------------------------------------------------------------- /example/non-etcd/pkg/apis/filepath/v1/burger_types.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 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 | "sigs.k8s.io/apiserver-runtime/pkg/builder/resource" 24 | ) 25 | 26 | // +genclient 27 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 28 | 29 | // Burger 30 | // +k8s:openapi-gen=true 31 | // +resource:path=burgers,strategy=BurgerStrategy,rest=BurgerREST 32 | type Burger struct { 33 | metav1.TypeMeta `json:",inline"` 34 | metav1.ObjectMeta `json:"metadata,omitempty"` 35 | 36 | Spec BurgerSpec `json:"spec,omitempty"` 37 | } 38 | 39 | // BurgerSpec defines the desired state of Burger 40 | type BurgerSpec struct { 41 | } 42 | 43 | var _ resource.Object = &Burger{} 44 | 45 | func (b *Burger) GetObjectMeta() *metav1.ObjectMeta { 46 | return &b.ObjectMeta 47 | } 48 | 49 | func (b *Burger) NamespaceScoped() bool { 50 | return true 51 | } 52 | 53 | func (b *Burger) New() runtime.Object { 54 | return &Burger{} 55 | } 56 | 57 | func (b *Burger) NewList() runtime.Object { 58 | return &BurgerList{} 59 | } 60 | 61 | func (b Burger) GetGroupVersionResource() schema.GroupVersionResource { 62 | return schema.GroupVersionResource{ 63 | Group: "filepath.k8s.io", 64 | Version: "v1", 65 | Resource: "burgers", 66 | } 67 | } 68 | 69 | func (b Burger) IsStorageVersion() bool { 70 | return true 71 | } 72 | 73 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 74 | type BurgerList struct { 75 | metav1.TypeMeta `json:",inline"` 76 | metav1.ListMeta `json:"metadata,omitempty"` 77 | 78 | Items []Burger `json:"items"` 79 | } 80 | 81 | var _ resource.ObjectList = &BurgerList{} 82 | 83 | func (in *BurgerList) GetListMeta() *metav1.ListMeta { 84 | return &in.ListMeta 85 | } 86 | -------------------------------------------------------------------------------- /example/non-etcd/pkg/apis/filepath/v1/doc.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 | // Api versions allow the api contract for a resource to be changed while keeping 18 | // backward compatibility by support multiple concurrent versions 19 | // of the same resource 20 | 21 | //go:generate deepcopy-gen -O zz_generated.deepcopy -i . -h ../../../../boilerplate.go.txt 22 | //go:generate defaulter-gen -O zz_generated.defaults -i . -h ../../../../boilerplate.go.txt 23 | //go:generate conversion-gen -O zz_generated.conversion -i . -h ../../../../boilerplate.go.txt 24 | 25 | // +k8s:openapi-gen=true 26 | // +k8s:deepcopy-gen=package,register 27 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/non-etcd/pkg/apis/filepath 28 | // +k8s:defaulter-gen=TypeMeta 29 | // +groupName=filepath.example.com 30 | package v1 // import "sigs.k8s.io/apiserver-builder-alpha/example/non-etcd/pkg/apis/filepath/v1" 31 | -------------------------------------------------------------------------------- /example/non-etcd/pkg/doc.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 pkg 18 | -------------------------------------------------------------------------------- /example/non-etcd/sample/burger.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: filepath.k8s.io/v1 2 | kind: Burger 3 | metadata: 4 | name: burger-example 5 | spec: 6 | -------------------------------------------------------------------------------- /example/podexec/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | default.etcd/ 3 | kubeconfig 4 | apiserver.local.config/ 5 | zz_generated* 6 | pkg/client/*_generated 7 | pkg/openapi/openapi_generated.go 8 | .crt 9 | .key 10 | vendor/** 11 | Gopkg.* 12 | violations.report 13 | -------------------------------------------------------------------------------- /example/podexec/Makefile: -------------------------------------------------------------------------------- 1 | 2 | # Image URL to use all building/pushing image targets 3 | IMG ?= controller:latest 4 | # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) 5 | CRD_OPTIONS ?= "crd:trivialVersions=true" 6 | 7 | # Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set) 8 | ifeq (,$(shell go env GOBIN)) 9 | GOBIN=$(shell go env GOPATH)/bin 10 | else 11 | GOBIN=$(shell go env GOBIN) 12 | endif 13 | 14 | VERSION=v0.0.21 15 | 16 | all: manager 17 | 18 | # Run tests 19 | test: generate fmt vet manifests 20 | go test ./... -coverprofile cover.out 21 | 22 | # Build manager binary 23 | manager: generate fmt vet 24 | go build -o bin/manager main.go 25 | 26 | # Run against the configured Kubernetes cluster in ~/.kube/config 27 | run: generate fmt vet manifests 28 | go run ./main.go 29 | 30 | # Install CRDs into a cluster 31 | install: manifests kustomize 32 | $(KUSTOMIZE) build config/crd | kubectl apply -f - 33 | 34 | # Uninstall CRDs from a cluster 35 | uninstall: manifests kustomize 36 | $(KUSTOMIZE) build config/crd | kubectl delete -f - 37 | 38 | # Deploy controller in the configured Kubernetes cluster in ~/.kube/config 39 | deploy: manifests kustomize 40 | cd config/manager && $(KUSTOMIZE) edit set image controller=${IMG} 41 | $(KUSTOMIZE) build config/default | kubectl apply -f - 42 | 43 | # Generate manifests e.g. CRD, RBAC etc. 44 | manifests: controller-gen 45 | $(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases 46 | 47 | # Run go fmt against code 48 | fmt: 49 | go fmt ./... 50 | 51 | # Run go vet against code 52 | vet: 53 | go vet ./... 54 | 55 | # Generate code 56 | generate: controller-gen 57 | $(CONTROLLER_GEN) object:headerFile="boilerplate.go.txt" paths="./..." 58 | 59 | # Build the docker image 60 | docker-build: test 61 | docker build . -t ${IMG} 62 | 63 | # Push the docker image 64 | docker-push: 65 | docker push ${IMG} 66 | 67 | # find or download controller-gen 68 | # download controller-gen if necessary 69 | controller-gen: 70 | ifeq (, $(shell which controller-gen)) 71 | @{ \ 72 | set -e ;\ 73 | CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\ 74 | cd $$CONTROLLER_GEN_TMP_DIR ;\ 75 | go mod init tmp ;\ 76 | go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.3.0 ;\ 77 | rm -rf $$CONTROLLER_GEN_TMP_DIR ;\ 78 | } 79 | CONTROLLER_GEN=$(GOBIN)/controller-gen 80 | else 81 | CONTROLLER_GEN=$(shell which controller-gen) 82 | endif 83 | 84 | kustomize: 85 | ifeq (, $(shell which kustomize)) 86 | @{ \ 87 | set -e ;\ 88 | KUSTOMIZE_GEN_TMP_DIR=$$(mktemp -d) ;\ 89 | cd $$KUSTOMIZE_GEN_TMP_DIR ;\ 90 | go mod init tmp ;\ 91 | go get sigs.k8s.io/kustomize/kustomize/v3@v3.5.4 ;\ 92 | rm -rf $$KUSTOMIZE_GEN_TMP_DIR ;\ 93 | } 94 | KUSTOMIZE=$(GOBIN)/kustomize 95 | else 96 | KUSTOMIZE=$(shell which kustomize) 97 | endif 98 | -------------------------------------------------------------------------------- /example/podexec/PROJECT: -------------------------------------------------------------------------------- 1 | 2 | version: "1" 3 | domain: example.com 4 | repo: sigs.k8s.io/apiserver-builder-alpha/example/podexec 5 | -------------------------------------------------------------------------------- /example/podexec/boilerplate.go.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /example/podexec/cmd/apiserver/main.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 main 18 | 19 | import ( 20 | "k8s.io/klog/v2" 21 | v1 "sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/apis/podexec/v1" 22 | "sigs.k8s.io/apiserver-runtime/pkg/builder" 23 | ) 24 | 25 | func main() { 26 | err := builder.APIServer. 27 | WithResource(&v1.Pod{}). // namespaced resource 28 | WithLocalDebugExtension(). 29 | ExposeLoopbackClientConfig(). 30 | WithOptionsFns(func(options *builder.ServerOptions) *builder.ServerOptions { 31 | options.RecommendedOptions.CoreAPI = nil 32 | options.RecommendedOptions.Admission = nil 33 | return options 34 | }). 35 | Execute() 36 | 37 | if err != nil { 38 | klog.Fatal(err) 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /example/podexec/docs/examples/pod/pod.yaml: -------------------------------------------------------------------------------- 1 | note: Pod Example 2 | sample: | 3 | apiVersion: podexec.example.com/v1 4 | kind: Pod 5 | metadata: 6 | name: pod-example 7 | spec: 8 | -------------------------------------------------------------------------------- /example/podexec/pkg/apis/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | // 22 | // +domain=example.com 23 | 24 | package apis 25 | 26 | -------------------------------------------------------------------------------- /example/podexec/pkg/apis/podexec/v1/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | // Api versions allow the api contract for a resource to be changed while keeping 21 | // backward compatibility by support multiple concurrent versions 22 | // of the same resource 23 | 24 | // +k8s:openapi-gen=true 25 | // +k8s:deepcopy-gen=package,register 26 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/apis/podexec 27 | // +k8s:defaulter-gen=TypeMeta 28 | // +groupName=podexec.example.com 29 | package v1 // import "sigs.k8s.io/apiserver-builder-alpha/example/podexec/pkg/apis/podexec/v1" 30 | 31 | -------------------------------------------------------------------------------- /example/podexec/pkg/apis/podexec/v1/pod_types.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 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | "k8s.io/apimachinery/pkg/runtime" 22 | "k8s.io/apimachinery/pkg/runtime/schema" 23 | "sigs.k8s.io/apiserver-runtime/pkg/builder/resource" 24 | ) 25 | 26 | // +genclient 27 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 28 | 29 | // Pod 30 | // +k8s:openapi-gen=true 31 | type Pod struct { 32 | metav1.TypeMeta `json:",inline"` 33 | metav1.ObjectMeta `json:"metadata,omitempty"` 34 | 35 | Spec PodSpec `json:"spec,omitempty"` 36 | Status PodStatus `json:"status,omitempty"` 37 | } 38 | 39 | var _ resource.Object = &Pod{} 40 | 41 | func (in *Pod) GetObjectMeta() *metav1.ObjectMeta { 42 | return &in.ObjectMeta 43 | } 44 | 45 | func (in *Pod) NamespaceScoped() bool { 46 | return true 47 | } 48 | 49 | func (in *Pod) New() runtime.Object { 50 | return &Pod{} 51 | } 52 | 53 | func (in *Pod) NewList() runtime.Object { 54 | return &PodList{} 55 | } 56 | 57 | func (in *Pod) GetGroupVersionResource() schema.GroupVersionResource { 58 | return schema.GroupVersionResource{ 59 | Group: "podexec.example.com", 60 | Version: "v1", 61 | Resource: "pods", 62 | } 63 | } 64 | 65 | func (in *Pod) IsStorageVersion() bool { 66 | return true 67 | } 68 | 69 | // PodSpec defines the desired state of Pod 70 | type PodSpec struct { 71 | } 72 | 73 | // PodStatus defines the observed state of Pod 74 | type PodStatus struct { 75 | } 76 | 77 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 78 | type PodList struct { 79 | metav1.TypeMeta `json:",inline"` 80 | metav1.ListMeta `json:"metadata,omitempty"` 81 | 82 | Items []Pod `json:"items"` 83 | } 84 | 85 | var _ resource.ObjectWithArbitrarySubResource = &Pod{} 86 | 87 | func (in *Pod) GetArbitrarySubResources() []resource.ArbitrarySubResource { 88 | return []resource.ArbitrarySubResource{ 89 | &PodExec{}, 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /example/podexec/pkg/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | package pkg 22 | 23 | -------------------------------------------------------------------------------- /example/podexec/sample/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: podexec.example.com/v1 2 | kind: Pod 3 | metadata: 4 | name: pod-example 5 | spec: 6 | -------------------------------------------------------------------------------- /example/podlogs/.gitignore: -------------------------------------------------------------------------------- 1 | bin/ 2 | default.etcd/ 3 | kubeconfig 4 | apiserver.local.config/ 5 | zz_generated* 6 | pkg/client/*_generated 7 | pkg/openapi/openapi_generated.go 8 | .crt 9 | .key 10 | vendor/** 11 | Gopkg.* 12 | violations.report 13 | -------------------------------------------------------------------------------- /example/podlogs/PROJECT: -------------------------------------------------------------------------------- 1 | 2 | version: "1" 3 | domain: example.com 4 | repo: sigs.k8s.io/apiserver-builder-alpha/example/podlogs 5 | -------------------------------------------------------------------------------- /example/podlogs/boilerplate.go.txt: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /example/podlogs/cmd/apiserver/main.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | package main 21 | 22 | import ( 23 | // Make sure dep tools picks up these dependencies 24 | _ "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | _ "github.com/go-openapi/loads" 26 | 27 | "sigs.k8s.io/apiserver-builder-alpha/pkg/cmd/server" 28 | _ "k8s.io/client-go/plugin/pkg/client/auth" // Enable cloud provider auth 29 | 30 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis" 31 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/openapi" 32 | ) 33 | 34 | func main() { 35 | version := "v0" 36 | 37 | err := server.StartApiServerWithOptions(&server.StartOptions{ 38 | EtcdPath: "/registry/example.com", 39 | Apis: apis.GetAllApiBuilders(), 40 | Openapidefs: openapi.GetOpenAPIDefinitions, 41 | Title: "Api", 42 | Version: version, 43 | 44 | // TweakConfigFuncs []func(apiServer *apiserver.Config) error 45 | // FlagConfigFuncs []func(*cobra.Command) error 46 | }) 47 | if err != nil { 48 | panic(err) 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /example/podlogs/cmd/manager/main.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 main 18 | 19 | import ( 20 | "flag" 21 | "os" 22 | 23 | _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" 24 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis" 25 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/webhook" 26 | "sigs.k8s.io/controller-runtime/pkg/client/config" 27 | "sigs.k8s.io/controller-runtime/pkg/manager" 28 | logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" 29 | "sigs.k8s.io/controller-runtime/pkg/runtime/signals" 30 | ) 31 | 32 | func main() { 33 | var metricsAddr string 34 | flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") 35 | flag.Parse() 36 | logf.SetLogger(logf.ZapLogger(false)) 37 | log := logf.Log.WithName("entrypoint") 38 | 39 | // Get a config to talk to the apiserver 40 | log.Info("setting up client for manager") 41 | cfg, err := config.GetConfig() 42 | if err != nil { 43 | log.Error(err, "unable to set up client config") 44 | os.Exit(1) 45 | } 46 | 47 | // Create a new Cmd to provide shared dependencies and start components 48 | log.Info("setting up manager") 49 | mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr}) 50 | if err != nil { 51 | log.Error(err, "unable to set up overall controller manager") 52 | os.Exit(1) 53 | } 54 | 55 | log.Info("Registering Components.") 56 | 57 | // Setup Scheme for all resources 58 | log.Info("setting up scheme") 59 | if err := apis.AddToScheme(mgr.GetScheme()); err != nil { 60 | log.Error(err, "unable add APIs to scheme") 61 | os.Exit(1) 62 | } 63 | 64 | // Setup all Controllers 65 | //log.Info("Setting up controller") 66 | //if err := controller.AddToManager(mgr); err != nil { 67 | // log.Error(err, "unable to register controllers to the manager") 68 | // os.Exit(1) 69 | //} 70 | 71 | log.Info("setting up webhooks") 72 | if err := webhook.AddToManager(mgr); err != nil { 73 | log.Error(err, "unable to register webhooks to the manager") 74 | os.Exit(1) 75 | } 76 | 77 | // Start the Cmd 78 | log.Info("Starting the Cmd.") 79 | if err := mgr.Start(signals.SetupSignalHandler()); err != nil { 80 | log.Error(err, "unable to run the manager") 81 | os.Exit(1) 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /example/podlogs/docs/examples/pod/pod.yaml: -------------------------------------------------------------------------------- 1 | note: Pod Example 2 | sample: | 3 | apiVersion: podlogs.example.com/v1 4 | kind: Pod 5 | metadata: 6 | name: pod-example 7 | spec: 8 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | // 22 | // +domain=example.com 23 | 24 | package apis 25 | 26 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | // +k8s:deepcopy-gen=package,register 22 | // +groupName=podlogs.example.com 23 | 24 | // Package api is the internal version of the API. 25 | package podlogs 26 | 27 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/install/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | package install 21 | 22 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/install/zz_generated.api.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 | // This file was autogenerated by apiregister-gen. Do not edit it manually! 18 | 19 | package install 20 | 21 | import ( 22 | "k8s.io/apimachinery/pkg/runtime" 23 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 24 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs" 25 | v1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 26 | "sigs.k8s.io/apiserver-builder-alpha/pkg/builders" 27 | ) 28 | 29 | func init() { 30 | Install(builders.Scheme) 31 | } 32 | 33 | func Install(scheme *runtime.Scheme) { 34 | utilruntime.Must(v1.AddToScheme(scheme)) 35 | utilruntime.Must(podlogs.AddToScheme(scheme)) 36 | utilruntime.Must(addKnownTypes(scheme)) 37 | } 38 | 39 | func addKnownTypes(scheme *runtime.Scheme) error { 40 | scheme.AddKnownTypes(podlogs.SchemeGroupVersion, 41 | &podlogs.Pod{}, 42 | &podlogs.PodList{}, 43 | &podlogs.PodLogs{}, 44 | ) 45 | return nil 46 | } 47 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/pod_strategy.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 podlogs 18 | 19 | import ( 20 | "context" 21 | 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "k8s.io/apimachinery/pkg/util/validation/field" 24 | "k8s.io/klog/v2" 25 | ) 26 | 27 | // Validate checks that an instance of Pod is well formed 28 | func (PodStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { 29 | o := obj.(*Pod) 30 | klog.Infof("Validating fields for Pod %s", o.Name) 31 | errors := field.ErrorList{} 32 | // perform validation here and add to errors using field.Invalid 33 | return errors 34 | } 35 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/v1/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | // Api versions allow the api contract for a resource to be changed while keeping 21 | // backward compatibility by support multiple concurrent versions 22 | // of the same resource 23 | 24 | // +k8s:openapi-gen=true 25 | // +k8s:deepcopy-gen=package,register 26 | // +k8s:conversion-gen=sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs 27 | // +k8s:defaulter-gen=TypeMeta 28 | // +groupName=podlogs.example.com 29 | package v1 // import "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 30 | 31 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/v1/logs_pod_types.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 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 21 | ) 22 | 23 | // +genclient 24 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 25 | 26 | // +subresource-request 27 | type PodLogs struct { 28 | metav1.TypeMeta `json:",inline"` 29 | 30 | // Container for which to return logs 31 | Container string 32 | // If true, follow the logs for the pod 33 | Follow bool 34 | // If true, return previous terminated container logs 35 | Previous bool 36 | // A relative time in seconds before the current time from which to show logs. If this value 37 | // precedes the time a pod was started, only logs since the pod start will be returned. 38 | // If this value is in the future, no logs will be returned. 39 | // Only one of sinceSeconds or sinceTime may be specified. 40 | SinceSeconds *int64 41 | // An RFC3339 timestamp from which to show logs. If this value 42 | // precedes the time a pod was started, only logs since the pod start will be returned. 43 | // If this value is in the future, no logs will be returned. 44 | // Only one of sinceSeconds or sinceTime may be specified. 45 | SinceTime *metav1.Time 46 | // If true, add an RFC3339 or RFC3339Nano timestamp at the beginning of every line 47 | // of log output. 48 | Timestamps bool 49 | // If set, the number of lines from the end of the logs to show. If not specified, 50 | // logs are shown from the creation of the container or sinceSeconds or sinceTime 51 | TailLines *int64 52 | // If set, the number of bytes to read from the server before terminating the 53 | // log output. This may not display a complete final line of logging, and may return 54 | // slightly more or slightly less than the specified limit. 55 | LimitBytes *int64 56 | } 57 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/v1/pod_types.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | package v1 21 | 22 | import ( 23 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 24 | ) 25 | 26 | // +genclient 27 | // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object 28 | 29 | // Pod 30 | // +k8s:openapi-gen=true 31 | // +resource:path=pods,strategy=PodStrategy 32 | // +subresource:request=PodLogs,path=logs,kind=PodLogs,rest=PodLogsREST 33 | type Pod struct { 34 | metav1.TypeMeta `json:",inline"` 35 | metav1.ObjectMeta `json:"metadata,omitempty"` 36 | 37 | Spec PodSpec `json:"spec,omitempty"` 38 | Status PodStatus `json:"status,omitempty"` 39 | } 40 | 41 | // PodSpec defines the desired state of Pod 42 | type PodSpec struct { 43 | } 44 | 45 | // PodStatus defines the observed state of Pod 46 | type PodStatus struct { 47 | } 48 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/v1/pod_types_test.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | package v1_test 21 | 22 | import ( 23 | . "github.com/onsi/ginkgo" 24 | . "github.com/onsi/gomega" 25 | 26 | metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 | 28 | . "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 29 | . "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/clientset_generated/clientset/typed/podlogs/v1" 30 | ) 31 | 32 | var _ = Describe("Pod", func() { 33 | var instance Pod 34 | var expected Pod 35 | var client PodInterface 36 | 37 | BeforeEach(func() { 38 | instance = Pod{} 39 | instance.Name = "instance-1" 40 | 41 | expected = instance 42 | }) 43 | 44 | AfterEach(func() { 45 | client.Delete(instance.Name, &metav1.DeleteOptions{}) 46 | }) 47 | 48 | Describe("when sending a storage request", func() { 49 | Context("for a valid config", func() { 50 | It("should provide CRUD access to the object", func() { 51 | client = cs.PodlogsV1().Pods("pod-test-valid") 52 | 53 | By("returning success from the create request") 54 | actual, err := client.Create(&instance) 55 | Expect(err).ShouldNot(HaveOccurred()) 56 | 57 | By("defaulting the expected fields") 58 | Expect(actual.Spec).To(Equal(expected.Spec)) 59 | 60 | By("returning the item for list requests") 61 | result, err := client.List(metav1.ListOptions{}) 62 | Expect(err).ShouldNot(HaveOccurred()) 63 | Expect(result.Items).To(HaveLen(1)) 64 | Expect(result.Items[0].Spec).To(Equal(expected.Spec)) 65 | 66 | By("returning the item for get requests") 67 | actual, err = client.Get(instance.Name, metav1.GetOptions{}) 68 | Expect(err).ShouldNot(HaveOccurred()) 69 | Expect(actual.Spec).To(Equal(expected.Spec)) 70 | 71 | By("deleting the item for delete requests") 72 | err = client.Delete(instance.Name, &metav1.DeleteOptions{}) 73 | Expect(err).ShouldNot(HaveOccurred()) 74 | result, err = client.List(metav1.ListOptions{}) 75 | Expect(err).ShouldNot(HaveOccurred()) 76 | Expect(result.Items).To(HaveLen(0)) 77 | }) 78 | }) 79 | }) 80 | }) 81 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/v1/v1_suite_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 v1_test 18 | 19 | import ( 20 | "testing" 21 | 22 | . "github.com/onsi/ginkgo" 23 | . "github.com/onsi/gomega" 24 | "k8s.io/client-go/rest" 25 | "sigs.k8s.io/apiserver-builder-alpha/pkg/test" 26 | 27 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis" 28 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/clientset_generated/clientset" 29 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/openapi" 30 | ) 31 | 32 | var testenv *test.TestEnvironment 33 | var config *rest.Config 34 | var cs *clientset.Clientset 35 | 36 | func TestV1(t *testing.T) { 37 | RegisterFailHandler(Fail) 38 | RunSpecsWithDefaultAndCustomReporters(t, "v1 Suite", []Reporter{test.NewlineReporter{}}) 39 | } 40 | 41 | var _ = BeforeSuite(func() { 42 | testenv = test.NewTestEnvironment(apis.GetAllApiBuilders(), openapi.GetOpenAPIDefinitions) 43 | config = testenv.Start() 44 | cs = clientset.NewForConfigOrDie(config) 45 | }) 46 | 47 | var _ = AfterSuite(func() { 48 | testenv.Stop() 49 | }) 50 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/v1/zz_generated.defaults.go: -------------------------------------------------------------------------------- 1 | // +build !ignore_autogenerated 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Code generated by defaulter-gen. DO NOT EDIT. 20 | 21 | package v1 22 | 23 | import ( 24 | runtime "k8s.io/apimachinery/pkg/runtime" 25 | ) 26 | 27 | // RegisterDefaults adds defaulters functions to the given scheme. 28 | // Public to allow building arbitrary schemes. 29 | // All generated defaulters are covering - they call all nested defaulters. 30 | func RegisterDefaults(scheme *runtime.Scheme) error { 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/podlogs/zz_generated.defaults.go: -------------------------------------------------------------------------------- 1 | // +build !ignore_autogenerated 2 | 3 | /* 4 | Copyright 2019 The Kubernetes Authors. 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | // Code generated by defaulter-gen. DO NOT EDIT. 20 | 21 | package podlogs 22 | 23 | import ( 24 | runtime "k8s.io/apimachinery/pkg/runtime" 25 | ) 26 | 27 | // RegisterDefaults adds defaulters functions to the given scheme. 28 | // Public to allow building arbitrary schemes. 29 | // All generated defaulters are covering - they call all nested defaulters. 30 | func RegisterDefaults(scheme *runtime.Scheme) error { 31 | return nil 32 | } 33 | -------------------------------------------------------------------------------- /example/podlogs/pkg/apis/zz_generated.api.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 | // This file was autogenerated by apiregister-gen. Do not edit it manually! 18 | 19 | package apis 20 | 21 | import ( 22 | "k8s.io/apimachinery/pkg/runtime" 23 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs" 24 | _ "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/install" 25 | podlogsv1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 26 | "sigs.k8s.io/apiserver-builder-alpha/pkg/builders" 27 | ) 28 | 29 | var ( 30 | localSchemeBuilder = runtime.SchemeBuilder{ 31 | podlogsv1.AddToScheme, 32 | } 33 | AddToScheme = localSchemeBuilder.AddToScheme 34 | ) 35 | 36 | // GetAllApiBuilders returns all known APIGroupBuilders 37 | // so they can be registered with the apiserver 38 | func GetAllApiBuilders() []*builders.APIGroupBuilder { 39 | return []*builders.APIGroupBuilder{ 40 | GetPodlogsAPIBuilder(), 41 | } 42 | } 43 | 44 | var podlogsApiGroup = builders.NewApiGroupBuilder( 45 | "podlogs.example.com", 46 | "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs"). 47 | WithUnVersionedApi(podlogs.ApiVersion). 48 | WithVersionedApis( 49 | podlogsv1.ApiVersion, 50 | ). 51 | WithRootScopedKinds() 52 | 53 | func GetPodlogsAPIBuilder() *builders.APIGroupBuilder { 54 | return podlogsApiGroup 55 | } 56 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/doc.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated clientset. 20 | package clientset 21 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/fake/doc.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated fake clientset. 20 | package fake 21 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/fake/register.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | runtime "k8s.io/apimachinery/pkg/runtime" 24 | schema "k8s.io/apimachinery/pkg/runtime/schema" 25 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 26 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 27 | podlogsv1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 28 | ) 29 | 30 | var scheme = runtime.NewScheme() 31 | var codecs = serializer.NewCodecFactory(scheme) 32 | var parameterCodec = runtime.NewParameterCodec(scheme) 33 | var localSchemeBuilder = runtime.SchemeBuilder{ 34 | podlogsv1.AddToScheme, 35 | } 36 | 37 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 38 | // of clientsets, like in: 39 | // 40 | // import ( 41 | // "k8s.io/client-go/kubernetes" 42 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 43 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 44 | // ) 45 | // 46 | // kclientset, _ := kubernetes.NewForConfig(c) 47 | // _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 48 | // 49 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 50 | // correctly. 51 | var AddToScheme = localSchemeBuilder.AddToScheme 52 | 53 | func init() { 54 | v1.AddToGroupVersion(scheme, schema.GroupVersion{Version: "v1"}) 55 | utilruntime.Must(AddToScheme(scheme)) 56 | } 57 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/scheme/doc.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package contains the scheme of the automatically generated clientset. 20 | package scheme 21 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/scheme/register.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package scheme 20 | 21 | import ( 22 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 23 | runtime "k8s.io/apimachinery/pkg/runtime" 24 | schema "k8s.io/apimachinery/pkg/runtime/schema" 25 | serializer "k8s.io/apimachinery/pkg/runtime/serializer" 26 | utilruntime "k8s.io/apimachinery/pkg/util/runtime" 27 | podlogsv1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 28 | ) 29 | 30 | var Scheme = runtime.NewScheme() 31 | var Codecs = serializer.NewCodecFactory(Scheme) 32 | var ParameterCodec = runtime.NewParameterCodec(Scheme) 33 | var localSchemeBuilder = runtime.SchemeBuilder{ 34 | podlogsv1.AddToScheme, 35 | } 36 | 37 | // AddToScheme adds all types of this clientset into the given scheme. This allows composition 38 | // of clientsets, like in: 39 | // 40 | // import ( 41 | // "k8s.io/client-go/kubernetes" 42 | // clientsetscheme "k8s.io/client-go/kubernetes/scheme" 43 | // aggregatorclientsetscheme "k8s.io/kube-aggregator/pkg/client/clientset_generated/clientset/scheme" 44 | // ) 45 | // 46 | // kclientset, _ := kubernetes.NewForConfig(c) 47 | // _ = aggregatorclientsetscheme.AddToScheme(clientsetscheme.Scheme) 48 | // 49 | // After this, RawExtensions in Kubernetes types will serialize kube-aggregator types 50 | // correctly. 51 | var AddToScheme = localSchemeBuilder.AddToScheme 52 | 53 | func init() { 54 | v1.AddToGroupVersion(Scheme, schema.GroupVersion{Version: "v1"}) 55 | utilruntime.Must(AddToScheme(Scheme)) 56 | } 57 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/typed/podlogs/v1/doc.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // This package has the automatically generated typed clients. 20 | package v1 21 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/typed/podlogs/v1/fake/doc.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | // Package fake has the automatically generated clients. 20 | package fake 21 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/typed/podlogs/v1/fake/fake_podlogs_client.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package fake 20 | 21 | import ( 22 | rest "k8s.io/client-go/rest" 23 | testing "k8s.io/client-go/testing" 24 | v1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/clientset_generated/clientset/typed/podlogs/v1" 25 | ) 26 | 27 | type FakePodlogsV1 struct { 28 | *testing.Fake 29 | } 30 | 31 | func (c *FakePodlogsV1) Pods(namespace string) v1.PodInterface { 32 | return &FakePods{c, namespace} 33 | } 34 | 35 | func (c *FakePodlogsV1) PodLogses(namespace string) v1.PodLogsInterface { 36 | return &FakePodLogses{c, namespace} 37 | } 38 | 39 | // RESTClient returns a RESTClient that is used to communicate 40 | // with API server by this client implementation. 41 | func (c *FakePodlogsV1) RESTClient() rest.Interface { 42 | var ret *rest.RESTClient 43 | return ret 44 | } 45 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/clientset_generated/clientset/typed/podlogs/v1/generated_expansion.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 | // Code generated by client-gen. DO NOT EDIT. 18 | 19 | package v1 20 | 21 | type PodExpansion interface{} 22 | 23 | type PodLogsExpansion interface{} 24 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/informers_generated/externalversions/generic.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 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package externalversions 20 | 21 | import ( 22 | "fmt" 23 | 24 | schema "k8s.io/apimachinery/pkg/runtime/schema" 25 | cache "k8s.io/client-go/tools/cache" 26 | v1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/apis/podlogs/v1" 27 | ) 28 | 29 | // GenericInformer is type of SharedIndexInformer which will locate and delegate to other 30 | // sharedInformers based on type 31 | type GenericInformer interface { 32 | Informer() cache.SharedIndexInformer 33 | Lister() cache.GenericLister 34 | } 35 | 36 | type genericInformer struct { 37 | informer cache.SharedIndexInformer 38 | resource schema.GroupResource 39 | } 40 | 41 | // Informer returns the SharedIndexInformer. 42 | func (f *genericInformer) Informer() cache.SharedIndexInformer { 43 | return f.informer 44 | } 45 | 46 | // Lister returns the GenericLister. 47 | func (f *genericInformer) Lister() cache.GenericLister { 48 | return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) 49 | } 50 | 51 | // ForResource gives generic access to a shared informer of the matching type 52 | // TODO extend this to unknown resources with a client pool 53 | func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { 54 | switch resource { 55 | // Group=podlogs.example.com, Version=v1 56 | case v1.SchemeGroupVersion.WithResource("pods"): 57 | return &genericInformer{resource: resource.GroupResource(), informer: f.Podlogs().V1().Pods().Informer()}, nil 58 | case v1.SchemeGroupVersion.WithResource("podlogses"): 59 | return &genericInformer{resource: resource.GroupResource(), informer: f.Podlogs().V1().PodLogses().Informer()}, nil 60 | 61 | } 62 | 63 | return nil, fmt.Errorf("no informer found for %v", resource) 64 | } 65 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/informers_generated/externalversions/internalinterfaces/factory_interfaces.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 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package internalinterfaces 20 | 21 | import ( 22 | time "time" 23 | 24 | v1 "k8s.io/apimachinery/pkg/apis/meta/v1" 25 | runtime "k8s.io/apimachinery/pkg/runtime" 26 | cache "k8s.io/client-go/tools/cache" 27 | clientset "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/clientset_generated/clientset" 28 | ) 29 | 30 | // NewInformerFunc takes clientset.Interface and time.Duration to return a SharedIndexInformer. 31 | type NewInformerFunc func(clientset.Interface, time.Duration) cache.SharedIndexInformer 32 | 33 | // SharedInformerFactory a small interface to allow for adding an informer without an import cycle 34 | type SharedInformerFactory interface { 35 | Start(stopCh <-chan struct{}) 36 | InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer 37 | } 38 | 39 | // TweakListOptionsFunc is a function that transforms a v1.ListOptions. 40 | type TweakListOptionsFunc func(*v1.ListOptions) 41 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/informers_generated/externalversions/podlogs/interface.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 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package podlogs 20 | 21 | import ( 22 | internalinterfaces "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/informers_generated/externalversions/internalinterfaces" 23 | v1 "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/informers_generated/externalversions/podlogs/v1" 24 | ) 25 | 26 | // Interface provides access to each of this group's versions. 27 | type Interface interface { 28 | // V1 provides access to shared informers for resources in V1. 29 | V1() v1.Interface 30 | } 31 | 32 | type group struct { 33 | factory internalinterfaces.SharedInformerFactory 34 | namespace string 35 | tweakListOptions internalinterfaces.TweakListOptionsFunc 36 | } 37 | 38 | // New returns a new Interface. 39 | func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { 40 | return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} 41 | } 42 | 43 | // V1 returns a new v1.Interface. 44 | func (g *group) V1() v1.Interface { 45 | return v1.New(g.factory, g.namespace, g.tweakListOptions) 46 | } 47 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/informers_generated/externalversions/podlogs/v1/interface.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 | // Code generated by informer-gen. DO NOT EDIT. 18 | 19 | package v1 20 | 21 | import ( 22 | internalinterfaces "sigs.k8s.io/apiserver-builder-alpha/example/podlogs/pkg/client/informers_generated/externalversions/internalinterfaces" 23 | ) 24 | 25 | // Interface provides access to all the informers in this group version. 26 | type Interface interface { 27 | // Pods returns a PodInformer. 28 | Pods() PodInformer 29 | // PodLogses returns a PodLogsInformer. 30 | PodLogses() PodLogsInformer 31 | } 32 | 33 | type version struct { 34 | factory internalinterfaces.SharedInformerFactory 35 | namespace string 36 | tweakListOptions internalinterfaces.TweakListOptionsFunc 37 | } 38 | 39 | // New returns a new Interface. 40 | func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { 41 | return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} 42 | } 43 | 44 | // Pods returns a PodInformer. 45 | func (v *version) Pods() PodInformer { 46 | return &podInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} 47 | } 48 | 49 | // PodLogses returns a PodLogsInformer. 50 | func (v *version) PodLogses() PodLogsInformer { 51 | return &podLogsInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} 52 | } 53 | -------------------------------------------------------------------------------- /example/podlogs/pkg/client/listers_generated/podlogs/v1/expansion_generated.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 | // Code generated by lister-gen. DO NOT EDIT. 18 | 19 | package v1 20 | 21 | // PodListerExpansion allows custom methods to be added to 22 | // PodLister. 23 | type PodListerExpansion interface{} 24 | 25 | // PodNamespaceListerExpansion allows custom methods to be added to 26 | // PodNamespaceLister. 27 | type PodNamespaceListerExpansion interface{} 28 | 29 | // PodLogsListerExpansion allows custom methods to be added to 30 | // PodLogsLister. 31 | type PodLogsListerExpansion interface{} 32 | 33 | // PodLogsNamespaceListerExpansion allows custom methods to be added to 34 | // PodLogsNamespaceLister. 35 | type PodLogsNamespaceListerExpansion interface{} 36 | -------------------------------------------------------------------------------- /example/podlogs/pkg/controller/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | package controller 22 | 23 | -------------------------------------------------------------------------------- /example/podlogs/pkg/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | package pkg 22 | 23 | -------------------------------------------------------------------------------- /example/podlogs/pkg/openapi/doc.go: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | Copyright 2019 The Kubernetes Authors. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | */ 17 | 18 | 19 | 20 | 21 | package openapi 22 | 23 | -------------------------------------------------------------------------------- /example/podlogs/pkg/webhook/webhook.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 webhook 18 | 19 | import ( 20 | "sigs.k8s.io/controller-runtime/pkg/manager" 21 | ) 22 | 23 | // AddToManagerFuncs is a list of functions to add all Controllers to the Manager 24 | var AddToManagerFuncs []func(manager.Manager) error 25 | 26 | // AddToManager adds all Controllers to the Manager 27 | // +kubebuilder:rbac:groups=admissionregistration.k8s.io,resources=mutatingwebhookconfigurations;validatingwebhookconfigurations,verbs=get;list;watch;create;update;patch;delete 28 | // +kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete 29 | // +kubebuilder:rbac:groups="",resources=services,verbs=get;list;watch;create;update;patch;delete 30 | func AddToManager(m manager.Manager) error { 31 | for _, f := range AddToManagerFuncs { 32 | if err := f(m); err != nil { 33 | return err 34 | } 35 | } 36 | return nil 37 | } 38 | -------------------------------------------------------------------------------- /example/podlogs/plugin/admission/install/zz_generated.api.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 | // This file was autogenerated by apiregister-gen. Do not edit it manually! 18 | 19 | package install 20 | -------------------------------------------------------------------------------- /example/podlogs/sample/pod.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: podlogs.example.com/v1 2 | kind: Pod 3 | metadata: 4 | name: pod-example 5 | spec: 6 | -------------------------------------------------------------------------------- /pkg/boot/build/build.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 build 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | var buildCmd = &cobra.Command{ 24 | Use: "build", 25 | Short: "Command group for building source into artifacts.", 26 | Long: `Command group for building source into artifacts.`, 27 | Example: `# Generate code and build the apiserver and controller-manager binaries into bin/ 28 | apiserver-boot build executables 29 | 30 | # Build a container with the apiserver and controller-manager executables 31 | apiserver-boot build container --image gcr.io/myrepo/myimage:mytag 32 | 33 | # Build resource config for running an aggregated apiserver in cluster 34 | apiserver-boot build config --name nameofservice --namespace mysystemnamespace --image gcr.io/myrepo/myimage:mytag 35 | `, 36 | Run: RunBuild, 37 | } 38 | 39 | func AddBuild(cmd *cobra.Command) { 40 | cmd.AddCommand(buildCmd) 41 | 42 | AddBuildExecutables(buildCmd) 43 | AddBuildContainer(buildCmd) 44 | AddBuildResourceConfig(buildCmd) 45 | AddDocs(buildCmd) 46 | } 47 | 48 | func RunBuild(cmd *cobra.Command, args []string) { 49 | cmd.Help() 50 | } 51 | -------------------------------------------------------------------------------- /pkg/boot/build/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 build 18 | 19 | import ( 20 | "io/ioutil" 21 | "path" 22 | "path/filepath" 23 | "regexp" 24 | 25 | "k8s.io/klog/v2" 26 | ) 27 | 28 | var versionedAPIs []string 29 | var unversionedAPIs []string 30 | var vendorDir string 31 | 32 | func initApis() { 33 | if len(versionedAPIs) == 0 { 34 | groups, err := ioutil.ReadDir(filepath.Join("pkg", "apis")) 35 | if err != nil { 36 | klog.Fatalf("could not read pkg/apis directory to find api Versions") 37 | } 38 | for _, g := range groups { 39 | if g.IsDir() { 40 | versionFiles, err := ioutil.ReadDir(filepath.Join("pkg", "apis", g.Name())) 41 | if err != nil { 42 | klog.Fatalf("could not read pkg/apis/%s directory to find api Versions", g.Name()) 43 | } 44 | versionMatch := regexp.MustCompile("^v\\d+(alpha\\d+|beta\\d+)*$") 45 | for _, v := range versionFiles { 46 | if v.IsDir() && versionMatch.MatchString(v.Name()) { 47 | versionedAPIs = append(versionedAPIs, filepath.Join(g.Name(), v.Name())) 48 | } 49 | } 50 | } 51 | } 52 | } 53 | u := map[string]bool{} 54 | for _, a := range versionedAPIs { 55 | u[path.Dir(a)] = true 56 | } 57 | for a := range u { 58 | unversionedAPIs = append(unversionedAPIs, a) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /pkg/boot/create/create.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 create 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | "path/filepath" 22 | ) 23 | 24 | var createCmd = &cobra.Command{ 25 | Use: "create", 26 | Short: "Command group for bootstrapping new resources.", 27 | Long: `Command group for bootstrapping new resources.`, 28 | Example: `# Create new resource "Bee" in the "insect" group with version "v1beta1" 29 | # Will automatically the group and version if they do not exist 30 | apiserver-boot create group version resource --group insect --version v1beta1 --kind Bee 31 | 32 | # Create a new group "insect" 33 | apiserver-boot create group --group insect 34 | 35 | # Create a new version "v1beta" of group "insect" 36 | # Will automatically create group if it does not exist 37 | apiserver-boot create group --group insect --version v1beta1`, 38 | Run: RunCreate, 39 | } 40 | 41 | var copyright string 42 | 43 | func AddCreate(cmd *cobra.Command) { 44 | cmd.AddCommand(createCmd) 45 | cmd.Flags().StringVar(©right, "copyright", filepath.Join("hack", "boilerplate.go.txt"), "Location of copyright boilerplate file.") 46 | AddCreateGroup(createCmd) 47 | AddCreateResource(createCmd) 48 | AddCreateSubresource(createCmd) 49 | AddCreateVersion(createCmd) 50 | } 51 | 52 | func RunCreate(cmd *cobra.Command, args []string) { 53 | cmd.Help() 54 | } 55 | -------------------------------------------------------------------------------- /pkg/boot/create/group.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 create 18 | 19 | import ( 20 | "os" 21 | "path/filepath" 22 | "strings" 23 | 24 | "github.com/spf13/cobra" 25 | "k8s.io/klog/v2" 26 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/util" 27 | ) 28 | 29 | var createGroupCmd = &cobra.Command{ 30 | Use: "group", 31 | Short: "Creates an API group", 32 | Long: `Creates an API group.`, 33 | Run: RunCreateGroup, 34 | } 35 | 36 | var groupName string 37 | var ignoreGroupExists bool = false 38 | 39 | func AddCreateGroup(cmd *cobra.Command) { 40 | createGroupCmd.Flags().StringVar(&groupName, "group", "", "name of the API group to create") 41 | 42 | cmd.AddCommand(createGroupCmd) 43 | createGroupCmd.AddCommand(createVersionCmd) 44 | } 45 | 46 | func RunCreateGroup(cmd *cobra.Command, args []string) { 47 | if _, err := os.Stat("pkg"); err != nil { 48 | klog.Fatalf("could not find 'pkg' directory. must run apiserver-boot init before creating resources") 49 | } 50 | 51 | util.GetDomain() 52 | if len(groupName) == 0 { 53 | klog.Fatalf("Must specify --group") 54 | } 55 | 56 | if strings.ToLower(groupName) != groupName { 57 | klog.Fatalf("--group must be lowercase was (%s)", groupName) 58 | } 59 | 60 | createGroup(util.GetCopyright(copyright)) 61 | } 62 | 63 | func createGroup(boilerplate string) { 64 | dir, err := os.Getwd() 65 | if err != nil { 66 | klog.Fatal(err) 67 | } 68 | 69 | a := groupTemplateArgs{ 70 | boilerplate, 71 | util.Domain, 72 | groupName, 73 | } 74 | 75 | path := filepath.Join(dir, "pkg", "apis", groupName, "doc.go") 76 | created := util.WriteIfNotFound(path, "group-template", groupTemplate, a) 77 | 78 | if !created && !ignoreGroupExists { 79 | klog.Fatalf("API group %s already exists.", groupName) 80 | } 81 | } 82 | 83 | type groupTemplateArgs struct { 84 | BoilerPlate string 85 | Domain string 86 | Name string 87 | } 88 | 89 | var groupTemplate = ` 90 | {{.BoilerPlate}} 91 | 92 | 93 | // +k8s:deepcopy-gen=package,register 94 | // +groupName={{.Name}}.{{.Domain}} 95 | 96 | // Package api is the internal version of the API. 97 | package {{.Name}} 98 | 99 | ` 100 | 101 | var installTemplate = ` 102 | {{.BoilerPlate}} 103 | 104 | package {{.Name}} 105 | ` 106 | -------------------------------------------------------------------------------- /pkg/boot/init_repo/init.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 init_repo 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | var initCmd = &cobra.Command{ 24 | Use: "init", 25 | Short: "Command group for bootstrapping new go projects.", 26 | Long: `Command group for bootstrapping new go projects.`, 27 | Example: ` 28 | # Bootstrap a new repo 29 | apiserver-boot init repo --domain example.com 30 | `, 31 | Run: RunInit, 32 | } 33 | 34 | func AddInit(cmd *cobra.Command) { 35 | cmd.AddCommand(initCmd) 36 | AddInitRepo(initCmd) 37 | } 38 | 39 | func RunInit(cmd *cobra.Command, args []string) { 40 | cmd.Help() 41 | } 42 | -------------------------------------------------------------------------------- /pkg/boot/init_repo/template.go: -------------------------------------------------------------------------------- 1 | package init_repo 2 | 3 | import _ "embed" 4 | 5 | var ( 6 | //go:embed templates/go.mod.tpl 7 | goModTemplate string 8 | //go:embed templates/apiserver.tpl 9 | apiserverTemplate string 10 | //go:embed templates/api.doc.tpl 11 | apisDocTemplate string 12 | //go:embed templates/package.doc.tpl 13 | packageDocTemplate string 14 | ) 15 | -------------------------------------------------------------------------------- /pkg/boot/init_repo/templates/api.doc.tpl: -------------------------------------------------------------------------------- 1 | {{.BoilerPlate}} 2 | 3 | 4 | //go:generate apiregister-gen --input-dirs ./... -h ../../boilerplate.go.txt 5 | 6 | // 7 | // +domain={{.Domain}} 8 | 9 | package apis 10 | -------------------------------------------------------------------------------- /pkg/boot/init_repo/templates/apiserver.tpl: -------------------------------------------------------------------------------- 1 | {{.BoilerPlate}} 2 | 3 | package main 4 | 5 | import ( 6 | "k8s.io/klog" 7 | "sigs.k8s.io/apiserver-runtime/pkg/builder" 8 | 9 | // +kubebuilder:scaffold:resource-imports 10 | ) 11 | 12 | func main() { 13 | err := builder.APIServer. 14 | // +kubebuilder:scaffold:resource-register 15 | Execute() 16 | if err != nil { 17 | klog.Fatal(err) 18 | } 19 | } -------------------------------------------------------------------------------- /pkg/boot/init_repo/templates/go.mod.tpl: -------------------------------------------------------------------------------- 1 | module {{.Repo}} 2 | 3 | go 1.17 4 | 5 | require ( 6 | github.com/go-logr/logr v0.2.1 // indirect 7 | github.com/go-logr/zapr v0.2.0 // indirect 8 | k8s.io/apimachinery v0.19.2 9 | k8s.io/client-go v0.19.2 10 | k8s.io/klog v1.0.0 11 | sigs.k8s.io/apiserver-runtime v1.0.3 12 | sigs.k8s.io/controller-runtime v0.11.1 13 | ) -------------------------------------------------------------------------------- /pkg/boot/init_repo/templates/package.doc.tpl: -------------------------------------------------------------------------------- 1 | {{.BoilerPlate}} 2 | 3 | {{.GoGenerateCommand}} 4 | package {{.Package}} 5 | -------------------------------------------------------------------------------- /pkg/boot/run/in_cluster.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 run 18 | 19 | import ( 20 | "path/filepath" 21 | 22 | "github.com/spf13/cobra" 23 | 24 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/build" 25 | "sigs.k8s.io/apiserver-builder-alpha/pkg/boot/util" 26 | ) 27 | 28 | var runInClusterCmd = &cobra.Command{ 29 | Use: "in-cluster", 30 | Short: "run the etcd, apiserver and the controller-manager as an aggegrated apiserver in a cluster", 31 | Long: `run the etcd, apiserver and the controller-manager as an aggegrated apiserver in a cluster`, 32 | Example: ` 33 | # Build a new image and run the apiserver and controller-manager in the cluster 34 | apiserver-boot run in-cluster --name example --namespace default --image gcr.io/myrepo/myimage:mytag 35 | 36 | # Clear the discovery cache for kubectl 37 | rm -rf ~/.kube/cache/discovery/ 38 | 39 | # Run kubectl and check for the new version 40 | kubectl api-versions 41 | 42 | # Create an instance and fetch it 43 | nano -w samples/.yaml 44 | kubectl apply -f samples/.yaml 45 | kubectl get `, 46 | Run: RunInCluster, 47 | } 48 | 49 | var buildImage bool 50 | var pushImage bool 51 | 52 | func AddInCluster(cmd *cobra.Command) { 53 | cmd.AddCommand(runInClusterCmd) 54 | 55 | build.AddBuildResourceConfigFlags(runInClusterCmd) 56 | runInClusterCmd.Flags().BoolVar(&buildImage, "build-image", true, "if true, build the container image.") 57 | runInClusterCmd.Flags().BoolVar(&buildImage, "push-image", true, "if true, push it to the image repo.") 58 | } 59 | 60 | func RunInCluster(cmd *cobra.Command, args []string) { 61 | if buildImage { 62 | // Build the container first 63 | build.RunBuildContainer(cmd, args) 64 | 65 | // Push the image 66 | if pushImage { 67 | util.DoCmd("docker", "push", build.Image) 68 | } 69 | } 70 | 71 | // Build the resource config 72 | build.RunBuildResourceConfig(cmd, args) 73 | 74 | // Apply the new config 75 | util.DoCmd("kubectl", "apply", "-f", filepath.Join(build.ResourceConfigDir)) 76 | } 77 | -------------------------------------------------------------------------------- /pkg/boot/run/run.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 run 18 | 19 | import ( 20 | "github.com/spf13/cobra" 21 | ) 22 | 23 | var runCmd = &cobra.Command{ 24 | Use: "run", 25 | Short: "Command group for launching instances.", 26 | Long: `Command group for launching instances.`, 27 | Example: `# Run a local etcd, apiserver and controller-manager. 28 | apiserver-boot run local 29 | 30 | # Check the api versions of the locally running server 31 | kubectl --kubeconfig kubeconfig api-versions 32 | 33 | # Run a etcd, apiserver and controller-manager remotely in a Kubernetes cluster as an aggregated apiserver 34 | apiserver-boot run in-cluster 35 | 36 | # Clear the discovery service cache 37 | rm -rf ~/.kube/cache/discovery/ 38 | 39 | # Check the api versions of the remotely running server 40 | kubectl api-versions`, 41 | Run: RunRun, 42 | } 43 | 44 | func AddRun(cmd *cobra.Command) { 45 | cmd.AddCommand(runCmd) 46 | AddInCluster(runCmd) 47 | AddLocal(runCmd) 48 | } 49 | 50 | func RunRun(cmd *cobra.Command, args []string) { 51 | cmd.Help() 52 | } 53 | -------------------------------------------------------------------------------- /pkg/boot/show/cmd.go: -------------------------------------------------------------------------------- 1 | package show 2 | 3 | import ( 4 | "os" 5 | 6 | "github.com/spf13/cobra" 7 | "k8s.io/cli-runtime/pkg/genericclioptions" 8 | ) 9 | 10 | var streams = genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr} 11 | var clientFactory *genericclioptions.ConfigFlags 12 | 13 | var showCmd = &cobra.Command{ 14 | Use: "show", 15 | Short: "Command group for show the installed aggregated apiserver.", 16 | Long: `Command group for show the installed aggregated apiserver.`, 17 | Example: ` 18 | # Show the current status for foo resource. 19 | apiserver-boot show resource foo 20 | `, 21 | Run: RunShow, 22 | } 23 | 24 | func AddShow(cmd *cobra.Command) { 25 | cmd.AddCommand(showCmd) 26 | AddShowResource(showCmd) 27 | AddApiserver(showCmd) 28 | } 29 | 30 | func RunShow(cmd *cobra.Command, args []string) { 31 | cmd.Help() 32 | } 33 | -------------------------------------------------------------------------------- /pkg/boot/util/repo.go: -------------------------------------------------------------------------------- 1 | package util 2 | 3 | import ( 4 | "fmt" 5 | "io/ioutil" 6 | "os" 7 | "path/filepath" 8 | "strings" 9 | 10 | "github.com/pkg/errors" 11 | "golang.org/x/mod/modfile" 12 | "k8s.io/klog/v2" 13 | ) 14 | 15 | var repo string 16 | 17 | func LoadRepoFromGoPath() error { 18 | gopath := os.Getenv("GOPATH") 19 | if len(gopath) == 0 { 20 | return fmt.Errorf("GOPATH not defined") 21 | } 22 | goSrc := filepath.Join(gopath, "src") 23 | wd, err := os.Getwd() 24 | if err != nil { 25 | return err 26 | } 27 | if !strings.HasPrefix(filepath.Dir(wd), goSrc) { 28 | return fmt.Errorf("apiserver-boot must be run from the directory containing the go package to "+ 29 | "bootstrap. This must be under $GOPATH/src/. "+ 30 | "\nCurrent GOPATH=%s. \nCurrent directory=%s", gopath, wd) 31 | } 32 | repo = strings.Replace(wd, goSrc+string(filepath.Separator), "", 1) 33 | return nil 34 | } 35 | 36 | func LoadRepoFromGoMod() error { 37 | mod, err := ioutil.ReadFile("go.mod") 38 | if err != nil { 39 | return errors.Wrap(err, "failed reading go.mod file") 40 | } 41 | modPath := modfile.ModulePath(mod) 42 | if len(modPath) == 0 { 43 | return fmt.Errorf("failed parsing go.mod, empty module path") 44 | } 45 | repo = modPath 46 | return nil 47 | } 48 | 49 | func LoadRepoFromGoPathOrGoMod() error { 50 | if err := LoadRepoFromGoMod(); err != nil { 51 | // reading from go mod 52 | return LoadRepoFromGoPath() 53 | } 54 | return nil 55 | } 56 | 57 | func GetRepo() string { 58 | if len(repo) > 0 { 59 | return repo 60 | } 61 | if err := LoadRepoFromGoPathOrGoMod(); err != nil { 62 | klog.Fatal(err) 63 | } 64 | return repo 65 | } 66 | 67 | func SetRepo(r string) { 68 | repo = r 69 | } 70 | -------------------------------------------------------------------------------- /pkg/boot/version/version.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 version 18 | 19 | import ( 20 | "runtime" 21 | 22 | "github.com/spf13/cobra" 23 | "k8s.io/klog/v2" 24 | ) 25 | 26 | var ( 27 | apiserverBuilderVersion = "unknown" 28 | kubernetesVendorVersion = "unknown" 29 | goos = runtime.GOOS 30 | goarch = runtime.GOARCH 31 | gitCommit = "$Format:%H$" // sha1 from git, output of $(git rev-parse HEAD) 32 | 33 | buildDate = "1970-01-01T00:00:00Z" // build date in ISO8601 format, output of $(date -u +'%Y-%m-%dT%H:%M:%SZ') 34 | ) 35 | 36 | type Version struct { 37 | ApiserverBuilderVersion string `json:"apiserverBuilderVersion"` 38 | KubernetesVendor string `json:"kubernetesVendor"` 39 | GitCommit string `json:"gitCommit"` 40 | BuildDate string `json:"buildDate"` 41 | GoOs string `json:"goOs"` 42 | GoArch string `json:"goArch"` 43 | } 44 | 45 | func GetVersion() Version { 46 | return Version{ 47 | apiserverBuilderVersion, 48 | kubernetesVendorVersion, 49 | gitCommit, 50 | buildDate, 51 | goos, 52 | goarch, 53 | } 54 | } 55 | 56 | func (v Version) Print() { 57 | klog.Infof("Version: %#v", v) 58 | } 59 | 60 | var versionCmd = &cobra.Command{ 61 | Use: "version", 62 | Short: "Print the apisever-builder version.", 63 | Long: `Print the apisever-builder version.`, 64 | Example: `apiserver-boot version`, 65 | Run: RunVersion, 66 | } 67 | 68 | func AddVersion(cmd *cobra.Command) { 69 | cmd.AddCommand(versionCmd) 70 | } 71 | 72 | func RunVersion(cmd *cobra.Command, args []string) { 73 | GetVersion().Print() 74 | } 75 | -------------------------------------------------------------------------------- /pkg/utils/prefixwriter.go: -------------------------------------------------------------------------------- 1 | // Copyright Contributors to the Open Cluster Management project 2 | package utils 3 | 4 | import ( 5 | "fmt" 6 | "io" 7 | "time" 8 | 9 | "github.com/briandowns/spinner" 10 | "github.com/fatih/color" 11 | corev1 "k8s.io/api/core/v1" 12 | ) 13 | 14 | var suffixColor = color.New(color.Bold, color.FgGreen) 15 | 16 | // PrefixWriter can write text at various indentation levels. 17 | type PrefixWriter interface { 18 | // Write writes text with the specified indentation level. 19 | Write(level int, format string, a ...interface{}) 20 | // WriteLine writes an entire line with no indentation level. 21 | WriteLine(a ...interface{}) 22 | // Flush forces indentation to be reset. 23 | Flush() 24 | } 25 | 26 | // Each level has 2 spaces for PrefixWriter 27 | const ( 28 | LEVEL_0 = iota 29 | LEVEL_1 30 | LEVEL_2 31 | LEVEL_3 32 | LEVEL_4 33 | ) 34 | 35 | // prefixWriter implements PrefixWriter 36 | type prefixWriter struct { 37 | out io.Writer 38 | } 39 | 40 | var _ PrefixWriter = &prefixWriter{} 41 | 42 | // NewPrefixWriter creates a new PrefixWriter. 43 | func NewPrefixWriter(out io.Writer) PrefixWriter { 44 | return &prefixWriter{out: out} 45 | } 46 | 47 | func (pw *prefixWriter) Write(level int, format string, a ...interface{}) { 48 | levelSpace := " " 49 | prefix := "" 50 | for i := 0; i < level; i++ { 51 | prefix += levelSpace 52 | } 53 | fmt.Fprintf(pw.out, prefix+format, a...) 54 | } 55 | 56 | func (pw *prefixWriter) WriteLine(a ...interface{}) { 57 | fmt.Fprintln(pw.out, a...) 58 | } 59 | 60 | func (pw *prefixWriter) Flush() { 61 | if f, ok := pw.out.(flusher); ok { 62 | f.Flush() 63 | } 64 | } 65 | 66 | type flusher interface { 67 | Flush() 68 | } 69 | 70 | func NewSpinner(suffix string, interval time.Duration) *spinner.Spinner { 71 | return spinner.New( 72 | spinner.CharSets[14], 73 | interval, 74 | spinner.WithColor("green"), 75 | spinner.WithHiddenCursor(true), 76 | spinner.WithSuffix(suffixColor.Sprintf(" %s", suffix))) 77 | } 78 | 79 | func NewSpinnerWithStatus(suffix string, interval time.Duration, final string, statusFunc func() string) *spinner.Spinner { 80 | s := NewSpinner(suffix, interval) 81 | s.FinalMSG = final 82 | s.PreUpdate = func(s *spinner.Spinner) { 83 | status := statusFunc() 84 | if len(status) > 0 { 85 | s.Suffix = suffixColor.Sprintf(" %s (%s)", suffix, status) 86 | } else { 87 | s.Suffix = suffixColor.Sprintf(" %s", suffix) 88 | } 89 | } 90 | return s 91 | } 92 | 93 | func GetSpinnerPodStatus(pod *corev1.Pod) string { 94 | reason := string(pod.Status.Phase) 95 | for _, containerStatus := range pod.Status.ContainerStatuses { 96 | if containerStatus.State.Waiting != nil { 97 | reason = containerStatus.State.Waiting.Reason 98 | } 99 | } 100 | return reason 101 | } 102 | -------------------------------------------------------------------------------- /scripts/print-workspace-status.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -o errexit 4 | set -o nounset 5 | set -o pipefail 6 | 7 | SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. 8 | 9 | apiserver_builder_version=$(git describe --always --tags HEAD) 10 | k8s_vendor=kubernetes-1.19.2 11 | git_commit="$(git describe --always --tags HEAD)" 12 | build_date="$(date +%Y-%m-%d-%H:%M:%S)" 13 | 14 | cat <