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

[bug]: Multiple capitol letters at beginning of property name generates invalid CRD definition #804

Open
EdwardCooke opened this issue Aug 26, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@EdwardCooke
Copy link

EdwardCooke commented Aug 26, 2024

Describe the bug

If you have a property with a name of something like IPAddress, the CLI generates a property in the CRD as iPAddress. However, when attempting to post that object to Kubernetes it uses a field named ipAddress. (Lower case p)

To reproduce

Create a class that has a field named IPAddress,

[EntityScope(EntityScope.Namespaced)]
[KubernetesEntity(Group ="multicluster.veccsolutions.io", ApiVersion = "v1alpha", Kind = "ClusterCache")]
public class V1ClusterCache : CustomKubernetesEntity
{
    public V1ClusterCache()
    {
        Kind = "ClusterCache";
        ApiVersion = "multicluster.veccsolutions.io/v1alpha";
    }

    public string LastHeartbeat { get; set; } = string.Empty;
    public HostCache[] Hostnames { get; set; } = Array.Empty<HostCache>();
    public EndpointCacheCount[] ServiceEndpointCounts { get; set; } = Array.Empty<EndpointCacheCount>();

    public class EndpointCacheCount
    {
        public string Namespace { get; set; } = string.Empty;
        public string Service { get; set; } = string.Empty;
        public int Count { get; set; }
    }

    public class HostCache
    {
        public string Hostname { get; set; } = string.Empty;
        public HostIPCache[] HostIPs { get; set; } = Array.Empty<HostIPCache>();
    }

    public class HostIPCache
    {
        public string IPAddress { get; set; } = string.Empty;
        public int Priority { get; set; }
        public int Weight { get; set; }
        public string ClusterIdentifier { get; set; } = string.Empty;
    }
}

Generate the CRD with ddotnet kubeops g op test
The result is this:

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: clustercaches.multicluster.veccsolutions.io
spec:
  group: multicluster.veccsolutions.io
  names:
    kind: ClusterCache
    listKind: ClusterCacheList
    plural: clustercaches
    singular: clustercache
  scope: Namespaced
  versions:
  - name: v1alpha
    schema:
      openAPIV3Schema:
        properties:
          lastHeartbeat:
            nullable: false
            type: string
          hostnames:
            items:
              properties:
                hostname:
                  nullable: false
                  type: string
                hostIPs:
                  items:
                    properties:
                      iPAddress:
                        nullable: false
                        type: string
                      priority:
                        format: int32
                        nullable: false
                        type: integer
                      weight:
                        format: int32
                        nullable: false
                        type: integer
                      clusterIdentifier:
                        nullable: false
                        type: string
                    type: object
                  nullable: false
                  type: array
              type: object
            nullable: false
            type: array
          serviceEndpointCounts:
            items:
              properties:
                namespace:
                  nullable: false
                  type: string
                service:
                  nullable: false
                  type: string
                count:
                  format: int32
                  nullable: false
                  type: integer
              type: object
            nullable: false
            type: array
        type: object
    served: true
    storage: true

Notice the incorrect iPAddress casing.

Expected behavior

The IPAddress property would render as ipAddress in the CRD.

Screenshots

No response

Additional Context

No response

@EdwardCooke EdwardCooke added the bug Something isn't working label Aug 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant