Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document how to build and deploy the sample-apiserver #73447

Merged

sample-apiserver/README.md: more/better doc on fetching sample-apiser…

…ver and its dependencies
  • Loading branch information...
MikeSpreitzer committed May 18, 2019
commit 35710c5d2a9a767eb7152a9f0c382b84a0227b8e
@@ -24,26 +24,58 @@ HEAD of this repo will match HEAD of k8s.io/apiserver, k8s.io/apimachinery, and
`sample-apiserver` is synced from https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/sample-apiserver.
Code changes are made in that location, merged into `k8s.io/kubernetes` and later synced here.

## Fetch Dependencies
## Fetch sample-apiserver and its dependencies

Using `godep` will work.
Like the rest of Kubernetes, sample-apiserver has used
[godep](https://github.com/tools/godep) and `$GOPATH` for years and is
now adopting go 1.11 modules. There are thus two alternative ways to
go about fetching this demo and its dependencies.

### Fetch with godep

When NOT using go 1.11 modules, you can use the following commands.

```sh
go get -d k8s.io/sample-apiserver
cd $GOPATH/src/k8s.io/sample-apiserver # assuming your GOPATH has just one entry
godep restore
```

### When using go 1.11 modules

When using go 1.11 modules (`GO111MODULE=on`), issue the following
commands --- starting in whatever working directory you like.

```sh
git clone https://github.com/kubernetes/sample-apiserver.git
cd sample-apiserver
```

Note, however, that if you intend to
[generate code](#changes-to-the-types) then you will also need the
code-generator repo to exist in an old-style location. One easy way
to do this is to use the command `go mod vendor` to create and
popdulate the `vendor` directory.

### A Note on kubernetes/kubernetes

If you are developing Kubernetes according to
https://github.com/kubernetes/community/blob/master/contributors/guide/github-workflow.md
then you already have a copy of this demo in
`kubernetes/staging/src/k8s.io/sample-apiserver` and its dependencies
--- including the code generator --- are in usable locations.

Using Go modules (`GO111MODULE=on`) will enable `go build` to work,
without putting dependencies anywhere obvious.

## Normal Build and Deploy

### Changes to the Types

If you change the API object type definitions in any of the
`pkg/apis/.../types.go` files then you will need to update the files
generated from the type definitions. To do this, invoke
`hack/update-codegen.sh` with `sample-apiserver` as your current
working directory; the script takes no arguments. But this requires
certain dependencies to appear on your `$GOPATH` or in a local
`vendor` directory. If you used Go modules then issue the command `go
mod vendor` before `hack/update-codegen.sh`, to first create a local
`vendor` directory with the needed dependencies.
generated from the type definitions. To do this, first
[create the vendor directory if necessary](#when-using-go-111-modules)
and then invoke `hack/update-codegen.sh` with `sample-apiserver` as
your current working directory; the script takes no arguments.

### Build the Binary

@@ -65,15 +97,6 @@ docker build -t MYPREFIX/kube-sample-apiserver:MYTAG ./artifacts/simple-image
docker push MYPREFIX/kube-sample-apiserver:MYTAG

This comment has been minimized.

Copy link
@caesarxuchao

caesarxuchao Feb 12, 2019

Member

Can you update the hack/build-image.sh?

Maybe we can add the go build command to the script as well.

This comment has been minimized.

Copy link
@MikeSpreitzer

MikeSpreitzer May 9, 2019

Author Member

I presume hack/build-image.sh is used by some stuff, which would have to be changed if I modified that script to take MYPREFIX and MYTAG as parameters --- but I do not know what that stuff is. I suggest leaving this to a separate PR.

```


### Build Binary and Container Image from Current Master Source

There is a Dockerfile at
https://github.com/kubernetes/kubernetes/blob/master/test/images/sample-apiserver/Dockerfile
that will build the binary, and a container image with that binary,
from the current `master` branch.


### Deploy into a Kubernetes Cluster

Edit `artifacts/example/rc.yaml`, updating the pod template's image
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.