Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions _topic_maps/_topic_map.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1542,6 +1542,8 @@ Topics:
File: osdk-working-bundle-images
- Name: Validating Operators using the scorecard
File: osdk-scorecard
- Name: Validating Operator bundles
File: osdk-bundle-validate
- Name: High-availability or single-node cluster detection and support
File: osdk-ha-sno
- Name: Configuring built-in monitoring with Prometheus
Expand Down
65 changes: 65 additions & 0 deletions modules/osdk-bundle-validate-about.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// Module included in the following assemblies:
//
// * operators/operator_sdk/osdk-bundle-validate.adoc

:_content-type: CONCEPT
[id="osdk-about-bundle-validate_{context}"]
= About the bundle validate command

While the Operator SDK `scorecard` command can run tests on your Operator based on a configuration file and test images, the `bundle validate` subcommand can validate local bundle directories and remote bundle images for content and structure.

.`bundle validate` command syntax
[source,terminal]
----
$ operator-sdk bundle validate <bundle_dir_or_image> <flags>
----

[NOTE]
====
The `bundle validate` command runs automatically when you build your bundle using the the `make bundle` command.
====

Bundle images are pulled from a remote registry and built locally before they are validated. Local bundle directories must contain Operator metadata and manifests. The bundle metadata and manifests must have a structure similar to the following bundle layout:

.Example bundle layout
[source,terminal]
----
./bundle
├── manifests
│   ├── cache.my.domain_memcacheds.yaml
│   └── memcached-operator.clusterserviceversion.yaml
└── metadata
└── annotations.yaml
----

Bundle tests pass validation and finish with an exit code of `0` if no errors are detected.

.Example output
[source,terminal]
----
INFO[0000] All validation tests have completed successfully
----

Tests fail validation and finish with an exit code of `1` if errors are detected.

.Example output
[source,terminal]
----
ERRO[0000] Error: Value cache.example.com/v1alpha1, Kind=Memcached: CRD "cache.example.com/v1alpha1, Kind=Memcached" is present in bundle "" but not defined in CSV
----

Bundle tests that result in warnings can still pass validation with an exit code of `0` as long as no errors are detected. Tests only fail on errors.

.Example output
[source,terminal]
----
WARN[0000] Warning: Value : (memcached-operator.v0.0.1) annotations not found
INFO[0000] All validation tests have completed successfully
----

For further information about the `bundle validate` subcommand, run:

[source,terminal]
----
$ operator-sdk bundle validate -h
----
62 changes: 62 additions & 0 deletions modules/osdk-bundle-validate-run.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Module included in the following assemblies:
//
// * operators/operator_sdk/osdk-bundle-validate.adoc

:_content-type: PROCEDURE
[id="osdk-bundle-validate-run_{context}"]
= Running the bundle validate command

The default validator runs a test every time you enter the `bundle validate` command. You can run optional validators using the `--select-optional` flag. Optional validators run tests in addition to the default test.

.Prerequisites

* Operator project generated by using the Operator SDK

.Procedure

. If you want to run the default validator against a local bundle directory, enter the following command from your Operator project directory:
+
[source,terminal]
----
$ operator-sdk bundle validate ./bundle
----

. If you want to run the default validator against a remote Operator bundle image, enter the following command:
+
[source,terminal]
----
$ operator-sdk bundle validate \
<bundle_registry>/<bundle_image_name>:<tag>
----
+
where:

<bundle_registry>:: Specifies the registry where the bundle is hosted, such as `quay.io/example`.
<bundle_image_name>:: Specifies the name of the bundle image, such as `memcached-operator`.
<tag>:: Specifies the tag of the bundle image, such as `v1.22.0`.
+
[NOTE]
====
If you want to validate an Operator bundle image, you must host your image in a remote registry. The Operator SDK pulls the image and builds it locally before running tests. The `bundle validate` command does not support testing local bundle images.
====

. If you want to run an additional validator against an Operator bundle, enter the following command:
+
[source,terminal]
----
$ operator-sdk bundle validate \
<bundle_dir_or_image> \
--select-optional <test_label>
----
+
where:

<bundle_dir_or_image>:: Specifies the local bundle directory or remote bundle image, such as `~/projects/memcached` or `quay.io/example/memcached-operator:v1.22`.
<test_label>:: Specifies the name of the validator you want to run, such as `name=good-practices`.
+
.Example output
[source,terminal]
----
ERRO[0000] Error: Value apiextensions.k8s.io/v1, Kind=CustomResource: unsupported media type registry+v1 for bundle object
WARN[0000] Warning: Value k8sevent.v0.0.1: owned CRD "k8sevents.k8s.k8sevent.com" has an empty description
----
37 changes: 37 additions & 0 deletions modules/osdk-bundle-validate-tests.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Module included in the following assemblies:
//
// * operators/operator_sdk/osdk-bundle-validate.adoc

:_content-type: REFERENCE
[id="osdk-bundle-validate-tests_{context}"]
= Built-in bundle validate tests

The Operator SDK ships with pre-defined validators arranged into suites. If you run the `bundle validate` command without specifying a validator, the default test runs. The default test verifies that a bundle adheres to the specifications defined by the Operator Framework community. For more information, see "Bundle format".

You can run optional validators to test for issues such as OperatorHub compatibility or deprecated Kubernetes APIs. Optional validators always run in addition to the default test.

.`bundle validate` command syntax for optional test suites
[source,terminal]
----
$ operator-sdk bundle validate <bundle_dir_or_image>
--select-optional <test_label>
----

[id="osdk-bundle-validate-additional-tests_{context}"]
.Addtional `bundle validate` validators
[cols="3,7,3",options="header"]
|===
|Name |Description |Label

|Operator Framework
|This validator tests an Operator bundle against the entire suite of validators provided by the Operator Framework.
|`suite=operatorframework`

|OperatorHub
|This validator tests an Operator bundle for compatibility with OperatorHub.
|`name=operatorhub`

|Good Practices
|This validator tests whether an Operator bundle complies with good practices as defined by the Operator Framework. It checks for issues, such as an empty CRD description or unsupported Operator Lifecycle Manager (OLM) resources.
|`name=good-practices`
|===
19 changes: 19 additions & 0 deletions operators/operator_sdk/osdk-bundle-validate.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
:_content-type: ASSEMBLY
[id="osdk-bundle-validate"]
= Validating Operator bundles
include::_attributes/common-attributes.adoc[]
:context: osdk-bundle-validate

toc::[]

As an Operator author, you can run the `bundle validate` command in the Operator SDK to validate the content and format of an Operator bundle. You can run the command on a remote Operator bundle image or a local Operator bundle directory.

include::modules/osdk-bundle-validate-about.adoc[leveloffset=+1]
include::modules/osdk-bundle-validate-tests.adoc[leveloffset=+1]

[role="_additional-resources"]
.Additional resources

* xref:../../operators/understanding/olm-packaging-format.adoc#olm-bundle-format_olm-packaging-format[Bundle format]

include::modules/osdk-bundle-validate-run.adoc[leveloffset=+1]