-
Notifications
You must be signed in to change notification settings - Fork 32
fix: SKRWebhook Condition Handling in Kyma CR #2626
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
Merged
LeelaChacha
merged 11 commits into
kyma-project:main
from
LeelaChacha:fix/#2396-skrwebook-condition
Aug 1, 2025
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e5964f
fix: SKRWebhook Condition Handling in Kyma CR
LeelaChacha 15e8db4
refactor: Make method a function
LeelaChacha 476d7ac
Merge branch 'main' into fix/#2396-skrwebook-condition
LeelaChacha 04947e5
chore: Add test coverage
LeelaChacha 77628dc
refactor: Test file
LeelaChacha 9f28046
Merge branch 'main' into fix/#2396-skrwebook-condition
LeelaChacha 0855172
refactor
LeelaChacha aa0dfb2
chore: coverage
LeelaChacha 854cb4e
Merge branch 'main' into fix/#2396-skrwebook-condition
LeelaChacha fc456a0
refactor: nestif linter
LeelaChacha 07d0121
Merge branch 'main' into fix/#2396-skrwebook-condition
medmes 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 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
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 |
|---|---|---|
| @@ -0,0 +1,129 @@ | ||
| package watcher_test | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| apiappsv1 "k8s.io/api/apps/v1" | ||
| apicorev1 "k8s.io/api/core/v1" | ||
| "sigs.k8s.io/controller-runtime/pkg/client" | ||
|
|
||
| "github.com/kyma-project/lifecycle-manager/pkg/watcher" | ||
| ) | ||
|
|
||
| func TestAssertDeploymentReady_ReturnsNoError_WhenDeploymentReady(t *testing.T) { | ||
| readyDeployment := &apiappsv1.Deployment{ | ||
| Status: apiappsv1.DeploymentStatus{ | ||
| ReadyReplicas: 1, | ||
| }, | ||
| } | ||
| getFunc := func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { | ||
| deployment, _ := obj.(*apiappsv1.Deployment) | ||
| *deployment = *readyDeployment | ||
| return nil | ||
| } | ||
| listFunc := func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { | ||
| return nil | ||
| } | ||
| mockClnt := &mockClient{getFunc: getFunc, listFunc: listFunc} | ||
| ctx := t.Context() | ||
|
|
||
| err := watcher.AssertDeploymentReady(ctx, mockClnt) | ||
| require.NoError(t, err) | ||
| } | ||
|
|
||
| func TestAssertDeploymentReady_ReturnsError_WhenDeploymentNotReady(t *testing.T) { | ||
| notReadyDeployment := &apiappsv1.Deployment{ | ||
| Status: apiappsv1.DeploymentStatus{ | ||
| ReadyReplicas: 0, | ||
| }, | ||
| } | ||
| getFunc := func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { | ||
| deployment, _ := obj.(*apiappsv1.Deployment) | ||
| *deployment = *notReadyDeployment | ||
| return nil | ||
| } | ||
| listFunc := func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { | ||
| return nil | ||
| } | ||
| mockClnt := &mockClient{getFunc: getFunc, listFunc: listFunc} | ||
| ctx := t.Context() | ||
|
|
||
| err := watcher.AssertDeploymentReady(ctx, mockClnt) | ||
| require.Error(t, err) | ||
| require.ErrorIs(t, err, watcher.ErrSkrWebhookDeploymentNotReady) | ||
| } | ||
|
|
||
| func TestAssertDeploymentReady_ReturnsError_WhenClientReturnsError(t *testing.T) { | ||
| unexpectedError := errors.New("unexpected error") | ||
| notFoundFunc := func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { | ||
| return unexpectedError | ||
| } | ||
| listFunc := func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { | ||
| return nil | ||
| } | ||
| mockClnt := &mockClient{getFunc: notFoundFunc, listFunc: listFunc} | ||
| ctx := t.Context() | ||
|
|
||
| err := watcher.AssertDeploymentReady(ctx, mockClnt) | ||
| require.Error(t, err) | ||
| require.ErrorIs(t, err, unexpectedError) | ||
| } | ||
|
|
||
| func TestAssertDeploymentReady_ReturnsError_WhenDeploymentInBackoff(t *testing.T) { | ||
| deployment := &apiappsv1.Deployment{ | ||
| Status: apiappsv1.DeploymentStatus{ | ||
| ReadyReplicas: 0, | ||
| }, | ||
| } | ||
| podList := &apicorev1.PodList{ | ||
| Items: []apicorev1.Pod{{ | ||
| Status: apicorev1.PodStatus{ | ||
| ContainerStatuses: []apicorev1.ContainerStatus{{ | ||
| State: apicorev1.ContainerState{ | ||
| Waiting: &apicorev1.ContainerStateWaiting{ | ||
| Reason: "CrashLoopBackOff", | ||
| }, | ||
| }, | ||
| }}, | ||
| }, | ||
| }}, | ||
| } | ||
| getFunc := func(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { | ||
| deploymentObj, ok := obj.(*apiappsv1.Deployment) | ||
| if ok { | ||
| *deploymentObj = *deployment | ||
| } | ||
| return nil | ||
| } | ||
| listFunc := func(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { | ||
| podListObj, ok := list.(*apicorev1.PodList) | ||
| if ok { | ||
| *podListObj = *podList | ||
| } | ||
| return nil | ||
| } | ||
| mockClnt := &mockClient{getFunc: getFunc, listFunc: listFunc} | ||
| ctx := t.Context() | ||
|
|
||
| err := watcher.AssertDeploymentReady(ctx, mockClnt) | ||
| require.Error(t, err) | ||
| require.ErrorIs(t, err, watcher.ErrSkrWebhookDeploymentInBackoff) | ||
| } | ||
|
|
||
| // Stub for tests | ||
|
|
||
| type mockClient struct { | ||
| getFunc func(context.Context, client.ObjectKey, client.Object, ...client.GetOption) error | ||
| listFunc func(context.Context, client.ObjectList, ...client.ListOption) error | ||
| } | ||
|
|
||
| func (m *mockClient) Get(ctx context.Context, key client.ObjectKey, obj client.Object, opts ...client.GetOption) error { | ||
| return m.getFunc(ctx, key, obj, opts...) | ||
| } | ||
|
|
||
| func (m *mockClient) List(ctx context.Context, list client.ObjectList, opts ...client.ListOption) error { | ||
| return m.listFunc(ctx, list, opts...) | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.