Skip to content

Commit 30181d1

Browse files
committed
Tighten CredentialRotation API per kube-api-linter
Surface a couple of guardrails that kube-api-linter (KAL) flagged on the new types: - Add an explicit MaxLength=36 on status.rotationID. The existing Pattern constrains the value to a canonical UUID, but MaxLength is the convention KAL expects and also limits the OpenAPI/CRD schema explicitly. - Promote the Conditions field's SSA tags (patchStrategy=merge, patchMergeKey=type) into godoc markers in addition to the struct tag. This matches the modern style upstream Kubernetes uses on metav1.Condition slices and what KAL recommends. Remaining KAL findings on the rest of the v1beta2 API (godoc should start with the json field name, +default vs +kubebuilder:default, etc.) are pre-existing project-wide and are not addressed here to avoid churn unrelated to this PR. Signed-off-by: shunki-fujita <shunki-fujita@cybozu.co.jp>
1 parent aefab17 commit 30181d1

4 files changed

Lines changed: 8 additions & 1 deletion

File tree

api/v1beta2/credentialrotation_types.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,16 @@ type CredentialRotationStatus struct {
4343
// for canonical Type/Reason definitions.
4444
// +listType=map
4545
// +listMapKey=type
46+
// +patchStrategy=merge
47+
// +patchMergeKey=type
4648
// +optional
4749
Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
4850

4951
// RotationID is the UUID for the in-flight rotation cycle.
50-
// Empty when no cycle is active.
52+
// Empty when no cycle is active. The value, if non-empty, is a
53+
// canonical 36-character UUID.
5154
// +kubebuilder:validation:Pattern=`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})?$`
55+
// +kubebuilder:validation:MaxLength=36
5256
// +optional
5357
RotationID string `json:"rotationID,omitempty"`
5458

charts/moco/templates/generated/crds/moco_crds.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2906,6 +2906,7 @@ spec:
29062906
type: integer
29072907
rotationID:
29082908
description: RotationID is the UUID for the in-flight rotation...
2909+
maxLength: 36
29092910
pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})?$
29102911
type: string
29112912
type: object

config/crd/bases/moco.cybozu.com_credentialrotations.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ spec:
142142
type: integer
143143
rotationID:
144144
description: RotationID is the UUID for the in-flight rotation...
145+
maxLength: 36
145146
pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})?$
146147
type: string
147148
type: object

config/crd/tests/apiextensions.k8s.io_v1_customresourcedefinition_credentialrotations.moco.cybozu.com.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ spec:
141141
type: integer
142142
rotationID:
143143
description: RotationID is the UUID for the in-flight rotation...
144+
maxLength: 36
144145
pattern: ^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})?$
145146
type: string
146147
type: object

0 commit comments

Comments
 (0)