Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ agents-api/
- `github.com/go-bindata/go-bindata` v3.1.2
- `google.golang.org/protobuf` v1.36.9
- **Code Generation Tools**:
- `controller-gen` v0.16.5 (downloaded to `./bin/`)
- `controller-gen` v0.18.0 (downloaded to `./bin/`)
- `openapi-gen` (version derived from go.mod)

## Build Commands
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ generate: controller-gen

CONTROLLER_GEN = $(shell pwd)/bin/controller-gen
controller-gen: ## Download controller-gen locally if necessary.
ifeq ("$(shell $(CONTROLLER_GEN) --version 2> /dev/null)", "Version: v0.16.5")
ifeq ("$(shell $(CONTROLLER_GEN) --version 2> /dev/null)", "Version: v0.18.0")
else
rm -rf $(CONTROLLER_GEN)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.16.5)
$(call go-get-tool,$(CONTROLLER_GEN),sigs.k8s.io/controller-tools/cmd/controller-gen@v0.18.0)
endif

OPENAPI_GEN = $(shell pwd)/bin/openapi-gen
Expand Down
349 changes: 349 additions & 0 deletions agents/crds/agents.kruise.io_poolautoscalers.yaml

Large diffs are not rendered by default.

16 changes: 12 additions & 4 deletions agents/crds/agents.kruise.io_sandboxclaims.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,12 @@ spec:
x-kubernetes-int-or-string: true
description: |-
Limits specifies the target resource limits for each container.
Only CPU is supported for now. The container's original limit must already be set;
otherwise the value is ignored.
Only CPU and memory are supported; other resource names are rejected.
The container's original limit must already be set; otherwise the value is ignored.
A limit must not be lower than the target request of the same resource.
Memory may only be increased: a target lower than the container's current memory is rejected.
Memory resize may restart the container when the pod template declares
resizePolicy: {resourceName: memory, restartPolicy: RestartContainer}.
The new value must not change the Pod's QoS class; otherwise the claim will be rejected.
type: object
requests:
Expand All @@ -148,8 +152,12 @@ spec:
x-kubernetes-int-or-string: true
description: |-
Requests specifies the target resource requests for each container.
Only CPU is supported for now. The container's original request must already be set;
otherwise the value is ignored.
Only CPU and memory are supported; other resource names are rejected.
The container's original request must already be set; otherwise the value is ignored.
A request must not exceed the target limit of the same resource.
Memory may only be increased: a target lower than the container's current memory is rejected.
Memory resize may restart the container when the pod template declares
resizePolicy: {resourceName: memory, restartPolicy: RestartContainer}.
The new value must not change the Pod's QoS class; otherwise the claim will be rejected.
type: object
type: object
Expand Down
337 changes: 336 additions & 1 deletion agents/crds/agents.kruise.io_sandboxes.yaml

Large diffs are not rendered by default.

318 changes: 313 additions & 5 deletions agents/crds/agents.kruise.io_sandboxsets.yaml

Large diffs are not rendered by default.

290 changes: 290 additions & 0 deletions agents/crds/agents.kruise.io_sandboxtemplates.yaml

Large diffs are not rendered by default.

17 changes: 7 additions & 10 deletions agents/v1alpha1/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,6 @@ const (
// SandboxHashImmutablePart represents the key of sandbox hash than exclude immutable part of sandbox
// e.g. metadata, image and resources
SandboxHashImmutablePart = "sandbox.agents.kruise.io/hash-immutable-part"

// AnnotationWakeOnTraffic enables wake-on-traffic for a paused sandbox.
// When set to "true", the sandbox-gateway will attempt to resume the sandbox
// by patching Spec.Paused=false when traffic arrives.
AnnotationWakeOnTraffic = InternalPrefix + "wake-on-traffic"

// AnnotationWakeTimeoutSeconds stores the auto-pause timeout (in seconds) to
// apply when the sandbox is woken by traffic. The gateway reads this to set
// ResumeOptions.Timeout.PauseTime, re-arming auto-pause after wake.
AnnotationWakeTimeoutSeconds = InternalPrefix + "wake-timeout-seconds"
)

// E2B annotations
Expand All @@ -114,3 +104,10 @@ const (
// patches the template and removes this annotation to trigger the actual
// pod replacement.
const AnnotationUpgradeResumeTrigger = InternalPrefix + "upgrade-resume-trigger"

// AnnotationPodProbe is the annotation key used by the PodProbeMarker Serverless
// protocol. The sandbox controller writes probe definitions to this annotation
// on the Pod, and the agent-runtime sidecar reads them, executes the probes,
// and writes results to Pod.Status.Conditions.
// See: https://openkruise.io/docs/user-manuals/podprobemarker#support-for-serverless-scenarios
const AnnotationPodProbe = "kruise.io/podprobe"
250 changes: 250 additions & 0 deletions agents/v1alpha1/poolautoscaler_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
/*
Copyright 2026.

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.
*/

package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/intstr"
)

