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

@SchemaSwap can only be used once #4350

Closed
xRodney opened this issue Aug 24, 2022 · 1 comment · Fixed by #4354
Closed

@SchemaSwap can only be used once #4350

xRodney opened this issue Aug 24, 2022 · 1 comment · Fixed by #4354
Assignees
Labels
bug component/crd-generator Related to the CRD generator
Milestone

Comments

@xRodney
Copy link
Contributor

xRodney commented Aug 24, 2022

Describe the bug

In the documentation, it is written that it is "Same as SchemaFrom, but can be applied at any point in the class hierarchy"

I also found in this PR: "The annotation serves to enable the use-case where you want to generate a valid CRD from a model that you don't own.". The PR references keycloak operator as an example of such model.

I believe I have a similar-enough use case:

  • In my schema, I use a huge object tree (hundreds of fields in dozens of classes) which I do not own.
  • Most of the classes are fine, only at a few places I need to tweak things.
  • If I owned the classes, I would have just added a few @SchemaFrom's here and there.

I am led to believe that @SchemaSwap is the way how to achieve the same result without editing external code.
For each @SchemaFrom I would like to have on a field of some class I do not own, I would instead put one @SchemaSwap on the root level.

There are two problems with this:

  1. @SchemaSwap is not repeatable. I am only entitled to one @SchemaSwap annotation per class.
  2. If the class and field referenced in @SchemaSwap is used multiple times in the class hierarchy, it is only replaced once.

Fabric8 Kubernetes Client version

5.12.3

Steps to reproduce

Generate CRD for this schema:

@Group("testresource.example.com")
@Version("v1")
@SchemaSwap(originalType = ExternalObject.class, fieldName = "shouldBeInt", targetType = Integer.class)
//@SchemaSwap(originalType = AnotherObject.class, fieldName = "shouldBeString", targetType = String.class)    // does not compile if uncommented
public class TestResource extends CustomResource<ExternalSpec, Void> implements Namespaced {
}

// I do not own these classes:

class ExternalSpec {
    ExternalObject first;
    ExternalObject second;
    AnotherObject third;
}

class ExternalObject {
    String shouldBeInt;
}

class AnotherObject {
    int shouldBeString;
}

It generates:

    schema:
      openAPIV3Schema:
        properties:
          spec:
            properties:
              first:
                properties:
                  shouldBeInt:
                    type: integer
                type: object
              second:
                properties:
                  shouldBeInt:
                    type: string
                type: object
              third:
                properties:
                  shouldBeString:
                    type: integer
                type: object
            type: object
          status:
            type: object
        type: object

Expected behavior

I want all three replacements in my example to happen.

Runtime

other (please specify in additional context)

Kubernetes API Server version

other (please specify in additional context)

Environment

other (please specify in additional context)

Fabric8 Kubernetes Client Logs

No response

Additional context

I believe these are bugs, rather than limitations by design, and judging from the code, they should not be hard to fix. I may attempt a PR if you agree.

Or am I using them wrong?

Thanks for advice and for a great library!

@andreaTP
Copy link
Member

Hi @xRodney !
Thanks a lot for rising this issue, I can confirm that you are experiencing bugs that I never found the time to fix (e.g. ref )
I would like to share some very very initial work I have started in the area here, but please consider it solely exploratory.

I may attempt a PR if you agree.

Please! Be my guest! Just let me know if, for any reason, you have to drop this effort so that I put this back on my long-term todo list 🙂

Feel free to ask any questions and/or support!

xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 25, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 25, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 25, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes fabric8io#4350
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 26, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes fabric8io#4350
@manusa manusa added bug component/crd-generator Related to the CRD generator labels Aug 29, 2022
@manusa manusa added this to the 6.1.0 milestone Aug 30, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Aug 30, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes fabric8io#4350
@manusa manusa modified the milestones: 6.1.0, 6.2.0 Aug 31, 2022
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Sep 3, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes fabric8io#4350
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Sep 5, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes fabric8io#4350
xRodney added a commit to xRodney/kubernetes-client that referenced this issue Sep 6, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes fabric8io#4350
andreaTP added a commit that referenced this issue Sep 8, 2022
@SchemaSwap is now repeatable, so multiple modifications can be applied from the same resource root.
Fixed a bug when the swap was "used up" after just one usage, meaning that if the referenced type was used multiple times in object hierarchy, only the first one was swapped.

Fixes #4350

Co-authored-by: Dusan Jakub <dusan.jakub@ysoft.com>
Co-authored-by: Andrea Peruffo <andrea.peruffo1982@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug component/crd-generator Related to the CRD generator
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants