Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(operator): Add Status.AvailableReplicas to Model CRD #5873

Merged
merged 4 commits into from
Jan 29, 2025
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
11 changes: 11 additions & 0 deletions k8s/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
* The generation of helm charts and yaml manifests relies on kubebuilder-generated manifests in
`../operator/config/[files]`.

* If you have modified CRD definitions in the operator (`../operator/apis/mlops/v1alpha1/*` and
dependencies), you must first run `make manifests` in the operator directory to update the manifests.
Only then you should run `make create` in this directory.

* Never modify files in `../operator/config/[files]` manually. These files are generated by
kubebuilder. Instead, modify the CRD definitions in the operator code


Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file generated by make create in [seldon-core-2-root]/k8s dir

Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,13 @@ spec:
jsonPath: .status.conditions[?(@.type=="ModelReady")].status
name: Ready
type: string
- description: Number of replicas
jsonPath: .status.replicas
name: Replicas
- description: Number of desired replicas
jsonPath: .spec.replicas
name: Desired Replicas
type: integer
- description: Number of replicas available to receive inference requests
jsonPath: .status.availableReplicas
name: Available Replicas
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -327,6 +331,10 @@ spec:
roughly akin to Annotations on any k8s resource, just the reconciler conveying
richer information outwards.
type: object
availableReplicas:
description: Number of available replicas
format: int32
type: integer
conditions:
description: Conditions the latest available observations of a resource's
current state.
Expand Down
14 changes: 11 additions & 3 deletions k8s/yaml/crds.yaml
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file generated by make create in [seldon-core-2-root]/k8s dir

Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,13 @@ spec:
jsonPath: .status.conditions[?(@.type=="ModelReady")].status
name: Ready
type: string
- description: Number of replicas
jsonPath: .status.replicas
name: Replicas
- description: Number of desired replicas
jsonPath: .spec.replicas
name: Desired Replicas
type: integer
- description: Number of replicas available to receive inference requests
jsonPath: .status.availableReplicas
name: Available Replicas
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -330,6 +334,10 @@ spec:
roughly akin to Annotations on any k8s resource, just the reconciler conveying
richer information outwards.
type: object
availableReplicas:
description: Number of available replicas
format: int32
type: integer
conditions:
description: Conditions the latest available observations of a resource's
current state.
Expand Down
11 changes: 7 additions & 4 deletions operator/apis/mlops/v1alpha1/model_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,17 +126,20 @@ type InferenceArtifactSpec struct {
// ModelStatus defines the observed state of Model
type ModelStatus struct {
// Total number of replicas targeted by this model
Replicas int32 `json:"replicas,omitempty"`
Selector string `json:"selector,omitempty"`
duckv1.Status `json:",inline"`
Replicas int32 `json:"replicas,omitempty"`
Selector string `json:"selector,omitempty"`
// Number of available replicas
AvailableReplicas int32 `json:"availableReplicas,omitempty"`
duckv1.Status `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status
//+kubebuilder:resource:shortName=mlm
//+kubebuilder:subresource:scale:specpath=.spec.replicas,statuspath=.status.replicas,selectorpath=.status.selector
//+kubebuilder:printcolumn:name="Ready",type=string,JSONPath=`.status.conditions[?(@.type=="ModelReady")].status`,description="Model ready status"
//+kubebuilder:printcolumn:name="Replicas",type=integer,JSONPath=`.status.replicas`, description="Number of replicas"
//+kubebuilder:printcolumn:name="Desired Replicas",type=integer,JSONPath=`.spec.replicas`,description="Number of desired replicas"
//+kubebuilder:printcolumn:name="Available Replicas",type=integer,JSONPath=`.status.availableReplicas`,description="Number of replicas available to receive inference requests"
//+kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`

// Model is the Schema for the models API
Expand Down
14 changes: 11 additions & 3 deletions operator/config/crd/bases/mlops.seldon.io_models.yaml
Copy link
Member Author

@lc525 lc525 Sep 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file generated by kubebuilder via make manifests in [seldon-core-2-root]/operator dir

Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ spec:
jsonPath: .status.conditions[?(@.type=="ModelReady")].status
name: Ready
type: string
- description: Number of replicas
jsonPath: .status.replicas
name: Replicas
- description: Number of desired replicas
jsonPath: .spec.replicas
name: Desired Replicas
type: integer
- description: Number of replicas available to receive inference requests
jsonPath: .status.availableReplicas
name: Available Replicas
type: integer
- jsonPath: .metadata.creationTimestamp
name: Age
Expand Down Expand Up @@ -171,6 +175,10 @@ spec:
roughly akin to Annotations on any k8s resource, just the reconciler conveying
richer information outwards.
type: object
availableReplicas:
description: Number of available replicas
format: int32
type: integer
conditions:
description: Conditions the latest available observations of a resource's
current state.
Expand Down
3 changes: 3 additions & 0 deletions operator/scheduler/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ func (s *SchedulerClient) SubscribeModelEvents(ctx context.Context, grpcClient s
modelStatus.GetAvailableReplicas() +
modelStatus.GetUnavailableReplicas(),
)
latestModel.Status.AvailableReplicas = int32(
modelStatus.GetAvailableReplicas(),
)
latestModel.Status.Selector = "server=" + latestVersionStatus.ServerName
return s.updateModelStatus(ctxWithTimeout, latestModel)
})
Expand Down
1 change: 1 addition & 0 deletions scheduler/pkg/scheduler/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ func (s *SimpleScheduler) scheduleToServer(modelName string) error {
logger.
WithField("candidate_servers", filteredServers).
WithField("desired_replicas", desiredReplicas).
WithField("min_replicas", minReplicas).
Debug("Identified candidate servers for model")

// The main logic of trying to find a server for the model is as follows:
Expand Down
3 changes: 2 additions & 1 deletion scheduler/pkg/store/memory_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,8 @@ func updateModelState(isLatest bool, modelVersion *ModelVersion, prevModelVersio
}

func (m *MemoryStore) FailedScheduling(modelVersion *ModelVersion, reason string, reset bool) {
availableReplicas := modelVersion.state.AvailableReplicas
// we use len of GetAssignment instead of .state.AvailableReplicas as it is more accurate in this context
availableReplicas := uint32(len(modelVersion.GetAssignment()))

modelVersion.state = ModelStatus{
State: ScheduleFailed,
Expand Down
Loading