Skip to content

Commit a494ce1

Browse files
camilamacedo86timflannagan
authored andcommitted
doc: further information and example of usage (openshift#205)
Upstream-repository: api Upstream-commit: 7f43803893b09e6160fbaffdb2e32e0c269005ff
1 parent f73f86c commit a494ce1

File tree

3 files changed

+86
-13
lines changed

3 files changed

+86
-13
lines changed

staging/api/README.md

Lines changed: 72 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,87 @@
1-
# api
1+
Api
2+
--
23

34
Contains the API definitions used by [Operator Lifecycle Manager][olm] (OLM) and [Marketplace Operator][marketplace]
45

56
## `pkg/validation`: Operator Manifest Validation
67

78
`pkg/validation` exposes a convenient set of interfaces to validate Kubernetes object manifests, primarily for use in an Operator project.
89

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.
1113

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
1374

1475
You can install the `operator-verify` tool from source using:
1576

1677
`$ make install`
1778

1879
To verify your ClusterServiceVersion yaml,
1980

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/

staging/api/pkg/validation/doc.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
// by exported functions for missing mandatory and optional fields,
99
// respectively. Each Error implements the error interface.
1010
//
11-
// Bundle format: https://github.com/operator-framework/operator-registry/#manifest-format
12-
// ClusterServiceVersion documentation: https://github.com/operator-framework/operator-lifecycle-manager/blob/master/Documentation/design/building-your-csv.md
13-
// Package manifest documentation: https://github.com/operator-framework/operator-lifecycle-manager#discovery-catalogs-and-automated-upgrades
14-
// CustomResourceDefinition documentation: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/
11+
// - Bundle format: https://github.com/operator-framework/operator-registry/#manifest-format
12+
//
13+
// - ClusterServiceVersion documentation: https://github.com/operator-framework/operator-lifecycle-manager/blob/master/Documentation/design/building-your-csv.md
14+
//
15+
// - Package manifest documentation: https://github.com/operator-framework/operator-lifecycle-manager#discovery-catalogs-and-automated-upgrades
16+
17+
// - CustomResourceDefinition documentation: https://kubernetes.io/docs/tasks/access-kubernetes-api/custom-resources/custom-resource-definitions/
1518
package validation

vendor/github.com/operator-framework/api/pkg/validation/doc.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)