Skip to content

Commit ed7d722

Browse files
committed
Add support for autoscaling to/from 0
Introduce support for autoscaling to/from 0 based on cluster-api contract. For this: - introduce a new controller for OSMT that updates status with capacity and nodeinfo - update e2e tests to include autoscaling scenario - add feature behind a featureGate - add a documentation page
1 parent 92268d3 commit ed7d722

34 files changed

+1589
-41
lines changed

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ e2e-templates: $(addprefix $(E2E_NO_ARTIFACT_TEMPLATES_DIR)/, \
195195
cluster-template-no-bastion.yaml \
196196
cluster-template-health-monitor.yaml \
197197
cluster-template-capi-v1beta1.yaml \
198-
cluster-template-cluster-identity.yaml)
198+
cluster-template-cluster-identity.yaml \
199+
cluster-template-topology-autoscaler.yaml)
199200
# Currently no templates that require CI artifacts
200201
# $(addprefix $(E2E_TEMPLATES_DIR)/, add-templates-here.yaml) \
201202
@@ -333,6 +334,7 @@ generate-codegen: generate-controller-gen $(OPENAPI_GEN) $(APPLYCONFIGURATION_GE
333334
k8s.io/api/core/v1 \
334335
k8s.io/apimachinery/pkg/apis/meta/v1 \
335336
k8s.io/apimachinery/pkg/runtime \
337+
k8s.io/apimachinery/pkg/api/resource \
336338
k8s.io/apimachinery/pkg/version
337339
@echo "** Generating openapi.json **"
338340
go run ./cmd/models-schema | jq > ./openapi.json

api/v1beta1/openstackmachinetemplate_types.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package v1beta1
1818

1919
import (
20+
corev1 "k8s.io/api/core/v1"
2021
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2122
)
2223

@@ -25,17 +26,39 @@ type OpenStackMachineTemplateSpec struct {
2526
Template OpenStackMachineTemplateResource `json:"template"`
2627
}
2728

29+
// OpenStackMachineTemplateStatus defines the observed state of OpenStackMachineTemplate.
30+
type OpenStackMachineTemplateStatus struct {
31+
// Capacity defines the resource capacity for this machine.
32+
// This value is used for autoscaling from zero operations as defined in:
33+
// https://github.com/kubernetes-sigs/cluster-api/blob/main/docs/proposals/20210310-opt-in-autoscaling-from-zero.md
34+
// +optional
35+
Capacity corev1.ResourceList `json:"capacity,omitempty"`
36+
// +optional
37+
NodeInfo NodeInfo `json:"nodeInfo,omitempty,omitzero"`
38+
}
39+
40+
// NodeInfo contains information about the node's architecture and operating system.
41+
// +kubebuilder:validation:MinProperties=1
42+
type NodeInfo struct {
43+
// operatingSystem is a string representing the operating system of the node.
44+
// This may be a string like 'linux' or 'windows'.
45+
// +optional
46+
OperatingSystem string `json:"operatingSystem,omitempty"`
47+
}
48+
2849
// +genclient
2950
// +kubebuilder:object:root=true
3051
// +kubebuilder:storageversion
3152
// +kubebuilder:resource:path=openstackmachinetemplates,scope=Namespaced,categories=cluster-api,shortName=osmt
53+
// +kubebuilder:subresource:status
3254

3355
// OpenStackMachineTemplate is the Schema for the openstackmachinetemplates API.
3456
type OpenStackMachineTemplate struct {
3557
metav1.TypeMeta `json:",inline"`
3658
metav1.ObjectMeta `json:"metadata,omitempty"`
3759

38-
Spec OpenStackMachineTemplateSpec `json:"spec,omitempty"`
60+
Spec OpenStackMachineTemplateSpec `json:"spec,omitempty"`
61+
Status OpenStackMachineTemplateStatus `json:"status,omitempty"`
3962
}
4063

4164
// +kubebuilder:object:root=true
@@ -50,3 +73,11 @@ type OpenStackMachineTemplateList struct {
5073
func init() {
5174
objectTypes = append(objectTypes, &OpenStackMachineTemplate{}, &OpenStackMachineTemplateList{})
5275
}
76+
77+
// GetIdentifyRef returns the object's namespace and IdentityRef if it has an IdentityRef, or nulls if it does not.
78+
func (r *OpenStackMachineTemplate) GetIdentityRef() (*string, *OpenStackIdentityReference) {
79+
if r.Spec.Template.Spec.IdentityRef != nil {
80+
return &r.Namespace, r.Spec.Template.Spec.IdentityRef
81+
}
82+
return nil, nil
83+
}

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api_violations.report

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@ API rule violation: names_match,k8s.io/api/core/v1,RBDVolumeSource,RBDPool
7373
API rule violation: names_match,k8s.io/api/core/v1,RBDVolumeSource,RadosUser
7474
API rule violation: names_match,k8s.io/api/core/v1,VolumeSource,CephFS
7575
API rule violation: names_match,k8s.io/api/core/v1,VolumeSource,StorageOS
76+
API rule violation: names_match,k8s.io/apimachinery/pkg/api/resource,Quantity,Format
77+
API rule violation: names_match,k8s.io/apimachinery/pkg/api/resource,Quantity,d
78+
API rule violation: names_match,k8s.io/apimachinery/pkg/api/resource,Quantity,i
79+
API rule violation: names_match,k8s.io/apimachinery/pkg/api/resource,Quantity,s
80+
API rule violation: names_match,k8s.io/apimachinery/pkg/api/resource,int64Amount,scale
81+
API rule violation: names_match,k8s.io/apimachinery/pkg/api/resource,int64Amount,value
7682
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,APIResourceList,APIResources
7783
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,Duration,Duration
7884
API rule violation: names_match,k8s.io/apimachinery/pkg/apis/meta/v1,InternalEvent,Object

0 commit comments

Comments
 (0)