4
4
"context"
5
5
"fmt"
6
6
7
- v1 "k8s.io/api/core/v1"
7
+ corev1 "k8s.io/api/core/v1"
8
8
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
9
9
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
10
10
"k8s.io/apimachinery/pkg/runtime"
@@ -22,7 +22,7 @@ func GetControllerDetails(event admission.Attributes, clientset kubernetes.Inter
22
22
23
23
pod , err := GetPodDetails (clientset , podName , namespace )
24
24
if err != nil {
25
- return "" , "" , "" , "" , fmt .Errorf ("failed to get pod details: %v " , err )
25
+ return "" , "" , "" , "" , fmt .Errorf ("failed to get pod details: %w " , err )
26
26
}
27
27
28
28
workloadKind , workloadName , workloadNamespace := ExtractPodOwner (pod , clientset )
@@ -32,16 +32,16 @@ func GetControllerDetails(event admission.Attributes, clientset kubernetes.Inter
32
32
}
33
33
34
34
// GetPodDetails returns the pod details from the Kubernetes API server.
35
- func GetPodDetails (clientset kubernetes.Interface , podName , namespace string ) (* v1 .Pod , error ) {
35
+ func GetPodDetails (clientset kubernetes.Interface , podName , namespace string ) (* corev1 .Pod , error ) {
36
36
pod , err := clientset .CoreV1 ().Pods (namespace ).Get (context .TODO (), podName , metav1.GetOptions {})
37
37
if err != nil {
38
- return nil , fmt .Errorf ("failed to get pod: %v " , err )
38
+ return nil , fmt .Errorf ("failed to get pod: %w " , err )
39
39
}
40
40
return pod , nil
41
41
}
42
42
43
43
// ExtractPodOwner returns the kind, name, and namespace of the controller that owns the pod.
44
- func ExtractPodOwner (pod * v1 .Pod , clientset kubernetes.Interface ) (string , string , string ) {
44
+ func ExtractPodOwner (pod * corev1 .Pod , clientset kubernetes.Interface ) (string , string , string ) {
45
45
for _ , ownerRef := range pod .OwnerReferences {
46
46
switch ownerRef .Kind {
47
47
case "ReplicaSet" :
@@ -91,9 +91,9 @@ func GetContainerNameFromExecToPodEvent(event admission.Attributes) (string, err
91
91
return "" , fmt .Errorf ("object is not of type *unstructured.Unstructured" )
92
92
}
93
93
94
- podExecOptions := & v1 .PodExecOptions {}
94
+ podExecOptions := & corev1 .PodExecOptions {}
95
95
if err := runtime .DefaultUnstructuredConverter .FromUnstructured (unstructuredObj .Object , podExecOptions ); err != nil {
96
- return "" , fmt .Errorf ("failed to decode PodExecOptions: %v " , err )
96
+ return "" , fmt .Errorf ("failed to decode PodExecOptions: %w " , err )
97
97
}
98
98
99
99
return podExecOptions .Container , nil
0 commit comments