Skip to content

Commit 6dc7f7a

Browse files
author
Aya Igarashi
committed
Generate VPA CRD v1 from types.go
1 parent 4b5c93f commit 6dc7f7a

File tree

11 files changed

+806
-15
lines changed

11 files changed

+806
-15
lines changed

vertical-pod-autoscaler/deploy/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ resources:
33
- recommender-deployment.yaml
44
- updater-deployment.yaml
55
- vpa-rbac.yaml
6-
- vpa-v1-crd.yaml
6+
- vpa-v1-crd-gen.yaml

vertical-pod-autoscaler/deploy/vpa-v1-crd-gen.yaml

Lines changed: 716 additions & 0 deletions
Large diffs are not rendered by default.

vertical-pod-autoscaler/hack/deploy-for-e2e.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ for i in ${COMPONENTS}; do
7373
ALL_ARCHITECTURES=amd64 make --directory ${SCRIPT_ROOT}/pkg/${i} release
7474
done
7575

76-
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd.yaml
76+
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd-gen.yaml
7777
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-rbac.yaml
7878

7979
for i in ${COMPONENTS}; do
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -o errexit
18+
set -o nounset
19+
set -o pipefail
20+
21+
REPOSITORY_ROOT=$(realpath $(dirname ${BASH_SOURCE})/..)
22+
CRD_OPTS=crd:trivialVersions=false,allowDangerousTypes=true
23+
APIS_PATH=${REPOSITORY_ROOT}/pkg/apis
24+
OUTPUT=${REPOSITORY_ROOT}/deploy/vpa-v1-crd-gen.yaml
25+
WORKSPACE=$(mktemp -d)
26+
27+
function cleanup() {
28+
rm -r ${WORKSPACE}
29+
}
30+
trap cleanup EXIT
31+
32+
if [[ -z $(which controller-gen) ]]; then
33+
(
34+
cd $WORKSPACE
35+
go mod init tmp
36+
go get sigs.k8s.io/controller-tools/cmd/[email protected]
37+
)
38+
CONTROLLER_GEN=${GOBIN:-$(go env GOPATH)/bin}/controller-gen
39+
else
40+
CONTROLLER_GEN=$(which controller-gen)
41+
fi
42+
43+
# The following commands always returns an error because controller-gen does not accept keys other than strings.
44+
${CONTROLLER_GEN} ${CRD_OPTS} paths="${APIS_PATH}/..." output:crd:dir=${WORKSPACE} >& ${WORKSPACE}/errors.log ||:
45+
grep -v -e 'map keys must be strings, not int' -e 'not all generators ran successfully' -e 'usage' ${WORKSPACE}/errors.log \
46+
&& { echo "Failed to generate CRD YAMLs."; exit 1; }
47+
48+
cd ${WORKSPACE}
49+
cat <<EOF > kustomization.yaml
50+
resources:
51+
- autoscaling.k8s.io_verticalpodautoscalers.yaml
52+
- autoscaling.k8s.io_verticalpodautoscalercheckpoints.yaml
53+
commonAnnotations:
54+
"api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
55+
EOF
56+
kubectl kustomize . > ${OUTPUT}

vertical-pod-autoscaler/hack/vpa-process-yamls.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ if [ $# -gt 2 ]; then
4040
fi
4141

4242
ACTION=$1
43-
COMPONENTS="vpa-v1-crd vpa-rbac updater-deployment recommender-deployment admission-controller-deployment"
43+
COMPONENTS="vpa-v1-crd-gen vpa-rbac updater-deployment recommender-deployment admission-controller-deployment"
4444
case ${ACTION} in
4545
delete|diff|print) COMPONENTS+=" vpa-beta2-crd" ;;
4646
esac

vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ limitations under the License.
1818

1919
// Package v1 contains definitions of Vertical Pod Autoscaler related objects.
2020
// +groupName=autoscaling.k8s.io
21+
// +kubebuilder:object:generate=true
2122
package v1

vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ type VerticalPodAutoscalerList struct {
3838

3939
// +genclient
4040
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
41+
// +kubebuilder:resource:shortName=vpa
4142

4243
// VerticalPodAutoscaler is the configuration for a vertical pod
4344
// autoscaler, which automatically manages pod resources based on historical and
4445
// real time resource utilization.
4546
type VerticalPodAutoscaler struct {
46-
metav1.TypeMeta `json:",inline"`
47-
// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
48-
// +optional
47+
metav1.TypeMeta `json:",inline"`
4948
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
5049

5150
// Specification of the behavior of the autoscaler.
@@ -96,6 +95,7 @@ type PodUpdatePolicy struct {
9695
}
9796

9897
// UpdateMode controls when autoscaler applies changes to the pod resoures.
98+
// +kubebuilder:validation:Enum=Off;Initial;Recreate;Auto
9999
type UpdateMode string
100100

101101
const (
@@ -167,6 +167,7 @@ const (
167167

168168
// ContainerScalingMode controls whether autoscaler is enabled for a specific
169169
// container.
170+
// +kubebuilder:validation:Enum=Auto;Off
170171
type ContainerScalingMode string
171172

172173
const (
@@ -177,6 +178,7 @@ const (
177178
)
178179

179180
// ContainerControlledValues controls which resource value should be autoscaled.
181+
// +kubebuilder:validation:Enum=RequestsAndLimits;RequestsOnly
180182
type ContainerControlledValues string
181183

182184
const (
@@ -286,13 +288,12 @@ type VerticalPodAutoscalerCondition struct {
286288
// +genclient
287289
// +genclient:noStatus
288290
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
291+
// +kubebuilder:resource:shortName=vpacheckpoint
289292

290293
// VerticalPodAutoscalerCheckpoint is the checkpoint of the internal state of VPA that
291294
// is used for recovery after recommender's restart.
292295
type VerticalPodAutoscalerCheckpoint struct {
293-
metav1.TypeMeta `json:",inline"`
294-
// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
295-
// +optional
296+
metav1.TypeMeta `json:",inline"`
296297
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
297298

298299
// Specification of the checkpoint.
@@ -326,6 +327,7 @@ type VerticalPodAutoscalerCheckpointSpec struct {
326327
// VerticalPodAutoscalerCheckpointStatus contains data of the checkpoint.
327328
type VerticalPodAutoscalerCheckpointStatus struct {
328329
// The time when the status was last refreshed.
330+
// +nullable
329331
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty" protobuf:"bytes,1,opt,name=lastUpdateTime"`
330332

331333
// Version of the format of the stored data.
@@ -338,9 +340,11 @@ type VerticalPodAutoscalerCheckpointStatus struct {
338340
MemoryHistogram HistogramCheckpoint `json:"memoryHistogram,omitempty" protobuf:"bytes,4,rep,name=memoryHistogram"`
339341

340342
// Timestamp of the fist sample from the histograms.
343+
// +nullable
341344
FirstSampleStart metav1.Time `json:"firstSampleStart,omitempty" protobuf:"bytes,5,opt,name=firstSampleStart"`
342345

343346
// Timestamp of the last sample from the histograms.
347+
// +nullable
344348
LastSampleStart metav1.Time `json:"lastSampleStart,omitempty" protobuf:"bytes,6,opt,name=lastSampleStart"`
345349

346350
// Total number of samples in the histograms.
@@ -350,9 +354,12 @@ type VerticalPodAutoscalerCheckpointStatus struct {
350354
// HistogramCheckpoint contains data needed to reconstruct the histogram.
351355
type HistogramCheckpoint struct {
352356
// Reference timestamp for samples collected within this histogram.
357+
// +nullable
353358
ReferenceTimestamp metav1.Time `json:"referenceTimestamp,omitempty" protobuf:"bytes,1,opt,name=referenceTimestamp"`
354359

355360
// Map from bucket index to bucket weight.
361+
// +kubebuilder:validation:Type=object
362+
// +kubebuilder:validation:XPreserveUnknownFields
356363
BucketWeights map[int]uint32 `json:"bucketWeights,omitempty" protobuf:"bytes,2,opt,name=bucketWeights"`
357364

358365
// Sum of samples to be used as denominator for weights from BucketWeights.

vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta1/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ limitations under the License.
1818

1919
// Package v1beta1 contains definitions of Vertical Pod Autoscaler related objects.
2020
// +groupName=autoscaling.k8s.io
21+
// +kubebuilder:skip
2122
package v1beta1

vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2/doc.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ limitations under the License.
1818

1919
// Package v1beta2 contains definitions of Vertical Pod Autoscaler related objects.
2020
// +groupName=autoscaling.k8s.io
21+
// +kubebuilder:object:generate=true
2122
package v1beta2

vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1beta2/types.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,14 @@ type VerticalPodAutoscalerList struct {
3838

3939
// +genclient
4040
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
41+
// +kubebuilder:resource:shortName=vpa
42+
// +kubebuilder:storageversion
4143

4244
// VerticalPodAutoscaler is the configuration for a vertical pod
4345
// autoscaler, which automatically manages pod resources based on historical and
4446
// real time resource utilization.
4547
type VerticalPodAutoscaler struct {
46-
metav1.TypeMeta `json:",inline"`
47-
// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
48-
// +optional
48+
metav1.TypeMeta `json:",inline"`
4949
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
5050

5151
// Specification of the behavior of the autoscaler.
@@ -96,6 +96,7 @@ type PodUpdatePolicy struct {
9696
}
9797

9898
// UpdateMode controls when autoscaler applies changes to the pod resoures.
99+
// +kubebuilder:validation:Enum=Off;Initial;Recreate;Auto
99100
type UpdateMode string
100101

101102
const (
@@ -157,6 +158,7 @@ const (
157158

158159
// ContainerScalingMode controls whether autoscaler is enabled for a specific
159160
// container.
161+
// +kubebuilder:validation:Enum=Auto;Off
160162
type ContainerScalingMode string
161163

162164
const (
@@ -265,13 +267,13 @@ type VerticalPodAutoscalerCondition struct {
265267
// +genclient
266268
// +genclient:noStatus
267269
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
270+
// +kubebuilder:storageversion
271+
// +kubebuilder:resource:shortName=vpacheckpoint
268272

269273
// VerticalPodAutoscalerCheckpoint is the checkpoint of the internal state of VPA that
270274
// is used for recovery after recommender's restart.
271275
type VerticalPodAutoscalerCheckpoint struct {
272-
metav1.TypeMeta `json:",inline"`
273-
// Standard object metadata. More info: https://git.k8s.io/community/contributors/devel/api-conventions.md#metadata
274-
// +optional
276+
metav1.TypeMeta `json:",inline"`
275277
metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
276278

277279
// Specification of the checkpoint.
@@ -305,6 +307,7 @@ type VerticalPodAutoscalerCheckpointSpec struct {
305307
// VerticalPodAutoscalerCheckpointStatus contains data of the checkpoint.
306308
type VerticalPodAutoscalerCheckpointStatus struct {
307309
// The time when the status was last refreshed.
310+
// +nullable
308311
LastUpdateTime metav1.Time `json:"lastUpdateTime,omitempty" protobuf:"bytes,1,opt,name=lastUpdateTime"`
309312

310313
// Version of the format of the stored data.
@@ -317,9 +320,11 @@ type VerticalPodAutoscalerCheckpointStatus struct {
317320
MemoryHistogram HistogramCheckpoint `json:"memoryHistogram,omitempty" protobuf:"bytes,4,rep,name=memoryHistogram"`
318321

319322
// Timestamp of the fist sample from the histograms.
323+
// +nullable
320324
FirstSampleStart metav1.Time `json:"firstSampleStart,omitempty" protobuf:"bytes,5,opt,name=firstSampleStart"`
321325

322326
// Timestamp of the last sample from the histograms.
327+
// +nullable
323328
LastSampleStart metav1.Time `json:"lastSampleStart,omitempty" protobuf:"bytes,6,opt,name=lastSampleStart"`
324329

325330
// Total number of samples in the histograms.
@@ -329,9 +334,12 @@ type VerticalPodAutoscalerCheckpointStatus struct {
329334
// HistogramCheckpoint contains data needed to reconstruct the histogram.
330335
type HistogramCheckpoint struct {
331336
// Reference timestamp for samples collected within this histogram.
337+
// +nullable
332338
ReferenceTimestamp metav1.Time `json:"referenceTimestamp,omitempty" protobuf:"bytes,1,opt,name=referenceTimestamp"`
333339

334340
// Map from bucket index to bucket weight.
341+
// +kubebuilder:validation:Type=object
342+
// +kubebuilder:validation:XPreserveUnknownFields
335343
BucketWeights map[int]uint32 `json:"bucketWeights,omitempty" protobuf:"bytes,2,opt,name=bucketWeights"`
336344

337345
// Sum of samples to be used as denominator for weights from BucketWeights.

0 commit comments

Comments
 (0)