Skip to content

Commit

Permalink
Added error messages for each failed assertion; Added comments and RE…
Browse files Browse the repository at this point in the history
…ADME

Signed-off-by: jubittajohn <jujohn@redhat.com>
  • Loading branch information
jubittajohn committed Jul 27, 2023
1 parent cab885b commit 4e15888
Show file tree
Hide file tree
Showing 7 changed files with 262 additions and 106 deletions.
53 changes: 53 additions & 0 deletions test/operator-e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# 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.

## 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

- 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.v0.1.0/
│ ├── manifests
│ └── Dockerfile
└── plain.v0.1.1/
├── manifests
└── Dockerfile
```
- The bundles should present in the testdata folder.
- The bundle paths and bundle image reference is hard coded in the test.

- After the bundle image is created and loaded, the FBC is created by accepting the required information in a config file named `catalog_config.yaml` in the directory `test/operator-e2e/config`.

- Example `catalog_config.yaml` file:
```
schema: catalog-config
packageName: plain
channelData:
- channelName: foo
channelEntries:
- entryVersion: 0.1.0
replaces: null
skipRange: null
skips:
- null
bundleData:
- bundleImage: foobar:v0.1.0
bundleVersion: 0.1.0
```
- The generated FBC will be present in the directory structure: `testdata/catalogs/plainv0-test-catalog`.
- The Dockerfile is generated and the FBC image is built and loaded.
- The output catalog path, catalog name, catalog image reference are hard-coded in the test.
- The FBC generated is validated using opm.

- The FBC image is then used to create an operator.
- Based on the catalog data, we hard code the package names and their version that is to be installed and upgraded.
6 changes: 3 additions & 3 deletions test/operator-e2e/config/catalog_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ channelData:
- entryVersion: 0.1.0
replaces: null
skips:
- 0.1.1
- null
skipRange: null
- entryVersion: 0.1.1
replaces: 0.1.0
replaces: null
skips:
- null
- 0.1.0
skipRange: null
- channelName: foo
channelEntries:
Expand Down
1 change: 1 addition & 0 deletions test/operator-e2e/config/read_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Config struct {
BundleData []BundleData `json:"bundleData"`
}

// Reads the catalog-config.yaml and maps it to the above structs
func ReadFile(f string) (*Config, error) {
b, err := readFile(f)
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions test/operator-e2e/create_fbc.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const (
BundleMediatype = "plain+v0"
)

// Reads the catalog-config and creates the FBC by calling functions for forming the package, channel and bundles.
func CreateFBC(configFilePath string) (*declcfg.DeclarativeConfig, error) {
config, err := config.ReadFile(configFilePath)
if err != nil {
Expand All @@ -38,6 +39,7 @@ func CreateFBC(configFilePath string) (*declcfg.DeclarativeConfig, error) {
return &fbc, nil
}

// Forms package schema for the FBC
func formPackage(config config.Config) declcfg.Package {
packageFormed := declcfg.Package{
Schema: SchemaPackage,
Expand All @@ -47,6 +49,7 @@ func formPackage(config config.Config) declcfg.Package {
return packageFormed
}

// Forms channel schema for the FBC
func formChannel(config config.Config) []declcfg.Channel {
channelFormed := make([]declcfg.Channel, 0, len(config.ChannelData))
for _, channel := range config.ChannelData {
Expand All @@ -61,6 +64,7 @@ func formChannel(config config.Config) []declcfg.Channel {
return channelFormed
}

// Forms the uprade graph for the FBC
func formChannelEntries(pkgName string, channel config.ChannelData) []declcfg.ChannelEntry {
channelEntries := make([]declcfg.ChannelEntry, 0, len(channel.ChannelEntries))
for _, channelEntry := range channel.ChannelEntries {
Expand All @@ -73,7 +77,7 @@ func formChannelEntries(pkgName string, channel config.ChannelData) []declcfg.Ch
if len(channelEntry.Skips) != 0 {
for _, s := range channelEntry.Skips {
if s != "" {
skip = append(skip, s)
skip = append(skip, pkgName+"."+s)
}
}
}
Expand All @@ -87,6 +91,7 @@ func formChannelEntries(pkgName string, channel config.ChannelData) []declcfg.Ch
return channelEntries
}

// Forms bundle schema for the FBC
func formBundle(config config.Config) []declcfg.Bundle {
bundleFormed := make([]declcfg.Bundle, 0, len(config.BundleData))
for _, bundle := range config.BundleData {
Expand All @@ -111,7 +116,8 @@ func formBundle(config config.Config) []declcfg.Bundle {
return bundleFormed
}

func WriteFBC(fbc declcfg.DeclarativeConfig, fbcFilePath string, fbcFileName string) error {
// Writes the formed FBC into catalog.yaml file
func WriteFBC(fbc declcfg.DeclarativeConfig, fbcFilePath, fbcFileName string) error {
var buf bytes.Buffer
err := declcfg.WriteYAML(fbc, &buf)
if err != nil {
Expand All @@ -122,13 +128,11 @@ func WriteFBC(fbc declcfg.DeclarativeConfig, fbcFilePath string, fbcFileName str
if os.IsNotExist(err) {
err := os.MkdirAll(fbcFilePath, 0755)
if err != nil {
fmt.Printf("Failed to create directory: %v\n", err)
return err
}
}
file, err := os.Create(fbcFilePath + "/" + fbcFileName)
if err != nil {
fmt.Printf("Failed to create file: %v\n", err)
return err
}
defer file.Close()
Expand Down
3 changes: 2 additions & 1 deletion test/operator-e2e/generate_dockerfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (
"text/template"
)

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

0 comments on commit 4e15888

Please sign in to comment.