CRD generation fails for nested V1ObjectMeta
See original GitHub issueDescribe the bug
The CRD for an entity that uses a V1PodTemplateSpec
does not allow any metadata fields to be set on that property.
To Reproduce Given the following custom entity:
using k8s.Models;
using KubeOps.Operator.Entities;
using KubeOps.Operator.Entities.Annotations;
namespace MyNamespace
{
/// <summary>
/// MyEntity specification.
/// </summary>
public class V1Alpha1MyEntitySpec
{
/// <summary>
/// Gets or sets the pod template.
/// </summary>
[Required]
public V1PodTemplateSpec Template { get; set; }
}
/// <summary>
/// MyEntity status.
/// </summary>
public class V1Alpha1MyEntityStatus
{
}
/// <summary>
/// Definition of a MyEntity entity. This entity contains a specification of MyEntity instance.
/// </summary>
[KubernetesEntity(Kind = "MyEntity", Group = "my.group.com", ApiVersion = "v1alpha1")]
public class V1Alpha1MyEntity : CustomKubernetesEntity<V1Alpha1MyEntitySpec, V1Alpha1MyEntityStatus>
{
}
}
It generates this CRD:
...
template:
description: Gets or sets the pod template.
properties:
metadata:
type: object // Here I would expect properties to be defined.
spec:
properties:
activeDeadlineSeconds:
format: int64
nullable: true
type: integer
...
If I would modify and persist an instance of the above entity, like below, it will not persists the labels or any other properties.
var entity = new V1Alpha1MyEntity();
entity.Spec.Template.Metadata.Labels["foo"] = "bar";
...
Expected behavior A valid CRD that accepts metadata.
Additional context
When I modify the CRD to include x-kubernetes-preserve-unknown-fields: true
, it works.
I believe it has to do with this part of the CRD generation, that may not hold for nested V1ObjectMeta
’s
Issue Analytics
- State:
- Created 2 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
Missing default value in nested field of kubernetes custom ...
I have a Custom Resource Definition which has nested fields with default values (some boilerplate omitted for brevity):
Read more >kubernetes.apiextensions.k8s.io.v1. ...
Must be a JSON Path under .spec . If there is no value under the given path in the custom resource, the /scale...
Read more >Package io.kubernetes.client.openapi.models
CertificateSigningRequestStatus contains conditions used to indicate approved/denied/failed status of the request, and the issued certificate.
Read more >Custom Resource Definition Reference - Grafana Agent
This is required for Integrations that generate Node-specific metrics like node_exporter, otherwise it must be false to avoid generating duplicate metrics.
Read more >Index | API reference | OpenShift Container Platform 4.11
MicroTime schema; io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta schema ... If the CRD is present in the Owned list, it is implicitly required.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ah, I guess I get it. 😃 Need to investigate again.
Hey, didn’t want to create a separate issue, but I think it’s related to this one. I’ve upgraded from 6.0.18 to the latest version (6.2.13). When using
V1ResourceRequirements
or some type that uses that built-in (for example in my caseV1PersistentVolumeClaimSpec
) type, the schema gets generated a bit differently and I can’t use my sample.The sample resource has the following value:
The generated CRD for the volume claim template:
And when applying the sample resource, it gives the following error:
.resources.requests.storage: Invalid value: "string": productionVolumeClaimTemplate.resources.requests.storage in body must be of type object: "string"
In version 6.0.18, on the resource’s
limits
andrequests
properties it generated just:Sorry for the mile-long text and thanks for making the awesome lib!