rebuild using kubebuilder 2.3.1#650
Conversation
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
$ kubebuilder version && kubebuilder init --domain ""
Version: version.Version{KubeBuilderVersion:"2.3.1", KubernetesVendor:"1.16.4", GitCommit:"8b53abeb4280186e494b726edf8f54ca7aa64a49", BuildDate:"2020-03-26T16:42:00Z", GoOs:"unknown", GoArch:"unknown"}
Writing scaffold for you to edit...
Get controller runtime:
$ go get sigs.k8s.io/controller-runtime@v0.5.0
Update go.mod:
$ go mod tidy
Running make:
$ make
/home/dhellmann/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..."
go fmt ./...
go vet ./...
go build -o bin/manager main.go
Next: define a resource with:
$ kubebuilder create api
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
$ kubebuilder edit --multigroup=true Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
$ kubebuilder create api --group metal3.io --version v1alpha1 --kind BareMetalHost Create Resource [y/n] y Create Controller [y/n] y Writing scaffold for you to edit... apis/metal3.io/v1alpha1/baremetalhost_types.go controllers/metal3.io/baremetalhost_controller.go Running make: $ make /home/dhellmann/go/bin/controller-gen object:headerFile="hack/boilerplate.go.txt" paths="./..." go fmt ./... go vet ./... go build -o bin/manager main.go make manifests Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Use the latest release and pass the arguments we need to allow us to use the float64 field for clock speed and to generate output consistent with what we had from the operator-sdk. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Move the old implementation to the new location. Update Makefile to only run controller-gen over our api package. Run 'make manifests' and 'make generate' and check in the output. Fix source of api version details for baremetalhost. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Move the environment variable check from init() to the point where the value of the variable would be used. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Filter reconcile events for hosts where the error count is what changed. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
* Ensure every provisioner created in the tests has a logger. * Use the right request and result types. * Create a separate test scheme and create the fake clients using that scheme. * Change old r.client.* calls to r.* Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Update the Makefile to include the targets from before the kubebuilder conversion. Fix the hack scripts used by some of those targets to handle the new layout. Add makefile rules for programs in cmds Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Update go.mod and go.sum based on the values used before the conversion. Run `make mod`. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: dhellmann The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
|
/test-integration |
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Match the go version in the module file. Fix source copy instructions in the build phase. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
metal3-dev-env expects this repo to have build/Dockerfile for building the image, since that's what the operator-sdk generated. The new kubebuilder Dockerfile is in the root of the repo. In order to be able to land this patch series, we need either to work. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
The event filter may be given references to owned objects, like the secrets used for passwords. It needs to accept those instead of panicking, so if the type assertion fails then we treat the case as needing reconciliation. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
f61be06 to
efff9d2
Compare
| spec: | ||
| containers: | ||
| - name: kube-rbac-proxy | ||
| image: gcr.io/kubebuilder/kube-rbac-proxy:v0.5.0 |
There was a problem hiding this comment.
is the image version not going to be needing updating? is it worth kustomizing
There was a problem hiding this comment.
This was produced by the code generator. @maelk and I are going to collaborate to fix up all of the kustomize inputs after this PR has landed and we can unblock the other PRs in this repo.
| "math/rand" | ||
|
|
||
| metal3 "github.com/metal3-io/baremetal-operator/pkg/apis/metal3/v1alpha1" | ||
| metal3 "github.com/metal3-io/baremetal-operator/apis/metal3.io/v1alpha1" |
There was a problem hiding this comment.
put "time" at the top? what import ordering/grouping are we following?
There was a problem hiding this comment.
I've fixed up the imports in all of the files in this directory to use a consistent order.
| } | ||
| }() | ||
|
|
||
| _ = context.Background() |
There was a problem hiding this comment.
is this ^ doing anything?
There was a problem hiding this comment.
No, that's debris from the code generator output. Removed.
| ironic.LogStartup() | ||
| } | ||
|
|
||
| if err = (&metal3iocontroller.BareMetalHostReconciler{ |
There was a problem hiding this comment.
personally not a fan of this making the Reconciler struct public, you could just make a metal3iocontroller.New()
There was a problem hiding this comment.
This is what kubebuilder generates. I don't know if the controller runtime expects these members to be public or not, but didn't want to deviate too far from what the code generator does in this PR.
| CONTROLLER_GEN=$(GOBIN)/controller-gen | ||
| else | ||
| CONTROLLER_GEN=$(shell which controller-gen) | ||
| endif |
There was a problem hiding this comment.
you could put this at the top
ifeq (, $(shell which controller-gen))
CONTROLLER_GEN=$(GOBIN)/controller-gen
else
CONTROLLER_GEN=$(shell which controller-gen)
endif
then
$(CONTROLLER_GEN):
#install stuff
just to avoid the phony target and repeated installs
There was a problem hiding this comment.
actually isn't it better to vendor? if the generated code varies across versions that's going to be a pain
There was a problem hiding this comment.
The install logic uses the specific version we need. It's based on what kubebuilder generates. We could enhance it to install into a local directory, like with kustomize, in another PR if we think that's important.
The old images used /baremetal-operator as the entry point, so let's use that for the new version to maintain compatibility. Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Group by stdlib, non-k8s, k8s, then metal3 Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
bf44d9d to
7487af6
Compare
Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
Update the version of go used in the baremetal-operator jobs in preparation for metal3-io/baremetal-operator#650 Signed-off-by: Doug Hellmann <dhellmann@redhat.com>
|
We may need metal3-io/project-infra#151 to make the jobs work. |
|
/test-integration |
zaneb
left a comment
There was a problem hiding this comment.
There's a lot here. The only way I've found to review it is to basically recreate the migration myself and then do diffs against this branch to find out what I missed. I'm only part way through, but I did have some questions so I'll post the ones I've found now.
I also have an idea for how to structure the history so that e.g. git blame is not lost on important files like the bmh controller. It should make rebasing a bit easier as well, so we might be able to unblock other changes. I'm still working my way through all the diffs though (with a goal of ending up in roughly the same place via a different history graph). So I'll have to come back to this on Monday.
| @@ -2,7 +2,14 @@ | |||
| # Image URL to use all building/pushing image targets | |||
| IMG ?= controller:latest | |||
| # Produce CRDs that work back to Kubernetes 1.11 (no version conversion) | |||
| # eventually allowing conversion webhooks | ||
| # allowDangerousTypes=true lets use the float64 field for clock speeds | ||
| # crdVersions=v1 generates the v1 version of the CRD type | ||
| # preserveUnknownFields=false causes the API server to discard "extra" data instead of storing it |
There was a problem hiding this comment.
I'm pretty sure this is unnecessary when crdVersions=v1 is set
There was a problem hiding this comment.
I think you're right. I figured being explicit wouldn't hurt, though.
| BootMode BootMode `json:"bootMode,omitempty"` | ||
| } | ||
|
|
||
| // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
There was a problem hiding this comment.
It appears that kubebuilder uses:
// +kubebuilder:object:root=true
instead of this (several times in this file). I assume that's a replacement for the same thing?
There was a problem hiding this comment.
Perhaps? I just moved the old file into the new location, and I probably should have done what I did with the controller where I copied the contents over by hand in pieces.
There was a problem hiding this comment.
Further research reveals that they're probably not related, but the deepcopy-gen thing was to cause it to generate a DeepCopyObject() method, which was some ancient workaround that doesn't appear to be needed any more since we are generating this anyway.
| flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.") | ||
| flag.BoolVar(&enableLeaderElection, "enable-leader-election", false, | ||
| "Enable leader election for controller manager. "+ | ||
| "Enabling this will ensure there is only one active controller manager.") |
There was a problem hiding this comment.
We don't want to keep the enableLeaderElection flag?
| // is for multi-tenancy, then the BMO should watch only the provided | ||
| // namespace. | ||
| flag.StringVar(&watchNamespace, "namespace", "", | ||
| "Namespace that the controller watches to reconcile BMO objects.") |
There was a problem hiding this comment.
Is it safe to add this without adding the code that we used to have to look up the current namespace if it wasn't supplied?
There was a problem hiding this comment.
The old lookup code was part of the operator-sdk library that has been dropped. AFAICT, we always set the namespace explicitly. We may want to add some logic to let us use an environment variable to do that more easily than a command line flag, for when we're running inside the cluster.
There was a problem hiding this comment.
That's fine by me as long as we comply with the CAPI requirements, that the namespace should be providable by command line, and if unset (both in command line and environment variable in that case), default to all namespaces.
Perhaps I should remove the holds on other PRs and redo this PR with that new approach. Let's talk Monday. |
If so, then we'll need to revert the change of image for the generate job in project-infra. That effectively is blocking all other PRs for now. |
Let's see if #655 is easier to review. If not, then I'll revert the image change in infra to unblock others while we figure out how to make the migration reviewable. |
|
It was not possible to review either this or #655 on Github UI due to the file number restriction (max 3000). But I managed with vscode Github extension. Unfortunately it did not properly show the moved files (they were displayed as added) but overall could be reviewed without major issues. |
|
The consensus seems to be that #655 is easier to follow, so I'm going to close this one. |
This implements the work described in
https://github.com/metal3-io/metal3-docs/blob/master/design/baremetal-operator/kubebuilder-migration.md
It deviates a bit from the work list, because it turns out not to be
necessary to fork controller-tools now that they have added a flag to
support "unsafe" types like our float64 field.