Skip to content
This repository has been archived by the owner on Jul 31, 2020. It is now read-only.

Commit

Permalink
Add special exception for CRDs generated by kubebuilder
Browse files Browse the repository at this point in the history
See kubernetes-sigs/controller-tools#402
According to the schema the generated CRDs are invalid, but kubernetes
seems not to care.
  • Loading branch information
phil9909 committed May 4, 2020
1 parent 16c4d9e commit ee1a861
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
74 changes: 74 additions & 0 deletions examples/lint/kubebuilder.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

---
apiVersion: apiextensions.k8s.io/v1beta1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.2.5
creationTimestamp: null
name: things.example.com
spec:
additionalPrinterColumns:
- JSONPath: .metadata.creationTimestamp
name: Age
type: date
- JSONPath: .status.state
description: Status of the Thing.
name: State
type: string
group: environment.sapcloud.io
names:
categories:
- all
kind: Thing
listKind: ThingList
plural: things
singular: thing
scope: Namespaced
subresources:
status: {}
validation:
openAPIV3Schema:
description: Thing is a thing
properties:
apiVersion:
type: string
kind:
type: string
metadata:
type: object
spec:
description: ThingSpec defines the desired state of the Thing
properties:
color:
description: Color of the thing
enum:
- red
- green
- blue
type: string
category:
description: Category of the thing
type: string
type: object
status:
description: ThingStatus is the things status
properties:
state:
description: State of the thing
type: string
required:
- state
type: object
type: object
version: v1alpha1
versions:
- name: v1alpha1
served: true
storage: true
status:
acceptedNames:
kind: ""
plural: ""
conditions: []
storedVersions: []
2 changes: 1 addition & 1 deletion pkg/yttlint/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ func (l *Linter) isSubset(defs v1.JSONSchemaDefinitions, subSchema, schema *v1.J
if l.Pedantic && !(magic.CouldBeString && !magic.CouldBeInt && !magic.CouldBeFloat) {
errors = append(errors, appendLocationIfKnownf(subSchema, `%s expected string got a computed value. Tip: use str(...) to convert to string`, path))
}
} else {
} else if path != ".metadata.creationTimestamp" { // https://github.com/kubernetes-sigs/controller-tools/issues/402
errors = append(errors, appendLocationIfKnownf(subSchema, "%s expected string got: %s", path, subSchema.Type))
}
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/yttlint/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func TestValidate(t *testing.T) {
filename: "../../examples/lint/array-parameter.yaml",
nonPedanticErrors: []LinterError{},
pedanticErrors: []LinterError{},
}, {
filename: "../../examples/lint/kubebuilder.yaml",
nonPedanticErrors: []LinterError{},
pedanticErrors: []LinterError{},
}, {
filename: "../../examples/lint/empty-pod.yaml",
nonPedanticErrors: []LinterError{{
Expand Down

0 comments on commit ee1a861

Please sign in to comment.