Skip to content

Commit

Permalink
Generate VPA CRD v1 from types.go
Browse files Browse the repository at this point in the history
  • Loading branch information
Aya Igarashi committed Oct 15, 2020
1 parent 4b5c93f commit b674b69
Show file tree
Hide file tree
Showing 11 changed files with 790 additions and 15 deletions.
2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/deploy/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ resources:
- recommender-deployment.yaml
- updater-deployment.yaml
- vpa-rbac.yaml
- vpa-v1-crd.yaml
- vpa-v1-crd-v1.yaml
708 changes: 708 additions & 0 deletions vertical-pod-autoscaler/deploy/vpa-v1-crd-v1.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/hack/deploy-for-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ for i in ${COMPONENTS}; do
ALL_ARCHITECTURES=amd64 make --directory ${SCRIPT_ROOT}/pkg/${i} release
done

kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd.yaml
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-v1-crd-v1.yaml
kubectl create -f ${SCRIPT_ROOT}/deploy/vpa-rbac.yaml

for i in ${COMPONENTS}; do
Expand Down
54 changes: 54 additions & 0 deletions vertical-pod-autoscaler/hack/generate-crd-yaml.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/bash

# Copyright 2020 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -o errexit
set -o nounset
set -o pipefail

REPOSITORY_ROOT=$(realpath $(dirname ${BASH_SOURCE})/..)
CRD_OPTS=crd:trivialVersions=false,allowDangerousTypes=true
APIS_PATH=${REPOSITORY_ROOT}/pkg/apis
OUTPUT=${REPOSITORY_ROOT}/deploy/vpa-v1-crd-v1.yaml
WORKSPACE=$(mktemp -d)

function cleanup() {
rm -r ${WORKSPACE}
}
trap cleanup EXIT

if [[ -z $(which controller-gen) ]]; then
(
cd $WORKSPACE
go mod init tmp
go get sigs.k8s.io/controller-tools/cmd/controller-gen@v0.4.0
)
CONTROLLER_GEN=${GOBIN:-$(go env GOPATH)/bin}/controller-gen
else
CONTROLLER_GEN=$(which controller-gen)
fi

# The following commands always returns an error because controller-gen does not accept keys other than strings.
${CONTROLLER_GEN} ${CRD_OPTS} paths="${APIS_PATH}/..." output:crd:dir=${WORKSPACE} ||:

cd ${WORKSPACE}
cat <<EOF > kustomization.yaml
resources:
- autoscaling.k8s.io_verticalpodautoscalers.yaml
- autoscaling.k8s.io_verticalpodautoscalercheckpoints.yaml
commonAnnotations:
"api-approved.kubernetes.io": "https://github.com/kubernetes/kubernetes/pull/63797"
EOF
kubectl kustomize . > ${OUTPUT}
2 changes: 1 addition & 1 deletion vertical-pod-autoscaler/hack/vpa-process-yamls.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ if [ $# -gt 2 ]; then
fi

ACTION=$1
COMPONENTS="vpa-v1-crd vpa-rbac updater-deployment recommender-deployment admission-controller-deployment"
COMPONENTS="vpa-v1-crd-v1 vpa-rbac updater-deployment recommender-deployment admission-controller-deployment"
case ${ACTION} in
delete|diff|print) COMPONENTS+=" vpa-beta2-crd" ;;
esac
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ limitations under the License.

// Package v1 contains definitions of Vertical Pod Autoscaler related objects.
// +groupName=autoscaling.k8s.io
// +kubebuilder:object:generate=true
package v1
16 changes: 10 additions & 6 deletions vertical-pod-autoscaler/pkg/apis/autoscaling.k8s.io/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,13 @@ type VerticalPodAutoscalerList struct {

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

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

// Specification of the behavior of the autoscaler.
Expand Down Expand Up @@ -96,6 +95,7 @@ type PodUpdatePolicy struct {
}

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

const (
Expand Down Expand Up @@ -167,6 +167,7 @@ const (

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

const (
Expand All @@ -177,6 +178,7 @@ const (
)

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

const (
Expand Down Expand Up @@ -286,13 +288,12 @@ type VerticalPodAutoscalerCondition struct {
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:resource:shortName=vpacheckpoint

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

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

// Version of the format of the stored data.
Expand Down Expand Up @@ -353,6 +355,8 @@ type HistogramCheckpoint struct {
ReferenceTimestamp metav1.Time `json:"referenceTimestamp,omitempty" protobuf:"bytes,1,opt,name=referenceTimestamp"`

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

// Sum of samples to be used as denominator for weights from BucketWeights.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ limitations under the License.

// Package v1beta1 contains definitions of Vertical Pod Autoscaler related objects.
// +groupName=autoscaling.k8s.io
// +kubebuilder:skip
package v1beta1
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ limitations under the License.

// Package v1beta2 contains definitions of Vertical Pod Autoscaler related objects.
// +groupName=autoscaling.k8s.io
// +kubebuilder:object:generate=true
package v1beta2
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ type VerticalPodAutoscalerList struct {

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

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

// Specification of the behavior of the autoscaler.
Expand Down Expand Up @@ -96,6 +96,7 @@ type PodUpdatePolicy struct {
}

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

const (
Expand Down Expand Up @@ -157,6 +158,7 @@ const (

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

const (
Expand Down Expand Up @@ -265,13 +267,13 @@ type VerticalPodAutoscalerCondition struct {
// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:storageversion
// +kubebuilder:resource:shortName=vpacheckpoint

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

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

// Version of the format of the stored data.
Expand Down Expand Up @@ -332,6 +335,8 @@ type HistogramCheckpoint struct {
ReferenceTimestamp metav1.Time `json:"referenceTimestamp,omitempty" protobuf:"bytes,1,opt,name=referenceTimestamp"`

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

// Sum of samples to be used as denominator for weights from BucketWeights.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ limitations under the License.

// Package v1alpha1 contains definitions of Vertical Pod Autoscaler related objects.
// +groupName=poc.autoscaling.k8s.io
// +kubebuilder:skip
package v1alpha1

0 comments on commit b674b69

Please sign in to comment.