Skip to content

Commit

Permalink
Added comments;Added README
Browse files Browse the repository at this point in the history
Signed-off-by: jubittajohn <jujohn@redhat.com>
  • Loading branch information
jubittajohn committed Jul 27, 2023
1 parent dbb8fcc commit f9cc878
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 9 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
10 changes: 8 additions & 2 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 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
3 changes: 2 additions & 1 deletion test/operator-e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (
err error
ctx context.Context
bundleInfo = []BundleInfo{
{
{ // The bundle directories of the plain bundles whose image is to be created and pushed along with the image reference
BundleImageRef: "localhost/testdata/bundles/plain-v0/plain:v0.1.0",
BundleDirectory: "plain.v0.1.0",
},
Expand Down Expand Up @@ -102,6 +102,7 @@ var _ = BeforeSuite(func() {

var _ = AfterSuite(func() {
Eventually(func(g Gomega) {
// Deleting the catalog object and checking if the deletion was successful
err = deleteAndCheckCatalogDeleted(operatorCatalog)
g.Expect(errors.IsNotFound(err)).To(BeTrue())
}).Should(Succeed())
Expand Down
4 changes: 2 additions & 2 deletions test/operator-e2e/read_manifests.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ type Object struct {
} `yaml:"metadata"`
}

// collects the Kubernetes objects present in the bundle manifest folder
func collectKubernetesObjects(packageName string, version string) ([]Object, error) {
// collects the Kubernetes objects present in the bundle manifest folder for a particular package and its version
func collectKubernetesObjects(packageName, version string) ([]Object, error) {
objects := []Object{}

bundleManifestPath := filepath.Join(bundlePath, packageName+".v"+version, "manifests")
Expand Down

0 comments on commit f9cc878

Please sign in to comment.