Skip to content

Commit

Permalink
[Core] Improve model adapter controller by handling existing resources (
Browse files Browse the repository at this point in the history
#54)

* Update ModelAdapter API definition

1. Clean up the conditions and only leave phase and []metav1.Condition
2. Enrich the phase and condition type

* Improve model adapter controller implementation

1. Update phase and conditions in the workflow
2. Initially support finalizer
3. Handle resource existing cases (status.instance, service & endpointslice etc)
  • Loading branch information
Jeffwan authored Jul 29, 2024
1 parent a5743da commit adeb124
Show file tree
Hide file tree
Showing 4 changed files with 384 additions and 182 deletions.
46 changes: 13 additions & 33 deletions api/model/v1alpha1/modeladapter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -49,61 +48,42 @@ const (
ModelAdapterPending ModelAdapterPhase = "Pending"
// ModelAdapterScheduling means the ModelAdapter is pending scheduling
ModelAdapterScheduling ModelAdapterPhase = "Scheduling"
// ModelAdapterBinding means the controller starts to load ModelAdapter on a selected pod
// ModelAdapterBinding means the controller loads ModelAdapter on a selected pod
ModelAdapterBinding ModelAdapterPhase = "Binding"
// ModelAdapterConfiguring means the controller starts to configure the service and endpoint for ModelAdapter
ModelAdapterConfiguring ModelAdapterPhase = "Configuring"
// ModelAdapterRunning means ModelAdapter has been running on the pod
ModelAdapterRunning ModelAdapterPhase = "Running"
// ModelAdapterFailed means ModelAdapter has terminated in a failure
ModelAdapterFailed ModelAdapterPhase = "Failed"
// ModelAdapterScaling means ModelAdapter is scaling, could be scaling in or out
// ModelAdapterScaling means ModelAdapter is scaling, could be scaling in or out. won't be enabled until we allow multiple replicas
ModelAdapterScaling ModelAdapterPhase = "Scaling"
)

// ModelAdapterStatus defines the observed state of ModelAdapter
type ModelAdapterStatus struct {

// Phase is a simple, high-level summary of where the ModelAdapter is in its lifecycle
// Phase maps to latest status.conditions.type
// +optional
Phase ModelAdapterPhase `json:"phase,omitempty"`
// Conditions represents the latest available observations of an object's state
// Conditions represents the observation of a model adapter's current state.
// +patchMergeKey=type
// +patchStrategy=merge
// +optional
Conditions []ModelAdapterCondition `json:"conditions,omitempty"`
// LastTransitionTime is the time the last Phase transitioned to the current one
// +optional
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`
// Reason is a unique, one-word, CamelCase reason for the phase's last transition
// +optional
Reason string `json:"reason,omitempty"`
// Message is a human-readable message indicating details about the last transition
// +optional
Message string `json:"message,omitempty"`
Conditions []metav1.Condition `json:"conditions,omitempty"`
// Instances lists all pod instances of ModelAdapter
// +optional
Instances []string `json:"instances,omitempty"`
}

type ModelAdapterConditionType string

// ModelAdapterCondition contains details for the current condition of this ModelAdapter
type ModelAdapterCondition struct {
// Type is the type of the condition
Type ModelAdapterConditionType `json:"type"`
// Status is the status of the condition
Status corev1.ConditionStatus `json:"status"`
// LastTransitionTime is the time the condition last transitioned from one status to another
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
// Reason is a unique, one-word, CamelCase reason for the condition's last transition
// +optional
Reason string `json:"reason,omitempty"`
// Message is a human-readable message indicating details about the transition
// +optional
Message string `json:"message,omitempty"`
}
const (
ModelAdapterConditionTypeInitialized ModelAdapterConditionType = "Initialized"
ModelAdapterConditionTypeSelectorMatched ModelAdapterConditionType = "SelectorMatched"
ModelAdapterConditionTypeScheduled ModelAdapterConditionType = "Scheduled"
ModelAdapterConditionTypeResourceCreated ModelAdapterConditionType = "ResourceCreated"
ModelAdapterConditionReady ModelAdapterConditionType = "Ready"
ModelAdapterConditionCleanup ModelAdapterConditionType = "Cleanup"
)

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
Expand Down
22 changes: 1 addition & 21 deletions api/model/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 55 additions & 27 deletions config/crd/bases/model.aibrix.ai_modeladapters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,32 +103,72 @@ spec:
description: ModelAdapterStatus defines the observed state of ModelAdapter
properties:
conditions:
description: Conditions represents the latest available observations
of an object's state
description: Conditions represents the observation of a model adapter's
current state.
items:
description: ModelAdapterCondition contains details for the current
condition of this ModelAdapter
description: "Condition contains details for one aspect of the current
state of this API Resource.\n---\nThis struct is intended for
direct use as an array at the field path .status.conditions. For
example,\n\n\n\ttype FooStatus struct{\n\t // Represents the
observations of a foo's current state.\n\t // Known .status.conditions.type
are: \"Available\", \"Progressing\", and \"Degraded\"\n\t //
+patchMergeKey=type\n\t // +patchStrategy=merge\n\t // +listType=map\n\t
\ // +listMapKey=type\n\t Conditions []metav1.Condition `json:\"conditions,omitempty\"
patchStrategy:\"merge\" patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t
\ // other fields\n\t}"
properties:
lastTransitionTime:
description: LastTransitionTime is the time the condition last
transitioned from one status to another
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: Message is a human-readable message indicating
details about the transition
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: Reason is a unique, one-word, CamelCase reason
for the condition's last transition
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: Status is the status of the condition
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: Type is the type of the condition
description: |-
type of condition in CamelCase or in foo.example.com/CamelCase.
---
Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be
useful (see .node.status.conditions), the ability to deconflict is important.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
Expand All @@ -138,22 +178,10 @@ spec:
items:
type: string
type: array
lastTransitionTime:
description: LastTransitionTime is the time the last Phase transitioned
to the current one
format: date-time
type: string
message:
description: Message is a human-readable message indicating details
about the last transition
type: string
phase:
description: Phase is a simple, high-level summary of where the ModelAdapter
is in its lifecycle
type: string
reason:
description: Reason is a unique, one-word, CamelCase reason for the
phase's last transition
description: |-
Phase is a simple, high-level summary of where the ModelAdapter is in its lifecycle
Phase maps to latest status.conditions.type
type: string
type: object
type: object
Expand Down
Loading

0 comments on commit adeb124

Please sign in to comment.