Skip to content
Open
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
5 changes: 5 additions & 0 deletions pkg/validate/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
runtimeschema "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/util/validation/field"
celconfig "k8s.io/apiserver/pkg/apis/cel"
kubescheme "k8s.io/client-go/kubernetes/scheme"

"github.com/crossplane/crossplane-runtime/v2/pkg/errors"
"github.com/crossplane/crossplane-runtime/v2/pkg/xcrd"
Expand Down Expand Up @@ -86,6 +87,10 @@ func validateResource(

sv, ok := schemaValidators[gvk]
if !ok {
if kubescheme.Scheme.Recognizes(gvk) {
rvr.Status = ValidationStatusValid
return rvr
}
rvr.Status = ValidationStatusMissingSchema
return rvr
}
Expand Down
23 changes: 23 additions & 0 deletions pkg/validate/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ func TestSchemaValidate(t *testing.T) {
"kind": "Unknown",
"metadata": map[string]any{"name": "no-crd"},
}}
kubernetesCoreResource := &unstructured.Unstructured{Object: map[string]any{
"apiVersion": "v1",
"kind": "Secret",
"metadata": map[string]any{"name": "connection-details"},
}}
kubernetesGroupedResource := &unstructured.Unstructured{Object: map[string]any{
"apiVersion": "apps/v1",
"kind": "Deployment",
"metadata": map[string]any{"name": "workload"},
}}
unknownFieldResource := &unstructured.Unstructured{Object: map[string]any{
"apiVersion": "test.org/v1alpha1",
"kind": "Test",
Expand Down Expand Up @@ -260,6 +270,19 @@ func TestSchemaValidate(t *testing.T) {
perRes: []expect{{status: ValidationStatusMissingSchema}},
},
},
"KubernetesBuiltIn": {
reason: "Built-in Kubernetes resources should not require CRD schemas.",
args: args{
resources: []*unstructured.Unstructured{kubernetesCoreResource, kubernetesGroupedResource},
},
want: want{
summary: ValidationSummary{Total: 2, Valid: 2},
perRes: []expect{
{status: ValidationStatusValid},
{status: ValidationStatusValid},
},
},
},
"UnknownField": {
reason: "A resource with a field not declared in the schema should surface an unknownField error on the offending field path.",
args: args{
Expand Down