-
Notifications
You must be signed in to change notification settings - Fork 11
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
Bump kubebuilder version from v2
to v3
#40
Conversation
The |
Signed-off-by: rustyclock <rustyclock@protonmail.com>
healthzName = "healthz" | ||
readyzName = "readyz" | ||
exitCode = 1 | ||
leaderElectionID = "spanner-autoscaler-leader-election" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was created by default with the hash of repo name: leaderElectionID = "54b82eb3.mercari.com"
. I reverted it to the old one.
bin/ | ||
config/ | ||
.git/ | ||
hack/ | ||
.gitignore | ||
LICENSE | ||
Makefile | ||
PROJECT | ||
README.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not need to remove them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just kept the default file in this case because I think it looked cleaner to have an allow-list instead have a block-list (block-list has to be updated whenever a new kind of file is added to the project). Let me know if you prefer to have both and I can add them back.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following configures seem to be correct.
$ cat .dockerignore
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files
**
# Except go related files
!pkg
!cmd
!**/*.mod
!**/*.sum
You can check the following command.
$ docker image build -t build-context -f - . <<EOF
FROM busybox
COPY . /build-context
WORKDIR /build-context
CMD find .
EOF
$ docker container run --rm build-context
.
./go.sum
./cmd
./cmd/spanner-autoscaler
./cmd/spanner-autoscaler/main.go
./pkg
./pkg/pointer
./pkg/pointer/pointer.go
./pkg/pointer/pointer_test.go
./pkg/api
./pkg/api/v1alpha1
./pkg/api/v1alpha1/zz_generated.deepcopy.go
./pkg/api/v1alpha1/spannerautoscaler_types.go
./pkg/api/v1alpha1/groupversion_info.go
./pkg/metrics
./pkg/metrics/metrics.go
./pkg/metrics/fake.go
./pkg/controllers
./pkg/controllers/spannerautoscaler_controller.go
./pkg/controllers/spannerautoscaler_controller_test.go
./pkg/spanner
./pkg/spanner/spanner.go
./pkg/spanner/fake.go
./pkg/logging
./pkg/logging/context.go
./pkg/syncer
./pkg/syncer/fake
./pkg/syncer/fake/fake.go
./pkg/syncer/syncer_test.go
./pkg/syncer/syncer.go
./go.mod
!**/*.go
doesn't work, so I choose !pkg
and !cmd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent catch!! Thank you 🙇♂️ , I was not aware that this is an open bug in docker. I have now fixed it as per your recommendation since !
does not work with wild cards.
References:
|
||
# Value of this field is prepended to the | ||
# names of all resources, e.g. a deployment named | ||
# "wordpress" becomes "alices-wordpress". | ||
# Note that it should also match with the prefix (text before '-') of the namespace | ||
# field above. | ||
# namePrefix: spanner-autoscaler- | ||
namePrefix: spanner-autoscaler- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was enabled by default. I think it is good because this makes it easier to identify the resources created for this controller specifically. If multiple operators/controllers are deployed in the same namespace, then this really helps in distinguishing resources quickly.
config/default/kustomization.yaml
Outdated
@@ -1,12 +1,12 @@ | |||
# Adds namespace to all resources. | |||
namespace: spanner-autoscaler | |||
namespace: spanner-autoscaler-system |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this change required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was auto generated. I have now reverted it to the original one.
Signed-off-by: rustyclock <rustyclock@protonmail.com>
resources: | ||
limits: | ||
cpu: 100m | ||
memory: 30Mi | ||
requests: | ||
cpu: 100m | ||
memory: 20Mi | ||
terminationGracePeriodSeconds: 20 | ||
serviceAccountName: controller-manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It may require to update Workload Identity and some RBAC configurations written in README.md
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed it! I think having a helm-chart would greatly simplify the deployment process here. Currently it requires too many files to be manually created and certain lines have to be searched and modified. I will see if kpt
can help with that or helm
.
Signed-off-by: rustyclock <rustyclock@protonmail.com>
bin/ | ||
config/ | ||
.git/ | ||
hack/ | ||
.gitignore | ||
LICENSE | ||
Makefile | ||
PROJECT | ||
README.md |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following configures seem to be correct.
$ cat .dockerignore
# More info: https://docs.docker.com/engine/reference/builder/#dockerignore-file
# Ignore all files
**
# Except go related files
!pkg
!cmd
!**/*.mod
!**/*.sum
You can check the following command.
$ docker image build -t build-context -f - . <<EOF
FROM busybox
COPY . /build-context
WORKDIR /build-context
CMD find .
EOF
$ docker container run --rm build-context
.
./go.sum
./cmd
./cmd/spanner-autoscaler
./cmd/spanner-autoscaler/main.go
./pkg
./pkg/pointer
./pkg/pointer/pointer.go
./pkg/pointer/pointer_test.go
./pkg/api
./pkg/api/v1alpha1
./pkg/api/v1alpha1/zz_generated.deepcopy.go
./pkg/api/v1alpha1/spannerautoscaler_types.go
./pkg/api/v1alpha1/groupversion_info.go
./pkg/metrics
./pkg/metrics/metrics.go
./pkg/metrics/fake.go
./pkg/controllers
./pkg/controllers/spannerautoscaler_controller.go
./pkg/controllers/spannerautoscaler_controller_test.go
./pkg/spanner
./pkg/spanner/spanner.go
./pkg/spanner/fake.go
./pkg/logging
./pkg/logging/context.go
./pkg/syncer
./pkg/syncer/fake
./pkg/syncer/fake/fake.go
./pkg/syncer/syncer_test.go
./pkg/syncer/syncer.go
./go.mod
!**/*.go
doesn't work, so I choose !pkg
and !cmd
.
Signed-off-by: rustyclock <rustyclock@protonmail.com>
.PHONY: lint/golangci-lint | ||
lint/golangci-lint: tools/golangci-lint .golangci.yml ## Run golangci-lint. | ||
golangci-lint run | ||
|
||
# Build the docker image | ||
docker-build: | ||
docker image build . -t ${IMG} | ||
|
||
# Push the docker image | ||
docker-push: | ||
docker image push ${IMG} | ||
|
||
kubebuilder: ${KUBEBUILDER_ASSETS}/kubebuilder | ||
${KUBEBUILDER_ASSETS}/kubebuilder: | ||
@{ \ | ||
set -e ;\ | ||
TMP_DIR=./tmp/kubebuilder ;\ | ||
mkdir -p $$TMP_DIR ;\ | ||
curl -sSL https://github.com/kubernetes-sigs/kubebuilder/releases/download/v${KUBEBUILDER_VERSION}/kubebuilder_${KUBEBUILDER_VERSION}_${GOOS}_${GOARCH}.tar.gz | tar -xz -C $$TMP_DIR ;\ | ||
mv $$TMP_DIR/kubebuilder_${KUBEBUILDER_VERSION}_${GOOS}_${GOARCH} ${KUBEBUILDER_ASSETS_DIR} ;\ | ||
rm -rf $$TMP_DIR ;\ | ||
} | ||
|
||
.PHONY: run | ||
run: $(SKAFFOLD) | ||
# NOTE: since skaffold uses kind executable from PATH directly, so this overrides PATH to use project local executable. | ||
@PATH=$${PWD}/bin:$${PATH} $(SKAFFOLD) dev --filename=./skaffold/skaffold.yaml | ||
|
||
.PHONY: manifests | ||
manifests: $(CONTROLLER_GEN) | ||
@$(CONTROLLER_GEN) crd:trivialVersions=true rbac:roleName=manager-role webhook paths="./pkg/api/..." output:crd:artifacts:config=config/crd/bases | ||
|
||
.PHONY: deepcopy | ||
deepcopy: $(CONTROLLER_GEN) | ||
@$(CONTROLLER_GEN) object:headerFile=./hack/boilerplate.go.txt paths="./..." | ||
|
||
controlller-gen: $(CONTROLLER_GEN) | ||
$(CONTROLLER_GEN): go.sum | ||
@go build -o $(CONTROLLER_GEN) sigs.k8s.io/controller-tools/cmd/controller-gen | ||
|
||
kind: $(KIND) | ||
$(KIND): go.sum | ||
@go build -o ./bin/kind sigs.k8s.io/kind | ||
|
||
kubectl: $(KUBECTL) | ||
$(KUBECTL): .kubectl-version | ||
@curl -Lso $(KUBECTL) https://storage.googleapis.com/kubernetes-release/release/$(shell cat .kubectl-version)/bin/$(GOOS)/$(GOARCH)/kubectl | ||
@chmod +x $(KUBECTL) | ||
|
||
skaffold: $(SKAFFOLD) | ||
$(SKAFFOLD): .skaffold-version | ||
@curl -Lso $(SKAFFOLD) https://storage.googleapis.com/skaffold/releases/$(shell cat .skaffold-version)/skaffold-$(GOOS)-$(GOARCH) | ||
@chmod +x $(SKAFFOLD) | ||
|
||
kpt: $(KPT) | ||
$(KPT): go.sum | ||
@go build -o $(KPT) github.com/GoogleContainerTools/kpt | ||
|
||
.PHONY: kind-cluster | ||
kind-cluster: $(KIND) $(KUBECTL) | ||
@$(KIND) delete cluster --name spanner-autoscaler | ||
@$(KIND) create cluster --name spanner-autoscaler --image kindest/node:v${KIND_NODE_VERSION} | ||
@$(KUBECTL) apply -f ./config/crd/bases/spanner.mercari.com_spannerautoscalers.yaml | ||
@$(KUBECTL) apply -f ./kind/namespace.yaml | ||
@$(KUBECTL) apply -f ./kind/rbac | ||
|
||
.PHONY: kpt/crd | ||
kpt/crd: manifests kpt | ||
@kustomize build config/crd > ./kpt/crd/spannerautoscalers.spanner.mercari.com.yaml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any reason why you removed these make tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref
This is the current status of the Makefile
:
-
The current
kpt
package was anyways broken (Upgrade and fix brokenkpt
package files #41), so I didn't bother on porting it over yet. I will fix it along withkpt
upgrade in Kpt package upgrade #43. -
As for others:
kubectl
: I think we don't need to install it on the developer's system because this is a basic tool for interaction with k8s and is expected to be present already.kind
: Same as above. I think any k8s developer would already have access to some kind of development k8s environment (be itkind
or any other k8s setup of their choice).kubebuilder
: Same as above. Anyone building or modifying operators, would already have it on their system I think. We shouldn't burden ourselves with maintaining more code/components than what is/are necessary.skaffold
: I'm not sure about this one. Is this really used by any of the current code owners for development? If so, then I can port it.
Let me know what you think and which (or all) targets should be ported over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
kubectl
- Yes, it may not be necessary.
kind
- I agree that installation is not necessary. However, I think it would be more developer-friendly to not leave out
make
tasks that make it easier to build a local environment usingkind
.
- I agree that installation is not necessary. However, I think it would be more developer-friendly to not leave out
kubebuilder
- Yes, it may not be necessary.
skaffold
- I have never used it. Does anyone use it? @mercari/spanner-autoscaler
The current kpt package was anyways broken (Upgrade and fix broken kpt package files #41), so I didn't bother on porting it over yet. I will fix it along with kpt upgrade in Kpt package upgrade #43.
OK!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the kind
target now. Please have a look. Thanks!
metricsAddr = flag.String("metrics-bind-address", ":8080", "The address the metric endpoint binds to.") | ||
probeAddr = flag.String("health-probe-bind-address", ":8081", "The address the probe endpoint binds to.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you don't have a strong motivation, it might be better to use the same flags and ports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were the default values generated by kubebuilder
v3. These port numbers are also configured in the k8s manifests automatically, so instead of changing them here and then everywhere else, I just kept the default ones. Same goes for the flags as well.
We can revert to the old ones, but I think it is better to move closer to the default kubebuilder
configuration for easier maintenance and migration in future.
Ref: https://book.kubebuilder.io/migration/manually_migration_guide_v2_v3.html#rename-the-manager-flags
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understood, thanks!
Also, this change might not be a problem because people will probably use the manifest file generated by kustomize.
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
name: spanner-autoscaler-manager | ||
name: controller-manager |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be friendly to write the migration steps in the README(or another documentation) if you want to change the name.
And the same for other resources.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed!
* Add targets for creating or resetting a `kind` cluster for development * Fix the RBAC resources which are created by `kind-cluster` target for development Signed-off-by: rustyclock <rustyclock@protonmail.com>
Signed-off-by: rustyclock <rustyclock@protonmail.com>
The new version v0.2.0 has been released 🎉 Changes: v0.1.5...v0.2.0 |
What this PR does / Why we need it
Upgrade
kubebuilder
version fromv2
tov3
using the migration guide - https://book.kubebuilder.io/migration/migration_guide_v2tov3.htmlWhich issue(s) this PR fixes
Fixes #39, #33