// CrossVersionObjectReference contains enough information to let you identify the referred resource.
type CrossVersionObjectReference struct {
// Kind of the referent; More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
// +required
// +kubebuilder:validation:Enum=SandboxSet
Kind string `json:"kind"`
// Name of the referent; More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
// +required
Name string `json:"name"`
// API version of the referent
// +optional
APIVersion string `json:"apiVersion,omitempty"`
}

// PoolAutoscalerSpec describes the desired functionality of the PoolAutoscaler.
// +kubebuilder:validation:XValidation:rule="self.minReplicas <= self.maxReplicas",message="minReplicas must not be greater than maxReplicas"
type PoolAutoscalerSpec struct {
// ScaleTargetRef points to the target warming pool to scale, and is used to select the pods for which instance status
// should be collected, as well as to actually change the replica count.
// +required
ScaleTargetRef CrossVersionObjectReference `json:"scaleTargetRef"`

// MaxReplicas is the upper limit for the number of replicas to which the autoscaler can scale up.
// It cannot be less than minReplicas.
// +required
// +kubebuilder:validation:Minimum=1
MaxReplicas int32 `json:"maxReplicas"`

// MinReplicas is the lower limit for the number of replicas to which the autoscaler
// can scale down. It defaults to 0 pods.
// +optional
// +kubebuilder:validation:Minimum=0
// +kubebuilder:default=0
MinReplicas int32 `json:"minReplicas"`

// CronPolicies is a list of potential cron scaling policies which can be used during scaling.
// When both CronPolicies and CapacityPolicy are set, CronPolicies takes higher priority.
// +optional
// +listType=map
// +listMapKey=name
// +kubebuilder:validation:MaxItems=20
CronPolicies []CronScalingPolicy `json:"cronPolicies,omitempty"`

// CapacityPolicy defines the capacity configuration of the target resource pool.
// +optional
CapacityPolicy *CapacityPolicy `json:"capacityPolicy,omitempty"`

// Suspend tells the controller to suspend subsequent executions.
// Defaults to false.
// +optional
Suspend *bool `json:"suspend,omitempty"`
}

// CronScalingPolicy defines the cron-based scaling configuration for the resource pool.
type CronScalingPolicy struct {
// Name is used to specify the scaling policy.
// +required
Name string `json:"name"`

// TimeZone is the time zone name for the given schedule, e.g. "Asia/Shanghai", "UTC".
// If not specified, this will default to the time zone of the autoscaler controller manager process.
// +optional
TimeZone *string `json:"timeZone,omitempty"`

// Schedule is a cron expression that defines when this policy should be executed.
// Supports standard cron format with 5 fields (minute hour day month weekday).
// +required
Schedule string `json:"schedule"`

// TargetReplicas is the desired replicas when this policy executes.
// +required
// +kubebuilder:validation:Minimum=0
TargetReplicas int32 `json:"targetReplicas"`
}

// CapacityPolicy defines the capacity configuration of the target resource pool.
type CapacityPolicy struct {
// TargetAvailable is the desired available replicas.
// Can be an absolute number (ex: 5) or a percentage of current replicas (ex: 70%).
// When the pool is empty, a percentage target is bootstrapped against
// maxReplicas so the pool can seed its initial idle capacity.
// +required
TargetAvailable intstr.IntOrString `json:"targetAvailable"`

// Tolerance is the tolerance between the watermark and desired value under which
// no updates are made to the desired number of replicas.
// Can be an absolute number (ex: 5) or a percentage (ex: 10%).
// If not set, defaults to 10%.
// A percentage tolerance is always resolved against the target value:
// when targetAvailable is also a percentage, both percentages are combined
// first and applied to the pool size; when targetAvailable is an absolute
// number, the percentage tolerance is applied to that resolved target
// (e.g. targetAvailable=5 with tolerance=10% yields watermarks [4, 6]).
// +optional
Tolerance *intstr.IntOrString `json:"tolerance,omitempty"`

// ScaleUp is the scaling rule for scaling up.
// +optional
ScaleUp *CapacityScalingRules `json:"scaleUp,omitempty"`

// ScaleDown is the scaling rule for scaling down.
// +optional
ScaleDown *CapacityScalingRules `json:"scaleDown,omitempty"`
}

