Skip to content

Commit

Permalink
# This is a combination of 15 commits.
Browse files Browse the repository at this point in the history
# This is the 1st commit message:

Document adding an external type

# This is the commit message kubernetes-sigs#2:

Fix typo in book: flag is --owner, not --owners

# This is the commit message kubernetes-sigs#3:

gitbook: fixed installation instructions

# This is the commit message kubernetes-sigs#4:

Fix domain resource issues in controller

- fix in controller-tools and vendor in kubebuilder
- bind resource for controller based on whether resource is created.

# This is the commit message kubernetes-sigs#5:

improve contributing guide

# This is the commit message kubernetes-sigs#6:

Fix URL for the Gitbook

The URL is .io, not .com
# This is the commit message kubernetes-sigs#7:

Check go version

Fixes kubernetes-sigs#353

# This is the commit message kubernetes-sigs#8:

Validate create api flags

Fixes kubernetes-sigs#321

# This is the commit message kubernetes-sigs#9:

Update stable version in book

Update newest stable version to "1.0.1".

# This is the commit message kubernetes-sigs#10:

thirdparty tools: Dockerfile uses k8s 1.11

# This is the commit message kubernetes-sigs#11:

build: update cloudbuild config for building tools to use k8s 1.11

# This is the commit message kubernetes-sigs#12:

add document for connecting to existing kind

# This is the commit message kubernetes-sigs#13:

add document for connecting to existing kind

# This is the commit message kubernetes-sigs#14:

removed company from doc

# This is the commit message kubernetes-sigs#15:

fixed typo
  • Loading branch information
superbrothers authored and jkevlin committed Aug 22, 2018
1 parent b1c1234 commit 9f1c319
Show file tree
Hide file tree
Showing 51 changed files with 3,165 additions and 124 deletions.
57 changes: 27 additions & 30 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
## Sign the CLA

Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests.
Please see https://git.k8s.io/community/CLA.md for more info

### Contributing A Patch
Please see https://git.k8s.io/community/CLA.md for more info.

## Contributing steps

1. Submit an issue describing your proposed change to the repo in question.
1. The [repo owners](OWNERS) will respond to your issue promptly.
Expand All @@ -15,31 +16,29 @@ Please see https://git.k8s.io/community/CLA.md for more info

## How to build kubebuilder locally

Setup:

