Skip to content

Commit d5d8b2c

Browse files
Merge pull request #22771 from bparees/leader
switch leader election lock for ocm to openshift-controller-manager
2 parents 21f1917 + f3be6c4 commit d5d8b2c

4 files changed

Lines changed: 41 additions & 9 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
apiVersion: v1
3+
kind: Namespace
4+
metadata:
5+
name: openshift-controller-manager
6+
spec:
7+
finalizers:
8+
- kubernetes

pkg/cmd/openshift-controller-manager/controller_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func RunOpenShiftControllerManager(config *openshiftcontrolplanev1.OpenShiftCont
8383
}
8484
rl, err := resourcelock.New(
8585
"configmaps",
86-
"kube-system",
86+
"openshift-controller-manager",
8787
"openshift-master-controllers", // this matches what ansible used to set
8888
kubeClient.CoreV1(),
8989
resourcelock.ResourceLockConfig{

test/integration/project_test.go

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,13 @@ func TestProjectWatchWithSelectionPredicate(t *testing.T) {
210210
t.Fatalf("unexpected error: %v", err)
211211
}
212212
// we are only watching ns-01, we should not receive events for other projects
213-
waitForNoEvent(w, t)
213+
waitForNoEvent(w, "ns-01", t)
214214

215215
if err := bobProjectClient.Projects().Delete("ns-03", nil); err != nil {
216216
t.Fatalf("unexpected error: %v", err)
217217
}
218218
// we are only watching ns-01, we should not receive events for other projects
219-
waitForNoEvent(w, t)
219+
waitForNoEvent(w, "ns-01", t)
220220

221221
// test the "start from beginning watch"
222222
beginningWatch, err := bobProjectClient.Projects().Watch(metav1.ListOptions{
@@ -236,14 +236,30 @@ func TestProjectWatchWithSelectionPredicate(t *testing.T) {
236236
t.Fatalf("unexpected error: %v", err)
237237
}
238238
// since we are only watching for events from "ns-01", and no projects are being modified, we should not receive any events here
239-
waitForNoEvent(fromNowWatch, t)
239+
waitForNoEvent(fromNowWatch, "ns-01", t)
240240
}
241241

242-
func waitForNoEvent(w watch.Interface, t *testing.T) {
243-
select {
244-
case event := <-w.ResultChan():
245-
t.Fatalf("unexpected event %v with object %#v", event, event.Object)
246-
case <-time.After(3 * time.Second):
242+
// waitForNoEvent ensures no stray events come in. skipProject allows modify events only for the named project
243+
func waitForNoEvent(w watch.Interface, skipProject string, t *testing.T) {
244+
for {
245+
select {
246+
case event := <-w.ResultChan():
247+
if event.Type != watch.Modified {
248+
t.Fatalf("unexpected event %v with object %#v", event, event.Object)
249+
}
250+
project, ok := event.Object.(*projectapi.Project)
251+
if !ok {
252+
t.Fatalf("unexpected event %v with object %#v", event, event.Object)
253+
}
254+
t.Logf("got %#v %#v", event, project)
255+
if project.Name != skipProject {
256+
t.Fatalf("unexpected event %v with object %#v", event, event.Object)
257+
}
258+
259+
continue
260+
case <-time.After(3 * time.Second):
261+
return
262+
}
247263
}
248264
}
249265

@@ -277,6 +293,7 @@ func waitForAdd(projectName string, w watch.Interface, t *testing.T) {
277293
}
278294
}
279295
}
296+
280297
func waitForOnlyAdd(projectName string, w watch.Interface, t *testing.T) {
281298
for {
282299
select {

test/util/server/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ func StartConfiguredMasterWithOptions(masterConfig *configapi.MasterConfig, stop
379379
return "", fmt.Errorf("Waiting for roles failed with: %v", err)
380380
}
381381

382+
// the openshift controller manager creates its lease object in this
383+
// namespace, so we have to ensure it exists.
384+
kubeClient, err := kubernetes.NewForConfig(clientConfig)
385+
ns := &corev1.Namespace{}
386+
ns.Name = "openshift-controller-manager"
387+
kubeClient.CoreV1().Namespaces().Create(ns)
388+
382389
return adminKubeConfigFile, nil
383390
}
384391

0 commit comments

Comments
 (0)