-
Notifications
You must be signed in to change notification settings - Fork 273
OCPBUGS-100060: staticpod: add installer precondition hook #2387
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
Open
mkowalski
wants to merge
2
commits into
openshift:master
Choose a base branch
from
mkowalski:ocpbugs-100060-installer-precondition
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+191
−0
Open
Changes from 1 commit
Commits
Show all changes
2 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -2769,3 +2769,97 @@ func TestWaitToObserveWrites(t *testing.T) { | |
| t.Fatalf("expected %d status apply, got %d", want, nApplies) | ||
| } | ||
| } | ||
|
|
||
| func TestCreateInstallerPodPrecondition(t *testing.T) { | ||
| newController := func(precondition InstallerPreconditionFunc) (*InstallerController, *events.Recorder, func() *corev1.Pod) { | ||
| kubeClient := fake.NewSimpleClientset( | ||
| &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: "test-config"}}, | ||
| &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: "test-secret"}}, | ||
| &corev1.Secret{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: fmt.Sprintf("%s-%d", "test-secret", 1)}}, | ||
| &corev1.ConfigMap{ObjectMeta: metav1.ObjectMeta{Namespace: "test", Name: fmt.Sprintf("%s-%d", "test-config", 1)}}, | ||
| ) | ||
| var installerPod *corev1.Pod | ||
| kubeClient.PrependReactor("create", "pods", func(action ktesting.Action) (handled bool, ret runtime.Object, err error) { | ||
| installerPod = action.(ktesting.CreateAction).GetObject().(*corev1.Pod) | ||
| return false, nil, nil | ||
| }) | ||
| kubeInformers := informers.NewSharedInformerFactoryWithOptions(kubeClient, 1*time.Minute, informers.WithNamespace("test")) | ||
| fakeStaticPodOperatorClient := v1helpers.NewFakeStaticPodOperatorClient( | ||
| &operatorv1.StaticPodOperatorSpec{OperatorSpec: operatorv1.OperatorSpec{ManagementState: operatorv1.Managed}}, | ||
| &operatorv1.StaticPodOperatorStatus{ | ||
| OperatorStatus: operatorv1.OperatorStatus{LatestAvailableRevision: 1}, | ||
| NodeStatuses: []operatorv1.NodeStatus{{NodeName: "test-node-1"}}, | ||
| }, | ||
| nil, nil, | ||
| ) | ||
| eventRecorder := events.NewRecorder(kubeClient.CoreV1().Events("test"), "test-operator", &corev1.ObjectReference{}, clocktesting.NewFakePassiveClock(time.Now())) | ||
| c := NewInstallerController( | ||
| "unit-test", "test", "test-pod", | ||
| []revision.RevisionResource{{Name: "test-config"}}, | ||
| []revision.RevisionResource{{Name: "test-secret"}}, | ||
| []string{"/bin/true"}, | ||
| kubeInformers, | ||
| fakeStaticPodOperatorClient, | ||
| kubeClient.CoreV1(), | ||
| kubeClient.CoreV1(), | ||
| kubeClient.CoreV1(), | ||
| eventRecorder, | ||
| ).WithInstallerPrecondition(precondition) | ||
| c.ownerRefsFn = func(ctx context.Context, revision int32) ([]metav1.OwnerReference, error) { | ||
| return []metav1.OwnerReference{}, nil | ||
| } | ||
| c.installerPodImageFn = func() string { return "docker.io/foo/bar" } | ||
| return c, &eventRecorder, func() *corev1.Pod { return installerPod } | ||
| } | ||
|
|
||
| t.Run("unmet precondition delays installer pod", func(t *testing.T) { | ||
| checkedNode := "" | ||
| c, eventRecorder, getPod := newController(func(ctx context.Context, nodeName string) (bool, string, error) { | ||
| checkedNode = nodeName | ||
| return false, "another master is rebooting", nil | ||
| }) | ||
| for i := 0; i < 3; i++ { | ||
| if err := c.Sync(context.TODO(), factory.NewSyncContext("InstallerController", *eventRecorder)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| if getPod() != nil { | ||
| t.Fatalf("expected no installer pod while the precondition is unmet") | ||
| } | ||
| if checkedNode != "test-node-1" { | ||
| t.Fatalf("expected precondition to be consulted for test-node-1, got %q", checkedNode) | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
Outdated
|
||
| }) | ||
|
|
||
| t.Run("met precondition allows installer pod", func(t *testing.T) { | ||
| c, eventRecorder, getPod := newController(func(ctx context.Context, nodeName string) (bool, string, error) { | ||
| return true, "", nil | ||
| }) | ||
| for i := 0; i < 3; i++ { | ||
|
Contributor
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.
The same goes for the next test. |
||
| if err := c.Sync(context.TODO(), factory.NewSyncContext("InstallerController", *eventRecorder)); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| } | ||
| if getPod() == nil { | ||
| t.Fatalf("expected installer pod to be created when the precondition is met") | ||
| } | ||
| }) | ||
|
|
||
| t.Run("precondition error fails sync", func(t *testing.T) { | ||
| c, eventRecorder, getPod := newController(func(ctx context.Context, nodeName string) (bool, string, error) { | ||
| return false, "", fmt.Errorf("boom") | ||
| }) | ||
| var syncErr error | ||
| for i := 0; i < 3; i++ { | ||
| if syncErr = c.Sync(context.TODO(), factory.NewSyncContext("InstallerController", *eventRecorder)); syncErr != nil { | ||
| break | ||
| } | ||
| } | ||
| if syncErr == nil { | ||
| t.Fatalf("expected sync error from precondition") | ||
| } | ||
| if getPod() != nil { | ||
| t.Fatalf("expected no installer pod on precondition error") | ||
| } | ||
| }) | ||
| } | ||
This file contains hidden or 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
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.
I think that it would be more flexible to return the backoff duration as a return value, so we could turn
safeinto atime.Durationand wait when that duration is> 0. We can then removeinstallerPreconditionRequeueDuration, which is not configurable.