Closed max-rocket-internet closed 1 year ago
@dims @sttts Hey guys, any idea on how to solve this? It's a bit confusing for beginners.
k8s.io$ git clone https://github.com/kubernetes/sample-controller
k8s.io$ cd sample-controller
sample-controller$ ./hack/update-codegen.sh
bash: ../code-generator/generate-groups.sh: No such file or directory
thanks in advance.
TBH I think this code generation thing adds more headache/complexity than it solves, especially when you're just beginning to write a controller using this repo as a start.
hey @max-rocket-internet, just realised that the fix is actually in the read me. Run go mod vendor
and you should be good.
Here's what I've figured out from a couple of hours of faffing around with this:
The first problem is "how do you run generate-groups.sh"? There are two answers. One was pointed out by @farah : populate the vendor directory. The other is to clone the code-generator project so that it's a sibling of sample-controller (which is where it lives in the kubernetes/kubernetes repo). You can look in hack/update-codegen.sh and you'll see that the script looks in the vendor directory and then falls back to ../code-generator.
The second problem is "where does generate-groups.sh put the files that it generates"? Remember how this repo is a mirror of a small part of kubernetes/kubernetes? Well, generate-groups.sh assumes and requires that everything is laid out exactly like it is in the kubernetes project. In that project, sample-controller is in k8s.io/sample-controller, i.e. {parent}/{project}. You'll see in generate-groups.sh that it goes up three directories, then uses the module path as a directory path which means that it doesn't work properly if your project's module isn't {parent}/{project}. You can hack update-codegen.sh to use a different output-base but you might still end up having to move the files after they're generated. I did.
This smells like it was written before Go modules and never updated to work with modules since it just so happens to work with the directory structure in the kubernetes/kubernetes project.
HTH
Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale
.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle stale
Did you find any solution? The go mod vendor doesn't work for me. This is what I did:
$ git clone https://github.com/kubernetes/sample-controller
$ cd sample-controller
$ go mod vendor
$ ./hack/update-codegen.sh
The script generates a bunch of dirs and filess inside my home
k8s.io/
k8s.io/sample-controller
k8s.io/sample-controller/pkg
k8s.io/sample-controller/pkg/generated
k8s.io/sample-controller/pkg/generated/clientset
k8s.io/sample-controller/pkg/generated/clientset/versioned
k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme
k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme/doc.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/scheme/register.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/generated_expansion.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/samplecontroller_client.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/doc.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/fake/fake_samplecontroller_client.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/typed/samplecontroller/v1alpha1/doc.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/fake
k8s.io/sample-controller/pkg/generated/clientset/versioned/fake/clientset_generated.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/fake/doc.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/fake/register.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/clientset.go
k8s.io/sample-controller/pkg/generated/clientset/versioned/doc.go
but all the files there are empty
I switched to kubebuilder, I think it's better.
Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten
.
Rotten issues close after an additional 30d of inactivity.
If this issue is safe to close now please do so with /close
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /lifecycle rotten
Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen
.
Mark the issue as fresh with /remove-lifecycle rotten
.
Send feedback to sig-testing, kubernetes/test-infra and/or fejta. /close
@fejta-bot: Closing this issue.
I edited my update-codegen script like this:
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
pkg/generated pkg/apis \
mycontroller:v1alpha1 \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../" \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt
This generates the files under the parent directory's pkg
folder but all of the files are empty as mentioned in this comment. Wonder if anyone found a solution for the empty files.
/remove-lifecycle rotten
/reopen
@vadasambar: You can't reopen an issue/PR unless you authored it or you are a collaborator.
/reopen
@max-rocket-internet: Reopened this issue.
Reopened for @vadasambar but I moved on from this topic a long time ago 🙂
I can reproduce the same problem when I try running the update-codegen.sh
script against the original sample-controller
inside the kubernetes
repo.
suraj@suraj:~/sandbox/kubernetes/staging/src/k8s.io/sample-controller$ git status
On branch master
Your branch is up to date with 'origin/master'.
nothing to commit, working tree clean
suraj@suraj:~/sandbox/kubernetes/staging/src/k8s.io/sample-controller$ sudo rm -R pkg/generated pkg/apis
suraj@suraj:~/sandbox/kubernetes/staging/src/k8s.io/sample-controller$ ./hack/update-codegen.sh
Generating deepcopy funcs
Generating clientset for samplecontroller:v1alpha1 at k8s.io/sample-controller/pkg/generated/clientset
Generating listers for samplecontroller:v1alpha1 at k8s.io/sample-controller/pkg/generated/listers
Generating informers for samplecontroller:v1alpha1 at k8s.io/sample-controller/pkg/generated/informers
Started a thread around the problem in Kubernetes slack here
This works for me:
#!/usr/bin/env bash
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -o errexit
set -o nounset
set -o pipefail
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
# Pre-requisites
# 1. this script needs ./pkg/apis/samplecontroller/v1alpha1 to generate everything else (generated files will be empty otherwise)
# 2. changing --output-base to something else doesn't work
#
# Only the following things can be auto-generated:
# 1. ./pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go
# 2. everything under ./pkg/apis/generated
bash "${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
k8s.io/sample-controller/pkg/generated k8s.io/sample-controller/pkg/apis \
samplecontroller:v1alpha1 \
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt
# This block:
# output_base: the directory outside the repo where auto-generated files are created
# 1. removes existing auto-generated files
# 2. copies over the auto-generated files from the output_base to pkg/apis and pkg/generated
# 3. removes output_base
rm -R ./pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go ./pkg/generated -f
mv "$(dirname "${BASH_SOURCE[0]}")/../../../k8s.io/sample-controller/pkg/apis/samplecontroller/v1alpha1/zz_generated.deepcopy.go" $SCRIPT_ROOT/pkg/apis/samplecontroller/v1alpha1 -f
mv "$(dirname "${BASH_SOURCE[0]}")/../../../k8s.io/sample-controller/pkg/generated" $SCRIPT_ROOT/pkg
rm -R "$(dirname "${BASH_SOURCE[0]}")/../../../k8s.io"
# To use your own boilerplate text append:
# --go-header-file "${SCRIPT_ROOT}"/hack/custom-boilerplate.go.txt
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:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle stale
/lifecycle rotten
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle stale
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues and PRs according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/remove-lifecycle rotten
/close
Please send feedback to sig-contributor-experience at kubernetes/community.
/lifecycle rotten
The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.
This bot triages issues according to the following rules:
lifecycle/stale
is appliedlifecycle/stale
was applied, lifecycle/rotten
is appliedlifecycle/rotten
was applied, the issue is closedYou can:
/reopen
/remove-lifecycle rotten
Please send feedback to sig-contributor-experience at kubernetes/community.
/close not-planned
@k8s-triage-robot: Closing this issue, marking it as "Not Planned".
To quote the README:
But:
Am I misunderstanding how this is supposed to work?