Skip to content

Commit

Permalink
Update API
Browse files Browse the repository at this point in the history
- use int32 instead of uint32 in accordance to api-conventions[1]
- change some drain status fields to be mandatory so they are not
  omitted if unset.

Signed-off-by: adrianc <[email protected]>
  • Loading branch information
adrianchiris committed Aug 21, 2024
1 parent ec0c566 commit cddcc66
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 11 deletions.
3 changes: 2 additions & 1 deletion api/v1alpha1/maintenanceoperatorconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ type MaintenanceOperatorConfigSpec struct {
// should be less than idle time for any autoscaler that is running.
// default to 30m (1600 seconds)
// +kubebuilder:default=1600
MaxNodeMaintenanceTimeSeconds uint32 `json:"maxNodeMaintenanceTimeSeconds,omitempty"`
// +kubebuilder:validation:Minimum:=0
MaxNodeMaintenanceTimeSeconds int32 `json:"maxNodeMaintenanceTimeSeconds,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
13 changes: 8 additions & 5 deletions api/v1alpha1/nodemaintenance_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type WaitForPodCompletionSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default:=0
// +kubebuilder:validation:Minimum:=0
TimeoutSecond uint32 `json:"timeoutSeconds,omitempty"`
TimeoutSecond int32 `json:"timeoutSeconds,omitempty"`
}

// DrainSpec describes configuration for node drain during automatic upgrade
Expand All @@ -123,7 +123,7 @@ type DrainSpec struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default:=300
// +kubebuilder:validation:Minimum:=0
TimeoutSecond uint32 `json:"timeoutSeconds,omitempty"`
TimeoutSecond int32 `json:"timeoutSeconds,omitempty"`

// DeleteEmptyDir indicates if should continue even if there are pods using emptyDir
// (local data that will be deleted when the node is drained)
Expand Down Expand Up @@ -163,13 +163,16 @@ type NodeMaintenanceStatus struct {
// DrainStatus represents the status of draining for the node
type DrainStatus struct {
// TotalPods is the number of pods on the node at the time NodeMaintenance started draining
TotalPods uint32 `json:"totalPods,omitempty"`
// +kubebuilder:validation:Minimum:=0
TotalPods int32 `json:"totalPods"`

// EvictionPods is the total number of pods that need to be evicted at the time NodeMaintenance started draining
EvictionPods uint32 `json:"evictionPods,omitempty"`
// +kubebuilder:validation:Minimum:=0
EvictionPods int32 `json:"evictionPods"`

// DrainProgress represents the draining progress as percentage
DrainProgress uint32 `json:"drainProgress,omitempty"`
// +kubebuilder:validation:Minimum:=0
DrainProgress int32 `json:"drainProgress"`

// WaitForEviction is the list of namespaced named pods that need to be evicted
WaitForEviction []string `json:"waitForEviction,omitempty"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ spec:
should be less than idle time for any autoscaler that is running.
default to 30m (1600 seconds)
format: int32
minimum: 0
type: integer
maxParallelOperations:
anyOf:
Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/maintenance.nvidia.com_nodemaintenances.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -236,23 +236,30 @@ spec:
description: DrainProgress represents the draining progress as
percentage
format: int32
minimum: 0
type: integer
evictionPods:
description: EvictionPods is the total number of pods that need
to be evicted at the time NodeMaintenance started draining
format: int32
minimum: 0
type: integer
totalPods:
description: TotalPods is the number of pods on the node at the
time NodeMaintenance started draining
format: int32
minimum: 0
type: integer
waitForEviction:
description: WaitForEviction is the list of namespaced named pods
that need to be evicted
items:
type: string
type: array
required:
- drainProgress
- evictionPods
- totalPods
type: object
waitForCompletion:
description: WaitForCompletion is the list of namespaced named pods
Expand Down
6 changes: 3 additions & 3 deletions internal/controller/nodemaintenance_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,13 @@ func (r *NodeMaintenanceReconciler) updateDrainStatus(ctx context.Context, nm *m
}

nm.Status.Drain = &maintenancev1.DrainStatus{
TotalPods: uint32(len(podsOnNode.Items)),
EvictionPods: uint32(len(ds.PodsToDelete)),
TotalPods: int32(len(podsOnNode.Items)),
EvictionPods: int32(len(ds.PodsToDelete)),
}
}

removedPods := utils.MaxInt(int(nm.Status.Drain.EvictionPods)-len(ds.PodsToDelete), 0)
nm.Status.Drain.DrainProgress = uint32(float32(removedPods) / float32(nm.Status.Drain.EvictionPods) * 100)
nm.Status.Drain.DrainProgress = int32(float32(removedPods) / float32(nm.Status.Drain.EvictionPods) * 100)
nm.Status.Drain.WaitForEviction = ds.PodsToDelete

err = r.Client.Status().Update(ctx, nm)
Expand Down
2 changes: 1 addition & 1 deletion internal/drain/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ var _ = Describe("DrainRequest tests", func() {
It("returns expected Spec", func() {
spec := drainReq.Spec()
Expect(spec.NodeName).To(Equal(node.Name))
Expect(spec.Spec.TimeoutSecond).To(Equal(uint32(10)))
Expect(spec.Spec.TimeoutSecond).To(Equal(int32(10)))
})
})

Expand Down
2 changes: 1 addition & 1 deletion internal/podcompletion/podcompletion.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (p *podCompletionHandler) HandlePodCompletion(ctx context.Context, reqLog l
// check expire time
if nm.Spec.WaitForPodCompletion.TimeoutSecond > 0 {
timeNow := time.Now()
timeExpire := startTime.Add(time.Duration(nm.Spec.WaitForPodCompletion.TimeoutSecond * uint32(time.Second)))
timeExpire := startTime.Add(time.Duration(nm.Spec.WaitForPodCompletion.TimeoutSecond * int32(time.Second)))
if timeNow.After(timeExpire) {
reqLog.Error(nil, "HandlePodCompletion timeout reached")
return nil, ErrPodCompletionTimeout
Expand Down

0 comments on commit cddcc66

Please sign in to comment.