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

fix: default value with k8s x-order extension #123

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ build-local-linux:
GOOS=linux GOARCH=amd64 CGO_ENABLED=0 \
go build -o ./_build/linux/kcl-openapi \
-ldflags="-s -w" .

build:
-rm -rf ./_build/local/
mkdir -p ./_build/local/
Expand Down
5,923 changes: 5,923 additions & 0 deletions pkg/kube_resource/generator/testdata/default_value/crd.golden.yaml

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
"""
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""
import regex
import k8s.apimachinery.pkg.apis.meta.v1
_regex_match = regex.match


schema GatewayClass:
r"""
GatewayClass describes a class of Gateways available to the user for creating Gateway resources.
It is recommended that this resource be used as a template for Gateways. This means that a Gateway is based on the state of the GatewayClass at the time it was created and changes to the GatewayClass or associated parameters are not propagated down to existing Gateways. This recommendation is intended to limit the blast radius of changes to GatewayClass or associated parameters. If implementations choose to propagate GatewayClass changes to existing Gateways, that MUST be clearly documented by the implementation.
Whenever one or more Gateways are using a GatewayClass, implementations SHOULD add the `gateway-exists-finalizer.gateway.networking.k8s.io` finalizer on the associated GatewayClass. This ensures that a GatewayClass associated with a Gateway is not deleted while in use.
GatewayClass is a Cluster level resource.

Attributes
----------
apiVersion : str, default is "gateway.networking.k8s.io/v1alpha2", required
APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
kind : str, default is "GatewayClass", required
Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
metadata : v1.ObjectMeta, default is Undefined, optional
metadata
spec : GatewayNetworkingK8sIoV1alpha2GatewayClassSpec, default is Undefined, required
spec
status : GatewayNetworkingK8sIoV1alpha2GatewayClassStatus, default is Undefined, optional
status
"""


apiVersion: "gateway.networking.k8s.io/v1alpha2" = "gateway.networking.k8s.io/v1alpha2"

kind: "GatewayClass" = "GatewayClass"

metadata?: v1.ObjectMeta

spec: GatewayNetworkingK8sIoV1alpha2GatewayClassSpec

status?: GatewayNetworkingK8sIoV1alpha2GatewayClassStatus


schema GatewayNetworkingK8sIoV1alpha2GatewayClassSpec:
r"""
Spec defines the desired state of GatewayClass.

Attributes
----------
controllerName : str, default is Undefined, required
ControllerName is the name of the controller that is managing Gateways of this class. The value of this field MUST be a domain prefixed path.
Example: "example.net/gateway-controller".
This field is not mutable and cannot be empty.
Support: Core
description : str, default is Undefined, optional
Description helps describe a GatewayClass with more details.
parametersRef : GatewayNetworkingK8sIoV1alpha2GatewayClassSpecParametersRef, default is Undefined, optional
parameters ref
"""


controllerName: str

description?: str

parametersRef?: GatewayNetworkingK8sIoV1alpha2GatewayClassSpecParametersRef


check:
len(controllerName) <= 253
len(controllerName) >= 1
_regex_match(str(controllerName), r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$")
len(description) <= 64 if description


schema GatewayNetworkingK8sIoV1alpha2GatewayClassSpecParametersRef:
r"""
ParametersRef is a reference to a resource that contains the configuration parameters corresponding to the GatewayClass. This is optional if the controller does not require any additional configuration.
ParametersRef can reference a standard Kubernetes resource, i.e. ConfigMap, or an implementation-specific custom resource. The resource can be cluster-scoped or namespace-scoped.
If the referent cannot be found, the GatewayClass's "InvalidParameters" status condition will be true.
Support: Implementation-specific

Attributes
----------
group : str, default is Undefined, required
Group is the group of the referent.
kind : str, default is Undefined, required
Kind is kind of the referent.
name : str, default is Undefined, required
Name is the name of the referent.
namespace : str, default is Undefined, optional
Namespace is the namespace of the referent. This field is required when referring to a Namespace-scoped resource and MUST be unset when referring to a Cluster-scoped resource.
"""


group: str

kind: str

name: str

namespace?: str


check:
len(group) <= 253
_regex_match(str(group), r"^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$")
len(kind) <= 63
len(kind) >= 1
_regex_match(str(kind), r"^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$")
len(name) <= 253
len(name) >= 1
len(namespace) <= 63 if namespace
len(namespace) >= 1 if namespace
_regex_match(str(namespace), r"^[a-z0-9]([-a-z0-9]*[a-z0-9])?$") if namespace


schema GatewayNetworkingK8sIoV1alpha2GatewayClassStatus:
r"""
Status defines the current state of GatewayClass.

