Skip to content

Commit

Permalink
test(e2e): add test for orphaned api services
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeff Peeler committed Mar 29, 2019
1 parent efecdee commit 6250afb
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions test/e2e/csv_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/wait"
"k8s.io/apimachinery/pkg/watch"
apiregistrationv1 "k8s.io/kube-aggregator/pkg/apis/apiregistration/v1"

"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1"
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1"
Expand Down Expand Up @@ -1744,6 +1745,72 @@ func TestCreateSameCSVWithOwnedAPIServiceMultiNamespace(t *testing.T) {
require.NoError(t, err)
}

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

c := newKubeClient(t)

mockGroup := fmt.Sprintf("hats.%s.redhat.com", genName(""))
version := "v1alpha1"
apiServiceName := strings.Join([]string{version, mockGroup}, ".")

apiService := &apiregistrationv1.APIService{
ObjectMeta: metav1.ObjectMeta{
Name: apiServiceName,
},
Spec: apiregistrationv1.APIServiceSpec{
Group: mockGroup,
Version: version,
GroupPriorityMinimum: 100,
VersionPriority: 100,
},
}

_, err := c.CreateAPIService(apiService)
require.NoError(t, err, "error creating expected APIService")
orphanedAPISvc, err := c.GetAPIService(apiServiceName)
require.NoError(t, err, "error getting expected APIService")

newLabels := map[string]string{"olm.owner": "hat-serverfd4r5", "olm.owner.kind": "ClusterServiceVersion", "olm.owner.namespace": "nonexistent-namespace"}
orphanedAPISvc.SetLabels(newLabels)
_, err = c.UpdateAPIService(orphanedAPISvc)
require.NoError(t, err, "error updating APIService")

watcher, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().Watch(metav1.ListOptions{FieldSelector: "metadata.name=" + apiServiceName})
require.NoError(t, err)

deleted := make(chan struct{})
quit := make(chan struct{})
defer close(quit)
go func() {
events := watcher.ResultChan()
for {
select {
case <-quit:
return
case evt := <-events:
if evt.Type == watch.Deleted {
deleted <- struct{}{}
}
case <-time.After(pollDuration):
require.FailNow(t, "orphaned apiservice not cleaned up as expected")
}
}
}()
<-deleted

_, err = c.CreateAPIService(apiService)
require.NoError(t, err, "error creating expected APIService")
orphanedAPISvc, err = c.GetAPIService(apiServiceName)
require.NoError(t, err, "error getting expected APIService")

newLabels = map[string]string{"olm.owner": "hat-serverfd4r5", "olm.owner.kind": "ClusterServiceVersion", "olm.owner.namespace": testNamespace}
orphanedAPISvc.SetLabels(newLabels)
_, err = c.UpdateAPIService(orphanedAPISvc)
require.NoError(t, err, "error updating APIService")
<-deleted
}

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

Expand Down

0 comments on commit 6250afb

Please sign in to comment.