Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

feat: add local schema location organized by group #925

Merged
merged 1 commit into from
Apr 10, 2023
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
11 changes: 7 additions & 4 deletions bl/validation/k8sValidator.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,22 +237,25 @@ func getAllSchemaLocations(userProvidedSchemaLocations []string, isOffline bool)
}

func getDefaultSchemaLocations() []string {
extractedSchemasDir, extractedSchemasDirByGroup := getExtractedSchemasDir()

return []string{
"default",
// this is a workaround for https://github.com/yannh/kubeconform/issues/100
// notice: order here is important because this fallback doesn't have strict mode enabled (in contrast to "default")
"https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}/{{ .ResourceKind }}{{ .KindSuffix }}.json",
"https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{ .Group }}/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json",
getExtractedSchemasDir(),
extractedSchemasDir,
extractedSchemasDirByGroup,
}
}

// when using the crd-extractor(https://github.com/datreeio/CRDs-catalog#crd-extractor) extracted schemas are saved to a local dir, which should be used as a schema-location by default
func getExtractedSchemasDir() string {
func getExtractedSchemasDir() (string, string) {
homeDir, err := os.UserHomeDir()
if err != nil {
return ""
return "", ""
}

return (homeDir + "/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json")
return (homeDir + "/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json"), (homeDir + "/.datree/crdSchemas/{{ .Group }}/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json")
}
1 change: 1 addition & 0 deletions bl/validation/k8sValidator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ func test_get_all_schema_locations_online(t *testing.T) {
"https://raw.githubusercontent.com/yannh/kubernetes-json-schema/master/{{ .NormalizedKubernetesVersion }}/{{ .ResourceKind }}{{ .KindSuffix }}.json",
"https://raw.githubusercontent.com/datreeio/CRDs-catalog/main/{{ .Group }}/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json",
homeDir + "/.datree/crdSchemas/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json",
homeDir + "/.datree/crdSchemas/{{ .Group }}/{{ .ResourceKind }}_{{ .ResourceAPIVersion }}.json",
}
actual := getAllSchemaLocations([]string{"/my-local-schema-location"}, false)
assert.Equal(t, expectedOutput, actual)
Expand Down