kubernetes-sigs / cluster-api-provider-azure

Cluster API implementation for Microsoft Azure
https://capz.sigs.k8s.io/
Apache License 2.0
295 stars 425 forks source link

Use `// +kubebuilder:default` annotations where possible #4204

Open nojnhuh opened 1 year ago

nojnhuh commented 1 year ago

/kind cleanup /good-first-issue /help

What needs cleanup:

There are several places in the defaulting webhooks where CAPZ defaults a static value that could be replaced with the // +kubebuilder:default annotation on the API type.

e.g. this code defaults a static value https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedcontrolplane_webhook.go#L75-L78

It should be removed and replaced by the following change to this block: https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedcontrolplane_types.go#L118-L123

diff --git a/api/v1beta1/azuremanagedcontrolplane_types.go b/api/v1beta1/azuremanagedcontrolplane_types.go
index 5d83db207..35adbf3db 100644
--- a/api/v1beta1/azuremanagedcontrolplane_types.go
+++ b/api/v1beta1/azuremanagedcontrolplane_types.go
@@ -126,6 +126,7 @@ type AzureManagedControlPlaneSpec struct {
    // Allowed values are "azure", "kubenet".
    // Immutable.
    // +kubebuilder:validation:Enum=azure;kubenet
+   // +kubebuilder:default:=azure
    // +optional
    NetworkPlugin *string `json:"networkPlugin,omitempty"`

Tests that verify the removed code should also be removed.

After modifying the annotations, run make generate-manifests to encode the new defaults in the CRDs.

Describe the solution you'd like Walk through the webhooks starting at the following places and replace hand-rolled code to default fields with static fields with the kubebuilder annotation:

https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremachine_webhook.go#L221 https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremachinetemplate_webhook.go#L145 https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedcontrolplane_webhook.go#L70 https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedmachinepool_webhook.go#L68 https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/exp/api/v1beta1/azuremachinepool_webhook.go#L59

Anything else you would like to add: [Miscellaneous information that will assist in solving the issue.]

k8s-ci-robot commented 1 year ago

@nojnhuh: This request has been marked as suitable for new contributors.

Guidelines

Please ensure that the issue body includes answers to the following questions:

For more details on the requirements of such an issue, please see here and ensure that they are met.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-good-first-issue command.

In response to [this](https://github.com/kubernetes-sigs/cluster-api-provider-azure/issues/4204): >/kind cleanup >/good-first-issue >/help > >**What needs cleanup:** > > >There are several places in the defaulting webhooks where CAPZ defaults a static value that could be replaced with the [`// +kubebuilder:default`](https://book.kubebuilder.io/reference/markers/crd-validation.html) annotation on the API type. > >e.g. this code defaults a static value >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedcontrolplane_webhook.go#L75-L78 > >It should be removed and replaced by the following change to this block: >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedcontrolplane_types.go#L118-L123 > >```diff >diff --git a/api/v1beta1/azuremanagedcontrolplane_types.go b/api/v1beta1/azuremanagedcontrolplane_types.go >index 5d83db207..35adbf3db 100644 >--- a/api/v1beta1/azuremanagedcontrolplane_types.go >+++ b/api/v1beta1/azuremanagedcontrolplane_types.go >@@ -126,6 +126,7 @@ type AzureManagedControlPlaneSpec struct { > // Allowed values are "azure", "kubenet". > // Immutable. > // +kubebuilder:validation:Enum=azure;kubenet >+ // +kubebuilder:default:=azure > // +optional > NetworkPlugin *string `json:"networkPlugin,omitempty"` >``` > >Tests that verify the removed code should also be removed. > >After modifying the annotations, run `make generate-manifests` to encode the new defaults in the CRDs. > >**Describe the solution you'd like** >Walk through the webhooks starting at the following places and replace hand-rolled code to default fields with static fields with the kubebuilder annotation: > >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremachine_webhook.go#L221 >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremachinetemplate_webhook.go#L145 >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedcontrolplane_webhook.go#L70 >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/api/v1beta1/azuremanagedmachinepool_webhook.go#L68 >https://github.com/kubernetes-sigs/cluster-api-provider-azure/blob/e2bd59253c859b151ac6f3222ad6c749e2a1ba75/exp/api/v1beta1/azuremachinepool_webhook.go#L59 > >**Anything else you would like to add:** >[Miscellaneous information that will assist in solving the issue.] > 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.
SubhasmitaSw commented 1 year ago

I'd like to work on this, assigning it to myself.

/assign

SubhasmitaSw commented 1 year ago

@nojnhuh I've submitted a PR the aforementioned cleanup. Kindly review it at your earliest convenience. Thank you!

nojnhuh commented 11 months ago

@SubhasmitaSw Feel free to re-assign yourself to this issue and reopen #4214 if you plan to get back to this.

/unassign @SubhasmitaSw

kumarankit999 commented 10 months ago

I would like to go with this issue! If anyone is not working on this issue!

nojnhuh commented 10 months ago

Thank you! /assign @kumarankit999

bryan-cox commented 2 months ago

It doesn't look like there has been any new progress on this issue. I can work on this issue if no one is actively working on it.

nawazkh commented 2 months ago

Feel free to pick it up @bryan-cox ! /unassign @kumarankit999

bryan-cox commented 2 months ago

/assign