2023-04-10 15:36:59 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2018-06-22 00:35:07 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2018-08-30 21:33:50 +00:00
|
|
|
"time"
|
|
|
|
|
2023-07-10 17:20:15 +00:00
|
|
|
"github.com/hashicorp/nomad/client/pluginmanager/csimanager"
|
2018-06-22 00:35:07 +00:00
|
|
|
"github.com/hashicorp/nomad/nomad/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
// State captures the state of the allocation runner.
|
|
|
|
type State struct {
|
2018-07-19 00:06:44 +00:00
|
|
|
// ClientStatus captures the overall state of the allocation
|
|
|
|
ClientStatus string
|
2018-06-22 00:35:07 +00:00
|
|
|
|
2018-07-19 00:06:44 +00:00
|
|
|
// ClientDescription is an optional human readable description of the
|
2018-06-22 00:35:07 +00:00
|
|
|
// allocations client state
|
2018-07-19 00:06:44 +00:00
|
|
|
ClientDescription string
|
2018-06-22 00:35:07 +00:00
|
|
|
|
|
|
|
// DeploymentStatus captures the status of the deployment
|
|
|
|
DeploymentStatus *structs.AllocDeploymentStatus
|
2018-09-27 00:08:43 +00:00
|
|
|
|
|
|
|
// TaskStates is a snapshot of task states.
|
|
|
|
TaskStates map[string]*structs.TaskState
|
2020-10-12 17:43:04 +00:00
|
|
|
|
|
|
|
// NetworkStatus captures network details not known until runtime
|
|
|
|
NetworkStatus *structs.AllocNetworkStatus
|
2018-06-22 00:35:07 +00:00
|
|
|
}
|
2018-08-30 21:33:50 +00:00
|
|
|
|
|
|
|
// SetDeploymentStatus is a helper for updating the client-controlled
|
|
|
|
// DeploymentStatus fields: Healthy and Timestamp. The Canary and ModifyIndex
|
|
|
|
// fields should only be updated by the server.
|
|
|
|
func (s *State) SetDeploymentStatus(timestamp time.Time, healthy bool) {
|
|
|
|
if s.DeploymentStatus == nil {
|
|
|
|
s.DeploymentStatus = &structs.AllocDeploymentStatus{}
|
|
|
|
}
|
|
|
|
|
|
|
|
s.DeploymentStatus.Healthy = &healthy
|
|
|
|
s.DeploymentStatus.Timestamp = timestamp
|
|
|
|
}
|
|
|
|
|
|
|
|
// ClearDeploymentStatus is a helper to clear the client-controlled
|
|
|
|
// DeploymentStatus fields: Healthy and Timestamp. The Canary and ModifyIndex
|
|
|
|
// fields should only be updated by the server.
|
|
|
|
func (s *State) ClearDeploymentStatus() {
|
|
|
|
if s.DeploymentStatus == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
s.DeploymentStatus.Healthy = nil
|
|
|
|
s.DeploymentStatus.Timestamp = time.Time{}
|
|
|
|
}
|
2018-09-27 00:08:43 +00:00
|
|
|
|
|
|
|
// Copy returns a deep copy of State.
|
|
|
|
func (s *State) Copy() *State {
|
|
|
|
taskStates := make(map[string]*structs.TaskState, len(s.TaskStates))
|
|
|
|
for k, v := range s.TaskStates {
|
|
|
|
taskStates[k] = v.Copy()
|
|
|
|
}
|
|
|
|
return &State{
|
|
|
|
ClientStatus: s.ClientStatus,
|
|
|
|
ClientDescription: s.ClientDescription,
|
|
|
|
DeploymentStatus: s.DeploymentStatus.Copy(),
|
|
|
|
TaskStates: taskStates,
|
2020-10-12 17:43:04 +00:00
|
|
|
NetworkStatus: s.NetworkStatus.Copy(),
|
2018-09-27 00:08:43 +00:00
|
|
|
}
|
|
|
|
}
|
2019-05-07 19:54:36 +00:00
|
|
|
|
|
|
|
// ClientTerminalStatus returns if the client status is terminal and will no longer transition
|
2021-12-20 10:44:21 +00:00
|
|
|
func (s *State) ClientTerminalStatus() bool {
|
|
|
|
switch s.ClientStatus {
|
2019-05-07 19:54:36 +00:00
|
|
|
case structs.AllocClientStatusComplete, structs.AllocClientStatusFailed, structs.AllocClientStatusLost:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
2023-07-10 17:20:15 +00:00
|
|
|
|
|
|
|
type AllocVolumes struct {
|
|
|
|
CSIVolumes map[string]*CSIVolumeStub // volume request name -> CSIVolumeStub
|
|
|
|
}
|
|
|
|
|
|
|
|
// CSIVolumeStub is a stripped-down version of the CSIVolume with just the
|
|
|
|
// relevant data that we need to persist about the volume.
|
|
|
|
type CSIVolumeStub struct {
|
|
|
|
VolumeID string
|
|
|
|
VolumeExternalID string
|
|
|
|
PluginID string
|
|
|
|
ExternalNodeID string
|
|
|
|
MountInfo *csimanager.MountInfo
|
|
|
|
}
|