kubernetes / sample-controller

Repository for sample controller. Complements sample-apiserver
Apache License 2.0
3.17k stars 1.1k forks source link

[enhancement] Move the code generator logic to a dockerfile #85

Closed alias-rahil closed 2 years ago

alias-rahil commented 2 years ago

Why?

Based on the current open issues, lots of users are having a hard time making the code generation script to work correctly for their projects. The current implementation is a bash script that heavily depends on:

  1. go envs should be correctly populated to shell
  2. location of the codebase should be $GOPATH/src/github.com/kubernetes/sample-controller
  3. maintaining a vendor directory, if using go modules

How?

Docker supports exporting build artifacts to the host machine via buildkit. We can leverage this feature. This will also make verifying codegen in CI pipelines very easy. Sample dockerfile:

# hack/Dockerfile.update-codegen

# Usage: docker buildx build --file hack/Dockerfile.update-codegen -o . .

FROM golang:1.17 AS build
WORKDIR /go/src/github.com/kubernetes/sample-controller
RUN go get k8s.io/code-generator@v0.23.4
COPY . .
RUN bash /go/pkg/mod/k8s.io/code-generator@v0.23.4/generate-groups.sh all \
    github.com/kubernetes/sample-controller/pkg/generated github.com/kubernetes/sample-controller/pkg/apis samplecontroller:v1alpha1 \
    --go-header-file /go/pkg/mod/k8s.io/code-generator@v0.23.4/hack/boilerplate.go.txt

FROM scratch
COPY --from=build /go/src/github.com/kubernetes/sample-controller/pkg pkg

I would be happy to make a PR or give more clarity on the idea if required.

k8s-triage-robot commented 2 years ago

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

You can:

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

k8s-ci-robot commented 2 years ago

@alias-rahil: Closing this issue.

In response to [this](https://github.com/kubernetes/sample-controller/issues/85#issuecomment-1154942998): >/close Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.