/
V1.purs
304 lines (270 loc) · 15.2 KB
/
V1.purs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
module Kubernetes.Api.Autoscaling.V1 where
import Prelude
import Prelude
import Prelude
import Control.Alt ((<|>))
import Data.Either (Either(Left,Right))
import Data.Generic.Rep (class Generic)
import Data.Generic.Rep.Show (genericShow)
import Data.Newtype (class Newtype)
import Data.Tuple (Tuple(Tuple))
import Effect.Aff (Aff)
import Foreign.Class (class Decode, class Encode, decode, encode)
import Prelude
import Data.Maybe (Maybe(Just,Nothing))
import Foreign.Class (class Decode, class Encode, encode, decode)
import Foreign.Generic (defaultOptions, genericDecode, genericEncode)
import Foreign.Generic (encodeJSON, genericEncode, genericDecode)
import Foreign.Generic.Types (Options)
import Foreign.Index (readProp)
import Foreign.Object (Object)
import Foreign.Object as Object
import Kubernetes.Client as Client
import Kubernetes.Config (Config)
import Kubernetes.Default (class Default)
import Kubernetes.Json (assertPropEq, decodeMaybe, encodeMaybe, jsonOptions)
import Kubernetes.Api.Meta.V1 as MetaV1
-- | CrossVersionObjectReference contains enough information to let you identify the referred resource.
-- |
-- | Fields:
-- | - `apiVersion`: API version of the referent
-- | - `kind`: Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#types-kinds"
-- | - `name`: Name of the referent; More info: http://kubernetes.io/docs/user-guide/identifiers#names
newtype CrossVersionObjectReference = CrossVersionObjectReference
{ apiVersion :: (Maybe String)
, kind :: (Maybe String)
, name :: (Maybe String) }
derive instance newtypeCrossVersionObjectReference :: Newtype CrossVersionObjectReference _
derive instance genericCrossVersionObjectReference :: Generic CrossVersionObjectReference _
instance showCrossVersionObjectReference :: Show CrossVersionObjectReference where show a = genericShow a
instance decodeCrossVersionObjectReference :: Decode CrossVersionObjectReference where
decode a = do
apiVersion <- decodeMaybe "apiVersion" a
kind <- decodeMaybe "kind" a
name <- decodeMaybe "name" a
pure $ CrossVersionObjectReference { apiVersion, kind, name }
instance encodeCrossVersionObjectReference :: Encode CrossVersionObjectReference where
encode (CrossVersionObjectReference a) = encode $ Object.fromFoldable $
[ Tuple "apiVersion" (encodeMaybe a.apiVersion)
, Tuple "kind" (encodeMaybe a.kind)
, Tuple "name" (encodeMaybe a.name) ]
instance defaultCrossVersionObjectReference :: Default CrossVersionObjectReference where
default = CrossVersionObjectReference
{ apiVersion: Nothing
, kind: Nothing
, name: Nothing }
-- | configuration of a horizontal pod autoscaler.
-- |
-- | Fields:
-- | - `metadata`: Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
-- | - `spec`: behaviour of autoscaler. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
-- | - `status`: current information about the autoscaler.
newtype HorizontalPodAutoscaler = HorizontalPodAutoscaler
{ metadata :: (Maybe MetaV1.ObjectMeta)
, spec :: (Maybe HorizontalPodAutoscalerSpec)
, status :: (Maybe HorizontalPodAutoscalerStatus) }
derive instance newtypeHorizontalPodAutoscaler :: Newtype HorizontalPodAutoscaler _
derive instance genericHorizontalPodAutoscaler :: Generic HorizontalPodAutoscaler _
instance showHorizontalPodAutoscaler :: Show HorizontalPodAutoscaler where show a = genericShow a
instance decodeHorizontalPodAutoscaler :: Decode HorizontalPodAutoscaler where
decode a = do
assertPropEq "apiVersion" "autoscaling/v1" a
assertPropEq "kind" "HorizontalPodAutoscaler" a
metadata <- decodeMaybe "metadata" a
spec <- decodeMaybe "spec" a
status <- decodeMaybe "status" a
pure $ HorizontalPodAutoscaler { metadata, spec, status }
instance encodeHorizontalPodAutoscaler :: Encode HorizontalPodAutoscaler where
encode (HorizontalPodAutoscaler a) = encode $ Object.fromFoldable $
[ Tuple "apiVersion" (encode "autoscaling/v1")
, Tuple "kind" (encode "HorizontalPodAutoscaler")
, Tuple "metadata" (encodeMaybe a.metadata)
, Tuple "spec" (encodeMaybe a.spec)
, Tuple "status" (encodeMaybe a.status) ]
instance defaultHorizontalPodAutoscaler :: Default HorizontalPodAutoscaler where
default = HorizontalPodAutoscaler
{ metadata: Nothing
, spec: Nothing
, status: Nothing }
-- | list of horizontal pod autoscaler objects.
-- |
-- | Fields:
-- | - `items`: list of horizontal pod autoscaler objects.
-- | - `metadata`: Standard list metadata.
newtype HorizontalPodAutoscalerList = HorizontalPodAutoscalerList
{ items :: (Maybe (Array HorizontalPodAutoscaler))
, metadata :: (Maybe MetaV1.ListMeta) }
derive instance newtypeHorizontalPodAutoscalerList :: Newtype HorizontalPodAutoscalerList _
derive instance genericHorizontalPodAutoscalerList :: Generic HorizontalPodAutoscalerList _
instance showHorizontalPodAutoscalerList :: Show HorizontalPodAutoscalerList where show a = genericShow a
instance decodeHorizontalPodAutoscalerList :: Decode HorizontalPodAutoscalerList where
decode a = do
assertPropEq "apiVersion" "autoscaling/v1" a
items <- decodeMaybe "items" a
assertPropEq "kind" "HorizontalPodAutoscalerList" a
metadata <- decodeMaybe "metadata" a
pure $ HorizontalPodAutoscalerList { items, metadata }
instance encodeHorizontalPodAutoscalerList :: Encode HorizontalPodAutoscalerList where
encode (HorizontalPodAutoscalerList a) = encode $ Object.fromFoldable $
[ Tuple "apiVersion" (encode "autoscaling/v1")
, Tuple "items" (encodeMaybe a.items)
, Tuple "kind" (encode "HorizontalPodAutoscalerList")
, Tuple "metadata" (encodeMaybe a.metadata) ]
instance defaultHorizontalPodAutoscalerList :: Default HorizontalPodAutoscalerList where
default = HorizontalPodAutoscalerList
{ items: Nothing
, metadata: Nothing }
-- | specification of a horizontal pod autoscaler.
-- |
-- | Fields:
-- | - `maxReplicas`: upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.
-- | - `minReplicas`: lower limit for the number of pods that can be set by the autoscaler, default 1.
-- | - `scaleTargetRef`: reference to scaled resource; horizontal pod autoscaler will learn the current resource consumption and will set the desired number of pods by using its Scale subresource.
-- | - `targetCPUUtilizationPercentage`: target average CPU utilization (represented as a percentage of requested CPU) over all the pods; if not specified the default autoscaling policy will be used.
newtype HorizontalPodAutoscalerSpec = HorizontalPodAutoscalerSpec
{ maxReplicas :: (Maybe Int)
, minReplicas :: (Maybe Int)
, scaleTargetRef :: (Maybe CrossVersionObjectReference)
, targetCPUUtilizationPercentage :: (Maybe Int) }
derive instance newtypeHorizontalPodAutoscalerSpec :: Newtype HorizontalPodAutoscalerSpec _
derive instance genericHorizontalPodAutoscalerSpec :: Generic HorizontalPodAutoscalerSpec _
instance showHorizontalPodAutoscalerSpec :: Show HorizontalPodAutoscalerSpec where show a = genericShow a
instance decodeHorizontalPodAutoscalerSpec :: Decode HorizontalPodAutoscalerSpec where
decode a = do
maxReplicas <- decodeMaybe "maxReplicas" a
minReplicas <- decodeMaybe "minReplicas" a
scaleTargetRef <- decodeMaybe "scaleTargetRef" a
targetCPUUtilizationPercentage <- decodeMaybe "targetCPUUtilizationPercentage" a
pure $ HorizontalPodAutoscalerSpec { maxReplicas, minReplicas, scaleTargetRef, targetCPUUtilizationPercentage }
instance encodeHorizontalPodAutoscalerSpec :: Encode HorizontalPodAutoscalerSpec where
encode (HorizontalPodAutoscalerSpec a) = encode $ Object.fromFoldable $
[ Tuple "maxReplicas" (encodeMaybe a.maxReplicas)
, Tuple "minReplicas" (encodeMaybe a.minReplicas)
, Tuple "scaleTargetRef" (encodeMaybe a.scaleTargetRef)
, Tuple "targetCPUUtilizationPercentage" (encodeMaybe a.targetCPUUtilizationPercentage) ]
instance defaultHorizontalPodAutoscalerSpec :: Default HorizontalPodAutoscalerSpec where
default = HorizontalPodAutoscalerSpec
{ maxReplicas: Nothing
, minReplicas: Nothing
, scaleTargetRef: Nothing
, targetCPUUtilizationPercentage: Nothing }
-- | current status of a horizontal pod autoscaler
-- |
-- | Fields:
-- | - `currentCPUUtilizationPercentage`: current average CPU utilization over all pods, represented as a percentage of requested CPU, e.g. 70 means that an average pod is using now 70% of its requested CPU.
-- | - `currentReplicas`: current number of replicas of pods managed by this autoscaler.
-- | - `desiredReplicas`: desired number of replicas of pods managed by this autoscaler.
-- | - `lastScaleTime`: last time the HorizontalPodAutoscaler scaled the number of pods; used by the autoscaler to control how often the number of pods is changed.
-- | - `observedGeneration`: most recent generation observed by this autoscaler.
newtype HorizontalPodAutoscalerStatus = HorizontalPodAutoscalerStatus
{ currentCPUUtilizationPercentage :: (Maybe Int)
, currentReplicas :: (Maybe Int)
, desiredReplicas :: (Maybe Int)
, lastScaleTime :: (Maybe MetaV1.Time)
, observedGeneration :: (Maybe Int) }
derive instance newtypeHorizontalPodAutoscalerStatus :: Newtype HorizontalPodAutoscalerStatus _
derive instance genericHorizontalPodAutoscalerStatus :: Generic HorizontalPodAutoscalerStatus _
instance showHorizontalPodAutoscalerStatus :: Show HorizontalPodAutoscalerStatus where show a = genericShow a
instance decodeHorizontalPodAutoscalerStatus :: Decode HorizontalPodAutoscalerStatus where
decode a = do
currentCPUUtilizationPercentage <- decodeMaybe "currentCPUUtilizationPercentage" a
currentReplicas <- decodeMaybe "currentReplicas" a
desiredReplicas <- decodeMaybe "desiredReplicas" a
lastScaleTime <- decodeMaybe "lastScaleTime" a
observedGeneration <- decodeMaybe "observedGeneration" a
pure $ HorizontalPodAutoscalerStatus { currentCPUUtilizationPercentage, currentReplicas, desiredReplicas, lastScaleTime, observedGeneration }
instance encodeHorizontalPodAutoscalerStatus :: Encode HorizontalPodAutoscalerStatus where
encode (HorizontalPodAutoscalerStatus a) = encode $ Object.fromFoldable $
[ Tuple "currentCPUUtilizationPercentage" (encodeMaybe a.currentCPUUtilizationPercentage)
, Tuple "currentReplicas" (encodeMaybe a.currentReplicas)
, Tuple "desiredReplicas" (encodeMaybe a.desiredReplicas)
, Tuple "lastScaleTime" (encodeMaybe a.lastScaleTime)
, Tuple "observedGeneration" (encodeMaybe a.observedGeneration) ]
instance defaultHorizontalPodAutoscalerStatus :: Default HorizontalPodAutoscalerStatus where
default = HorizontalPodAutoscalerStatus
{ currentCPUUtilizationPercentage: Nothing
, currentReplicas: Nothing
, desiredReplicas: Nothing
, lastScaleTime: Nothing
, observedGeneration: Nothing }
-- | Scale represents a scaling request for a resource.
-- |
-- | Fields:
-- | - `metadata`: Standard object metadata; More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata.
-- | - `spec`: defines the behavior of the scale. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status.
-- | - `status`: current status of the scale. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#spec-and-status. Read-only.
newtype Scale = Scale
{ metadata :: (Maybe MetaV1.ObjectMeta)
, spec :: (Maybe ScaleSpec)
, status :: (Maybe ScaleStatus) }
derive instance newtypeScale :: Newtype Scale _
derive instance genericScale :: Generic Scale _
instance showScale :: Show Scale where show a = genericShow a
instance decodeScale :: Decode Scale where
decode a = do
assertPropEq "apiVersion" "autoscaling/v1" a
assertPropEq "kind" "Scale" a
metadata <- decodeMaybe "metadata" a
spec <- decodeMaybe "spec" a
status <- decodeMaybe "status" a
pure $ Scale { metadata, spec, status }
instance encodeScale :: Encode Scale where
encode (Scale a) = encode $ Object.fromFoldable $
[ Tuple "apiVersion" (encode "autoscaling/v1")
, Tuple "kind" (encode "Scale")
, Tuple "metadata" (encodeMaybe a.metadata)
, Tuple "spec" (encodeMaybe a.spec)
, Tuple "status" (encodeMaybe a.status) ]
instance defaultScale :: Default Scale where
default = Scale
{ metadata: Nothing
, spec: Nothing
, status: Nothing }
-- | ScaleSpec describes the attributes of a scale subresource.
-- |
-- | Fields:
-- | - `replicas`: desired number of instances for the scaled object.
newtype ScaleSpec = ScaleSpec
{ replicas :: (Maybe Int) }
derive instance newtypeScaleSpec :: Newtype ScaleSpec _
derive instance genericScaleSpec :: Generic ScaleSpec _
instance showScaleSpec :: Show ScaleSpec where show a = genericShow a
instance decodeScaleSpec :: Decode ScaleSpec where
decode a = do
replicas <- decodeMaybe "replicas" a
pure $ ScaleSpec { replicas }
instance encodeScaleSpec :: Encode ScaleSpec where
encode (ScaleSpec a) = encode $ Object.fromFoldable $
[ Tuple "replicas" (encodeMaybe a.replicas) ]
instance defaultScaleSpec :: Default ScaleSpec where
default = ScaleSpec
{ replicas: Nothing }
-- | ScaleStatus represents the current status of a scale subresource.
-- |
-- | Fields:
-- | - `replicas`: actual number of observed instances of the scaled object.
-- | - `selector`: label query over pods that should match the replicas count. This is same as the label selector but in the string format to avoid introspection by clients. The string will be in the same format as the query-param syntax. More info about label selectors: http://kubernetes.io/docs/user-guide/labels#label-selectors
newtype ScaleStatus = ScaleStatus
{ replicas :: (Maybe Int)
, selector :: (Maybe String) }
derive instance newtypeScaleStatus :: Newtype ScaleStatus _
derive instance genericScaleStatus :: Generic ScaleStatus _
instance showScaleStatus :: Show ScaleStatus where show a = genericShow a
instance decodeScaleStatus :: Decode ScaleStatus where
decode a = do
replicas <- decodeMaybe "replicas" a
selector <- decodeMaybe "selector" a
pure $ ScaleStatus { replicas, selector }
instance encodeScaleStatus :: Encode ScaleStatus where
encode (ScaleStatus a) = encode $ Object.fromFoldable $
[ Tuple "replicas" (encodeMaybe a.replicas)
, Tuple "selector" (encodeMaybe a.selector) ]
instance defaultScaleStatus :: Default ScaleStatus where
default = ScaleStatus
{ replicas: Nothing
, selector: Nothing }
-- | get available resources
getAPIResources :: Config -> Aff (Either MetaV1.Status MetaV1.APIResourceList)
getAPIResources cfg = Client.makeRequest (Client.get cfg url Nothing)
where
url = "/apis/autoscaling/v1/"