Skip to content

Commit

Permalink
Refractored the plain bundle and registry bundle intercations; Update…
Browse files Browse the repository at this point in the history
…d the comments, README; Renamed the files

Signed-off-by: jubittajohn <jujohn@redhat.com>
  • Loading branch information
jubittajohn committed Jul 26, 2023
1 parent 2dbce7b commit 0ae996e
Show file tree
Hide file tree
Showing 9 changed files with 767 additions and 329 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ test-e2e: $(GINKGO) ## Run the e2e tests
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress $(FOCUS) test/e2e

test-operator-developer-e2e: $(GINKGO) ## Run operator create, upgrade and delete tests
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress test/operator-e2e
$(GINKGO) --tags $(GO_BUILD_TAGS) $(E2E_FLAGS) -trace -progress test/operator-framework-e2e

ENVTEST_VERSION = $(shell go list -m k8s.io/client-go | cut -d" " -f2 | sed 's/^v0\.\([[:digit:]]\{1,\}\)\.[[:digit:]]\{1,\}$$/1.\1.x/')
UNIT_TEST_DIRS=$(shell go list ./... | grep -v /test/)
Expand Down
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ require (
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.7.0 // indirect
github.com/h2non/filetype v1.1.1 // indirect
github.com/h2non/go-is-svg v0.0.0-20160927212452-35e8c4b0612c // indirect
github.com/imdario/mergo v0.3.13 // indirect
Expand All @@ -91,7 +93,10 @@ require (
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/operator-framework/api v0.17.3 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc2 // indirect
github.com/operator-framework/api v0.17.4-0.20230223191600-0131a6301e42 // indirect
github.com/otiai10/copy v1.2.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.14.0 // indirect
Expand Down
255 changes: 245 additions & 10 deletions go.sum

Large diffs are not rendered by default.

53 changes: 0 additions & 53 deletions test/operator-e2e/README.md

This file was deleted.

113 changes: 113 additions & 0 deletions test/operator-framework-e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Cross-component E2E for operator framework

This is a cross-component demo with all OLM v1 repositories. The ginkgo test does the following:
- Automates the creation of `plain+v0` bundles and FBCs for a set of bundle manifest directories.
- Creates, upgrades and deletes a `plain+v0` operator.
- Uses operator-sdk to build `registry+v1` bundles and create catalogs to include the bundles.
- Creates, upgrades and deletes a `registry+v1` operator.

## Objective
- Development on OLM v1 is split across multiple repositories, and the list of relevant repositories may grow over time. While we have demos showing improvements in functionality of components over time, it can be difficult to have a picture of the state of OLM v1 at any given time for someone not following its development closely. Having a single source to look for OLM v1 behavior can provide more clarity about the state of the project.
- With the scale of the OLM v1 project, it is useful to have a means to test components in the operator development + lifecycle pipeline together to create a more cohesive experience for all users.

## Getting Started

- The following structs defined are required as input for both plain+v0 and registry+v1 bundles:
- For getting bundle related inputs:
```
type BundleInfo struct {
baseFolderPath string
bundles []BundleContent
}

type BundleContent struct {
bInputDir string
bundleVersion string
imageRef string
}
```
- `baseFolderPath` - Base path of the folder for the specific bundle type input data.
- `bundles` - Stores the data relevant to different versions of the bundle.
- `bInputDir` - The input directory containing the specific version of the bundle data.
- `bundleVersion` - The specific version of the bundle data.
- `imageRef` - This is formed. Stores the bundle image reference which will be of the format `docker.io/<username>/<operator_name>:v.<bundleVersion>`
- For getting catalog related inputs:
```
type CatalogDInfo struct {
baseFolderPath string
catalogDir string
operatorName string
desiredChannelName string
imageRef string
fbcFileName string
}
```
- `baseFolderPath` - Base path of the folder for the catalogs.
- `operatorName` - Name of the operator to be installed from the bundles.
- `desiredChannelName` - Desired channel name for the operator.
- `catalogDir` - This is formed. The directory to store the FBC. The formed value will be of the format: `<operator-name>-catalog`
- `imageRef` - This is formed. Stores the FBC image reference which will be of the format: `docker.io/<username>/<catalogDir>:test`
- `fbcFileName` - Name of the FBC file. This is hard-coded as `catalog.yaml`.
- For getting information related to the install/upgrade action for operators:
```
type OperatorActionInfo struct {
installVersion string
upgradeVersion string
}
```
- `installVersion` - Version of the operator to be installed on the cluster.
- `upgradeVersion` - Version of the operator to be upgraded on the cluster.

### Plain bundles
- Plain bundle manifests are taken as input.

- The plain bundle manifest directory taken as input should follow the below directory structure:
```
bundles/
└── plain-v0/
├── plain.v<version>/
│ ├── manifests
│ └── Dockerfile
└── plain.v<version>/
├── manifests
└── Dockerfile
```
- The bundles should be present in the testdata folder.

- After the bundle image is created and loaded, the FBC is formed by a custom routine by using the operatorName, desiredChannelName, bundle imageRefs and bundleVersions.

- The generated FBC will be present in the file path: `testdata/catalogs/<operatorName>-catalog/catalog.yaml` and the Dockerfile will be formed in the file path: `testdata/catalogs/<operatorName>-catalog.Dockerfile`
- `Default channel` is not used in forming the FBC as it is not an OLMv1 concept.
- The package schema name will be the operatorName and the bundle name will be `<operatorName>.v<version>`.

- The catalog resource is then formed with the name `<operatorName>-catalog`.

- The operator is then installed and has the name `<operatorName>`.

### Registry Bundles

- The registry+v1 bundles are formed using operator-sdk.
- The below input is used to form the bundle using operator-sdk.
```
type SdkProjectInfo struct {
projectName string
domainName string
group string
version string
kind string
}
```
- The generated CSV uses the default values.
- The bundle content is formed in the operator-sdk project directory in the folder `bundle`. This is moved to the folder path: `testdata/bundles/registry-v1/<operatorName>.v<version>`.
- The generated Dockerfile has the name `bundle.Dockerfile`.
- After the bundle image is created and loaded, the FBC is formed using `semver` and `opm` tool.
- The semver named `registry-semver.yaml` is formed by passing the bundle imageRefs.
- The generated FBC will be present in the file path: `testdata/catalogs/<operatorName>-catalog/catalog.yaml` and the Dockerfile will be formed in the file path: `testdata/catalogs/<operatorName>-catalog.Dockerfile`
- The package schema name will be the operator-sdk projectName.

- The catalog resource is then formed with the name `<operatorName>-catalog`.

- The operator is then installed and has the name `<operatorName>`.


- After the e2e workflow, all the files formed are cleared and the catalog is deleted.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"

"github.com/operator-framework/operator-registry/alpha/declcfg"
"github.com/operator-framework/operator-registry/alpha/property"
Expand All @@ -18,12 +19,9 @@ const (
BundleMediatype = "plain+v0"
)

// reuires bundle info
// operatorname
// defaultchannel
// Reads the catalog-config and creates the FBC by calling functions for forming the package, channel and bundles.
// Forms the FBC declartive config and creates the FBC by calling functions for forming the package, channel and bundles.
func CreateFBC(operatorName, defaultChannel string, bundleRef, bundleVersions []string) *declcfg.DeclarativeConfig {
dPackage := formPackage(operatorName, defaultChannel)
dPackage := formPackage(operatorName)
dChannel := formChannel(operatorName, defaultChannel, bundleVersions)
dBundle := formBundle(operatorName, bundleVersions, bundleRef)

Expand All @@ -36,11 +34,10 @@ func CreateFBC(operatorName, defaultChannel string, bundleRef, bundleVersions []
}

// Forms package schema for the FBC
func formPackage(pkgName, defaultChannelName string) declcfg.Package {
func formPackage(pkgName string) declcfg.Package {
packageFormed := declcfg.Package{
Schema: SchemaPackage,
Name: pkgName,
DefaultChannel: defaultChannelName,
Schema: SchemaPackage,
Name: pkgName,
}
return packageFormed
}
Expand All @@ -63,11 +60,11 @@ func formChannelEntries(pkgName string, bundleVersions []string) []declcfg.Chann
for i, version := range bundleVersions {
replace := ""
if i != 0 {
replace = pkgName + "." + bundleVersions[i-1]
replace = pkgName + ".v" + bundleVersions[i-1]
}

channelEntries = append(channelEntries, declcfg.ChannelEntry{
Name: pkgName + "." + version,
Name: pkgName + ".v" + version,
Replaces: replace,
})
}
Expand All @@ -90,7 +87,7 @@ func formBundle(pkgName string, versions, imageRefs []string) []declcfg.Bundle {

bundleFormed = append(bundleFormed, declcfg.Bundle{
Schema: SchemaBundle,
Name: pkgName + "." + versions[i],
Name: pkgName + ".v" + versions[i],
Package: pkgName,
Image: imageRefs[i],
Properties: properties,
Expand Down Expand Up @@ -127,3 +124,32 @@ func WriteFBC(fbc declcfg.DeclarativeConfig, fbcFilePath, fbcFileName string) er

return nil
}

// Generates the semver using the bundle images passed
func generateOLMSemverFile(semverFileName string, bundleImages []string) error {
images := make([]string, 0, len(bundleImages))
for _, bundleImage := range bundleImages {
images = append(images, fmt.Sprintf(" - image: %s", bundleImage))
}

fileContent := fmt.Sprintf(`schema: olm.semver
generatemajorchannels: false
generateminorchannels: false
stable:
bundles:
%s
`, strings.Join(images, "\n"))

file, err := os.Create(semverFileName)
if err != nil {
return fmt.Errorf("error creating the semver yaml file %v : %v", semverFileName, err)
}
defer file.Close()

_, err = file.WriteString(fileContent)
if err != nil {
return fmt.Errorf("error forming the semver yaml file %v : %v", semverFileName, err)
}

return nil
}
36 changes: 36 additions & 0 deletions test/operator-framework-e2e/generate_dockerfile.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package operatore2e

import (
"os"
"path/filepath"
"text/template"
)

// generates Dockerfile and its contents for a given set of yaml files
func generateDockerFile(dockerFilePath, yamlFolderName, dockerFileName string) error {
t, err := template.New("dockerfile").Parse(dockerfileTmpl)
if err != nil {
panic(err)
}

dockerFilePath = filepath.Join(dockerFilePath, dockerFileName)
file, err := os.Create(dockerFilePath)
if err != nil {
return err
}
defer file.Close()

_, err = file.WriteString("FROM scratch\n")
if err != nil {
return err
}
err = t.Execute(file, struct{ YamlDir string }{yamlFolderName})
if err != nil {
return err
}

return nil
}

const dockerfileTmpl = `ADD {{.YamlDir}} /configs/{{.YamlDir}}
`
Loading

0 comments on commit 0ae996e

Please sign in to comment.