diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index aa33999..0000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -name: Bug report -about: Create a report to help us improve -title: "[bug]" -labels: bug -assignees: '' - ---- - -**Describe the bug** -A clear and concise description of what the bug is. - -**To Reproduce** -Steps to reproduce the behavior: -1. Go to '...' -2. Click on '....' -3. Scroll down to '....' -4. See error - -**Expected behavior** -A clear and concise description of what you expected to happen. - -**Screenshots** -If applicable, add screenshots to help explain your problem. - -**Desktop (please complete the following information):** - - OS: [e.g. macOS] - - Version [e.g. 1.1.0] - -**Additional context** -Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index e2fe813..0000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -name: Feature request -about: Suggest an idea for this project -title: "[feature request]" -labels: enhancement -assignees: '' - ---- - -**Is your feature request related to a problem? Please describe.** -A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] - -**Describe the solution you'd like** -A clear and concise description of what you want to happen. - -**Describe alternatives you've considered** -A clear and concise description of any alternative solutions or features you've considered. - -**Additional context** -Add any other context or screenshots about the feature request here. diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md deleted file mode 100644 index 00669cd..0000000 --- a/.github/pull_request_template.md +++ /dev/null @@ -1,24 +0,0 @@ - - -#### Description - - -#### What does this PR do? - - - - - -#### Types of changes - -- [ ] Bug fix (non-breaking change which fixes an issue) -- [ ] New feature (non-breaking change which adds functionality) -- [ ] Breaking change (fix or feature that would cause existing functionality to change) -- [ ] New chore (expected functionality to be implemented) - -#### Checklist: - - -- [ ] My change requires a change to the documentation. - - [ ] I have updated the documentation accordingly. -- [ ] I've signed off with an email address that matches the commit author. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index d71ef70..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -name: CI - -on: - pull_request: - -jobs: - ci: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - - uses: actions/setup-go@v3 - with: - go-version-file: 'go.mod' - check-latest: true - - - run: | - go vet ./... - go test ./... --cover diff --git a/.gitignore b/.gitignore deleted file mode 100644 index 66fd13c..0000000 --- a/.gitignore +++ /dev/null @@ -1,15 +0,0 @@ -# Binaries for programs and plugins -*.exe -*.exe~ -*.dll -*.so -*.dylib - -# Test binary, built with `go test -c` -*.test - -# Output of the go coverage tool, specifically when used with LiteIDE -*.out - -# Dependency directories (remove the comment below to include it) -# vendor/ diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md deleted file mode 100644 index 87323c6..0000000 --- a/CODE_OF_CONDUCT.md +++ /dev/null @@ -1,126 +0,0 @@ -# Contributor Covenant Code of Conduct - -## Our Pledge - -We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of gender identity and expression, sexual orientation, disability, physical appearance, body size, citizenship, nationality, ethnic or social origin, pregnancy, familial status, veteran status, genetic information, religion or belief (or lack thereof), membership of a national minority, property, age, education, socio-economic status, technical choices, and experience level. - -We pledge to act and interact in ways that contribute to an open, welcoming, -diverse, inclusive, and healthy community. - -We do not tolerate harassment by and/or of members of our community in any form. - -## Our Standards - -Examples of behavior that contributes to a positive environment for our -community include: - -- Demonstrating empathy and kindness toward other people -- Being respectful of differing opinions, viewpoints, and experiences -- Giving and gracefully accepting constructive feedback -- Accepting responsibility and apologizing to those affected by our mistakes, - and learning from the experience -- Focusing on what is best not just for us as individuals, but for the overall - community -- Giving everyone an opportunity to be heard -- Using welcoming and inclusive language - -Examples of unacceptable behavior include: - -- The use of sexualized language or imagery, and sexual attention or advances of - any kind -- Trolling, insulting or derogatory remarks, and personal or political attacks -- Public or private harassment -- Publishing others' private information, such as a physical or email address, - without their explicit permission -- Other conduct which could reasonably be considered inappropriate in a - professional setting - -## Enforcement Responsibilities - -Community leaders are responsible for clarifying and enforcing our standards of -acceptable behavior and will take appropriate and fair corrective action in -response to any behavior that they deem inappropriate, threatening, offensive, -or harmful. - -Community leaders have the right and responsibility to remove, edit, or reject -comments, commits, code, wiki edits, issues, and other contributions that are -not aligned to this Code of Conduct, and will communicate reasons for moderation -decisions when appropriate. - -## Scope - -This Code of Conduct applies within all community spaces, and also applies when -an individual is officially representing the community in public spaces. -Examples of representing our community include using an official e-mail address, -posting via an official social media account, or acting as an appointed -representative at an online or offline event. - -## Enforcement - -Instances of abusive, harassing, or otherwise unacceptable behavior may be -reported to the community leaders responsible for enforcement at abuse@score.dev. - -All complaints will be reviewed and investigated promptly and fairly. - -All community leaders are obligated to respect the privacy and security of the -reporter of any incident. - -## Enforcement Guidelines - -Community leaders will follow these Community Impact Guidelines in determining -the consequences for any action they deem in violation of this Code of Conduct: - -### 1. Correction - -**Community Impact**: Use of inappropriate language or other behavior deemed -unprofessional or unwelcome in the community. - -**Consequence**: A private, written warning from community leaders, providing -clarity around the nature of the violation and an explanation of why the -behavior was inappropriate. A public apology may be requested. - -### 2. Warning - -**Community Impact**: A violation through a single incident or series of -actions. - -**Consequence**: A warning with consequences for continued behavior. No -interaction with the people involved, including unsolicited interaction with -those enforcing the Code of Conduct, for a specified period of time. This -includes avoiding interactions in community spaces as well as external channels -like social media. Violating these terms may lead to a temporary or permanent -ban. - -### 3. Temporary Ban - -**Community Impact**: A serious violation of community standards, including -sustained inappropriate behavior. - -**Consequence**: A temporary ban from any sort of interaction or public -communication with the community for a specified period of time. No public or -private interaction with the people involved, including unsolicited interaction -with those enforcing the Code of Conduct, is allowed during this period. -Violating these terms may lead to a permanent ban. - -### 4. Permanent Ban - -**Community Impact**: Demonstrating a pattern of violation of community -standards, including sustained inappropriate behavior, harassment of an -individual, or aggression toward or disparagement of classes of individuals. - -**Consequence**: A permanent ban from any sort of public interaction within the -community. - -## Attribution - -This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. - -Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. - -For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. - -[homepage]: https://www.contributor-covenant.org -[v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html -[Mozilla CoC]: https://github.com/mozilla/diversity -[FAQ]: https://www.contributor-covenant.org/faq -[translations]: https://www.contributor-covenant.org/translations diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md deleted file mode 100644 index 3ae6285..0000000 --- a/CONTRIBUTING.md +++ /dev/null @@ -1,82 +0,0 @@ -# Contributor guidelines - -We'd love to accept your patches and contributions to this project. There are just a few small guidelines you need to follow. - -When contributing to this project, you must agree that you have authored the content, that you have the necessary rights to the content and that the content you contribute may be provided under the [APACHE LICENSE, VERSION 2.0](LICENSE). - -### What do I need to know to help? - -If you are looking to help to with a code contribution, our project uses Golang. If you don't feel ready to make a code contribution yet, no problem! You can also check out the documentation . - -If you are interested in making a code contribution and would like to learn more about the technologies that we use, check out the list below. - -- [https://humanitec.com](https://humanitec.com/) -- [https://docs.docker.com/compose/](https://docs.docker.com/compose/) -- [https://helm.sh/docs/](https://helm.sh/docs/) - -### How do I make a contribution? - -Never made an open-source contribution before? Wondering how contributions work in our project? Here's a quick rundown! - -1. Find an issue that you are interested in addressing or a feature that you would like to add. -2. Fork the repository associated with the issue to your local GitHub organization. This means that you will have a copy of the repository under **your-GitHub-username/repository-name**. -3. Clone the repository to your local machine using **git clone**. -4. Create a new branch for your fix using **git checkout -b your-branch-name**. -5. Make the appropriate changes for the issue you are trying to address or the feature that you want to add. -6. Use **git add insert-paths-of-changed-files-here** to add the file contents of the changed files to the "snapshot" git uses to manage the state of the project, also known as the index. -7. Use **git commit -s -m "Insert a brief message of the changes made here"** to store the contents of the index with a descriptive message. -8. Push the changes to the remote repository using **git push origin your-branch-name**. -9. Submit a pull request to the upstream repository. -10. Title the pull request with a brief description of the changes made and the issue or bug number associated with your change. For example, you can title an issue like so, "Added more log outputting to resolve #4352". -11. In the description of the pull request, explain the changes that you made, any issues you think exist with the pull request you made, and any questions you have for the maintainer. It's OK if your pull request is not perfect (no pull request is), the reviewer will be able to help you resolve any problems and improve it! -12. Wait for the pull request to be reviewed by a maintainer. -13. Introduce changes to the pull request if the reviewing maintainer recommends them. -14. Celebrate your success after your pull request is merged! - -## Feature requests - -## Code reviews - -All submissions, including submissions by project members, require review. - -Score uses GitHub pull requests for this purpose. - -The general workflow for code contributions: - -1. Submit/find an issue in this repository. -2. Clone the relevant repo. -3. Make your code change. -4. Write tests and update docs. -5. Build and test locally. -6. Submit a pull request. -7. Iterate as needed. -8. Your PR will be approved and merged. - -### Where can I go for help? - -If you need help, you can create an issue. - -### Reporting bugs - -#### Before submitting an issue - -A good bug report shouldn't leave others needing to chase you up for more information. Therefore, we ask you to investigate carefully, collect information and describe the issue in detail in your report. Please complete the following steps in advance to help us fix any potential bug as fast as possible. - -- Make sure that you are using the latest version. -- Determine if your bug is really a bug and not an error on your side for example using incompatible environment components/versions (Make sure that you have read the [documentation](https://github.com/score-dev/docs). If you are looking for support. -- To see if other users have experienced (and potentially already solved) the same issue you are having, check if there is not already a bug report existing for your bug. -- Also make sure to search the internet (including Stack Overflow) to see if users outside the GitHub community have discussed the issue. -- Collect information about the bug: - - Stack trace (Traceback). - - OS, Platform and Version (Windows, Linux, macOS, x86, ARM). - - Version of the interpreter, compiler, SDK, runtime environment, package manager, depending on what seems relevant. - - Possibly your input and the output. - - Can you reliably reproduce the issue? - -### **What does the Code of Conduct mean for me?** - -Our [Code of Conduct](CODE_OF_CONDUCT.md) means that you are responsible for treating everyone on the project with respect and courtesy, regardless of their identity. If you are the victim of any inappropriate behavior or comments as described in our Code of Conduct, we are here for you and will do the best to ensure that the abuser is reprimanded appropriately, per our code. - -## Community Guidelines - -For information on our community guidelines, see [CONTRIBUTING.md](CONTRIBUTING.md). diff --git a/LICENSE b/LICENSE index 55b66ab..261eeb9 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright 2022 Humanitec + Copyright [yyyy] [name of copyright owner] Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/README.md b/README.md index af52534..e5cc499 100644 --- a/README.md +++ b/README.md @@ -1,42 +1,34 @@ -# score-go -Reference library for the parsing and loading SCORE files - -## Parsing SCORE files - -This library includes a few utility methods to parse source SCORE files. - -```go -import ( - "io" - "os" - - "github.com/score-spec/score-go/loader" - score "github.com/score-spec/score-go/types" -) - -func main() { - var ( - err error - src io.Reader - ) - - if src, err = os.Open("score.yaml"); err != nil { - panic(err) - } - defer src.Close() - - var srcMap map[string]interface{} - if err = loader.ParseYAML(&srcMap, src); err != nil { - panic(err) - } - - var spec score.WorkloadSpec - if err = loader.MapSpec(&spec, srcMap); err != nil { - panic(err) - } - - // Do something with the spec - // ... -} +# JSON schemas for Score files +| version | file | +| --- | --- | +| v1-beta1 | score-v1b1.json | + +## Embed schemas into project + +Add Score schemas into projects with `git subtree add` command: + +``` +git subtree add \ + --prefix schemas \ + git@github.com:score-spec/schema.git main \ + --squash ``` + +> **Note:** To avoid storing the entire history of the sub-project in the main repository, make sure to include `--squash` flag. + +## Update schemas from upstream + +Get the latest versions of the schemas `git subtree pull` command: + +``` +git subtree pull \ + --prefix schemas \ + git@github.com:score-spec/schema.git main \ + --squash +``` + +## Contribute changes to upstream + +All changes to `score-spec/schema` should be done via pull requests and comply with the review and sign-off policies. + diff --git a/go.mod b/go.mod deleted file mode 100644 index fa6069f..0000000 --- a/go.mod +++ /dev/null @@ -1,15 +0,0 @@ -module github.com/score-spec/score-go - -go 1.19 - -require ( - github.com/mitchellh/mapstructure v1.5.0 - github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 - github.com/stretchr/testify v1.8.0 - gopkg.in/yaml.v3 v3.0.1 -) - -require ( - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect -) diff --git a/go.sum b/go.sum deleted file mode 100644 index 9cbc3fa..0000000 --- a/go.sum +++ /dev/null @@ -1,19 +0,0 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= -github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= -github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 h1:lZUw3E0/J3roVtGQ+SCrUrg3ON6NgVqpn3+iol9aGu4= -github.com/santhosh-tekuri/jsonschema/v5 v5.3.1/go.mod h1:uToXkOrWAZ6/Oc07xWQrPOhJotwFIyu2bBVN41fcDUY= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/loader/loader.go b/loader/loader.go deleted file mode 100644 index 4392806..0000000 --- a/loader/loader.go +++ /dev/null @@ -1,35 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package loader - -import ( - "fmt" - "io" - - "github.com/mitchellh/mapstructure" - "github.com/score-spec/score-go/types" - "gopkg.in/yaml.v3" -) - -// ParseYAML parses YAML into the target mapping structure. -func ParseYAML(dest *map[string]interface{}, r io.Reader) error { - return yaml.NewDecoder(r).Decode(dest) -} - -// MapSpec converts the source mapping structure into the target WorkloadSpec. -func MapSpec(dest *types.WorkloadSpec, src map[string]interface{}) error { - mapper, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{ - Result: dest, - TagName: "json", - }) - if err != nil { - return fmt.Errorf("initializing decoder: %w", err) - } - - return mapper.Decode(src) -} diff --git a/loader/loader_test.go b/loader/loader_test.go deleted file mode 100644 index f1e4906..0000000 --- a/loader/loader_test.go +++ /dev/null @@ -1,231 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package loader - -import ( - "bytes" - "errors" - "io" - "testing" - - "github.com/score-spec/score-go/types" - "github.com/stretchr/testify/assert" -) - -func TestDecodeYaml(t *testing.T) { - var tests = []struct { - Name string - Source io.Reader - Output types.WorkloadSpec - Error error - }{ - { - Name: "Should handle empty input", - Source: bytes.NewReader([]byte{}), - Error: errors.New("EOF"), - }, - { - Name: "Should handle invalid YAML input", - Source: bytes.NewReader([]byte("")), - Error: errors.New("cannot unmarshal"), - }, - { - Name: "Should decode the SCORE spec", - Source: bytes.NewReader([]byte(` ---- -apiVersion: score.dev/v1b1 -metadata: - name: hello-world - -service: - ports: - www: - port: 80 - targetPort: 8080 - -containers: - hello: - image: busybox - command: - - "/bin/echo" - args: - - "Hello $(FRIEND)" - variables: - FRIEND: World! - files: - - target: /etc/hello-world/config.yaml - mode: "666" - content: | - --- - ${resources.env.APP_CONFIG} - noExpand: true - volumes: - - source: ${resources.data} - path: sub/path - target: /mnt/data - read_only: true - resources: - limits: - memory: "128Mi" - cpu: "500m" - requests: - memory: "64Mi" - cpu: "250m" - livenessProbe: - httpGet: - path: /alive - port: 8080 - readinessProbe: - httpGet: - host: "1.1.1.1" - scheme: HTTPS - path: /ready - port: 8080 - httpHeaders: - - name: Custom-Header - value: Awesome - -resources: - env: - type: environment - dns: - type: dns - data: - type: volume - db: - type: postgres - metadata: - annotations: - "my.org/version": "0.1" - params: { - extensions: { - uuid-ossp: { - schema: "uuid_schema", - version: "1.1" - } - } - } -`)), - Output: types.WorkloadSpec{ - ApiVersion: "score.dev/v1b1", - Metadata: types.WorkloadMeta{ - Name: "hello-world", - }, - Service: types.ServiceSpec{ - Ports: types.ServicePortsSpecs{ - "www": types.ServicePortSpec{ - Port: 80, - Protocol: "", - TargetPort: 8080, - }, - }, - }, - Containers: types.ContainersSpecs{ - "hello": types.ContainerSpec{ - Image: "busybox", - Command: []string{"/bin/echo"}, - Args: []string{"Hello $(FRIEND)"}, - Variables: map[string]string{ - "FRIEND": "World!", - }, - Files: []types.FileMountSpec{ - { - Target: "/etc/hello-world/config.yaml", - Mode: "666", - Source: "", - Content: "---\n${resources.env.APP_CONFIG}\n", - NoExpand: true, - }, - }, - Volumes: []types.VolumeMountSpec{ - { - Source: "${resources.data}", - Path: "sub/path", - Target: "/mnt/data", - ReadOnly: true, - }, - }, - Resources: types.ContainerResourcesRequirementsSpec{ - Limits: map[string]interface{}{ - "memory": "128Mi", - "cpu": "500m", - }, - Requests: map[string]interface{}{ - "memory": "64Mi", - "cpu": "250m", - }, - }, - LivenessProbe: types.ContainerProbeSpec{ - HTTPGet: types.HTTPGetActionSpec{ - Path: "/alive", - Port: 8080, - }, - }, - ReadinessProbe: types.ContainerProbeSpec{ - HTTPGet: types.HTTPGetActionSpec{ - Host: "1.1.1.1", - Scheme: "HTTPS", - Path: "/ready", - Port: 8080, - HTTPHeaders: []types.HTTPHeaderSpec{ - {Name: "Custom-Header", Value: "Awesome"}, - }, - }, - }, - }, - }, - Resources: map[string]types.ResourceSpec{ - "env": { - Type: "environment", - }, - "dns": {Type: "dns"}, - "data": {Type: "volume"}, - "db": { - Type: "postgres", - Metadata: types.ResourceMeta{ - Annotations: map[string]string{ - "my.org/version": "0.1", - }, - }, - Params: map[string]interface{}{ - "extensions": map[string]interface{}{ - "uuid-ossp": map[string]interface{}{ - "schema": "uuid_schema", - "version": "1.1", - }, - }, - }, - }, - }, - }, - }, - } - - for _, tt := range tests { - t.Run(tt.Name, func(t *testing.T) { - var srcMap map[string]interface{} - var spec types.WorkloadSpec - - var err = ParseYAML(&srcMap, tt.Source) - if err == nil { - err = MapSpec(&spec, srcMap) - } - - if tt.Error != nil { - // On Error - // - assert.ErrorContains(t, err, tt.Error.Error()) - } else { - // On Success - // - assert.NoError(t, err) - assert.Equal(t, tt.Output, spec) - } - }) - } -} diff --git a/schema/files/LICENSE b/schema/files/LICENSE deleted file mode 100644 index 261eeb9..0000000 --- a/schema/files/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/schema/files/README.md b/schema/files/README.md deleted file mode 100644 index e5cc499..0000000 --- a/schema/files/README.md +++ /dev/null @@ -1,34 +0,0 @@ -# JSON schemas for Score files - -| version | file | -| --- | --- | -| v1-beta1 | score-v1b1.json | - -## Embed schemas into project - -Add Score schemas into projects with `git subtree add` command: - -``` -git subtree add \ - --prefix schemas \ - git@github.com:score-spec/schema.git main \ - --squash -``` - -> **Note:** To avoid storing the entire history of the sub-project in the main repository, make sure to include `--squash` flag. - -## Update schemas from upstream - -Get the latest versions of the schemas `git subtree pull` command: - -``` -git subtree pull \ - --prefix schemas \ - git@github.com:score-spec/schema.git main \ - --squash -``` - -## Contribute changes to upstream - -All changes to `score-spec/schema` should be done via pull requests and comply with the review and sign-off policies. - diff --git a/schema/files/score-v1b1.json b/schema/files/score-v1b1.json deleted file mode 100644 index 219c687..0000000 --- a/schema/files/score-v1b1.json +++ /dev/null @@ -1,345 +0,0 @@ -{ - "$schema": "https://json-schema.org/draft/2020-12/schema", - "$id": "https://score.dev/schemas/score", - "title": "Score schema", - "description": "Score workload specification", - "type": "object", - "required": [ - "apiVersion", - "metadata", - "containers" - ], - "additionalProperties": false, - "properties": { - "apiVersion": { - "description": "The declared Score Specification version.", - "type": "string" - }, - "metadata": { - "description": "The metadata description of the Workload.", - "type": "object", - "required": [ - "name" - ], - "additionalProperties": true, - "properties": { - "name": { - "description": "A string that can describe the Workload.", - "type": "string" - } - } - }, - "service": { - "description": "The service that the workload provides.", - "type": "object", - "additionalProperties": false, - "properties": { - "ports": { - "description": "List of network ports published by the service.", - "type": "object", - "additionalProperties": true, - "minProperties": 1, - "patternProperties": { - "^*": { - "description": "The network port description.", - "type": "object", - "required": [ - "targetPort" - ], - "additionalProperties": false, - "properties": { - "port": { - "description": "The public service port.", - "type": "number" - }, - "targetPort": { - "description": "The internal service port.", - "type": "number" - } - } - } - } - } - } - }, - "containers": { - "description": "The declared Score Specification version.", - "type": "object", - "additionalProperties": true, - "minProperties": 1, - "patternProperties": { - "^*": { - "description": "The container name.", - "type": "object", - "required": [ - "image" - ], - "additionalProperties": false, - "properties": { - "image": { - "description": "The image name and tag.", - "type": "string" - }, - "command": { - "description": "If specified, overrides container entry point.", - "type": "array", - "minItems": 1, - "items": { - "type": "string" - } - }, - "args": { - "description": "If specified, overrides container entry point arguments.", - "type": "array", - "minItems": 1, - "items": { - "type": "string" - } - }, - "variables": { - "description": "The environment variables for the container.", - "type": "object", - "minProperties": 1, - "additionalProperties": { - "type": "string" - } - }, - "files": { - "description": "The extra files to mount.", - "type": "array", - "minItems": 1, - "items": { - "type": "object", - "required": [ - "target" - ], - "properties": { - "target": { - "description": "The file path and name.", - "type": "string" - }, - "mode": { - "description": "The file access mode.", - "type": "string" - }, - "source": { - "description": "The relative or absolute path to the content file.", - "type": "string", - "minLength": 1 - }, - "content": { - "description": "The inline content for the file.", - "anyOf": [{ - "type": "string" - }, { - "deprecated": true, - "type": "array", - "minItems": 1, - "items": { - "type": "string" - } - }] - }, - "noExpand": { - "description": "If set to true, the placeholders expansion will not occur in the contents of the file.", - "type": "boolean" - } - }, - "oneOf": [{ - "required": ["content"] - }, { - "required": ["source"] - }] - } - }, - "volumes": { - "description": "The volumes to mount.", - "type": "array", - "minItems": 1, - "items": { - "type": "object", - "required": [ - "source", - "target" - ], - "properties": { - "source": { - "description": "The external volume reference.", - "type": "string" - }, - "path": { - "description": "An optional sub path in the volume.", - "type": "string" - }, - "target": { - "description": "The target mount on the container.", - "type": "string" - }, - "read_only": { - "description": "Indicates if the volume should be mounted in a read-only mode.", - "type": "boolean" - } - } - } - }, - "resources": { - "description": "The compute resources for the container.", - "type": "object", - "minProperties": 1, - "additionalProperties": false, - "properties": { - "limits": { - "description": "The maximum allowed resources for the container.", - "$ref": "#/properties/containers/definitions/resourcesLimits" - }, - "requests": { - "description": "The minimal resources required for the container.", - "$ref": "#/properties/containers/definitions/resourcesLimits" - } - } - }, - "livenessProbe": { - "description": "The liveness probe for the container.", - "$ref": "#/properties/containers/definitions/containerProbe" - }, - "readinessProbe": { - "description": "The readiness probe for the container.", - "$ref": "#/properties/containers/definitions/containerProbe" - } - } - } - }, - "definitions": { - "resourcesLimits": { - "description": "The compute resources limits.", - "type": "object", - "minProperties": 1, - "additionalProperties": false, - "properties": { - "memory": { - "description": "The memory limit.", - "type": "string" - }, - "cpu": { - "description": "The CPU limit.", - "type": "string" - } - } - }, - "containerProbe": { - "type": "object", - "minProperties": 1, - "additionalProperties": false, - "properties": { - "httpGet": { - "$ref": "#/properties/containers/definitions/httpProbe" - } - } - }, - "httpProbe": { - "description": "An HTTP probe details.", - "type": "object", - "additionalProperties": false, - "required": [ - "path" - ], - "properties": { - "host": { - "description": "Host name to connect to. Defaults to the container IP.", - "type": "string" - }, - "scheme": { - "description": "Scheme to use for connecting to the host (HTTP or HTTPS). Defaults to HTTP.", - "type": "string", - "enum": [ - "HTTP", - "HTTPS" - ] - }, - "path": { - "description": "The path of the HTTP probe endpoint.", - "type": "string" - }, - "port": { - "description": "The path of the HTTP probe endpoint.", - "type": "number" - }, - "httpHeaders": { - "description": "Additional HTTP headers to send with the request", - "type": "array", - "minItems": 1, - "items": { - "type": "object", - "additionalProperties": false, - "properties": { - "name": { - "description": "The HTTP header name.", - "type": "string" - }, - "value": { - "description": "The HTTP header value.", - "type": "string" - } - } - } - } - } - } - } - }, - "resources": { - "description": "The dependencies needed by the Workload.", - "type": "object", - "minProperties": 1, - "additionalProperties": true, - "patternProperties": { - "^*": { - "description": "The resource name.", - "type": "object", - "additionalProperties": false, - "required": [ - "type" - ], - "properties": { - "type": { - "description": "The resource in the target environment.", - "type": "string" - }, - "class": { - "description": "A specialisation of the resource type.", - "type": "string", - "pattern": "^[a-z0-9](?:-?[a-z0-9]+)+$" - }, - "metadata": { - "description": "The metadata for the resource.", - "type": "object", - "minProperties": 1, - "additionalProperties": true, - "properties": { - "annotations": { - "description": "Annotations that apply to the property.", - "type": "object", - "minProperties": 1, - "additionalProperties": { - "type": "string" - } - } - } - }, - "properties": { - "description": "DEPRECATED: The properties that can be referenced in other places in the Score Specification file.", - "type": [ - "object", - "null" - ] - }, - "params": { - "description": "The parameters used to validate or provision the resource in the environment.", - "type": "object" - } - } - } - } - } - } -} diff --git a/schema/schema.go b/schema/schema.go deleted file mode 100644 index 59d9e71..0000000 --- a/schema/schema.go +++ /dev/null @@ -1,13 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package schema - -import _ "embed" - -//go:embed files/score-v1b1.json -var ScoreSchemaV1b1 string diff --git a/schema/schema_test.go b/schema/schema_test.go deleted file mode 100644 index 69b6b3e..0000000 --- a/schema/schema_test.go +++ /dev/null @@ -1,1592 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package schema - -import ( - "bytes" - "testing" - - "github.com/santhosh-tekuri/jsonschema/v5" - "github.com/stretchr/testify/assert" - "gopkg.in/yaml.v3" -) - -func newTestDocument() map[string]interface{} { - var data = []byte(` ---- -apiVersion: score.dev/v1b1 -metadata: - name: hello-world - -service: - ports: - www: - port: 80 - targetPort: 8080 - -containers: - hello: - image: busybox - command: - - "/bin/echo" - args: - - "Hello $(FRIEND)" - variables: - FRIEND: World! - files: - - target: /etc/hello-world/config.yaml - mode: "666" - content: "${resources.env.APP_CONFIG}" - volumes: - - source: ${resources.data} - path: sub/path - target: /mnt/data - read_only: true - resources: - limits: - memory: "128Mi" - cpu: "500m" - requests: - memory: "64Mi" - cpu: "250m" - livenessProbe: - httpGet: - path: /alive - port: 8080 - readinessProbe: - httpGet: - path: /ready - port: 8080 - httpHeaders: - - name: Custom-Header - value: Awesome - -resources: - env: - type: environment - dns: - type: dns - data: - type: volume - db: - type: postgres - metadata: - annotations: - "my.org/version": "0.1" - params: { - extensions: { - uuid-ossp: { - schema: "uuid_schema", - version: "1.1" - } - } - } -`) - - var obj map[string]interface{} - var yamlReader = bytes.NewReader(data) - yaml.NewDecoder(yamlReader).Decode(&obj) - return obj -} - -func TestSchema(t *testing.T) { - var tests = []struct { - Name string - Src map[string]interface{} - Message string - }{ - { - Name: "Valid input", - Src: func() map[string]interface{} { - src := newTestDocument() - return src - }(), - Message: "", - }, - - // apiVersion - // - { - Name: "apiVersion is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - delete(src, "apiVersion") - return src - }(), - Message: "missing properties: 'apiVersion'", - }, - { - Name: "apiVersion is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["apiVersion"] = nil - return src - }(), - Message: "/apiVersion", - }, - { - Name: "apiVersion is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - src["apiVersion"] = 12 - return src - }(), - Message: "/apiVersion", - }, - - // metadata - // - { - Name: "metadata is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - delete(src, "metadata") - return src - }(), - Message: "missing properties: 'metadata'", - }, - { - Name: "metadata is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["metadata"] = nil - return src - }(), - Message: "/metadata", - }, - { - Name: "metadata.name is required", - Src: func() map[string]interface{} { - src := newTestDocument() - delete(src["metadata"].(map[string]interface{}), "name") - return src - }(), - Message: "/metadata", - }, - { - Name: "metadata.name is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - src["metadata"].(map[string]interface{})["name"] = 12 - return src - }(), - Message: "/metadata/name", - }, - - // service - // - { - Name: "service is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = nil - return src - }(), - Message: "/service", - }, - { - Name: "service.ports is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": nil, - } - return src - }(), - Message: "/service/ports", - }, - { - Name: "service.ports is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{}, - } - return src - }(), - Message: "/service/ports", - }, - { - Name: "service.ports.* is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{ - "www": nil, - }, - } - return src - }(), - Message: "/service/ports/www", - }, - { - Name: "service.ports.*.targetPort is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{ - "www": map[string]interface{}{}, - }, - } - return src - }(), - Message: "/service/ports/www", - }, - { - Name: "service.ports.*.targetPort is not a number", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{ - "www": map[string]interface{}{ - "targetPort": false, - }, - }, - } - return src - }(), - Message: "/service/ports/www/targetPort", - }, - { - Name: "service.ports.*.port is optional", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{ - "www": map[string]interface{}{ - "targetPort": 8080, - }, - }, - } - return src - }(), - Message: "", - }, - { - Name: "service.ports.*.port is not a number", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{ - "www": map[string]interface{}{ - "port": false, - "targetPort": 8080, - }, - }, - } - return src - }(), - Message: "/service/ports/www/port", - }, - { - Name: "service with multiple ports", - Src: func() map[string]interface{} { - src := newTestDocument() - src["service"] = map[string]interface{}{ - "ports": map[string]interface{}{ - "www": map[string]interface{}{ - "port": 80, - "targetPort": 8080, - }, - "admin": map[string]interface{}{ - "targetPort": 8090, - }, - }, - } - return src - }(), - Message: "", - }, - - // containers - // - { - Name: "containers is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - delete(src, "containers") - return src - }(), - Message: "missing properties: 'containers'", - }, - { - Name: "containers is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["containers"] = nil - return src - }(), - Message: "/containers", - }, - { - Name: "containers is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - src["containers"] = map[string]interface{}{} - return src - }(), - Message: "/containers", - }, - { - Name: "containers.* is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["containers"].(map[string]interface{})["hello"] = nil - return src - }(), - Message: "/containers/hello", - }, - - // containers.*.image - // - { - Name: "containers.*.image is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - delete(hello, "image") - return src - }(), - Message: "/containers/hello", - }, - { - Name: "containers.*.image is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["image"] = nil - return src - }(), - Message: "/containers/hello/image", - }, - { - Name: "containers.*.image is not a sring", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["image"] = 12 - return src - }(), - Message: "/containers/hello/image", - }, - - // containers.*.command - // - { - Name: "containers.*.command is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["command"] = nil - return src - }(), - Message: "/containers/hello/command", - }, - { - Name: "containers.*.command is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["command"] = []interface{}{} - return src - }(), - Message: "/containers/hello/command", - }, - - // containers.*.args - // - { - Name: "containers.*.args is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["args"] = nil - return src - }(), - Message: "/containers/hello/args", - }, - { - Name: "containers.*.args is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["args"] = []interface{}{} - return src - }(), - Message: "/containers/hello/args", - }, - - // containers.*.variables - // - { - Name: "containers.*.variables is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["variables"] = nil - return src - }(), - Message: "/containers/hello/variables", - }, - { - Name: "containers.*.variables is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["variables"] = map[string]interface{}{} - return src - }(), - Message: "/containers/hello/variables", - }, - { - Name: "containers.*.variables.* is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["variables"].(map[string]interface{})["FRIEND"] = nil - return src - }(), - Message: "/containers/hello/variables/FRIEND", - }, - { - Name: "containers.*.variables.* is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["variables"].(map[string]interface{})["FRIEND"] = 12 - return src - }(), - Message: "/containers/hello/variables/FRIEND", - }, - - // containers.*.files - // - { - Name: "containers.*.files is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["files"] = nil - return src - }(), - Message: "/containers/hello/files", - }, - { - Name: "containers.*.files is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["files"] = []interface{}{} - return src - }(), - Message: "/containers/hello/files", - }, - { - Name: "containers.*.files.*.target is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "target") - return src - }(), - Message: "/containers/hello/files/0", - }, - { - Name: "containers.*.files.*.target is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["target"] = nil - return src - }(), - Message: "/containers/hello/files/0/target", - }, - { - Name: "containers.*.files.*.target is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["target"] = 12 - return src - }(), - Message: "/containers/hello/files/0/target", - }, - { - Name: "containers.*.files.*.mode is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["mode"] = nil - return src - }(), - Message: "/containers/hello/files/0/mode", - }, - { - Name: "containers.*.files.*.mode is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["mode"] = 12 - return src - }(), - Message: "/containers/hello/files/0/mode", - }, - { - Name: "containers.*.files.*.source is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "content") - return src - }(), - Message: "/containers/hello/files/0", - }, - { - Name: "containers.*.files.*.source is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "content") - file["source"] = nil - return src - }(), - Message: "/containers/hello/files/0", - }, - { - Name: "containers.*.files.*.source is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "content") - file["source"] = "" - return src - }(), - Message: "/containers/hello/files/0/source", - }, - { - Name: "containers.*.files.*.source is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "content") - file["source"] = 5 - return src - }(), - Message: "/containers/hello/files/0/source", - }, - { - Name: "containers.*.files.*.noExpand isset to true", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["noExpand"] = true - return src - }(), - Message: "", - }, - { - Name: "containers.*.files.*.noExpand isset to false", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["noExpand"] = false - return src - }(), - Message: "", - }, - { - Name: "containers.*.files.*.noExpand is not a boolean", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "content") - file["noExpand"] = 5 - return src - }(), - Message: "/containers/hello/files/0/noExpand", - }, - { - Name: "containers.*.files.*.content is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - delete(file, "content") - return src - }(), - Message: "/containers/hello/files/0", - }, - { - Name: "containers.*.files.*.content is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["content"] = nil - return src - }(), - Message: "/containers/hello/files/0/content", - }, - { - Name: "containers.*.files.*.content is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["content"] = 5 - return src - }(), - Message: "/containers/hello/files/0/content", - }, - { - Name: "containers.*.files.*.content is an empty array", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["content"] = []interface{}{} - return src - }(), - Message: "/containers/hello/files/0/content", - }, - { - Name: "containers.*.files.*.content is an array of strings", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var file = hello["files"].([]interface{})[0].(map[string]interface{}) - file["content"] = []interface{}{ - "Line 1", - "Line 2", - } - return src - }(), - Message: "", - }, - - // containers.*.volumes - // - { - Name: "containers.*.volumes is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["volumes"] = nil - return src - }(), - Message: "/containers/hello/volumes", - }, - { - Name: "containers.*.volumes is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["volumes"] = []interface{}{} - return src - }(), - Message: "/containers/hello/volumes", - }, - { - Name: "containers.*.volumes.*.source is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - delete(volumes, "source") - return src - }(), - Message: "/containers/hello/volumes/0", - }, - { - Name: "containers.*.volumes.*.source is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["source"] = nil - return src - }(), - Message: "/containers/hello/volumes/0/source", - }, - { - Name: "containers.*.volumes.*.source is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["source"] = 12 - return src - }(), - Message: "/containers/hello/volumes/0/source", - }, - { - Name: "containers.*.volumes.*.path is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["path"] = nil - return src - }(), - Message: "/containers/hello/volumes/0/path", - }, - { - Name: "containers.*.volumes.*.path is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["path"] = 12 - return src - }(), - Message: "/containers/hello/volumes/0/path", - }, - { - Name: "containers.*.volumes.*.target is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - delete(volumes, "target") - return src - }(), - Message: "/containers/hello/volumes/0", - }, - { - Name: "containers.*.volumes.*.target is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["target"] = nil - return src - }(), - Message: "/containers/hello/volumes/0/target", - }, - { - Name: "containers.*.volumes.*.target is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["target"] = 12 - return src - }(), - Message: "/containers/hello/volumes/0/target", - }, - { - Name: "containers.*.volumes.*.read_only is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["read_only"] = nil - return src - }(), - Message: "/containers/hello/volumes/0/read_only", - }, - { - Name: "containers.*.volumes.*.read_only is not a boolean", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var volumes = hello["volumes"].([]interface{})[0].(map[string]interface{}) - volumes["read_only"] = 12 - return src - }(), - Message: "/containers/hello/volumes/0/read_only", - }, - - // containers.*.resources - // - { - Name: "containers.*.resources is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["resources"] = nil - return src - }(), - Message: "/containers/hello/resources", - }, - { - Name: "containers.*.resources is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["resources"] = map[string]interface{}{} - return src - }(), - Message: "/containers/hello/resources", - }, - { - Name: "containers.*.resources.limits is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["resources"].(map[string]interface{})["limits"] = nil - return src - }(), - Message: "/containers/hello/resources/limits", - }, - { - Name: "containers.*.resources.limits is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["resources"].(map[string]interface{})["limits"] = map[string]interface{}{} - return src - }(), - Message: "/containers/hello/resources/limits", - }, - { - Name: "containers.*.resources.limits.memory is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var limits = hello["resources"].(map[string]interface{})["limits"].(map[string]interface{}) - limits["memory"] = nil - return src - }(), - Message: "/containers/hello/resources/limits/memory", - }, - { - Name: "containers.*.resources.limits.memory is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var limits = hello["resources"].(map[string]interface{})["limits"].(map[string]interface{}) - limits["memory"] = 12 - return src - }(), - Message: "/containers/hello/resources/limits/memory", - }, - { - Name: "containers.*.resources.limits.memory is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var limits = hello["resources"].(map[string]interface{})["limits"].(map[string]interface{}) - limits["memory"] = nil - return src - }(), - Message: "/containers/hello/resources/limits/memory", - }, - { - Name: "containers.*.resources.limits.cpu is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var limits = hello["resources"].(map[string]interface{})["limits"].(map[string]interface{}) - limits["cpu"] = 12 - return src - }(), - Message: "/containers/hello/resources/limits/cpu", - }, - { - Name: "containers.*.resources.requests is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["resources"].(map[string]interface{})["requests"] = nil - return src - }(), - Message: "/containers/hello/resources/requests", - }, - { - Name: "containers.*.resources.requests is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["resources"].(map[string]interface{})["requests"] = map[string]interface{}{} - return src - }(), - Message: "/containers/hello/resources/requests", - }, - { - Name: "containers.*.resources.requests.memory is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var requests = hello["resources"].(map[string]interface{})["requests"].(map[string]interface{}) - requests["memory"] = nil - return src - }(), - Message: "/containers/hello/resources/requests/memory", - }, - { - Name: "containers.*.resources.requests.memory is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var requests = hello["resources"].(map[string]interface{})["requests"].(map[string]interface{}) - requests["memory"] = 12 - return src - }(), - Message: "/containers/hello/resources/requests/memory", - }, - { - Name: "containers.*.resources.requests.memory is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var requests = hello["resources"].(map[string]interface{})["requests"].(map[string]interface{}) - requests["memory"] = nil - return src - }(), - Message: "/containers/hello/resources/requests/memory", - }, - { - Name: "containers.*.resources.requests.cpu is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var requests = hello["resources"].(map[string]interface{})["requests"].(map[string]interface{}) - requests["cpu"] = 12 - return src - }(), - Message: "/containers/hello/resources/requests/cpu", - }, - - // containers.*.livenessProbe - // - { - Name: "containers.*.livenessProbe is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["livenessProbe"] = nil - return src - }(), - Message: "/containers/hello/livenessProbe", - }, - { - Name: "containers.*.livenessProbe is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["livenessProbe"] = map[string]interface{}{} - return src - }(), - Message: "/containers/hello/livenessProbe", - }, - { - Name: "containers.*.livenessProbe.httpGet is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["livenessProbe"].(map[string]interface{})["httpGet"] = nil - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet", - }, - { - Name: "containers.*.livenessProbe.httpGet.host is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["host"] = 12 - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/host", - }, - { - Name: "containers.*.livenessProbe.httpGet.host is 1.1.1.1", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["host"] = "1.1.1.1" - return src - }(), - Message: "", - }, - { - Name: "containers.*.livenessProbe.httpGet.scheme is HTTP", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["scheme"] = "HTTP" - return src - }(), - Message: "", - }, - { - Name: "containers.*.livenessProbe.httpGet.scheme is HTTPS", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["scheme"] = "HTTP" - return src - }(), - Message: "", - }, - { - Name: "containers.*.livenessProbe.httpGet.scheme is TCP", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["scheme"] = "TCP" - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/scheme", - }, - { - Name: "containers.*.livenessProbe.httpGet.scheme is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["scheme"] = 12 - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/scheme", - }, - { - Name: "containers.*.livenessProbe.httpGet.path is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - delete(httpGet, "path") - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet", - }, - { - Name: "containers.*.livenessProbe.httpGet.path is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["path"] = nil - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/path", - }, - { - Name: "containers.*.livenessProbe.httpGet.path is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["path"] = 12 - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/path", - }, - { - Name: "containers.*.livenessProbe.httpGet.port is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["port"] = nil - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/port", - }, - { - Name: "containers.*.livenessProbe.httpGet.port is not a number", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["port"] = "12" - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/port", - }, - { - Name: "containers.*.livenessProbe.httpGet.httpHeaders is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = nil - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/httpHeaders", - }, - { - Name: "containers.*.livenessProbe.httpGet.httpHeaders is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{} - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/httpHeaders", - }, - { - Name: "containers.*.livenessProbe.httpGet.httpHeaders.*.name is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": nil, - "value": "Awesome", - }, - } - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/httpHeaders/0/name", - }, - { - Name: "containers.*.livenessProbe.httpGet.httpHeaders.*.name is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": 12, - "value": "Awesome", - }, - } - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/httpHeaders/0/name", - }, - { - Name: "containers.*.livenessProbe.httpGet.httpHeaders.*.value is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": "Custom-Header", - "value": nil, - }, - } - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/httpHeaders/0/value", - }, - { - Name: "containers.*.livenessProbe.httpGet.httpHeaders.*.value is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["livenessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": "Custom-Header", - "value": nil, - }, - } - return src - }(), - Message: "/containers/hello/livenessProbe/httpGet/httpHeaders/0/value", - }, - - // containers.*.readinessProbe - // - { - Name: "containers.*.readinessProbe is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["readinessProbe"] = nil - return src - }(), - Message: "/containers/hello/readinessProbe", - }, - { - Name: "containers.*.readinessProbe is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["readinessProbe"] = map[string]interface{}{} - return src - }(), - Message: "/containers/hello/readinessProbe", - }, - { - Name: "containers.*.readinessProbe.httpGet is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - hello["readinessProbe"].(map[string]interface{})["httpGet"] = nil - return src - }(), - Message: "/containers/hello/readinessProbe", - }, - { - Name: "containers.*.readinessProbe.httpGet.path is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - delete(httpGet, "path") - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet", - }, - { - Name: "containers.*.readinessProbe.httpGet.path is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["path"] = nil - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/path", - }, - { - Name: "containers.*.readinessProbe.httpGet.path is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["path"] = 12 - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/path", - }, - { - Name: "containers.*.readinessProbe.httpGet.port is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["port"] = nil - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/port", - }, - { - Name: "containers.*.readinessProbe.httpGet.port is not a number", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["port"] = "12" - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/port", - }, - { - Name: "containers.*.readinessProbe.httpGet.httpHeaders is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = nil - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/httpHeaders", - }, - { - Name: "containers.*.readinessProbe.httpGet.httpHeaders is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{} - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/httpHeaders", - }, - { - Name: "containers.*.readinessProbe.httpGet.httpHeaders.*.name is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": nil, - "value": "Awesome", - }, - } - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/httpHeaders/0/name", - }, - { - Name: "containers.*.readinessProbe.httpGet.httpHeaders.*.name is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": 12, - "value": "Awesome", - }, - } - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/httpHeaders/0/name", - }, - { - Name: "containers.*.readinessProbe.httpGet.httpHeaders.*.value is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": "Custom-Header", - "value": nil, - }, - } - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/httpHeaders/0/value", - }, - { - Name: "containers.*.readinessProbe.httpGet.httpHeaders.*.value is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var hello = src["containers"].(map[string]interface{})["hello"].(map[string]interface{}) - var httpGet = hello["readinessProbe"].(map[string]interface{})["httpGet"].(map[string]interface{}) - httpGet["httpHeaders"] = []interface{}{ - map[string]interface{}{ - "name": "Custom-Header", - "value": nil, - }, - } - return src - }(), - Message: "/containers/hello/readinessProbe/httpGet/httpHeaders/0/value", - }, - - // resources - // - { - Name: "resources is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["resources"] = nil - return src - }(), - Message: "/resources", - }, - { - Name: "resources is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - src["resources"] = map[string]interface{}{} - return src - }(), - Message: "/resources", - }, - { - Name: "resources.* is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - src["resources"].(map[string]interface{})["db"] = nil - return src - }(), - Message: "/resources", - }, - - // resources.*.type - // - { - Name: "resources.*.type is missing", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - delete(db, "type") - return src - }(), - Message: "/resources/db", - }, - { - Name: "resources.*.type is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["type"] = nil - return src - }(), - Message: "/resources/db/type", - }, - { - Name: "resources.*.type is not a sring", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["type"] = 12 - return src - }(), - Message: "/resources/db/type", - }, - - // resources.*.metadata - // - { - Name: "resources.*.metadata is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["metadata"] = nil - return src - }(), - Message: "/resources/db/metadata", - }, - { - Name: "resources.*.metadata is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["metadata"] = map[string]interface{}{} - return src - }(), - Message: "/resources/db/metadata", - }, - - // resources.*.metadata.annotations - // - { - Name: "resources.*.metadata.annotations is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - var metadata = db["metadata"].(map[string]interface{}) - metadata["annotations"] = nil - return src - }(), - Message: "/resources/db/metadata/annotations", - }, - { - Name: "resources.*.metadata.annotations is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - var metadata = db["metadata"].(map[string]interface{}) - metadata["annotations"] = map[string]interface{}{} - return src - }(), - Message: "/resources/db/metadata/annotations", - }, - { - Name: "resources.*.metadata.annotations.* is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - var metadata = db["metadata"].(map[string]interface{}) - metadata["annotations"] = map[string]interface{}{ - "one": nil, - "two": "three", - } - return src - }(), - Message: "/resources/db/metadata/annotations/one", - }, - { - Name: "resources.*.metadata.annotations.* is not a string", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - var metadata = db["metadata"].(map[string]interface{}) - metadata["annotations"] = map[string]interface{}{ - "one": 12, - "two": "three", - } - return src - }(), - Message: "/resources/db/metadata/annotations/one", - }, - - // resources.*.properties - // - { - Name: "resources.*.properties is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["properties"] = nil - return src - }(), - Message: "", - }, - { - Name: "resources.*.properties is empty", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["properties"] = map[string]interface{}{} - return src - }(), - Message: "", - }, - { - Name: "resources.*.properties is ignored", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["properties"] = map[string]interface{}{ - "key": "value", - } - return src - }(), - Message: "", - }, - - // resources.*.params - // - { - Name: "resources.*.params is not set", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["params"] = nil - return src - }(), - Message: "/resources/db/params", - }, - { - Name: "resources.*.params is not an object", - Src: func() map[string]interface{} { - src := newTestDocument() - var db = src["resources"].(map[string]interface{})["db"].(map[string]interface{}) - db["params"] = 12 - return src - }(), - Message: "/resources/db/params", - }, - } - - for _, tt := range tests { - t.Run(tt.Name, func(t *testing.T) { - err := Validate(tt.Src) - - if tt.Message == "" { - assert.NoError(t, err) - } else { - assert.IsType(t, &jsonschema.ValidationError{}, err) - assert.ErrorContains(t, err, tt.Message) - } - }) - } -} diff --git a/schema/validate.go b/schema/validate.go deleted file mode 100644 index 3998265..0000000 --- a/schema/validate.go +++ /dev/null @@ -1,58 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package schema - -import ( - "encoding/json" - "fmt" - "io" - - "github.com/santhosh-tekuri/jsonschema/v5" - "gopkg.in/yaml.v3" -) - -// Validates source JSON file. -// -// For all vaidation errors returned error would be a *jsonschema.ValidationError. -func ValidateJson(r io.Reader) error { - var obj interface{} - - var dec = json.NewDecoder(r) - dec.UseNumber() - if err := dec.Decode(&obj); err != nil { - return fmt.Errorf("decoding source JSON structure: %w", err) - } - - return Validate(obj) -} - -// Validates source YAML file. -// -// For all vaidation errors returned error would be a *jsonschema.ValidationError. -func ValidateYaml(r io.Reader) error { - var obj interface{} - - var dec = yaml.NewDecoder(r) - if err := dec.Decode(&obj); err != nil { - return fmt.Errorf("decoding source YAML structure: %w", err) - } - - return Validate(obj) -} - -// Validates source structure. -// -// For all vaidation errors returned error would be a *jsonschema.ValidationError. -func Validate(src interface{}) error { - schema, err := jsonschema.CompileString("", ScoreSchemaV1b1) - if err != nil { - return fmt.Errorf("compiling Score schema: %w", err) - } - - return schema.Validate(src) -} diff --git a/schema/validate_test.go b/schema/validate_test.go deleted file mode 100644 index 9808c3f..0000000 --- a/schema/validate_test.go +++ /dev/null @@ -1,379 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package schema - -import ( - "bytes" - "testing" - - "github.com/stretchr/testify/assert" -) - -func TestValidateYaml(t *testing.T) { - var source = []byte(` ---- -apiVersion: score.dev/v1b1 -metadata: - name: hello-world - -service: - ports: - www: - port: 80 - targetPort: 8080 - -containers: - hello: - image: busybox - command: - - "/bin/echo" - args: - - "Hello $(FRIEND)" - variables: - FRIEND: World! - files: - - target: /etc/hello-world/config.yaml - mode: "666" - content: "${resources.env.APP_CONFIG}" - volumes: - - source: ${resources.data} - path: sub/path - target: /mnt/data - read_only: true - resources: - limits: - memory: "128Mi" - cpu: "500m" - requests: - memory: "64Mi" - cpu: "250m" - livenessProbe: - httpGet: - path: /alive - port: 8080 - readinessProbe: - httpGet: - path: /ready - port: 8080 - httpHeaders: - - name: Custom-Header - value: Awesome - -resources: - env: - type: environment - dns: - type: dns - data: - type: volume - db: - type: postgres - metadata: - annotations: - "my.org/version": "0.1" - params: { - extensions: { - uuid-ossp: { - schema: "uuid_schema", - version: "1.1" - } - } - } -`) - - err := ValidateYaml(bytes.NewReader(source)) - assert.NoError(t, err) -} - -func TestValidateYaml_Error(t *testing.T) { - var source = []byte(` ---- -apiVersion: score.dev/v1b1 -metadata: - no-name: hello-world - -service: - ports: - www: - port: 80 - targetPort: 8080 - -containers: - hello: - image: busybox - command: - - "/bin/echo" - args: - - "Hello $(FRIEND)" - variables: - FRIEND: World! - files: - - target: /etc/hello-world/config.yaml - mode: "666" - content: "${resources.env.APP_CONFIG}" - volumes: - - source: ${resources.data} - path: sub/path - target: /mnt/data - read_only: true - resources: - limits: - memory: "128Mi" - cpu: "500m" - requests: - memory: "64Mi" - cpu: "250m" - livenessProbe: - httpGet: - path: /alive - port: 8080 - readinessProbe: - httpGet: - path: /ready - port: 8080 - httpHeaders: - - name: Custom-Header - value: Awesome - -resources: - env: - type: environment - dns: - type: dns - data: - type: volume - db: - type: postgres - metadata: - annotations: - "my.org/version": "0.1" - params: { - extensions: { - uuid-ossp: { - schema: "uuid_schema", - version: "1.1" - } - } - } -`) - - err := ValidateYaml(bytes.NewReader(source)) - assert.Error(t, err) -} - -func TestValidateJson(t *testing.T) { - var source = []byte(` -{ - "apiVersion": "score.dev/v1b1", - "metadata": { - "name": "hello-world" - }, - "service": { - "ports": { - "www": { - "port": 80, - "targetPort": 8080 - } - } - }, - "containers": { - "hello": { - "image": "busybox", - "command": [ - "/bin/echo" - ], - "args": [ - "Hello $(FRIEND)" - ], - "variables": { - "FRIEND": "World!" - }, - "files": [ - { - "target": "/etc/hello-world/config.yaml", - "mode": "666", - "content": "${resources.env.APP_CONFIG}" - } - ], - "volumes": [ - { - "source": "${resources.data}", - "path": "sub/path", - "target": "/mnt/data", - "read_only": true - } - ], - "resources": { - "limits": { - "memory": "128Mi", - "cpu": "500m" - }, - "requests": { - "memory": "64Mi", - "cpu": "250m" - } - }, - "livenessProbe": { - "httpGet": { - "path": "/alive", - "port": 8080 - } - }, - "readinessProbe": { - "httpGet": { - "path": "/ready", - "port": 8080, - "httpHeaders": [ - { - "name": "Custom-Header", - "value": "Awesome" - } - ] - } - } - } - }, - "resources": { - "env": { - "type": "environment" - }, - "dns": { - "type": "dns" - }, - "data": { - "type": "volume" - }, - "db": { - "type": "postgres", - "metadata": { - "annotations": { - "my.org/version": "0.1" - } - }, - "params": { - "extensions": { - "uuid-ossp": { - "schema": "uuid_schema", - "version": "1.1" - } - } - } - } - } -} -`) - - err := ValidateJson(bytes.NewReader(source)) - assert.NoError(t, err) -} - -func TestValidateJson_Error(t *testing.T) { - var source = []byte(` -{ - "apiVersion": "score.dev/v1b1", - "metadata": { - "no-name": "hello-world" - }, - "service": { - "ports": { - "www": { - "port": 80, - "targetPort": 8080 - } - } - }, - "containers": { - "hello": { - "image": "busybox", - "command": [ - "/bin/echo" - ], - "args": [ - "Hello $(FRIEND)" - ], - "variables": { - "FRIEND": "World!" - }, - "files": [ - { - "target": "/etc/hello-world/config.yaml", - "mode": "666", - "content": "${resources.env.APP_CONFIG}" - } - ], - "volumes": [ - { - "source": "${resources.data}", - "path": "sub/path", - "target": "/mnt/data", - "read_only": true - } - ], - "resources": { - "limits": { - "memory": "128Mi", - "cpu": "500m" - }, - "requests": { - "memory": "64Mi", - "cpu": "250m" - } - }, - "livenessProbe": { - "httpGet": { - "path": "/alive", - "port": 8080 - } - }, - "readinessProbe": { - "httpGet": { - "path": "/ready", - "port": 8080, - "httpHeaders": [ - { - "name": "Custom-Header", - "value": "Awesome" - } - ] - } - } - } - }, - "resources": { - "env": { - "type": "environment" - }, - "dns": { - "type": "dns" - }, - "data": { - "type": "volume" - }, - "db": { - "type": "postgres", - "metadata": { - "annotations": { - "my.org/version": "0.1" - } - }, - "params": { - "extensions": { - "uuid-ossp": { - "schema": "uuid_schema", - "version": "1.1" - } - } - } - } - } -} -`) - - err := ValidateJson(bytes.NewReader(source)) - assert.Error(t, err) -} diff --git a/score-v1b1.json b/score-v1b1.json new file mode 100644 index 0000000..110e9db --- /dev/null +++ b/score-v1b1.json @@ -0,0 +1,346 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://score.dev/schemas/score", + "title": "Score schema", + "description": "Score workload specification", + "type": "object", + "required": [ + "apiVersion", + "metadata", + "containers" + ], + "additionalProperties": false, + "properties": { + "apiVersion": { + "description": "The declared Score Specification version.", + "type": "string" + }, + "metadata": { + "description": "The metadata description of the Workload.", + "type": "object", + "required": [ + "name" + ], + "additionalProperties": true, + "properties": { + "name": { + "description": "A string that can describe the Workload.", + "type": "string" + } + } + }, + "service": { + "description": "The service that the workload provides.", + "type": "object", + "additionalProperties": false, + "properties": { + "ports": { + "description": "List of network ports published by the service.", + "type": "object", + "minProperties": 1, + "additionalProperties": { + "description": "The network port description.", + "type": "object", + "required": [ + "targetPort" + ], + "additionalProperties": false, + "properties": { + "port": { + "description": "The public service port.", + "type": "number" + }, + "targetPort": { + "description": "The internal service port.", + "type": "number" + } + } + } + } + } + }, + "containers": { + "description": "The declared Score Specification version.", + "type": "object", + "minProperties": 1, + "additionalProperties": { + "description": "The container name.", + "type": "object", + "required": [ + "image" + ], + "additionalProperties": false, + "properties": { + "image": { + "description": "The image name and tag.", + "type": "string" + }, + "command": { + "description": "If specified, overrides container entry point.", + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + }, + "args": { + "description": "If specified, overrides container entry point arguments.", + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + }, + "variables": { + "description": "The environment variables for the container.", + "type": "object", + "minProperties": 1, + "additionalProperties": { + "type": "string" + } + }, + "files": { + "description": "The extra files to mount.", + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "required": [ + "target" + ], + "properties": { + "target": { + "description": "The file path and name.", + "type": "string" + }, + "mode": { + "description": "The file access mode.", + "type": "string" + }, + "source": { + "description": "The relative or absolute path to the content file.", + "type": "string", + "minLength": 1 + }, + "content": { + "description": "The inline content for the file.", + "anyOf": [ + { + "type": "string" + }, + { + "deprecated": true, + "type": "array", + "minItems": 1, + "items": { + "type": "string" + } + } + ] + }, + "noExpand": { + "description": "If set to true, the placeholders expansion will not occur in the contents of the file.", + "type": "boolean" + } + }, + "oneOf": [ + { + "required": [ + "content" + ] + }, + { + "required": [ + "source" + ] + } + ] + } + }, + "volumes": { + "description": "The volumes to mount.", + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "required": [ + "source", + "target" + ], + "properties": { + "source": { + "description": "The external volume reference.", + "type": "string" + }, + "path": { + "description": "An optional sub path in the volume.", + "type": "string" + }, + "target": { + "description": "The target mount on the container.", + "type": "string" + }, + "read_only": { + "description": "Indicates if the volume should be mounted in a read-only mode.", + "type": "boolean" + } + } + } + }, + "resources": { + "description": "The compute resources for the container.", + "type": "object", + "minProperties": 1, + "additionalProperties": false, + "properties": { + "limits": { + "description": "The maximum allowed resources for the container.", + "$ref": "#/$defs/resourcesLimits" + }, + "requests": { + "description": "The minimal resources required for the container.", + "$ref": "#/$defs/resourcesLimits" + } + } + }, + "livenessProbe": { + "description": "The liveness probe for the container.", + "$ref": "#/$defs/containerProbe" + }, + "readinessProbe": { + "description": "The readiness probe for the container.", + "$ref": "#/$defs/containerProbe" + } + } + } + }, + "resources": { + "description": "The dependencies needed by the Workload.", + "type": "object", + "minProperties": 1, + "additionalProperties": { + "description": "The resource name.", + "type": "object", + "additionalProperties": false, + "required": [ + "type" + ], + "properties": { + "type": { + "description": "The resource in the target environment.", + "type": "string" + }, + "class": { + "description": "A specialisation of the resource type.", + "type": "string", + "pattern": "^[a-z0-9](?:-?[a-z0-9]+)+$" + }, + "metadata": { + "description": "The metadata for the resource.", + "type": "object", + "minProperties": 1, + "additionalProperties": true, + "properties": { + "annotations": { + "description": "Annotations that apply to the property.", + "type": "object", + "minProperties": 1, + "additionalProperties": { + "type": "string" + } + } + } + }, + "properties": { + "description": "DEPRECATED: The properties that can be referenced in other places in the Score Specification file.", + "type": [ + "object", + "null" + ] + }, + "params": { + "description": "The parameters used to validate or provision the resource in the environment.", + "type": "object" + } + } + } + } + }, + "$defs": { + "resourcesLimits": { + "description": "The compute resources limits.", + "type": "object", + "minProperties": 1, + "additionalProperties": false, + "properties": { + "memory": { + "description": "The memory limit.", + "type": "string" + }, + "cpu": { + "description": "The CPU limit.", + "type": "string" + } + } + }, + "containerProbe": { + "type": "object", + "minProperties": 1, + "additionalProperties": false, + "properties": { + "httpGet": { + "$ref": "#/$defs/httpProbe" + } + } + }, + "httpProbe": { + "description": "An HTTP probe details.", + "type": "object", + "additionalProperties": false, + "required": [ + "path" + ], + "properties": { + "host": { + "description": "Host name to connect to. Defaults to the container IP.", + "type": "string" + }, + "scheme": { + "description": "Scheme to use for connecting to the host (HTTP or HTTPS). Defaults to HTTP.", + "type": "string", + "enum": [ + "HTTP", + "HTTPS" + ] + }, + "path": { + "description": "The path of the HTTP probe endpoint.", + "type": "string" + }, + "port": { + "description": "The path of the HTTP probe endpoint.", + "type": "number" + }, + "httpHeaders": { + "description": "Additional HTTP headers to send with the request", + "type": "array", + "minItems": 1, + "items": { + "type": "object", + "additionalProperties": false, + "properties": { + "name": { + "description": "The HTTP header name.", + "type": "string" + }, + "value": { + "description": "The HTTP header value.", + "type": "string" + } + } + } + } + } + } + } +} diff --git a/types/containers.go b/types/containers.go deleted file mode 100644 index 39e364c..0000000 --- a/types/containers.go +++ /dev/null @@ -1,75 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package types - -// ContainersSpecs is a map of workload containers specifications. -type ContainersSpecs map[string]ContainerSpec - -// ContainerSpec is a workload container specification. -type ContainerSpec struct { - Image string `json:"image"` - Command []string `json:"command"` - Args []string `json:"args"` - Variables map[string]string `json:"variables"` - Files []FileMountSpec `json:"files"` - Volumes []VolumeMountSpec `json:"volumes"` - Resources ContainerResourcesRequirementsSpec `json:"resources"` - LivenessProbe ContainerProbeSpec `json:"livenessProbe"` - ReadinessProbe ContainerProbeSpec `json:"readinessProbe"` -} - -// ContainerResourcesRequirementsSpec is a container resources requirements. -type ContainerResourcesRequirementsSpec struct { - Limits map[string]interface{} `json:"limits"` - Requests map[string]interface{} `json:"requests"` -} - -// FileMountSpec is a container's file mount specification. -type FileMountSpec struct { - // The mounted file path and name. - Target string `json:"target"` - // The mounted file access mode. - Mode string `json:"mode"` - // File content, if scpecified, could be a single string or an array of strings (parsed as []interface{}, DEPRECATED). - // This property can't be used if 'source' property is used. - Content interface{} `json:"content"` - // If specified, file content should be read from the local file, referenced by the source property. - // The file path is always relative to the source Score file. - // This property can't be used if 'content' property is used. - Source string `json:"source"` - // If set to true, the placeholders expansion will not occur in the contents of the file. - NoExpand bool `json:"noExpand"` -} - -// VolumeMountSpec is a container volume mount point specification. -type VolumeMountSpec struct { - Source string `json:"source"` - Path string `json:"path"` - Target string `json:"target"` - ReadOnly bool `json:"read_only"` -} - -// ContainerProbeSpec is a container probe specification. -type ContainerProbeSpec struct { - HTTPGet HTTPGetActionSpec `json:"httpGet"` -} - -// HTTPGetActionSpec is an HTTP GET Action specification. -type HTTPGetActionSpec struct { - Scheme string `json:"scheme"` - Host string `json:"host"` - Port int `json:"port"` - Path string `json:"path"` - HTTPHeaders []HTTPHeaderSpec `json:"httpHeaders"` -} - -// HTTPHeaderSpec is an HTTP Header specification. -type HTTPHeaderSpec struct { - Name string `json:"name"` - Value string `json:"value"` -} diff --git a/types/resources.go b/types/resources.go deleted file mode 100644 index 7a37cbd..0000000 --- a/types/resources.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package types - -// ResourcesSpecs is a map of workload resources specifications. -type ResourcesSpecs map[string]ResourceSpec - -// ResourceSpec is a resource specification. -type ResourceSpec struct { - Type string `json:"type"` - Metadata ResourceMeta `json:"metadata,omitempty"` - Params map[string]interface{} `json:"params,omitempty"` -} - -// ResourceMeta is an additional resource metadata. -type ResourceMeta struct { - Annotations map[string]string `json:"annotations,omitempty"` -} diff --git a/types/service.go b/types/service.go deleted file mode 100644 index 26c5f50..0000000 --- a/types/service.go +++ /dev/null @@ -1,23 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package types - -// ServiceSpec is a workload service specification. -type ServiceSpec struct { - Ports ServicePortsSpecs `json:"ports"` -} - -// ServicePortsSpecs is a map of named service ports specifications. -type ServicePortsSpecs map[string]ServicePortSpec - -// ServicePortSpec is a service port specification. -type ServicePortSpec struct { - Port int `json:"port"` - TargetPort int `json:"targetPort"` - Protocol string `json:"protocol"` -} diff --git a/types/workload.go b/types/workload.go deleted file mode 100644 index d963369..0000000 --- a/types/workload.go +++ /dev/null @@ -1,82 +0,0 @@ -/* -Apache Score -Copyright 2020 The Apache Software Foundation - -This product includes software developed at -The Apache Software Foundation (http://www.apache.org/). -*/ -package types - -// WorkloadSpec is a single workload specification. -// -// YAML example: -// -// apiVersion: score.dev/v1b1 -// metadata: -// name: hello-world -// service: -// ports: -// www: -// hostPort: 80 -// protocol: TCP -// port: 8080 -// containers: -// hello: -// image: busybox -// command: ["/bin/echo"] -// args: ["Hello $(FRIEND)"] -// variables: -// FRIEND: World! -// resources: -// limits: -// memory: "128Mi" -// cpu: "500m" -// requests: -// memory: "64Mi" -// cpu: "250m" -// livenessProbe: -// httpGet: -// path: /health -// port: 8080 -// httpHeaders: -// - name: Custom-Header -// value: Awesome -// files: -// - target: etc/hello-world/config.yaml -// mode: "666" -// content: ${resources.env.APP_CONFIG} -// volumes: -// - source: ${resources.data} -// path: sub/path -// target: /mnt/data -// read_only: true -// resources: -// env: -// type: environment -// properties: -// APP_CONFIG: -// dns: -// type: dns -// properties: -// domain: -// data: -// type: volume -// db: -// type: postgres -// properties: -// host: -// default: localhost -// port: -// default: 5432 -type WorkloadSpec struct { - ApiVersion string `json:"apiVersion"` - Metadata WorkloadMeta `json:"metadata"` - Service ServiceSpec `json:"service"` - Containers ContainersSpecs `json:"containers"` - Resources ResourcesSpecs `json:"resources"` -} - -// WorkloadMeta is a workload metadata. -type WorkloadMeta struct { - Name string `json:"name"` -}