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]: Not setting maxLength in the Length attribute when generating CRD's outputs maxLength: -1 #805

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

Comments

@EdwardCooke
Copy link

Describe the bug

When using the Length attribute and only specifying the min length, like this [Length(minLength: 1)], the resulting generated CRD has this in it:

maxLength: -1
minLength: 1
nullable: false
type: string

To reproduce

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

        /// <summary>
        /// Reference to the ingress or service
        /// </summary>
        [Required]
        public V1ObjectReference ObjectReference { get; set; } = new V1ObjectReference();

        /// <summary>
        /// Hostnames to expose the ingress or service as
        /// </summary>
        [Required]
        public string[] Hostnames { get; set; } = Array.Empty<string>();

        /// <summary>
        /// External IP to return instead of what is in the ingress or service
        /// </summary>
        public string[]? IPOverrides { get; set; }

        /// <summary>
        /// Priority to assign this GSLB object. Highest priority is chosen first.
        /// </summary>
        [Required]
        [RangeMinimum(0)]
        public int Priority { get; set; } = 0;

        /// <summary>
        /// Weight to assign this GSLB object when doing round robin load balancing type. Defaults to 50.
        /// The calculation to determine the final weighting of all objects is (weight / sum of all weights) * 100.
        /// </summary>
        [Required]
        [RangeMinimum(0)]
        public int Weight { get; set; } = 50;

        public class V1ObjectReference
        {
            [Required]
            [Length(minLength: 1)]
            public string Name { get; set; } = string.Empty;

            [Required]
            public ReferenceType Kind { get; set; }

            public enum ReferenceType
            {
                Ingress,
                Service
            }
        }
    }

Use dotnet kubeops g op test
Generates this CRD

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: gslbs.multicluster.veccsolutions.io
spec:
  group: multicluster.veccsolutions.io
  names:
    kind: GSLB
    listKind: GSLBList
    plural: gslbs
    singular: gslb
  scope: Namespaced
  versions:
  - name: v1alpha
    schema:
      openAPIV3Schema:
        properties:
          objectReference:
            nullable: false
            properties:
              name:
                maxLength: -1
                minLength: 1
                nullable: false
                type: string
              kind:
                enum:
                - Ingress
                - Service
                nullable: false
                type: string
            required:
            - name
            - kind
            type: object
          hostnames:
            items:
              nullable: false
              type: string
            nullable: false
            type: array
          iPOverrides:
            items:
              nullable: false
              type: string
            nullable: true
            type: array
          priority:
            exclusiveMinimum: false
            format: int32
            minimum: 0.0
            nullable: false
            type: integer
          weight:
            exclusiveMinimum: false
            format: int32
            minimum: 0.0
            nullable: false
            type: integer
        type: object
    served: true
    storage: true

Expected behavior

The CRD wouldn't have maxLength in it.

Screenshots

No response

Additional Context

No response

@EdwardCooke EdwardCooke added the bug Something isn't working label Aug 26, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 2024
@github-staff github-staff deleted a comment from Lxx-c Oct 23, 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

2 participants
@EdwardCooke and others