Skip to content

Commit

Permalink
fix(e2e): create CSV first to use in CRD ownerref
Browse files Browse the repository at this point in the history
  • Loading branch information
alecmerdler authored and njhale committed Dec 4, 2018
1 parent b384006 commit 120a530
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 37 deletions.
4 changes: 2 additions & 2 deletions cmd/olm/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
"interval", defaultWakeupInterval, "wake up interval")

watchedNamespaces = flag.String(
"watchedNamespaces", "", "comma separated list of namespaces for alm operator to watch. "+
"watchedNamespaces", "", "comma separated list of namespaces for olm operator to watch. "+
"If not set, or set to the empty string (e.g. `-watchedNamespaces=\"\"`), "+
"olm operator will watch all namespaces in the cluster.")

Expand All @@ -48,7 +48,7 @@ func init() {
metrics.Register()
}

// main function - entrypoint to ALM operator
// main function - entrypoint to OLM operator
func main() {
stopCh := signals.SetupSignalHandler()

Expand Down
54 changes: 19 additions & 35 deletions test/e2e/csv_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -596,11 +596,16 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) {
},
}

// Create dependency first (CRD)
// Create CSV first, knowing it will fail
cleanupCSV, err := createCSV(t, c, crc, csv, testNamespace, true, false)
require.NoError(t, err)
defer cleanupCSV()

fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvPendingChecker)
require.NoError(t, err)

crd := extv1beta1.CustomResourceDefinition{
ObjectMeta: metav1.ObjectMeta{
Name: crdName,
},
ObjectMeta: metav1.ObjectMeta{Name: crdName},
Spec: extv1beta1.CustomResourceDefinitionSpec{
Group: "cluster.com",
Version: "v1alpha1",
Expand All @@ -613,6 +618,12 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) {
Scope: "Namespaced",
},
}
crd.SetOwnerReferences([]metav1.OwnerReference{{
Name: fetchedCSV.GetName(),
APIVersion: v1alpha1.ClusterServiceVersionAPIVersion,
Kind: v1alpha1.ClusterServiceVersionKind,
UID: fetchedCSV.GetUID(),
}})
cleanupCRD, err := createCRD(c, crd)
require.NoError(t, err)

Expand Down Expand Up @@ -714,39 +725,12 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) {
_, err = c.CreateClusterRoleBinding(&nonResourceClusterRoleBinding)
require.NoError(t, err, "could not create ClusterRoleBinding")

cleanupCSV, err := createCSV(t, c, crc, csv, testNamespace, true, false)
require.NoError(t, err)
defer cleanupCSV()

fmt.Println("checking for deployment")
// Poll for deployment to be ready
err = wait.Poll(pollInterval, pollDuration, func() (bool, error) {
dep, err := c.GetDeployment(testNamespace, depName)
if k8serrors.IsNotFound(err) {
fmt.Printf("deployment %s not found\n", depName)
return false, nil
} else if err != nil {
fmt.Printf("unexpected error fetching deployment %s\n", depName)
return false, err
}
if dep.Status.UpdatedReplicas == *(dep.Spec.Replicas) &&
dep.Status.Replicas == *(dep.Spec.Replicas) &&
dep.Status.AvailableReplicas == *(dep.Spec.Replicas) {
fmt.Println("deployment ready")
return true, nil
}
fmt.Println("deployment not ready")
return false, nil
})
require.NoError(t, err)

fetchedCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
// Wait for CSV success
_, err = fetchCSV(t, crc, csv.Name, csvSucceededChecker)
require.NoError(t, err)

// Fetch cluster service version again to check for unnecessary control loops
sameCSV, err := fetchCSV(t, crc, csv.Name, csvSucceededChecker)
fetchedCSV, err = fetchCSV(t, crc, csv.Name, csvSucceededChecker)
require.NoError(t, err)
compareResources(t, fetchedCSV, sameCSV)

// Delete CRD
cleanupCRD()
Expand All @@ -760,7 +744,7 @@ func TestCreateCSVRequirementsMetCRD(t *testing.T) {
require.NoError(t, err)
defer cleanupCRD()

// Wait for CSV success
// Wait for CSV success again
fetchedCSV, err = fetchCSV(t, crc, csv.Name, csvSucceededChecker)
require.NoError(t, err)
}
Expand Down

0 comments on commit 120a530

Please sign in to comment.