Skip to content

Commit

Permalink
Merge pull request #50 from triffer/pod-field-selector-fake
Browse files Browse the repository at this point in the history
Add support for pod status.phase field selector in fake client
  • Loading branch information
kyma-bot authored Jan 11, 2023
2 parents 3fedab2 + ec14e86 commit dd37de0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
6 changes: 5 additions & 1 deletion operator/pkg/lib/sidecars/pods/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ func createClientSet(t *testing.T, objects ...client.Object) client.Client {
err = v1.AddToScheme(scheme.Scheme)
require.NoError(t, err)

fakeClient := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(objects...).Build()
fakeClient := fake.NewClientBuilder().
WithScheme(scheme.Scheme).
WithObjects(objects...).
WithIndex(&v1.Pod{}, "status.phase", helpers.FakePodStatusPhaseIndexer).
Build()

return fakeClient
}
Expand Down
15 changes: 15 additions & 0 deletions operator/pkg/lib/sidecars/test/helpers/fake_client_indexer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package helpers

import (
"fmt"
"k8s.io/api/core/v1"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func FakePodStatusPhaseIndexer(object client.Object) []string {
p, ok := object.(*v1.Pod)
if !ok {
panic(fmt.Errorf("indexer function for type %T's status.phase field received object of type %T", v1.Pod{}, object))
}
return []string{string(p.Status.Phase)}
}
14 changes: 9 additions & 5 deletions operator/pkg/lib/sidecars/test/test_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,15 @@ func newScenario() (*scenario, error) {
}

return &scenario{
Client: fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(
helpers.FixNamespaceWith(noAnnotationNamespace, nil),
helpers.FixNamespaceWith(sidecarEnabledNamespace, map[string]string{"istio-injection": "enabled"}),
helpers.FixNamespaceWith(sidecarDisabledNamespace, map[string]string{"istio-injection": "disabled"}),
).Build(),
Client: fake.NewClientBuilder().
WithScheme(scheme.Scheme).
WithObjects(
helpers.FixNamespaceWith(noAnnotationNamespace, nil),
helpers.FixNamespaceWith(sidecarEnabledNamespace, map[string]string{"istio-injection": "enabled"}),
helpers.FixNamespaceWith(sidecarDisabledNamespace, map[string]string{"istio-injection": "disabled"}),
).
WithIndex(&corev1.Pod{}, "status.phase", helpers.FakePodStatusPhaseIndexer).
Build(),
logger: logr.Discard(),
injectionNamespaceSelector: SidecarEnabled,
}, nil
Expand Down

0 comments on commit dd37de0

Please sign in to comment.