-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(olm): add deletion monitoring for api services #750
Merged
openshift-merge-robot
merged 3 commits into
operator-framework:master
from
jpeeler:apiservice-sync
May 21, 2019
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ import ( | |
"fmt" | ||
"strings" | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
appsv1 "k8s.io/api/apps/v1" | ||
|
@@ -17,8 +18,10 @@ import ( | |
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"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" | ||
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" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/api/client/clientset/versioned" | ||
"github.com/operator-framework/operator-lifecycle-manager/pkg/controller/install" | ||
|
@@ -1217,9 +1220,31 @@ func TestCreateCSVWithOwnedAPIService(t *testing.T) { | |
csv.SetName(depName) | ||
|
||
// Create the APIService CSV | ||
cleanupCSV, err := createCSV(t, c, crc, csv, testNamespace, false, true) | ||
cleanupCSV, err := createCSV(t, c, crc, csv, testNamespace, false, false) | ||
require.NoError(t, err) | ||
defer cleanupCSV() | ||
defer func() { | ||
watcher, err := c.ApiregistrationV1Interface().ApiregistrationV1().APIServices().Watch(metav1.ListOptions{FieldSelector: "metadata.name=" + apiServiceName}) | ||
require.NoError(t, err) | ||
|
||
deleted := make(chan struct{}) | ||
go func() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
events := watcher.ResultChan() | ||
for { | ||
select { | ||
case evt := <-events: | ||
if evt.Type == watch.Deleted { | ||
deleted <- struct{}{} | ||
return | ||
} | ||
case <-time.After(pollDuration): | ||
require.FailNow(t, "apiservice not cleaned up after CSV deleted") | ||
} | ||
} | ||
}() | ||
|
||
cleanupCSV() | ||
<-deleted | ||
}() | ||
|
||
fetchedCSV, err := fetchCSV(t, crc, csv.Name, testNamespace, csvSucceededChecker) | ||
require.NoError(t, err) | ||
|
@@ -1720,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, | ||
}, | ||
} | ||
|
||
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") | ||
} | ||
} | ||
}() | ||
|
||
_, 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") | ||
<-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) | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also generate some rolebindings in kube-system for APIServices that we should clean up
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still need to do this. But I admit I'm less concerned about it since I've never seen any stray RBAC cause package server install issues.