Skip to content

Commit d8e2ec5

Browse files
Merge pull request #146 from exdx/feat/validate-bundle-files
Add bundle contents validation
2 parents 5ec9f93 + 0d31556 commit d8e2ec5

File tree

415 files changed

+68254
-11924
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

415 files changed

+68254
-11924
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ bin
449449

450450
# Ignore sqlite
451451
*.db
452+
*.db-journal
452453

453454
# Ignore vscode
454455
.vscode

cmd/opm/alpha/bundle/validate.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package bundle
33
import (
44
"io/ioutil"
55
"os"
6+
"path/filepath"
67

78
"github.com/operator-framework/operator-registry/pkg/lib/bundle"
89
log "github.com/sirupsen/logrus"
@@ -54,9 +55,14 @@ func validateFunc(cmd *cobra.Command, args []string) error {
5455
return err
5556
}
5657

57-
logger.Info("Unpacked image layers, validating bundle image contents")
58+
logger.Info("Unpacked image layers, validating bundle image format & contents")
5859

59-
err = imageValidator.ValidateBundle(dir)
60+
err = imageValidator.ValidateBundleFormat(dir)
61+
if err != nil {
62+
return err
63+
}
64+
65+
err = imageValidator.ValidateBundleContent(filepath.Join(dir, bundle.ManifestsDir))
6066
if err != nil {
6167
return err
6268
}

docs/design/operator-bundle.md

Lines changed: 42 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -91,40 +91,34 @@ $ tree
9191

9292
## Operator Bundle Commands
9393

94-
Operator SDK CLI is available to generate Bundle annotations and Dockerfile based on provided operator manifests.
94+
`opm` (Operator Package Manager) is a CLI tool to generate bundle annotations, build bundle manifests image, validate bundle manifests image and other functionalities. Please note that the `generate`, `build` and `validate` features of `opm` CLI are currently in alpha and only meant for development use.
9595

96-
### Operator SDK CLI
96+
### `opm` (Operator Package Manager)
9797

98-
In order to use Operator SDK CLI, follow the operator-SDK installation instruction:
98+
In order to use `opm` CLI, follow the `opm` build instruction:
9999

100-
1. Install the [Operator SDK CLI](https://github.com/operator-framework/operator-sdk/blob/master/doc/user/install-operator-sdk.md)
100+
1. Clone the operator registry repository:
101101

102-
Now, a binary named `operator-sdk` is available in OLM's directory to use.
103102
```bash
104-
$ ./operator-sdk
105-
An SDK for building operators with ease
106-
107-
Usage:
108-
operator-sdk [command]
109-
110-
Available Commands:
111-
bundle Operator bundle commands
103+
$ git clone https://github.com/operator-framework/operator-registry
104+
```
112105

113-
Flags:
114-
-h, --help help for operator-sdk
115-
--verbose Enable verbose logging
106+
2. Build `opm` binary using this command:
116107

117-
Use "operator-sdk [command] --help" for more information about a command.
108+
```bash
109+
$ go build ./cmd/opm/
118110
```
119111

112+
Now, a binary named `opm` is now built in current directory and ready to be used.
113+
120114
### Generate Bundle Annotations and DockerFile
121115
*Notes:*
122116
* If there are `annotations.yaml` and `Dockerfile` existing in the directory, they will be overwritten.
123117

124-
Using `operator-sdk` CLI, bundle annotations can be generated from provided operator manifests. The overall `bundle generate` command usage is:
118+
Using `opm` CLI, bundle annotations can be generated from provided operator manifests. The overall `bundle generate` command usage is:
125119
```bash
126120
Usage:
127-
operator-sdk bundle generate [flags]
121+
opm alpha bundle generate [flags]
128122

129123
Flags:
130124
-c, --channels string The list of channels that bundle image belongs to
@@ -141,7 +135,7 @@ The `--directory/-d`, `--channels/-c`, `--package/-p` are required flags while `
141135

142136
The command for `generate` task is:
143137
```bash
144-
$ ./operator-sdk bundle generate --directory /test --package test-operator \
138+
$ ./opm alpha bundle generate --directory /test --package test-operator \
145139
--channels stable,beta --default stable
146140
```
147141

@@ -173,7 +167,7 @@ $ docker build -f /path/to/Dockerfile -t quay.io/test/test-operator:latest /path
173167
Operator bundle image can be built from provided operator manifests using `build` command (see *Notes* below). The overall `bundle build` command usage is:
174168
```bash
175169
Usage:
176-
operator-SDK bundle build [flags]
170+
opm alpha bundle build [flags]
177171

178172
Flags:
179173
-c, --channels string The list of channels that bundle image belongs to
@@ -192,15 +186,15 @@ Flags:
192186
193187
The command for `build` task is:
194188
```bash
195-
$ ./operator-sdk bundle build --directory /test --tag quay.io/coreos/test-operator.v0.1.0:latest \
189+
$ ./opm alpha bundle build --directory /test --tag quay.io/coreos/test-operator.v0.1.0:latest \
196190
--package test-operator --channels stable,beta --default stable
197191
```
198192
199193
The `--directory` or `-d` specifies the directory where the operator manifests for a specific version are located. The `--tag` or `-t` specifies the image tag that you want the operator bundle image to have. By using `build` command, the `annotations.yaml` and `Dockerfile` are automatically generated in the background.
200194
201195
The default image builder is `Docker`. However, ` Buildah` and `Podman` are also supported. An image builder can specified via `--image-builder` or `-b` optional tag in `build` command. For example:
202196
```bash
203-
$ ./operator-sdk bundle build --directory /test/0.1.0/ --tag quay.io/coreos/test-operator.v0.1.0:latest \
197+
$ ./opm alpha bundle build --directory /test/0.1.0/ --tag quay.io/coreos/test-operator.v0.1.0:latest \
204198
--image-builder podman --package test-operator --channels stable,beta --default stable
205199
```
206200
@@ -209,3 +203,28 @@ The `--package` or `-p` is the name of package fo the operator such as `etcd` wh
209203
*Notes:*
210204
* If there is `Dockerfile` existing in the directory, it will be overwritten.
211205
* If there is an existing `annotations.yaml` in `/metadata` directory, the cli will attempt to validate it and returns any found errors. If the ``annotations.yaml`` is valid, it will be used as a part of build process. The optional boolean `--overwrite/-o` flag can be enabled (false by default) to allow cli to overwrite the `annotations.yaml` if existed.
206+
207+
### Validate Bundle Image
208+
209+
Operator bundle image can validate bundle image that is publicly available in an image registry using `validate` command (see *Notes* below). The overall `bundle validate` command usage is:
210+
```bash
211+
Usage:
212+
opm alpha bundle validate [flags]
213+
214+
Flags:
215+
-t, --tag string The name of the bundle image will be built
216+
-b, --image-builder string Tool to extract container images. One of: [docker, podman] (default "docker")
217+
-h, --help help for build
218+
```
219+
220+
The command for `validate` task is:
221+
```bash
222+
$ ./opm alpha bundle build --tag quay.io/coreos/test-operator.v0.1.0:latest --image-builder docker
223+
```
224+
225+
The `validate` command will first extract the contents of the bundle image into a temporary directory after it pulls the image from its image registry. Then, it will validate the format of bundle image to ensure manifests and metadata are located in their appropriate directories (`/manifests/` for bundle manifests files such as CSV and `/metadata/` for metadata files such as `annotations.yaml`). Also, it will validate the information in `annotations.yaml` to confirm that metadata is matching the provided data. For example, the provided media type in annotations.yaml just matches the actual media type is provided in the bundle image.
226+
227+
After the bundle image format is confirmed, the command will validate the bundle contents such as manifests and metadata files if the bundle format is `RegistryV1` or "Plain" type. "RegistryV1" format means it contains `ClusterResourceVersion` and its associated Kubernetes objects while `PlainType` means it contains all Kubernetes objects. The content validation process will ensure the individual file in the bundle image is valid and can be applied to an OLM-enabled cluster provided all necessary permissions and configurations are met.
228+
229+
*Notes:*
230+
* The bundle content validation is best effort which means it will not guarantee 100% accuracy due to nature of Kubernetes objects may need certain permissions and configurations, which users may not have, in order to be applied successfully in a cluster.

go.mod

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
module github.com/operator-framework/operator-registry
22

3+
go 1.13
4+
35
require (
46
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6
57
github.com/docker/distribution v2.7.1+incompatible
68
github.com/ghodss/yaml v1.0.0
79
github.com/golang-migrate/migrate/v4 v4.6.2
8-
github.com/golang/mock v1.2.0
10+
github.com/golang/mock v1.3.1
911
github.com/golang/protobuf v1.3.2
1012
github.com/grpc-ecosystem/grpc-health-probe v0.2.1-0.20181220223928-2bf0a5b182db
1113
github.com/mattn/go-sqlite3 v1.10.0
1214
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
1315
github.com/onsi/ginkgo v1.10.1
1416
github.com/onsi/gomega v1.7.0
17+
github.com/operator-framework/api v0.0.0-20200120235816-80fd2f1a09c9
18+
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20191115003340-16619cd27fa5
1519
github.com/otiai10/copy v1.0.1
16-
github.com/otiai10/curr v0.0.0-20190513014714-f5a3d24e5776 // indirect
1720
github.com/pkg/errors v0.8.1
1821
github.com/sirupsen/logrus v1.4.2
1922
github.com/spf13/cobra v0.0.5
@@ -23,14 +26,35 @@ require (
2326
google.golang.org/grpc v1.24.0
2427
gopkg.in/yaml.v2 v2.2.4
2528
helm.sh/helm/v3 v3.0.1
26-
k8s.io/api v0.0.0-20191016110408-35e52d86657a
27-
k8s.io/apiextensions-apiserver v0.0.0-20191016113550-5357c4baaf65
28-
k8s.io/apimachinery v0.0.0-20191004115801-a2eda9f80ab8
29-
k8s.io/client-go v0.0.0-20191016111102-bec269661e48
29+
k8s.io/api v0.0.0
30+
k8s.io/apiextensions-apiserver v0.0.0
31+
k8s.io/apimachinery v0.0.0
32+
k8s.io/client-go v8.0.0+incompatible
3033
k8s.io/klog v1.0.0
31-
k8s.io/kubectl v0.0.0-20191016120415-2ed914427d51
34+
k8s.io/kubectl v0.0.0
3235
)
3336

34-
replace github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
35-
36-
go 1.13
37+
replace (
38+
github.com/docker/docker => github.com/moby/moby v0.7.3-0.20190826074503-38ab9da00309 // Required by Helm
39+
k8s.io/api => k8s.io/api v0.0.0-20190918155943-95b840bb6a1f
40+
k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.0.0-20190918161926-8f644eb6e783
41+
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20190913080033-27d36303b655
42+
k8s.io/apiserver => k8s.io/apiserver v0.0.0-20191016112112-5190913f932d
43+
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20191016114015-74ad18325ed5
44+
k8s.io/client-go => k8s.io/client-go v0.0.0-20190918160344-1fbdaa4c8d90
45+
k8s.io/cloud-provider => k8s.io/cloud-provider v0.0.0-20191016115326-20453efc2458
46+
k8s.io/cluster-bootstrap => k8s.io/cluster-bootstrap v0.0.0-20191016115129-c07a134afb42
47+
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20191004115455-8e001e5d1894
48+
k8s.io/component-base => k8s.io/component-base v0.0.0-20191016111319-039242c015a9
49+
k8s.io/cri-api => k8s.io/cri-api v0.0.0-20190828162817-608eb1dad4ac
50+
k8s.io/csi-translation-lib => k8s.io/csi-translation-lib v0.0.0-20191016115521-756ffa5af0bd
51+
k8s.io/kube-aggregator => k8s.io/kube-aggregator v0.0.0-20191016112429-9587704a8ad4
52+
k8s.io/kube-controller-manager => k8s.io/kube-controller-manager v0.0.0-20191016114939-2b2b218dc1df
53+
k8s.io/kube-proxy => k8s.io/kube-proxy v0.0.0-20191016114407-2e83b6f20229
54+
k8s.io/kube-scheduler => k8s.io/kube-scheduler v0.0.0-20191016114748-65049c67a58b
55+
k8s.io/kubectl => k8s.io/kubectl v0.0.0-20191016120415-2ed914427d51
56+
k8s.io/kubelet => k8s.io/kubelet v0.0.0-20191016114556-7841ed97f1b2
57+
k8s.io/legacy-cloud-providers => k8s.io/legacy-cloud-providers v0.0.0-20191016115753-cf0698c3a16b
58+
k8s.io/metrics => k8s.io/metrics v0.0.0-20191016113814-3b1a734dba6e
59+
k8s.io/sample-apiserver => k8s.io/sample-apiserver v0.0.0-20191016112829-06bb3c9d77c9
60+
)

0 commit comments

Comments
 (0)