blob: 78e5eab09dc1a68c0fa04cdfa38274f4351ed40d [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001/*
2Copyright 2017 The Kubernetes Authors.
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package v1alpha1
18
19import (
20 "strings"
21
22 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
23 "k8s.io/apimachinery/pkg/conversion"
24 "k8s.io/apiserver/pkg/apis/audit"
25)
26
27func Convert_audit_ObjectReference_To_v1alpha1_ObjectReference(in *audit.ObjectReference, out *ObjectReference, s conversion.Scope) error {
28 // Begin by copying all fields
29 if err := autoConvert_audit_ObjectReference_To_v1alpha1_ObjectReference(in, out, s); err != nil {
30 return err
31 }
32 // empty string means the core api group
33 if in.APIGroup == "" {
34 out.APIVersion = in.APIVersion
35 } else {
36 out.APIVersion = in.APIGroup + "/" + in.APIVersion
37 }
38 return nil
39}
40
41func Convert_v1alpha1_ObjectReference_To_audit_ObjectReference(in *ObjectReference, out *audit.ObjectReference, s conversion.Scope) error {
42 // Begin by copying all fields
43 if err := autoConvert_v1alpha1_ObjectReference_To_audit_ObjectReference(in, out, s); err != nil {
44 return err
45 }
46 i := strings.LastIndex(in.APIVersion, "/")
47 if i == -1 {
48 // In fact it should always contain a "/"
49 out.APIVersion = in.APIVersion
50 } else {
51 out.APIGroup = in.APIVersion[:i]
52 out.APIVersion = in.APIVersion[i+1:]
53 }
54 return nil
55}
56
57func Convert_v1alpha1_Event_To_audit_Event(in *Event, out *audit.Event, s conversion.Scope) error {
58 if err := autoConvert_v1alpha1_Event_To_audit_Event(in, out, s); err != nil {
59 return err
60 }
61 if out.StageTimestamp.IsZero() {
62 out.StageTimestamp = metav1.NewMicroTime(in.CreationTimestamp.Time)
63 }
64 if out.RequestReceivedTimestamp.IsZero() {
65 out.RequestReceivedTimestamp = metav1.NewMicroTime(in.Timestamp.Time)
66 }
67 return nil
68}
69
70func Convert_audit_Event_To_v1alpha1_Event(in *audit.Event, out *Event, s conversion.Scope) error {
71 if err := autoConvert_audit_Event_To_v1alpha1_Event(in, out, s); err != nil {
72 return err
73 }
74 out.CreationTimestamp = metav1.NewTime(in.StageTimestamp.Time)
75 out.Timestamp = metav1.NewTime(in.RequestReceivedTimestamp.Time)
76 return nil
77
78}