- Download [google container builder](https://cloud.google.com/container-builder/docs/build-debug-locally)
- Export `OUTPUT` to a location to write the directory containing the final build artifacts

```sh
export OUTPUT=/tmp/kubebuilder
```

Run container-builder:

```sh
container-builder-local --config=build/cloudbuild_local.yaml --dryrun=false \
--write-workspace=$OUTPUT .
```

Extract `tar.gz` from $OUTPUT to /usr/local

## Running kubebuilder tests

```sh
go test ./pkg/...
```

## Community, discussion, contribution, and support
1. Setup tools
1. Download and setup [gcloud](https://cloud.google.com/sdk/docs/downloads-interactive)
1. Install `cloud-build-local` via `gcloud`
```bash
$ gcloud install cloud-build-local
```
1. Build
1. Export `OUTPUT` to a location to write the directory containing the final build artifacts
```sh
$ export OUTPUT=/tmp/kubebuilder
```
2. Run container-builder:
```sh
$ cloud-build-local --config=build/cloudbuild_local.yaml --dryrun=false \
--write-workspace=$OUTPUT .
```
1. Extract `tar.gz` from $OUTPUT to /usr/local
1. Test
```sh
go test ./pkg/...
```

## Community, discussion and support

Learn how to engage with the Kubernetes community on the [community page](http://kubernetes.io/community/).

Expand All @@ -48,8 +47,6 @@ You can reach the maintainers of this project at:
- [Slack](http://slack.k8s.io/)
- [Mailing List](https://groups.google.com/forum/#!forum/kubernetes-kubebuilder)

### Code of conduct
## Code of conduct

Participation in the Kubernetes community is governed by the [Kubernetes Code of Conduct](code-of-conduct.md).

[google container builder]: https://github.com/kubernetes-sigs/container-builder-local
2 changes: 1 addition & 1 deletion build/cloudbuild_tools.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

steps:
- name: "gcr.io/kubebuilder/thirdparty-${_GOOS}:1.10.1"
- name: "gcr.io/kubebuilder/thirdparty-${_GOOS}:1.11.0"
args: ["cp", "/kubebuilder_${_GOOS}_${_GOARCH}.tar.gz", "/workspace/kubebuilder-${TAG_NAME}-${_GOOS}-${_GOARCH}.tar.gz"]
env:
- 'GOOS=${_GOOS}'
Expand Down
16 changes: 8 additions & 8 deletions build/thirdparty/darwin/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
# - reference-docs

# Build k8s.io/kubernetes binaries
FROM golang:1.10-stretch as kubernetes-darwin
FROM golang:1.10.2-stretch as kubernetes-darwin
# Install tools
RUN apt update
RUN apt install rsync -y
RUN go get github.com/jteeuwen/go-bindata/go-bindata
ENV CGO 0
ENV DEST /usr/local/kubebuilder/bin/
RUN mkdir -p $DEST || echo ""
RUN git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes --depth=1 -b release-1.10
RUN git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes --depth=1 -b release-1.11
WORKDIR /go/src/k8s.io/kubernetes

# Build for linux first otherwise it won't work for darwin - :(
Expand All @@ -52,7 +52,7 @@ RUN make WHAT=cmd/kubectl
RUN cp _output/local/bin/$KUBE_BUILD_PLATFORMS/kubectl $DEST

# Build coreos/etcd binaries
FROM golang:1.10-stretch as etcd-darwin
FROM golang:1.10.2-stretch as etcd-darwin
ENV CGO 0
ENV GOOS darwin
ENV GOARCH amd64
Expand All @@ -62,13 +62,13 @@ RUN git clone https://github.com/coreos/etcd $GOPATH/src/github.com/coreos/etcd
RUN go build -o $DEST/etcd github.com/coreos/etcd

# Build k8s.io/code-generator binaries
FROM golang:1.10-stretch as code-generator-darwin
FROM golang:1.10.2-stretch as code-generator-darwin
ENV CGO 0
ENV GOOS darwin
ENV GOARCH amd64
ENV DEST /usr/local/kubebuilder/bin/
RUN mkdir -p $DEST || echo ""
RUN git clone https://github.com/kubernetes/code-generator $GOPATH/src/k8s.io/code-generator --depth=1 -b release-1.10
RUN git clone https://github.com/kubernetes/code-generator $GOPATH/src/k8s.io/code-generator --depth=1 -b release-1.11
RUN go build -o $DEST/client-gen k8s.io/code-generator/cmd/client-gen
RUN go build -o $DEST/conversion-gen k8s.io/code-generator/cmd/conversion-gen
RUN go build -o $DEST/deepcopy-gen k8s.io/code-generator/cmd/deepcopy-gen
Expand All @@ -79,7 +79,7 @@ RUN go build -o $DEST/openapi-gen k8s.io/code-generator/cmd/openapi-gen

# Build kubernetes-incubator/reference-docs binaries

FROM golang:1.10-stretch as reference-docs-darwin
FROM golang:1.10.2-stretch as reference-docs-darwin
ENV CGO 0
ENV GOOS darwin
ENV GOARCH amd64
Expand All @@ -89,7 +89,7 @@ RUN git clone https://github.com/kubernetes-incubator/reference-docs $GOPATH/src
RUN go build -o $DEST/gen-apidocs github.com/kubernetes-incubator/reference-docs/gen-apidocs

# Copy all binaries into a single tar.gz file
FROM golang:1.10-stretch as darwin
FROM golang:1.10.2-stretch as darwin
RUN mkdir -p /usr/local/kubebuilder/bin/
COPY --from=etcd-darwin /usr/local/kubebuilder/bin/* /usr/local/kubebuilder/bin/
COPY --from=kubernetes-darwin /usr/local/kubebuilder/bin/* /usr/local/kubebuilder/bin/
Expand All @@ -100,4 +100,4 @@ RUN tar -czvf /kubebuilder_darwin_amd64.tar.gz kubebuilder/

# Host the tar.gz file in a thin image
FROM alpine:3.7
COPY --from=darwin /kubebuilder_darwin_amd64.tar.gz /kubebuilder_darwin_amd64.tar.gz
COPY --from=darwin /kubebuilder_darwin_amd64.tar.gz /kubebuilder_darwin_amd64.tar.gz
16 changes: 8 additions & 8 deletions build/thirdparty/linux/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
# - *-gen code generators
# - reference-docs

FROM golang:1.10-stretch as kubernetes-linux
FROM golang:1.10.2-stretch as kubernetes-linux
# Install tools
RUN apt update
RUN apt install rsync -y
RUN go get github.com/jteeuwen/go-bindata/go-bindata
ENV CGO 0
ENV DEST /usr/local/kubebuilder/bin/
RUN mkdir -p $DEST || echo ""
RUN git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes --depth=1 -b release-1.10
RUN git clone https://github.com/kubernetes/kubernetes $GOPATH/src/k8s.io/kubernetes --depth=1 -b release-1.11
WORKDIR /go/src/k8s.io/kubernetes
ENV KUBE_BUILD_PLATFORMS linux/amd64
RUN make WHAT=cmd/kube-apiserver
Expand All @@ -38,7 +38,7 @@ RUN cp _output/local/bin/$KUBE_BUILD_PLATFORMS/kube-apiserver $DEST
RUN cp _output/local/bin/$KUBE_BUILD_PLATFORMS/kube-controller-manager $DEST
RUN cp _output/local/bin/$KUBE_BUILD_PLATFORMS/kubectl $DEST

FROM golang:1.10-stretch as etcd-linux
FROM golang:1.10.2-stretch as etcd-linux
ENV CGO 0
ENV GOOS linux
ENV GOARCH amd64
Expand All @@ -47,13 +47,13 @@ RUN mkdir -p $DEST || echo ""
RUN git clone https://github.com/coreos/etcd $GOPATH/src/github.com/coreos/etcd --depth=1
RUN go build -o $DEST/etcd github.com/coreos/etcd

FROM golang:1.10-stretch as code-generator-linux
FROM golang:1.10.2-stretch as code-generator-linux
ENV CGO 0
ENV GOOS linux
ENV GOARCH amd64
ENV DEST /usr/local/kubebuilder/bin/
RUN mkdir -p $DEST || echo ""
RUN git clone https://github.com/kubernetes/code-generator $GOPATH/src/k8s.io/code-generator --depth=1 -b release-1.10
RUN git clone https://github.com/kubernetes/code-generator $GOPATH/src/k8s.io/code-generator --depth=1 -b release-1.11
RUN go build -o $DEST/client-gen k8s.io/code-generator/cmd/client-gen
RUN go build -o $DEST/conversion-gen k8s.io/code-generator/cmd/conversion-gen
RUN go build -o $DEST/deepcopy-gen k8s.io/code-generator/cmd/deepcopy-gen
Expand All @@ -62,7 +62,7 @@ RUN go build -o $DEST/informer-gen k8s.io/code-generator/cmd/informer-gen
RUN go build -o $DEST/lister-gen k8s.io/code-generator/cmd/lister-gen
RUN go build -o $DEST/openapi-gen k8s.io/code-generator/cmd/openapi-gen

FROM golang:1.10-stretch as reference-docs-linux
FROM golang:1.10.2-stretch as reference-docs-linux
ENV CGO 0
ENV GOOS linux
ENV GOARCH amd64
Expand All @@ -71,7 +71,7 @@ RUN mkdir -p $DEST || echo ""
RUN git clone https://github.com/kubernetes-incubator/reference-docs $GOPATH/src/github.com/kubernetes-incubator/reference-docs --branch kubebuilder --depth=1
RUN go build -o $DEST/gen-apidocs github.com/kubernetes-incubator/reference-docs/gen-apidocs

FROM golang:1.10-stretch as linux
FROM golang:1.10.2-stretch as linux
RUN mkdir -p /usr/local/kubebuilder/bin/
COPY --from=etcd-linux /usr/local/kubebuilder/bin/* /usr/local/kubebuilder/bin/
COPY --from=kubernetes-linux /usr/local/kubebuilder/bin/* /usr/local/kubebuilder/bin/
Expand All @@ -81,4 +81,4 @@ WORKDIR /usr/local
RUN tar -czvf /kubebuilder_linux_amd64.tar.gz kubebuilder/

FROM alpine:3.7
COPY --from=linux /kubebuilder_linux_amd64.tar.gz /kubebuilder_linux_amd64.tar.gz
COPY --from=linux /kubebuilder_linux_amd64.tar.gz /kubebuilder_linux_amd64.tar.gz
10 changes: 8 additions & 2 deletions cmd/Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions cmd/Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,7 @@
[[constraint]]
branch = "master"
name = "sigs.k8s.io/controller-tools"

[[constraint]]
name = "github.com/Masterminds/semver"
version = "1.4.2"
53 changes: 38 additions & 15 deletions cmd/kubebuilder/initproject/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@ import (
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"strconv"
"strings"

"github.com/Masterminds/semver"
"github.com/kubernetes-sigs/kubebuilder/cmd/kubebuilder/util"
"github.com/spf13/cobra"
"sigs.k8s.io/controller-tools/pkg/scaffold/manager"
"sigs.k8s.io/controller-tools/pkg/scaffold/project"
)


type initOptions struct {
domain string
copyright string
bazel bool
domain string
copyright string
bazel bool
controllerOnly bool
projectVersion string
projectOptions
Expand All @@ -52,20 +52,19 @@ func AddInit(cmd *cobra.Command) {
kubebuilder init repo --domain mydomain
`,
Run: func(cmd *cobra.Command, args []string) {
o.runInitRepo()
o.runInitRepo()
},
}

v0comment := "Works only with project-version v0, "
initCmd.Flags().StringVar(&o.domain, "domain", "", "domain for the API groups")
initCmd.Flags().StringVar(&o.copyright, "copyright", filepath.Join("hack", "boilerplate.go.txt"), v0comment + "Location of copyright boilerplate file.")
initCmd.Flags().BoolVar(&o.bazel, "bazel", false, v0comment + "if true, setup Bazel workspace artifacts")
initCmd.Flags().BoolVar(&o.controllerOnly, "controller-only", false, v0comment + "if true, setup controller only")
initCmd.Flags().StringVar(&o.copyright, "copyright", filepath.Join("hack", "boilerplate.go.txt"), v0comment+"Location of copyright boilerplate file.")
initCmd.Flags().BoolVar(&o.bazel, "bazel", false, v0comment+"if true, setup Bazel workspace artifacts")
initCmd.Flags().BoolVar(&o.controllerOnly, "controller-only", false, v0comment+"if true, setup controller only")
initCmd.Flags().StringVar(&o.projectVersion, "project-version", "v1", "if set to v0, init project with kubebuilder legacy version")


initCmd.Flags().BoolVar(
&o.dep, "dep", true,"if specified, determines whether dep will be used.")
&o.dep, "dep", true, "if specified, determines whether dep will be used.")
o.depFlag = initCmd.Flag("dep")

o.prj = projectForFlags(initCmd.Flags())
Expand All @@ -78,10 +77,8 @@ kubebuilder init repo --domain mydomain
}

func (o *initOptions) runInitRepo() {
version := runtime.Version()
if versionCmp(version, "go1.10") < 0 {
log.Fatalf("The go version is %v, must be 1.10+", version)
}
checkGoVersion()

if !depExists() {
log.Fatalf("Dep is not installed. Follow steps at: https://golang.github.io/dep/docs/installation.html")
}
Expand Down Expand Up @@ -129,6 +126,32 @@ func (o *initOptions) runInitRepo() {
"$ kubebuilder create resource\n")
}

func checkGoVersion() {
cmd := exec.Command("go", "version")
out, err := cmd.Output()
if err != nil {
log.Fatalf("Could not execute 'go version': %v", err)
}

split := strings.Split(string(out), " ")
if len(split) < 3 {
log.Fatalf("Invalid go version: %q", string(out))
}
goVersion := strings.TrimPrefix(split[2], "go")
if ver, err := semver.NewVersion(goVersion); err != nil {
if err != nil {
log.Fatalf("Invalid go version %q: %v", goVersion, err)
}
c, err := semver.NewConstraint(">= 1.10")
if err != nil {
log.Fatal("Invalid constraint: %v", err)
}
if !c.Check(ver) {
log.Fatalf("The go version is %v, must be 1.10+", goVersion)
}
}
}

func execute(path, templateName, templateValue string, data interface{}) {
dir, err := os.Getwd()
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions cmd/kubebuilder/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,22 @@ func (o *apiOptions) RunAddAPI() {
fmt.Println("Create Resource under pkg/apis [y/n]?")
o.doResource = util.Yesno(reader)
}

if !o.controllerFlag.Changed {
fmt.Println("Create Controller under pkg/controller [y/n]?")
o.doController = util.Yesno(reader)
}

if o.r.Group == "" {
log.Fatalf("Must specify --group")
}
if o.r.Version == "" {
log.Fatalf("Must specify --version")
}
if o.r.Kind == "" {
log.Fatalf("Must specify --kind")
}

fmt.Println("Writing scaffold for you to edit...")

r := o.r
Expand Down
Loading

0 comments on commit 9f1c319

Please sign in to comment.