Skip to content
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

Generate crd with controller gen #159

Merged
merged 22 commits into from
May 28, 2021
Merged

Conversation

181192
Copy link
Collaborator

@181192 181192 commented Mar 10, 2021

About this PR

This PR enables the generation of the CRDs from the APIs, using the controller-gen cli, which is part of the KubeBuilder project.

Annotations has been added to the types to make it as close as possible as the manually created CRD.

See the diff on the generated CRD here.

Changes

Some changes was needed to be done:

  • Removal of unused (?) field Poll from AzureKeyVaultObject type 2db1085
  • Several annotations in the types to generate the same CRD as created manually
  • Added enum's for some types 2c462e8 and f999a27
  • Added AzureIdentity struct 4c44534 to align with the original CRD (this was a bug, need to make sure code references are still OK)
  • Added Makefile target for generating CRD's
  • Added the API for version v2alpha1 that exists in manual CRD 1cf7336 075b8fe
  • Updated hack/update-codegen.sh with running code-generator inside a container and modifying repository files directly
  • Populate status field as shown bellow

Previous status field was only type object with preserve unknown fields enabled

status:
  type: object
  x-kubernetes-preserve-unknown-fields: true

Now it generates with correct fields

status:
  description: AzureKeyVaultSecretStatus is the status for a AzureKeyVaultSecret resource
  properties:
    lastAzureUpdate:
      format: date-time
      type: string
    secretHash:
      type: string
    secretName:
      type: string
  required:
  - secretHash
  - secretName
  type: object

The spec field is also now required, but not status as the controller will update the status field later

schema:
  openAPIV3Schema:
    < .... > # omitted for brevity
  required:
  - spec
  type: object

Development Workflow

To generate client code

make codegen

To generate crd

make crdgen

@181192 181192 requested a review from torresdal as a code owner March 10, 2021 13:22
@181192 181192 marked this pull request as draft March 10, 2021 14:11
@181192 181192 force-pushed the generate-crd-with-controller-gen branch 2 times, most recently from a71ee34 to d25df20 Compare March 10, 2021 14:28
@181192 181192 marked this pull request as ready for review March 10, 2021 14:58
@181192 181192 force-pushed the generate-crd-with-controller-gen branch from 70794e9 to 1b76567 Compare March 29, 2021 18:02
@181192
Copy link
Collaborator Author

181192 commented Mar 29, 2021

Missed generating clients due to having repo in non default GOPATH, updated hack/update-codegen.sh with running code-generator inside a container and modifying repository files directly.

181192 added 4 commits March 30, 2021 09:55
Introduced breaking changes with generated crd that change group and crd name, that breaks all existing azurekeyvaultsecrets.spv.no applied to a cluster
Changes group identifier of generated code from Spv to AzureKeyVault
Mark status field as a subresource
@181192
Copy link
Collaborator Author

181192 commented Mar 30, 2021

Introduced breaking changes with generated crd that change group and crd name, that breaks all existing azurekeyvaultsecrets.spv.no applied to a cluster.
Reverted to use group name +groupName=spv.no and added +groupGoName=AzureKeyVault to get "nicer" group names on generated Go code (Spv was a bit to general)

Added +kubebuilder:subresource:status to mark the Status field as a subresource, updating status field was failing.
Also added Age field to additional printer columns

@181192 181192 force-pushed the generate-crd-with-controller-gen branch 2 times, most recently from d3b4976 to c3ee0bf Compare April 7, 2021 14:00
@181192 181192 merged commit 37f73d5 into master May 28, 2021
@181192 181192 deleted the generate-crd-with-controller-gen branch May 28, 2021 09:39
@181192 181192 added this to the Version 1.3.0 milestone Aug 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant