-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(metrics-operator): improve logging (#2269)
- Loading branch information
1 parent
91dd45e
commit 2e35273
Showing
4 changed files
with
51 additions
and
12 deletions.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package common | ||
|
||
import ctrl "sigs.k8s.io/controller-runtime" | ||
|
||
// GetRequestInfo extracts name and namespace from a controller request. | ||
func GetRequestInfo(req ctrl.Request) map[string]string { | ||
return map[string]string{ | ||
"name": req.Name, | ||
"namespace": req.Namespace, | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"k8s.io/apimachinery/pkg/types" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
) | ||
|
||
func TestGetRequestInfo(t *testing.T) { | ||
req := ctrl.Request{ | ||
NamespacedName: types.NamespacedName{ | ||
Name: "example", | ||
Namespace: "test-namespace", | ||
}} | ||
|
||
info := GetRequestInfo(req) | ||
expected := map[string]string{ | ||
"name": "example", | ||
"namespace": "test-namespace", | ||
} | ||
require.Equal(t, expected, info) | ||
} |
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