Skip to content

Add RoleSet and StormService detail spec #1226

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

Merged
merged 1 commit into from
Jun 25, 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
122 changes: 122 additions & 0 deletions api/orchestration/v1alpha1/condition.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*
Copyright 2025 The Aibrix Team.

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 (
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// A ConditionType represents a condition a resource could be in.
type ConditionType string

// A Condition that may apply to a resource.
type Condition struct {
// Type of this condition. At most one of each condition type may apply to a resource at any point in time.
Type ConditionType `json:"type"`

// Status of this condition; is it currently True, False, or Unknown?
Status corev1.ConditionStatus `json:"status"`

// LastTransitionTime is the last time this condition transitioned from one status to another.
// +optional
LastTransitionTime *metav1.Time `json:"lastTransitionTime,omitempty"`

// LastUpdateTime is the last time this condition was updated.
// +optional
LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"`

// LastUpdateMicroTime is the last time with microsecond level precision this condition was updated.
// +optional
LastUpdateMicroTime *metav1.MicroTime `json:"lastUpdateMicroTime,omitempty"`

// The Reason for the condition's last transition.
Reason string `json:"reason,omitempty"`

// A Message containing details about this condition's last transition from one status to another, if any.
// +optional
Message string `json:"message,omitempty"`
}

func NewCondition(ct ConditionType, status corev1.ConditionStatus, msg string) Condition {
return Condition{
Type: ct,
Status: status,
Message: msg,
}
Comment on lines +55 to +60

Choose a reason for hiding this comment

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

medium

Consider adding a comment explaining what this function does and the meaning of its parameters.

}

// Conditions reflects the observed status of a resource. Only
// one condition of each type may exist.
type Conditions []Condition

// GetCondition returns the condition for the given ConditionType if exists,
// otherwise returns nil
func (s Conditions) GetCondition(ct ConditionType) Condition {
for _, c := range s {
if c.Type == ct {
return c
}
}

return Condition{Type: ct, Status: corev1.ConditionUnknown}
}

// SetConditions sets the supplied conditions, replacing any existing conditions
// of the same type. This is a no-op if all supplied conditions are identical,
// ignoring the last transition time, to those already set.
func (s *Conditions) SetConditions(conditions ...Condition) {
for _, c := range conditions {
found := false
for i := range *s {
ref := &(*s)[i]
if ref.Type != c.Type {
continue
}

found = true

if ref.Equal(&c) {
if !c.LastUpdateTime.Equal(ref.LastUpdateTime) {
ref.LastUpdateTime = c.LastUpdateTime
}
if !c.LastUpdateMicroTime.Equal(ref.LastUpdateMicroTime) {
ref.LastUpdateMicroTime = c.LastUpdateMicroTime
}
continue
}
if ref.Status != c.Status {
now := metav1.Now()
c.LastTransitionTime = &now
}
*ref = c
}
if !found {
now := metav1.Now()
c.LastTransitionTime = &now
*s = append(*s, c)
}
}
}

// Equal used to judge weather two condition is equal.
// LastTransitionTime, LastUpdateTime and LastUpdateMicroTime is ignored.
func (c *Condition) Equal(candidate *Condition) bool {
return c.Message == candidate.Message &&
c.Type == candidate.Type &&
c.Status == candidate.Status
}
5 changes: 5 additions & 0 deletions api/orchestration/v1alpha1/groupversion_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ import (
"sigs.k8s.io/controller-runtime/pkg/scheme"
)

const (
StormServiceKind = "StormService"
RoleSetKind = "RoleSet"
)

var (
// GroupVersion is group version used to register these objects
GroupVersion = schema.GroupVersion{Group: "orchestration.aibrix.ai", Version: "v1alpha1"}
Expand Down
104 changes: 95 additions & 9 deletions api/orchestration/v1alpha1/roleset_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,111 @@ limitations under the License.
package v1alpha1

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

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
// let's temporarily use godel scheduler's definition, consider to switch to community definitions
schedv1alpha1 "github.com/kubewharf/godel-scheduler-api/pkg/apis/scheduling/v1alpha1"
Comment on lines +24 to +25

Choose a reason for hiding this comment

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

medium

This comment is useful, but consider expanding it to explain why Godel scheduler's definition is being used temporarily and what the criteria for switching to community definitions would be.

)

// RoleSetSpec defines the desired state of RoleSet
type RoleSetSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file
Roles []RoleSpec `json:"roles,omitempty"`

// +optional
UpdateStrategy RoleSetUpdateStrategyType `json:"updateStrategy,omitempty"`

// +optional
SchedulingStrategy SchedulingStrategy `json:"schedulingStrategy,omitempty"`
}

// Foo is an example field of RoleSet. Edit roleset_types.go to remove/update
Foo string `json:"foo,omitempty"`
// +enum
type SchedulingStrategy struct {
PodGroup *schedv1alpha1.PodGroupSpec `json:"podGroup,omitempty"`
}

// +enum
type RoleSetUpdateStrategyType string

const (
// ParallelRoleSetUpdateStrategyType update all roles in parallel
ParallelRoleSetUpdateStrategyType RoleSetUpdateStrategyType = "Parallel"
// SequentialRoleSetStrategyType update all roles in sequential
SequentialRoleSetStrategyType RoleSetUpdateStrategyType = "Sequential"
// InterleaveRoleSetStrategyType update all roles in interleave, follow the rolling step defined in roles
InterleaveRoleSetStrategyType RoleSetUpdateStrategyType = "Interleave"
)

type DisruptionTolerance struct {
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty"`
}

type RoleSpec struct {
Name string `json:"name,omitempty"`

// Replicas is the number of desired replicas.
// +optional
Replicas *int32 `json:"replicas,omitempty"`

// +optional
// +patchStrategy=retainKeys
UpdateStrategy RoleUpdateStrategy `json:"updateStrategy,omitempty"`

// +optional
Stateful bool `json:"stateful,omitempty"`

// +optional
Template v1.PodTemplateSpec `json:"template,omitempty"`

// DisruptionTolerance indicates how many pods can be unavailable during the preemption/eviction.
// +optional
DisruptionTolerance DisruptionTolerance `json:"disruptionTolerance,omitempty"`
}

// +enum
type RoleUpdateStrategy struct {
// +optional
MaxUnavailable *intstr.IntOrString `json:"maxUnavailable,omitempty" protobuf:"bytes,1,opt,name=maxUnavailable"`

// +optional
MaxSurge *intstr.IntOrString `json:"maxSurge,omitempty" protobuf:"bytes,2,opt,name=maxSurge"`
}

// RoleSetStatus defines the observed state of RoleSet
type RoleSetStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
Roles []RoleStatus `json:"roles,omitempty"`
// +optional
// +patchMergeKey=type
// +patchStrategy=merge
Conditions Conditions `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type"`
}

// These are valid conditions of roleSet.
const (
// RoleSetReady means the roleSet meeting the minimal requirements for the roleSet to be considered ready.
RoleSetReady ConditionType = "Ready"
RoleSetReplicaFailure ConditionType = "ReplicaFailure"
RoleSetProgressing ConditionType = "Progressing"
)

type RoleStatus struct {
Name string `json:"name,omitempty"`

// Replicas is the most recently oberved number of replicas.
Replicas int32 `json:"replicas"`

// +optional
ReadyReplicas int32 `json:"readyReplicas,omitempty"`

// +optional
NotReadyReplicas int32 `json:"notReadyReplicas,omitempty"`

// +optional
UpdatedReplicas int32 `json:"updatedReplicas,omitempty"`

// +optional
UpdatedReadyReplicas int32 `json:"updatedReadyReplicas,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
Loading