// CapacityScalingRules configures the scaling behavior for one direction.
type CapacityScalingRules struct {
// StabilizationWindowSeconds is the cooldown period after any scale action before
// a scale in this direction is allowed. This is a cooldown model: the first scale
// action is immediate, subsequent actions must wait for the window to elapse since
// the most recent scale action (in either direction).
// Must be >= 60 and <= 3600 (one hour) when set.
// Scale-up defaults to 60 seconds when omitted and is normalized at runtime to at
// least the process-wide Sandbox Pending timeout plus 10 seconds.
// Scale-down defaults to 300 seconds when omitted.
// +optional
// +kubebuilder:validation:Minimum=60
// +kubebuilder:validation:Maximum=3600
StabilizationWindowSeconds *int32 `json:"stabilizationWindowSeconds,omitempty"`
}

// PoolAutoscalerStatus describes the current status of a pool autoscaler.
type PoolAutoscalerStatus struct {
// ObservedGeneration is the most recent generation observed by this autoscaler.
// +optional
ObservedGeneration int64 `json:"observedGeneration,omitempty"`

// LastScaleTime is the last time the PoolAutoscaler scaled the number of pods.
// +optional
LastScaleTime *metav1.Time `json:"lastScaleTime,omitempty"`

// CurrentReplicas is current number of replicas of pods managed by this autoscaler.
CurrentReplicas int32 `json:"currentReplicas"`

// DesiredReplicas is the desired number of replicas of pods managed by this autoscaler.
DesiredReplicas int32 `json:"desiredReplicas"`

// Suspended indicates whether the autoscaler is currently suspended.
// +optional
Suspended bool `json:"suspended,omitempty"`

// AppliedCronPolicies is the execution status of cron policies.
// +optional
// +listType=map
// +listMapKey=name
AppliedCronPolicies []CronScalingPolicyStatus `json:"appliedCronPolicies,omitempty"`

// CurrentCapacity is the last read state of the capacity used by this autoscaler.
// +optional
CurrentCapacity CapacityStatus `json:"currentCapacity,omitempty"`

// Conditions is the set of conditions required for this autoscaler to scale its target.
// +optional
// +listType=map
// +listMapKey=type
Conditions []metav1.Condition `json:"conditions,omitempty"`
}

// CronScalingPolicyStatus records the last schedule time for a cron policy.
type CronScalingPolicyStatus struct {
// Name is the cron policy name.
Name string `json:"name"`

// LastScheduleTime is the last time the policy was successfully scheduled.
// +optional
LastScheduleTime *metav1.Time `json:"lastScheduleTime,omitempty"`
}

// CapacityStatus records the current capacity observed by the autoscaler.
type CapacityStatus struct {
// Available is current number of available pods managed by this autoscaler.
Available int32 `json:"available"`
}

// PoolAutoscalerConditionType are the valid conditions of a PoolAutoscaler.
type PoolAutoscalerConditionType string

const (
// PoolAutoscalerConditionScalingActive indicates that the autoscaler is able to scale.
PoolAutoscalerConditionScalingActive PoolAutoscalerConditionType = "ScalingActive"
// PoolAutoscalerConditionAbleToScale indicates that the autoscaler is able to calculate and set scale.
PoolAutoscalerConditionAbleToScale PoolAutoscalerConditionType = "AbleToScale"
// PoolAutoscalerConditionScalingLimited indicates that the autoscaler is constrained by min/max bounds.
PoolAutoscalerConditionScalingLimited PoolAutoscalerConditionType = "ScalingLimited"
)

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:path=poolautoscalers,shortName={pa},singular=poolautoscaler
// +kubebuilder:storageversion
// +kubebuilder:printcolumn:name="Reference",type="string",JSONPath=".spec.scaleTargetRef.name"
// +kubebuilder:printcolumn:name="MinReplicas",type="integer",JSONPath=".spec.minReplicas"
// +kubebuilder:printcolumn:name="MaxReplicas",type="integer",JSONPath=".spec.maxReplicas"
// +kubebuilder:printcolumn:name="CurrentReplicas",type="integer",JSONPath=".status.currentReplicas"
// +kubebuilder:printcolumn:name="DesiredReplicas",type="integer",JSONPath=".status.desiredReplicas"
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"

// PoolAutoscaler is the configuration for a warming pool autoscaler,
// which automatically manages the replica count of the warming pool
// based on the policies specified.
type PoolAutoscaler struct {
metav1.TypeMeta `json:",inline"`

// +optional
metav1.ObjectMeta `json:"metadata,omitempty,omitzero"`

// Spec defines the desired behavior of the autoscaler.
Spec PoolAutoscalerSpec `json:"spec"`

// Status is the current information about the autoscaler.
// +optional
Status PoolAutoscalerStatus `json:"status,omitempty"`
}

// +kubebuilder:object:root=true

// PoolAutoscalerList contains a list of PoolAutoscaler.
type PoolAutoscalerList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []PoolAutoscaler `json:"items"`
}

func init() {
SchemeBuilder.Register(&PoolAutoscaler{}, &PoolAutoscalerList{})
}
Loading
Loading