dotnet-operator-sdk
dotnet-operator-sdk copied to clipboard
[bug]: Not setting maxLength in the Length attribute when generating CRD's outputs maxLength: -1
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