Skip to content

Commit

Permalink
test(catalog): add e2e test to verify configmap changes are detected
Browse files Browse the repository at this point in the history
and recorded on the catalogsource object
  • Loading branch information
ecordell committed Jan 15, 2019
1 parent 63aa1e1 commit 32103ac
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 10 deletions.
2 changes: 1 addition & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ k8s.io/apimachinery v0.0.0-20181203235515-3d8ee2261517/go.mod h1:ccL7Eh7zubPUSh9
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170 h1:CqI85nZvPaV+7JFono0nAOGOx2brocqefcOhDPVhHKI=
k8s.io/apiserver v0.0.0-20181026151315-13cfe3978170/go.mod h1:6bqaTSOSJavUIXUtfaR9Os9JtTCm8ZqH2SUl2S60C4w=
k8s.io/client-go v0.0.0-20180718001006-59698c7d9724/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/client-go v8.0.0+incompatible h1:tTI4hRmb1DRMl4fG6Vclfdi6nTM82oIrTT7HfitmxC4=
k8s.io/client-go v8.0.0+incompatible h1:2pUaSg2x6iEHr8cia6zmWhoCXG1EDG9TCx9s//Aq7HY=
k8s.io/client-go v8.0.0+incompatible/go.mod h1:7vJpHMYJwNQCWgzmNV+VYUl1zCObLyodBc8nIyt8L5s=
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3 h1:f/Aa24HPnPEDWia884BCF94E1b29KYjOTVTHcBzvT2Q=
k8s.io/code-generator v0.0.0-20181203235156-f8cba74510f3/go.mod h1:MYiN+ZJZ9HkETbgVZdWw2AsuAi9PZ4V80cwfuf2axe8=
Expand Down
94 changes: 94 additions & 0 deletions test/e2e/catalog_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ package e2e

import (
"fmt"
"strings"
"testing"

"github.com/coreos/go-semver/semver"
"github.com/ghodss/yaml"
"github.com/stretchr/testify/require"
appsv1 "k8s.io/api/apps/v1"
"k8s.io/apiextensions-apiserver/pkg/apis/apiextensions"
Expand Down Expand Up @@ -97,6 +99,98 @@ func TestDefaultCatalogLoading(t *testing.T) {
}
}

func TestConfigMapUpdateTriggersRegistryPodRollout(t *testing.T) {
defer cleaner.NotifyTestComplete(t, true)

mainPackageName := genName("nginx-")
dependentPackageName := genName("nginxdep-")

mainPackageStable := fmt.Sprintf("%s-stable", mainPackageName)
dependentPackageStable := fmt.Sprintf("%s-stable", dependentPackageName)

stableChannel := "stable"

mainNamedStrategy := newNginxInstallStrategy(genName("dep-"), nil, nil)
dependentNamedStrategy := newNginxInstallStrategy(genName("dep-"), nil, nil)

crdPlural := genName("ins-")

dependentCRD := newCRD(crdPlural)
mainCSV := newCSV(mainPackageStable, testNamespace, "", *semver.New("0.1.0"), nil, []apiextensions.CustomResourceDefinition{dependentCRD}, mainNamedStrategy)
dependentCSV := newCSV(dependentPackageStable, testNamespace, "", *semver.New("0.1.0"), []apiextensions.CustomResourceDefinition{dependentCRD}, nil, dependentNamedStrategy)

c := newKubeClient(t)
crc := newCRClient(t)
defer func() {
require.NoError(t, crc.OperatorsV1alpha1().Subscriptions(testNamespace).DeleteCollection(&metav1.DeleteOptions{}, metav1.ListOptions{}))
}()

mainCatalogName := genName("mock-ocs-main-")

// Create separate manifests for each CatalogSource
mainManifests := []registry.PackageManifest{
{
PackageName: mainPackageName,
Channels: []registry.PackageChannel{
{Name: stableChannel, CurrentCSVName: mainPackageStable},
},
DefaultChannelName: stableChannel,
},
}

dependentManifests := []registry.PackageManifest{
{
PackageName: dependentPackageName,
Channels: []registry.PackageChannel{
{Name: stableChannel, CurrentCSVName: dependentPackageStable},
},
DefaultChannelName: stableChannel,
},
}

// Create the initial catalogsource
_, cleanupMainCatalogSource := createInternalCatalogSource(t, c, crc, mainCatalogName, testNamespace, mainManifests, nil, []v1alpha1.ClusterServiceVersion{mainCSV})
defer cleanupMainCatalogSource()

// Attempt to get the catalog source before creating install plan
fetchedInitialCatalog, err := fetchCatalogSource(t, crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
require.NoError(t, err)

// Get initial configmap
configMap, err := c.KubernetesInterface().CoreV1().ConfigMaps(testNamespace).Get(fetchedInitialCatalog.Spec.ConfigMap, metav1.GetOptions{})
require.NoError(t, err)

// Update raw manifests
manifestsRaw, err := yaml.Marshal(append(mainManifests, dependentManifests...))
require.NoError(t, err)
configMap.Data[registry.ConfigMapPackageName] = string(manifestsRaw)

// Update raw CRDs
var crdsRaw []byte
crdStrings := []string{}
for _, crd := range []apiextensions.CustomResourceDefinition{dependentCRD} {
crdStrings = append(crdStrings, serializeCRD(t, crd))
}
crdsRaw, err = yaml.Marshal(crdStrings)
require.NoError(t, err)
configMap.Data[registry.ConfigMapCRDName] = strings.Replace(string(crdsRaw), "- |\n ", "- ", -1)

// Update raw CSVs
csvsRaw, err := yaml.Marshal([]v1alpha1.ClusterServiceVersion{mainCSV, dependentCSV})
require.NoError(t, err)
configMap.Data[registry.ConfigMapCSVName] = string(csvsRaw)

// Update configmap
updatedConfigMap, err := c.KubernetesInterface().CoreV1().ConfigMaps(testNamespace).Update(configMap)
require.NoError(t, err)

fetchedUpdatedCatalog, err := fetchCatalogSource(t, crc, mainCatalogName, testNamespace, catalogSourceRegistryPodSynced)
require.NoError(t, err)

require.NotEqual(t, fetchedUpdatedCatalog.Status.ConfigMapResource.ResourceVersion, fetchedInitialCatalog.Status.ConfigMapResource.ResourceVersion)
require.Equal(t, updatedConfigMap.GetResourceVersion(), fetchedUpdatedCatalog.Status.ConfigMapResource.ResourceVersion)
}

func getOperatorDeployment(c operatorclient.ClientInterface, namespace string, operatorLabels labels.Set) (*appsv1.Deployment, error) {
deployments, err := c.ListDeploymentsWithLabels(namespace, operatorLabels)
if err != nil || deployments == nil || len(deployments.Items) != 1 {
Expand Down
10 changes: 3 additions & 7 deletions test/e2e/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,9 @@ const (
pollInterval = 1 * time.Second
pollDuration = 2 * time.Minute

etcdVersion = "3.2.13"
prometheusVersion = "v2.3.2"
expectedEtcdNodes = 1
expectedPrometheusSize = 1
ocsConfigMap = "rh-operators"
olmConfigMap = "olm-operators"
packageServerCSV = "packageserver.v1.0.0"
ocsConfigMap = "rh-operators"
olmConfigMap = "olm-operators"
packageServerCSV = "packageserver.v1.0.0"
)

var (
Expand Down
4 changes: 2 additions & 2 deletions vendor/k8s.io/client-go/pkg/version/base.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 32103ac

Please sign in to comment.