...
1
16
17 package horizontalpodautoscaler
18
19 import (
20 "context"
21
22 "k8s.io/apimachinery/pkg/runtime"
23 "k8s.io/apimachinery/pkg/util/validation/field"
24 "k8s.io/apiserver/pkg/storage/names"
25 "k8s.io/kubernetes/pkg/api/legacyscheme"
26 "k8s.io/kubernetes/pkg/apis/autoscaling"
27 "k8s.io/kubernetes/pkg/apis/autoscaling/validation"
28 "sigs.k8s.io/structured-merge-diff/v4/fieldpath"
29 )
30
31
32 type autoscalerStrategy struct {
33 runtime.ObjectTyper
34 names.NameGenerator
35 }
36
37
38
39 var Strategy = autoscalerStrategy{legacyscheme.Scheme, names.SimpleNameGenerator}
40
41
42 func (autoscalerStrategy) NamespaceScoped() bool {
43 return true
44 }
45
46
47
48 func (autoscalerStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
49 fields := map[fieldpath.APIVersion]*fieldpath.Set{
50 "autoscaling/v1": fieldpath.NewSet(
51 fieldpath.MakePathOrDie("status"),
52 ),
53 "autoscaling/v2": fieldpath.NewSet(
54 fieldpath.MakePathOrDie("status"),
55 ),
56 "autoscaling/v2beta1": fieldpath.NewSet(
57 fieldpath.MakePathOrDie("status"),
58 ),
59 "autoscaling/v2beta2": fieldpath.NewSet(
60 fieldpath.MakePathOrDie("status"),
61 ),
62 }
63
64 return fields
65 }
66
67
68 func (autoscalerStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) {
69 newHPA := obj.(*autoscaling.HorizontalPodAutoscaler)
70
71
72 newHPA.Status = autoscaling.HorizontalPodAutoscalerStatus{}
73 }
74
75
76 func (autoscalerStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList {
77 autoscaler := obj.(*autoscaling.HorizontalPodAutoscaler)
78 return validation.ValidateHorizontalPodAutoscaler(autoscaler)
79 }
80
81
82 func (autoscalerStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string {
83 return nil
84 }
85
86
87 func (autoscalerStrategy) Canonicalize(obj runtime.Object) {
88 }
89
90
91 func (autoscalerStrategy) AllowCreateOnUpdate() bool {
92 return false
93 }
94
95
96 func (autoscalerStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
97 newHPA := obj.(*autoscaling.HorizontalPodAutoscaler)
98 oldHPA := old.(*autoscaling.HorizontalPodAutoscaler)
99
100 newHPA.Status = oldHPA.Status
101 }
102
103
104 func (autoscalerStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
105 return validation.ValidateHorizontalPodAutoscalerUpdate(obj.(*autoscaling.HorizontalPodAutoscaler), old.(*autoscaling.HorizontalPodAutoscaler))
106 }
107
108
109 func (autoscalerStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
110 return nil
111 }
112
113 func (autoscalerStrategy) AllowUnconditionalUpdate() bool {
114 return true
115 }
116
117 type autoscalerStatusStrategy struct {
118 autoscalerStrategy
119 }
120
121
122 var StatusStrategy = autoscalerStatusStrategy{Strategy}
123
124
125
126 func (autoscalerStatusStrategy) GetResetFields() map[fieldpath.APIVersion]*fieldpath.Set {
127 fields := map[fieldpath.APIVersion]*fieldpath.Set{
128 "autoscaling/v1": fieldpath.NewSet(
129 fieldpath.MakePathOrDie("spec"),
130 ),
131 "autoscaling/v2": fieldpath.NewSet(
132 fieldpath.MakePathOrDie("spec"),
133 ),
134 "autoscaling/v2beta1": fieldpath.NewSet(
135 fieldpath.MakePathOrDie("spec"),
136 ),
137 "autoscaling/v2beta2": fieldpath.NewSet(
138 fieldpath.MakePathOrDie("spec"),
139 ),
140 }
141
142 return fields
143 }
144
145 func (autoscalerStatusStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) {
146 newAutoscaler := obj.(*autoscaling.HorizontalPodAutoscaler)
147 oldAutoscaler := old.(*autoscaling.HorizontalPodAutoscaler)
148
149 newAutoscaler.Spec = oldAutoscaler.Spec
150 }
151
152 func (autoscalerStatusStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList {
153 return validation.ValidateHorizontalPodAutoscalerStatusUpdate(obj.(*autoscaling.HorizontalPodAutoscaler), old.(*autoscaling.HorizontalPodAutoscaler))
154 }
155
156
157 func (autoscalerStatusStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string {
158 return nil
159 }
160
View as plain text