|
1 |
| -# api |
| 1 | +Api |
| 2 | +-- |
2 | 3 |
|
3 | 4 | Contains the API definitions used by [Operator Lifecycle Manager][olm] (OLM) and [Marketplace Operator][marketplace]
|
4 | 5 |
|
5 | 6 | ## `pkg/validation`: Operator Manifest Validation
|
6 | 7 |
|
7 | 8 | `pkg/validation` exposes a convenient set of interfaces to validate Kubernetes object manifests, primarily for use in an Operator project.
|
8 | 9 |
|
9 |
| -[olm]:https://github.com/operator-framework/operator-lifecycle-manager |
10 |
| -[marketplace]:https://github.com/operator-framework/operator-marketplace |
| 10 | +The Validators are static checks (linters) that can scan the manifests and provide |
| 11 | +with low-cost valuable results to ensure the quality of the package of distributions |
| 12 | +(bundle or package formats) which will be distributed via OLM. |
11 | 13 |
|
12 |
| -## Usage |
| 14 | +The validators implemented in this project aims to provide common validators |
| 15 | +(which can be useful or required for any solution which will be distributed via [Operator Lifecycle Manager][olm]). |
| 16 | +([More info](https://pkg.go.dev/github.com/operator-framework/api@master/pkg/validation)) |
| 17 | + |
| 18 | +Note that [Operator-SDK][sdk] leverage in this project. By using it you can |
| 19 | +test your bundle against the spec criteria (Default Validators) by running: |
| 20 | + |
| 21 | +```sh |
| 22 | +$ operator-sdk bundle validate <bundle-path> |
| 23 | +``` |
| 24 | + |
| 25 | +Also, [Operator-SDK][sdk] allows you check your bundles against the Optional Validators |
| 26 | +provided by using the flag option `--select-optional` such as the following example: |
| 27 | + |
| 28 | +```sh |
| 29 | +$ operator-sdk bundle validate ./bundle --select-optional suite=operatorframework --optional-values=k8s-version=<k8s-version> |
| 30 | +``` |
| 31 | + |
| 32 | +For further information see the [doc][sdk-command-doc]. |
| 33 | + |
| 34 | +### Example of usage: |
| 35 | + |
| 36 | +Note that you can leverage in this project to call and indeed create your own validators. |
| 37 | +Following an example. |
| 38 | + |
| 39 | +```go |
| 40 | + import ( |
| 41 | + ... |
| 42 | + apimanifests "github.com/operator-framework/api/pkg/manifests" |
| 43 | + apivalidation "github.com/operator-framework/api/pkg/validation" |
| 44 | + "github.com/operator-framework/api/pkg/validation/errors" |
| 45 | + ... |
| 46 | + ) |
| 47 | + |
| 48 | + // Load the directory (which can be in packagemanifest or bundle format) |
| 49 | + bundle, err := apimanifests.GetBundleFromDir(path) |
| 50 | + if err != nil { |
| 51 | + ... |
| 52 | + return nil |
| 53 | + } |
| 54 | + |
| 55 | + // Call all default validators and the OperatorHubValidator |
| 56 | + validators := apivalidation.DefaultBundleValidators |
| 57 | + validators = validators.WithValidators(apivalidation.OperatorHubValidator) |
| 58 | + |
| 59 | + objs := bundle.ObjectsToValidate() |
| 60 | + |
| 61 | + results := validators.Validate(objs...) |
| 62 | + nonEmptyResults := []errors.ManifestResult{} |
| 63 | + |
| 64 | + for _, result := range results { |
| 65 | + if result.HasError() || result.HasWarn() { |
| 66 | + nonEmptyResults = append(nonEmptyResults, result) |
| 67 | + } |
| 68 | + } |
| 69 | + // return the results |
| 70 | + return nonEmptyResults |
| 71 | +``` |
| 72 | + |
| 73 | +## API CLI Usage |
13 | 74 |
|
14 | 75 | You can install the `operator-verify` tool from source using:
|
15 | 76 |
|
16 | 77 | `$ make install`
|
17 | 78 |
|
18 | 79 | To verify your ClusterServiceVersion yaml,
|
19 | 80 |
|
20 |
| -`$ operator-verify manifests /path/to/filename.yaml` |
| 81 | +`$ operator-verify manifests /path/to/filename.yaml` |
| 82 | + |
| 83 | +[sdk]: https://github.com/operator-framework/operator-sdk |
| 84 | +[olm]: https://github.com/operator-framework/operator-lifecycle-manager |
| 85 | +[marketplace]: https://github.com/operator-framework/operator-marketplace |
| 86 | +[bundle]: https://github.com/operator-framework/operator-registry/blob/v1.19.5/docs/design/operator-bundle.md |
| 87 | +[sdk-command-doc]: https://master.sdk.operatorframework.io/docs/cli/operator-sdk_bundle_validate/ |
0 commit comments