Skip to content

Commit 74b3726

Browse files
committed
SQUASH: Move ForResource to its own file
Signed-off-by: Dr. Stefan Schimanski <[email protected]>
1 parent 9ef9737 commit 74b3726

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

pkg/logging/helpers.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
Copyright 2023 The Crossplane Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package logging
18+
19+
import (
20+
"fmt"
21+
22+
"sigs.k8s.io/controller-runtime/pkg/client"
23+
)
24+
25+
// ForResource returns logging values for a resource.
26+
func ForResource(object client.Object) []string {
27+
ret := make([]string, 0, 10)
28+
gvk := object.GetObjectKind().GroupVersionKind()
29+
if gvk.Kind == "" {
30+
gvk.Kind = fmt.Sprintf("%T", object) // best effort for native Go types
31+
}
32+
ret = append(ret,
33+
"name", object.GetName(),
34+
"kind", gvk.Kind,
35+
"version", gvk.Version,
36+
"group", gvk.Group,
37+
)
38+
if ns := object.GetNamespace(); ns != "" {
39+
ret = append(ret, "namespace", ns)
40+
}
41+
42+
return ret
43+
}

pkg/logging/logging.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,7 @@ limitations under the License.
3737
package logging
3838

3939
import (
40-
"fmt"
41-
4240
"github.com/go-logr/logr"
43-
"sigs.k8s.io/controller-runtime/pkg/client"
4441
)
4542

4643
// A Logger logs messages. Messages may be supplemented by structured data.
@@ -95,23 +92,3 @@ func (l logrLogger) Debug(msg string, keysAndValues ...any) {
9592
func (l logrLogger) WithValues(keysAndValues ...any) Logger {
9693
return logrLogger{log: l.log.WithValues(keysAndValues...)} //nolint:logrlint // False positive - logrlint thinks there's an odd number of args.
9794
}
98-
99-
// ForResource returns logging values for a resource.
100-
func ForResource(object client.Object) []string {
101-
ret := make([]string, 0, 10)
102-
gvk := object.GetObjectKind().GroupVersionKind()
103-
if gvk.Kind == "" {
104-
gvk.Kind = fmt.Sprintf("%T", object) // best effort for native Go types
105-
}
106-
ret = append(ret,
107-
"name", object.GetName(),
108-
"kind", gvk.Kind,
109-
"version", gvk.Version,
110-
"group", gvk.Group,
111-
)
112-
if ns := object.GetNamespace(); ns != "" {
113-
ret = append(ret, "namespace", ns)
114-
}
115-
116-
return ret
117-
}

0 commit comments

Comments
 (0)