Attributes
----------
conditions : [GatewayNetworkingK8sIoV1alpha2GatewayClassStatusConditionsItems0], default is [{"lastTransitionTime": "1970-01-01T00:00:00Z", "message": "Waiting for controller", "reason": "Pending", "status": "Unknown", "type": "Accepted"}], optional
Conditions is the current status from the controller for this GatewayClass.
Controllers should prefer to publish conditions using values of GatewayClassConditionType for the type of each Condition.
"""


conditions?: [GatewayNetworkingK8sIoV1alpha2GatewayClassStatusConditionsItems0] = [{"lastTransitionTime": "1970-01-01T00:00:00Z", "message": "Waiting for controller", "reason": "Pending", "status": "Unknown", "type": "Accepted"}]


check:
len(conditions) <= 8 if conditions


schema GatewayNetworkingK8sIoV1alpha2GatewayClassStatusConditionsItems0:
r"""
Condition contains details for one aspect of the current state of this API Resource. --- This struct is intended for direct use as an array at the field path .status.conditions. For example,
type FooStatus struct{ // Represents the observations of a foo's current state. // Known .status.conditions.type are: "Available", "Progressing", and "Degraded" // +patchMergeKey=type // +patchStrategy=merge // +listType=map // +listMapKey=type Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"`
// other fields }

Attributes
----------
lastTransitionTime : str, default is Undefined, required
lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
message : str, default is Undefined, required
message is a human readable message indicating details about the transition. This may be an empty string.
observedGeneration : int, default is Undefined, optional
observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.
reason : str, default is Undefined, required
reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.
status : str, default is Undefined, required
status of the condition, one of True, False, Unknown.
$type : str, default is Undefined, required
type of condition in CamelCase or in foo.example.com/CamelCase. --- Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be useful (see .node.status.conditions), the ability to deconflict is important. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
"""


lastTransitionTime: str

message: str

observedGeneration?: int

reason: str

status: "True" | "False" | "Unknown"

$type: str


check:
len(message) <= 32768
observedGeneration >= 0 if observedGeneration not in [None, Undefined]
len(reason) <= 1024
len(reason) >= 1
_regex_match(str(reason), r"^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$")
len($type) <= 316
_regex_match(str($type), r"^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$")


Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
"""
This is the managed_fields_entry module in k8s.apimachinery.pkg.apis.meta.v1 package.
This file was generated by the KCL auto-gen tool. DO NOT EDIT.
Editing this file might prove futile when you re-run the KCL auto-gen generate command.
"""


schema ManagedFieldsEntry:
r"""
ManagedFieldsEntry is a workflow-id, a FieldSet and the group version of the resource that the fieldset applies to.

Attributes
----------
apiVersion : str, default is Undefined, optional
APIVersion defines the version of this resource that this field set applies to. The format is "group/version" just like the top-level APIVersion field. It is necessary to track the version of a field set because it cannot be automatically converted.
fieldsType : str, default is Undefined, optional
FieldsType is the discriminator for the different fields format and version. There is currently only one possible value: "FieldsV1"
fieldsV1 : any, default is Undefined, optional
FieldsV1 holds the first JSON version format as described in the "FieldsV1" type.
manager : str, default is Undefined, optional
Manager is an identifier of the workflow managing these fields.
operation : str, default is Undefined, optional
Operation is the type of operation which lead to this ManagedFieldsEntry being created. The only valid values for this field are 'Apply' and 'Update'.
time : str, default is Undefined, optional
Time is timestamp of when these fields were set. It should always be empty if Operation is 'Apply'
"""


apiVersion?: str

fieldsType?: str

fieldsV1?: any

manager?: str

operation?: str

time?: str


Loading
Loading