From ab6b7a3a1d6b81bec426bb225b878c76b32ab1cd Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Tue, 13 Jun 2023 15:52:40 +0200 Subject: [PATCH] crd: reduce CRD size Signed-off-by: Alexander Yastrebov --- Makefile | 5 +- docs/stack_crd.yaml | 203 --------------- docs/stackset_crd.yaml | 552 ----------------------------------------- hack/crd/trim.go | 106 ++++++++ 4 files changed, 109 insertions(+), 757 deletions(-) create mode 100644 hack/crd/trim.go diff --git a/Makefile b/Makefile index c3c2d0ac..ecd5ca5a 100644 --- a/Makefile +++ b/Makefile @@ -36,8 +36,9 @@ $(GENERATED): go.mod $(CRD_TYPE_SOURCE) $(GENERATED_CRDS): $(GENERATED) $(CRD_SOURCES) go run sigs.k8s.io/controller-tools/cmd/controller-gen crd:crdVersions=v1,allowDangerousTypes=true paths=./pkg/apis/... output:crd:dir=docs || /bin/true || true - mv docs/zalando.org_stacksets.yaml docs/stackset_crd.yaml - mv docs/zalando.org_stacks.yaml docs/stack_crd.yaml + go run hack/crd/trim.go < docs/zalando.org_stacksets.yaml > docs/stackset_crd.yaml + go run hack/crd/trim.go < docs/zalando.org_stacks.yaml > docs/stack_crd.yaml + rm docs/zalando.org_stacksets.yaml docs/zalando.org_stacks.yaml build.local: $(LOCAL_BINARIES) $(GENERATED_CRDS) build.linux: $(LINUX_BINARIES) diff --git a/docs/stack_crd.yaml b/docs/stack_crd.yaml index 1f956f83..57102841 100644 --- a/docs/stack_crd.yaml +++ b/docs/stack_crd.yaml @@ -1,4 +1,3 @@ ---- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: @@ -945,16 +944,6 @@ spec: Gt, and Lt. type: string values: - description: An array of string values. - If the operator is In or NotIn, - the values array must be non-empty. - If the operator is Exists or DoesNotExist, - the values array must be empty. - If the operator is Gt or Lt, the - values array must have a single - element, which will be interpreted - as an integer. This array is replaced - during a strategic merge patch. items: type: string type: array @@ -983,16 +972,6 @@ spec: Gt, and Lt. type: string values: - description: An array of string values. - If the operator is In or NotIn, - the values array must be non-empty. - If the operator is Exists or DoesNotExist, - the values array must be empty. - If the operator is Gt or Lt, the - values array must have a single - element, which will be interpreted - as an integer. This array is replaced - during a strategic merge patch. items: type: string type: array @@ -1051,16 +1030,6 @@ spec: Gt, and Lt. type: string values: - description: An array of string values. - If the operator is In or NotIn, - the values array must be non-empty. - If the operator is Exists or DoesNotExist, - the values array must be empty. - If the operator is Gt or Lt, the - values array must have a single - element, which will be interpreted - as an integer. This array is replaced - during a strategic merge patch. items: type: string type: array @@ -1089,16 +1058,6 @@ spec: Gt, and Lt. type: string values: - description: An array of string values. - If the operator is In or NotIn, - the values array must be non-empty. - If the operator is Exists or DoesNotExist, - the values array must be empty. - If the operator is Gt or Lt, the - values array must have a single - element, which will be interpreted - as an integer. This array is replaced - during a strategic merge patch. items: type: string type: array @@ -1156,25 +1115,10 @@ spec: the key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to a set - of values. Valid operators are - In, NotIn, Exists and DoesNotExist. type: string values: - description: values is an array - of string values. If the operator - is In or NotIn, the values array - must be non-empty. If the operator - is Exists or DoesNotExist, the - values array must be empty. - This array is replaced during - a strategic merge patch. items: type: string type: array @@ -1220,25 +1164,10 @@ spec: the key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to a set - of values. Valid operators are - In, NotIn, Exists and DoesNotExist. type: string values: - description: values is an array - of string values. If the operator - is In or NotIn, the values array - must be non-empty. If the operator - is Exists or DoesNotExist, the - values array must be empty. - This array is replaced during - a strategic merge patch. items: type: string type: array @@ -1497,25 +1426,10 @@ spec: the key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to a set - of values. Valid operators are - In, NotIn, Exists and DoesNotExist. type: string values: - description: values is an array - of string values. If the operator - is In or NotIn, the values array - must be non-empty. If the operator - is Exists or DoesNotExist, the - values array must be empty. - This array is replaced during - a strategic merge patch. items: type: string type: array @@ -1561,25 +1475,10 @@ spec: the key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to a set - of values. Valid operators are - In, NotIn, Exists and DoesNotExist. type: string values: - description: values is an array - of string values. If the operator - is In or NotIn, the values array - must be non-empty. If the operator - is Exists or DoesNotExist, the - values array must be empty. - This array is replaced during - a strategic merge patch. items: type: string type: array @@ -6919,25 +6818,10 @@ spec: the key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to a set - of values. Valid operators are - In, NotIn, Exists and DoesNotExist. type: string values: - description: values is an array - of string values. If the operator - is In or NotIn, the values array - must be non-empty. If the operator - is Exists or DoesNotExist, the - values array must be empty. - This array is replaced during - a strategic merge patch. items: type: string type: array @@ -7378,32 +7262,11 @@ spec: path within a volume. properties: key: - description: The key to project. type: string mode: - description: 'Optional: mode bits - used to set permissions on this - file. Must be an octal value between - 0000 and 0777 or a decimal value - between 0 and 511. YAML accepts - both octal and decimal values, - JSON requires decimal values for - mode bits. If not specified, the - volume defaultMode will be used. - This might be in conflict with - other options that affect the - file mode, like fsGroup, and the - result can be other mode bits - set.' format: int32 type: integer path: - description: The relative path of - the file to map the key to. May - not be an absolute path. May not - contain the path element '..'. - May not start with the string - '..'. type: string required: - key @@ -7434,75 +7297,30 @@ spec: the pod field properties: fieldRef: - description: 'Required: Selects - a field of the pod: only annotations, - labels, name and namespace are - supported.' properties: apiVersion: - description: Version of the - schema the FieldPath is written - in terms of, defaults to "v1". type: string fieldPath: - description: Path of the field - to select in the specified - API version. type: string required: - fieldPath type: object mode: - description: 'Optional: mode bits - used to set permissions on this - file, must be an octal value between - 0000 and 0777 or a decimal value - between 0 and 511. YAML accepts - both octal and decimal values, - JSON requires decimal values for - mode bits. If not specified, the - volume defaultMode will be used. - This might be in conflict with - other options that affect the - file mode, like fsGroup, and the - result can be other mode bits - set.' format: int32 type: integer path: - description: 'Required: Path is the - relative path name of the file - to be created. Must not be absolute - or contain the ''..'' path. Must - be utf-8 encoded. The first item - of the relative path must not - start with ''..''' type: string resourceFieldRef: - description: 'Selects a resource - of the container: only resources - limits and requests (limits.cpu, - limits.memory, requests.cpu and - requests.memory) are currently - supported.' properties: containerName: - description: 'Container name: - required for volumes, optional - for env vars' type: string divisor: anyOf: - type: integer - type: string - description: Specifies the output - format of the exposed resources, - defaults to "1" pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true resource: - description: 'Required: resource - to select' type: string required: - resource @@ -7535,32 +7353,11 @@ spec: path within a volume. properties: key: - description: The key to project. type: string mode: - description: 'Optional: mode bits - used to set permissions on this - file. Must be an octal value between - 0000 and 0777 or a decimal value - between 0 and 511. YAML accepts - both octal and decimal values, - JSON requires decimal values for - mode bits. If not specified, the - volume defaultMode will be used. - This might be in conflict with - other options that affect the - file mode, like fsGroup, and the - result can be other mode bits - set.' format: int32 type: integer path: - description: The relative path of - the file to map the key to. May - not be an absolute path. May not - contain the path element '..'. - May not start with the string - '..'. type: string required: - key diff --git a/docs/stackset_crd.yaml b/docs/stackset_crd.yaml index 72b84df3..a41ee40f 100644 --- a/docs/stackset_crd.yaml +++ b/docs/stackset_crd.yaml @@ -1,4 +1,3 @@ ---- apiVersion: apiextensions.k8s.io/v1 kind: CustomResourceDefinition metadata: @@ -1228,32 +1227,10 @@ spec: that relates the key and values. properties: key: - description: The label key - that the selector applies - to. type: string operator: - description: Represents a - key's relationship to a - set of values. Valid operators - are In, NotIn, Exists, DoesNotExist. - Gt, and Lt. type: string values: - description: An array of string - values. If the operator - is In or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the values - array must be empty. If - the operator is Gt or Lt, - the values array must have - a single element, which - will be interpreted as an - integer. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -1272,32 +1249,10 @@ spec: that relates the key and values. properties: key: - description: The label key - that the selector applies - to. type: string operator: - description: Represents a - key's relationship to a - set of values. Valid operators - are In, NotIn, Exists, DoesNotExist. - Gt, and Lt. type: string values: - description: An array of string - values. If the operator - is In or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the values - array must be empty. If - the operator is Gt or Lt, - the values array must have - a single element, which - will be interpreted as an - integer. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -1347,32 +1302,10 @@ spec: that relates the key and values. properties: key: - description: The label key - that the selector applies - to. type: string operator: - description: Represents a - key's relationship to a - set of values. Valid operators - are In, NotIn, Exists, DoesNotExist. - Gt, and Lt. type: string values: - description: An array of string - values. If the operator - is In or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the values - array must be empty. If - the operator is Gt or Lt, - the values array must have - a single element, which - will be interpreted as an - integer. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -1391,32 +1324,10 @@ spec: that relates the key and values. properties: key: - description: The label key - that the selector applies - to. type: string operator: - description: Represents a - key's relationship to a - set of values. Valid operators - are In, NotIn, Exists, DoesNotExist. - Gt, and Lt. type: string values: - description: An array of string - values. If the operator - is In or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the values - array must be empty. If - the operator is Gt or Lt, - the values array must have - a single element, which - will be interpreted as an - integer. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -1468,42 +1379,13 @@ spec: pods. properties: matchExpressions: - description: matchExpressions - is a list of label selector - requirements. The requirements - are ANDed. items: - description: A label selector - requirement is a selector - that contains values, a - key, and an operator that - relates the key and values. properties: key: - description: key is the - label key that the selector - applies to. type: string operator: - description: operator - represents a key's relationship - to a set of values. - Valid operators are - In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is - an array of string values. - If the operator is In - or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the - values array must be - empty. This array is - replaced during a strategic - merge patch. items: type: string type: array @@ -1515,16 +1397,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is - a map of {key,value} pairs. - A single {key,value} in the - matchLabels map is equivalent - to an element of matchExpressions, - whose key field is "key", - the operator is "In", and - the values array contains - only "value". The requirements - are ANDed. type: object type: object namespaceSelector: @@ -1543,42 +1415,13 @@ spec: feature is enabled. properties: matchExpressions: - description: matchExpressions - is a list of label selector - requirements. The requirements - are ANDed. items: - description: A label selector - requirement is a selector - that contains values, a - key, and an operator that - relates the key and values. properties: key: - description: key is the - label key that the selector - applies to. type: string operator: - description: operator - represents a key's relationship - to a set of values. - Valid operators are - In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is - an array of string values. - If the operator is In - or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the - values array must be - empty. This array is - replaced during a strategic - merge patch. items: type: string type: array @@ -1590,16 +1433,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is - a map of {key,value} pairs. - A single {key,value} in the - matchLabels map is equivalent - to an element of matchExpressions, - whose key field is "key", - the operator is "In", and - the values array contains - only "value". The requirements - are ANDed. type: object type: object namespaces: @@ -1682,28 +1515,10 @@ spec: key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to - a set of values. Valid operators - are In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is an - array of string values. - If the operator is In or - NotIn, the values array - must be non-empty. If the - operator is Exists or DoesNotExist, - the values array must be - empty. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -1752,28 +1567,10 @@ spec: key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to - a set of values. Valid operators - are In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is an - array of string values. - If the operator is In or - NotIn, the values array - must be non-empty. If the - operator is Exists or DoesNotExist, - the values array must be - empty. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -1862,42 +1659,13 @@ spec: pods. properties: matchExpressions: - description: matchExpressions - is a list of label selector - requirements. The requirements - are ANDed. items: - description: A label selector - requirement is a selector - that contains values, a - key, and an operator that - relates the key and values. properties: key: - description: key is the - label key that the selector - applies to. type: string operator: - description: operator - represents a key's relationship - to a set of values. - Valid operators are - In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is - an array of string values. - If the operator is In - or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the - values array must be - empty. This array is - replaced during a strategic - merge patch. items: type: string type: array @@ -1909,16 +1677,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is - a map of {key,value} pairs. - A single {key,value} in the - matchLabels map is equivalent - to an element of matchExpressions, - whose key field is "key", - the operator is "In", and - the values array contains - only "value". The requirements - are ANDed. type: object type: object namespaceSelector: @@ -1937,42 +1695,13 @@ spec: feature is enabled. properties: matchExpressions: - description: matchExpressions - is a list of label selector - requirements. The requirements - are ANDed. items: - description: A label selector - requirement is a selector - that contains values, a - key, and an operator that - relates the key and values. properties: key: - description: key is the - label key that the selector - applies to. type: string operator: - description: operator - represents a key's relationship - to a set of values. - Valid operators are - In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is - an array of string values. - If the operator is In - or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the - values array must be - empty. This array is - replaced during a strategic - merge patch. items: type: string type: array @@ -1984,16 +1713,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is - a map of {key,value} pairs. - A single {key,value} in the - matchLabels map is equivalent - to an element of matchExpressions, - whose key field is "key", - the operator is "In", and - the values array contains - only "value". The requirements - are ANDed. type: object type: object namespaces: @@ -2076,28 +1795,10 @@ spec: key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to - a set of values. Valid operators - are In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is an - array of string values. - If the operator is In or - NotIn, the values array - must be non-empty. If the - operator is Exists or DoesNotExist, - the values array must be - empty. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -2146,28 +1847,10 @@ spec: key and values. properties: key: - description: key is the label - key that the selector applies - to. type: string operator: - description: operator represents - a key's relationship to - a set of values. Valid operators - are In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is an - array of string values. - If the operator is In or - NotIn, the values array - must be non-empty. If the - operator is Exists or DoesNotExist, - the values array must be - empty. This array is replaced - during a strategic merge - patch. items: type: string type: array @@ -2513,12 +2196,8 @@ spec: HTTP probes properties: name: - description: The header field - name type: string value: - description: The header field - value type: string required: - name @@ -2631,12 +2310,8 @@ spec: HTTP probes properties: name: - description: The header field - name type: string value: - description: The header field - value type: string required: - name @@ -4008,12 +3683,8 @@ spec: HTTP probes properties: name: - description: The header field - name type: string value: - description: The header field - value type: string required: - name @@ -4126,12 +3797,8 @@ spec: HTTP probes properties: name: - description: The header field - name type: string value: - description: The header field - value type: string required: - name @@ -5502,12 +5169,8 @@ spec: HTTP probes properties: name: - description: The header field - name type: string value: - description: The header field - value type: string required: - name @@ -5620,12 +5283,8 @@ spec: HTTP probes properties: name: - description: The header field - name type: string value: - description: The header field - value type: string required: - name @@ -7749,21 +7408,10 @@ spec: as the DataSourceRef field.' properties: apiGroup: - description: APIGroup is the - group for the resource being - referenced. If APIGroup is - not specified, the specified - Kind must be in the core API - group. For any other third-party - types, APIGroup is required. type: string kind: - description: Kind is the type - of resource being referenced type: string name: - description: Name is the name - of resource being referenced type: string required: - kind @@ -7805,21 +7453,10 @@ spec: feature gate to be enabled.' properties: apiGroup: - description: APIGroup is the - group for the resource being - referenced. If APIGroup is - not specified, the specified - Kind must be in the core API - group. For any other third-party - types, APIGroup is required. type: string kind: - description: Kind is the type - of resource being referenced type: string name: - description: Name is the name - of resource being referenced type: string required: - kind @@ -7844,10 +7481,6 @@ spec: - type: string pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true - description: 'Limits describes - the maximum amount of compute - resources allowed. More info: - https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object requests: additionalProperties: @@ -7856,14 +7489,6 @@ spec: - type: string pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true - description: 'Requests describes - the minimum amount of compute - resources required. If Requests - is omitted for a container, - it defaults to Limits if that - is explicitly specified, otherwise - to an implementation-defined - value. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/' type: object type: object selector: @@ -7871,42 +7496,13 @@ spec: volumes to consider for binding. properties: matchExpressions: - description: matchExpressions - is a list of label selector - requirements. The requirements - are ANDed. items: - description: A label selector - requirement is a selector - that contains values, a - key, and an operator that - relates the key and values. properties: key: - description: key is the - label key that the selector - applies to. type: string operator: - description: operator - represents a key's relationship - to a set of values. - Valid operators are - In, NotIn, Exists and - DoesNotExist. type: string values: - description: values is - an array of string values. - If the operator is In - or NotIn, the values - array must be non-empty. - If the operator is Exists - or DoesNotExist, the - values array must be - empty. This array is - replaced during a strategic - merge patch. items: type: string type: array @@ -7918,16 +7514,6 @@ spec: matchLabels: additionalProperties: type: string - description: matchLabels is - a map of {key,value} pairs. - A single {key,value} in the - matchLabels map is equivalent - to an element of matchExpressions, - whose key field is "key", - the operator is "In", and - the values array contains - only "value". The requirements - are ANDed. type: object type: object storageClassName: @@ -8364,60 +7950,14 @@ spec: configMap data to project properties: items: - description: If unspecified, each - key-value pair in the Data field - of the referenced ConfigMap - will be projected into the volume - as a file whose name is the - key and content is the value. - If specified, the listed keys - will be projected into the specified - paths, and unlisted keys will - not be present. If a key is - specified which is not present - in the ConfigMap, the volume - setup will error unless it is - marked optional. Paths must - be relative and may not contain - the '..' path or start with - '..'. items: - description: Maps a string key - to a path within a volume. properties: key: - description: The key to - project. type: string mode: - description: 'Optional: - mode bits used to set - permissions on this file. - Must be an octal value - between 0000 and 0777 - or a decimal value between - 0 and 511. YAML accepts - both octal and decimal - values, JSON requires - decimal values for mode - bits. If not specified, - the volume defaultMode - will be used. This might - be in conflict with other - options that affect the - file mode, like fsGroup, - and the result can be - other mode bits set.' format: int32 type: integer path: - description: The relative - path of the file to map - the key to. May not be - an absolute path. May - not contain the path element - '..'. May not start with - the string '..'. type: string required: - key @@ -8444,95 +7984,32 @@ spec: description: Items is a list of DownwardAPIVolume file items: - description: DownwardAPIVolumeFile - represents information to - create the file containing - the pod field properties: fieldRef: - description: 'Required: - Selects a field of the - pod: only annotations, - labels, name and namespace - are supported.' properties: apiVersion: - description: Version - of the schema the - FieldPath is written - in terms of, defaults - to "v1". type: string fieldPath: - description: Path of - the field to select - in the specified API - version. type: string required: - fieldPath type: object mode: - description: 'Optional: - mode bits used to set - permissions on this file, - must be an octal value - between 0000 and 0777 - or a decimal value between - 0 and 511. YAML accepts - both octal and decimal - values, JSON requires - decimal values for mode - bits. If not specified, - the volume defaultMode - will be used. This might - be in conflict with other - options that affect the - file mode, like fsGroup, - and the result can be - other mode bits set.' format: int32 type: integer path: - description: 'Required: - Path is the relative - path name of the file - to be created. Must not - be absolute or contain - the ''..'' path. Must - be utf-8 encoded. The - first item of the relative - path must not start with - ''..''' type: string resourceFieldRef: - description: 'Selects a - resource of the container: - only resources limits - and requests (limits.cpu, - limits.memory, requests.cpu - and requests.memory) are - currently supported.' properties: containerName: - description: 'Container - name: required for - volumes, optional - for env vars' type: string divisor: anyOf: - type: integer - type: string - description: Specifies - the output format - of the exposed resources, - defaults to "1" pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$ x-kubernetes-int-or-string: true resource: - description: 'Required: - resource to select' type: string required: - resource @@ -8564,42 +8041,13 @@ spec: and may not contain the '..' path or start with '..'. items: - description: Maps a string key - to a path within a volume. properties: key: - description: The key to - project. type: string mode: - description: 'Optional: - mode bits used to set - permissions on this file. - Must be an octal value - between 0000 and 0777 - or a decimal value between - 0 and 511. YAML accepts - both octal and decimal - values, JSON requires - decimal values for mode - bits. If not specified, - the volume defaultMode - will be used. This might - be in conflict with other - options that affect the - file mode, like fsGroup, - and the result can be - other mode bits set.' format: int32 type: integer path: - description: The relative - path of the file to map - the key to. May not be - an absolute path. May - not contain the path element - '..'. May not start with - the string '..'. type: string required: - key diff --git a/hack/crd/trim.go b/hack/crd/trim.go new file mode 100644 index 00000000..cccd4ae9 --- /dev/null +++ b/hack/crd/trim.go @@ -0,0 +1,106 @@ +// This program removes descriptions from the input CRD yaml to reduce its size. +// +// # Why +// +// When CRD is applied via `kubectl apply -f docs/stackset_crd.yaml` (aka client-side apply) kubectl stores +// CRD content into the kubectl.kubernetes.io/last-applied-configuration annotation which has +// size limit of 262144 bytes. +// If the size of the annotation exceeds the limit, kubectl will fail with the following error: +// +// The CustomResourceDefinition "stacksets.zalando.org" is invalid: metadata.annotations: Too long: must have at most 262144 bytes +// +// See https://github.com/kubernetes/kubectl/issues/712 +// +// The CRD contains a lot of descriptions for k8s.io types and controller-gen +// does not allow to skip descriptions per field or per package, +// see https://github.com/kubernetes-sigs/controller-tools/issues/441 +// +// # How +// +// It removes descriptions starting at the deepest level of the yaml tree +// until the size of the yaml converted to json is less than the maximum allowed annotation size. +package main + +import ( + "encoding/json" + "io" + "log" + "os" + "sort" + + "sigs.k8s.io/yaml" +) + +const maxAnnotationSize = 262144 + +func must(err error) { + if err != nil { + log.Fatal(err) + } +} + +func mustGet[T any](v T, err error) T { + must(err) + return v +} + +type description struct { + depth int + property map[string]any + value string +} + +func main() { + yamlBytes := mustGet(io.ReadAll(os.Stdin)) + + o := make(map[string]any) + must(yaml.Unmarshal(yamlBytes, &o)) + + jsonBytes := mustGet(json.Marshal(o)) + size := len(jsonBytes) + + descriptions := collect(o, 0) + + sort.Slice(descriptions, func(i, j int) bool { + if descriptions[i].depth == descriptions[j].depth { + return len(descriptions[i].value) > len(descriptions[j].value) + } + return descriptions[i].depth > descriptions[j].depth + }) + + for _, d := range descriptions { + if size <= maxAnnotationSize { + break + } + size -= len(d.value) + delete(d.property, "description") + } + + if size > maxAnnotationSize { + log.Fatalf("YAML converted to JSON must be at most %d bytes long but it is %d bytes", maxAnnotationSize, size) + } + + outYaml := mustGet(yaml.Marshal(o)) + mustGet(os.Stdout.Write(outYaml)) +} + +func collect(o any, depth int) (descriptions []description) { + switch o := o.(type) { + case map[string]any: + for key, value := range o { + switch value := value.(type) { + case string: + if key == "description" { + descriptions = append(descriptions, description{depth, o, value}) + } + default: + descriptions = append(descriptions, collect(value, depth+1)...) + } + } + case []any: + for _, item := range o { + descriptions = append(descriptions, collect(item, depth+1)...) + } + } + return descriptions +}