Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace k8s rules with those from yannh/kubernetes-json-schema, move our rules to other directories #191

Merged
merged 8 commits into from
Jan 14, 2025
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,21 @@ File names should match, but since projects will change independently, care shou
### Troubleshoot

```
cp <troubleshoot root>/schemas/*.json <kots-lint root>/kubernetes_json_schema/schema/v1.23.6-standalone-strict/
cp <troubleshoot root>/schemas/*.json <kots-lint root>/kubernetes_json_schema/schema/troubleshoot/
```

### KOTS

```
cp <kots root>/kotskinds/schemas/*.json <kots-lint root>/kubernetes_json_schema/schema/v1.23.6-standalone-strict/
```
cp <kots root>/kotskinds/schemas/*.json <kots-lint root>/kubernetes_json_schema/schema/kots/
```

### Kubernetes

```
git clone git@github.com:yannh/kubernetes-json-schema.git
cp <kubernetes-json-schema>/<desired-version>-standalone-strict/*.json <kots-lint root>/kubernetes_json_schema/schema/<desired-version>-standalone-strict/
rm -rf <kots-lint root>/kubernetes_json_schema/schema/<previous-version>-standalone-strict/
```

Finally, update the `KUBERNETES_LINT_VERSION` constant in the `kubernetes_json_schema/schema.go` file.
13 changes: 8 additions & 5 deletions kubernetes_json_schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@ package kubernetes_json_schema

import (
"embed"
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
)

const KUBERNETES_LINT_VERSION = "1.31.4"

//go:embed schema/**/*.json
var kubernetesJsonSchemaFS embed.FS

Expand All @@ -22,7 +24,7 @@ func InitKubernetesJsonSchemaDir() (string, error) {
}

func initKubernetesJsonSchemaDir(schemaFS embed.FS) (string, error) {
tempDir, err := ioutil.TempDir("", "kubernetesjsonschema")
tempDir, err := os.MkdirTemp("", "kubernetesjsonschema")
if err != nil {
return "", errors.Wrap(err, "failed to create temp dir")
}
Expand All @@ -42,17 +44,18 @@ func initKubernetesJsonSchemaDir(schemaFS embed.FS) (string, error) {
}

parts := strings.Split(path, string(os.PathSeparator))
if len(parts) < 2 {
if len(parts) < 3 {
return nil
}
destPath := filepath.Join(parts[1:]...) // trim root directory
destPath := filepath.Join(parts[2:]...) // trim root directory
destPath = filepath.Join(fmt.Sprintf("v%s-standalone-strict", KUBERNETES_LINT_VERSION), destPath)

destDir := filepath.Dir(filepath.Join(tempDir, destPath))
if err := os.MkdirAll(destDir, 0755); err != nil {
return errors.Wrapf(err, "failed to create dir %s", destDir)
}

if err := ioutil.WriteFile(filepath.Join(tempDir, destPath), data, 0755); err != nil {
if err := os.WriteFile(filepath.Join(tempDir, destPath), data, 0755); err != nil {
return errors.Wrap(err, "failed to write file")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,4 +239,4 @@
"type": "object"
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,24 @@
"channelName": {
"type": "string"
},
"embeddedClusterArtifacts": {
"description": "EmbeddedClusterArtifacts maps embedded cluster artifacts to their path",
"type": "object",
"properties": {
"binaryAmd64": {
"type": "string"
},
"charts": {
"type": "string"
},
"imagesAmd64": {
"type": "string"
},
"metadata": {
"type": "string"
}
}
},
"format": {
"type": "string"
},
Expand All @@ -35,6 +53,12 @@
"releaseNotes": {
"type": "string"
},
"replicatedChartNames": {
"type": "array",
"items": {
"type": "string"
}
},
"requiredReleases": {
"type": "array",
"items": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@
"channelName": {
"type": "string"
},
"embeddedClusterArtifacts": {
"description": "EmbeddedClusterArtifacts maps embedded cluster artifacts to their path",
"type": "object",
"properties": {
"binaryAmd64": {
"type": "string"
},
"charts": {
"type": "string"
},
"imagesAmd64": {
"type": "string"
},
"metadata": {
"type": "string"
}
}
},
"encryptionKey": {
"type": "string"
},
Expand Down Expand Up @@ -50,6 +68,18 @@
"type": "string",
"format": "date-time"
},
"replicatedChartNames": {
"type": "array",
"items": {
"type": "string"
}
},
"replicatedProxyDomain": {
"type": "string"
},
"replicatedRegistryDomain": {
"type": "string"
},
"updateCursor": {
"type": "string"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,4 +492,4 @@
}
}
}
}
}
119 changes: 119 additions & 0 deletions kubernetes_json_schema/schema/other/application-kgrid-v1beta1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"description": "Application is the Schema for the applications API",
"type": "object",
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
"type": "object"
},
"spec": {
"description": "ApplicationSpec defines the desired state of Application",
"type": "object",
"properties": {
"kots": {
"type": "object",
"required": [
"clusters",
"licenseID"
],
"properties": {
"appSlug": {
"type": "string"
},
"channelID": {
"type": "string"
},
"channelSequence": {
"type": "integer"
},
"clusters": {
"type": "array",
"items": {
"type": "string"
}
},
"configValues": {
"description": "App is the Schema for the app API",
"type": "object",
"properties": {
"apiVersion": {
"description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
"type": "string"
},
"kind": {
"description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
"type": "string"
},
"metadata": {
"type": "object"
},
"spec": {
"description": "ConfigValuesSpec defines the desired state of ConfigValue",
"type": "object",
"required": [
"values"
],
"properties": {
"values": {
"type": "object",
"additionalProperties": {
"type": "object",
"properties": {
"data": {
"type": "string"
},
"dataPlaintext": {
"type": "string"
},
"default": {
"type": "string"
},
"value": {
"type": "string"
},
"valuePlaintext": {
"type": "string"
}
}
}
}
}
},
"status": {
"description": "ConfigValuesStatus defines the observed state of ConfigValues",
"type": "object"
}
}
},
"endpoint": {
"type": "string"
},
"licenseID": {
"type": "string"
},
"namespace": {
"type": "string"
},
"skipPreflights": {
"type": "boolean"
},
"version": {
"type": "string"
}
}
}
}
},
"status": {
"description": "ApplicationStatus defines the observed state of Application",
"type": "object"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,15 @@
"podCapacity": {
"type": "string"
},
"resourceAllocatable": {
"type": "string"
},
"resourceCapacity": {
"type": "string"
},
"resourceName": {
"type": "string"
},
"selector": {
"type": "object",
"properties": {
Expand Down
Loading