penguin/monok8s

k8s image for Mono Gateway Dev Kit

clitools/pkg/apis/monok8s/v1alpha1/osupgrade.go

raw ยท 7766 bytes

package v1alpha1

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

type OSUpgradePhase string

const (
	OSUpgradePhasePending  OSUpgradePhase = "Pending"
	OSUpgradePhaseAccepted OSUpgradePhase = "Accepted"
	OSUpgradePhaseRejected OSUpgradePhase = "Rejected"
)

type OSUpgradeProgressPhase string

const (
	OSUpgradeProgressPhasePending     OSUpgradeProgressPhase = "pending"
	OSUpgradeProgressPhaseDownloading OSUpgradeProgressPhase = "downloading"
	OSUpgradeProgressPhaseWriting     OSUpgradeProgressPhase = "writing"
	OSUpgradeProgressPhaseVerifying   OSUpgradeProgressPhase = "verifying"
	OSUpgradeProgressPhaseCompleted   OSUpgradeProgressPhase = "completed"
	OSUpgradeProgressPhaseFailed      OSUpgradeProgressPhase = "failed"
	OSUpgradeProgressPhaseRejected    OSUpgradeProgressPhase = "rejected"

	// Rebooting is the point-of-no-return phase.
	//
	// Once a node reaches Rebooting, the agent may have already changed the boot
	// environment and requested a reboot. The controller must not supersede,
	// retry, retarget, or otherwise mutate this progress object until the node
	// comes back and the agent reports Completed or Failed.
	OSUpgradeProgressPhaseRebooting OSUpgradeProgressPhase = "rebooting"
)

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Namespaced,shortName=osu
// +kubebuilder:printcolumn:name="Desired",type=string,JSONPath=`.spec.desiredVersion`
// +kubebuilder:printcolumn:name="Resolved",type=string,JSONPath=`.status.resolvedVersion`
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
type OSUpgrade struct {
	metav1.TypeMeta   `json:",inline" yaml:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

	// Specification of the desired behavior of the OSUpgrade.
	Spec OSUpgradeSpec `json:"spec,omitempty" yaml:"spec,omitempty"`

	// Most recently observed status of the OSUpgrade.
	Status *OSUpgradeStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// +kubebuilder:object:root=true
type OSUpgradeList struct {
	metav1.TypeMeta `json:",inline" yaml:",inline"`
	metav1.ListMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	Items           []OSUpgrade `json:"items" yaml:"items"`
}

type OSUpgradeSpec struct {
	// +kubebuilder:validation:MinLength=1
	DesiredVersion string `json:"desiredVersion,omitempty" yaml:"desiredVersion,omitempty"`

	// +kubebuilder:validation:Enum=fast;balanced;safe
	// +kubebuilder:default=balanced
	// Profiles (TODO)
	//    safe     - api-server can be responsive most of the time
	//    balanced - api-server can sometimes be unresponsive
	//    fast     - disable throttling. Good for worker node.
	FlashProfile string `json:"flashProfile,omitempty" yaml:"flashProfile,omitempty"`

	Catalog      *VersionCatalogSource `json:"catalog,omitempty" yaml:"catalog,omitempty"`
	NodeSelector *metav1.LabelSelector `json:"nodeSelector,omitempty" yaml:"nodeSelector,omitempty"`
}

type VersionCatalogSource struct {
	URL       string `json:"url,omitempty" yaml:"url,omitempty"`
	Inline    string `json:"inline,omitempty" yaml:"inline,omitempty"`
	ConfigMap string `json:"configMapRef,omitempty" yaml:"configMapRef,omitempty"`
}

type OSUpgradeStatus struct {
	Phase              OSUpgradePhase     `json:"phase,omitempty" yaml:"phase,omitempty"`
	ResolvedVersion    string             `json:"resolvedVersion,omitempty" yaml:"resolvedVersion,omitempty"`
	ObservedGeneration int64              `json:"observedGeneration,omitempty" yaml:"observedGeneration,omitempty"`
	Conditions         []metav1.Condition `json:"conditions,omitempty" yaml:"conditions,omitempty"`
	Reason             string             `json:"reason,omitempty" yaml:"reason,omitempty"`
	Message            string             `json:"message,omitempty" yaml:"message,omitempty"`
}

// +genclient
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:resource:scope=Namespaced,shortName=osup
// +kubebuilder:printcolumn:name="Node",type=string,JSONPath=`.spec.nodeName`
// +kubebuilder:printcolumn:name="Source",type=string,JSONPath=`.spec.sourceRef.name`
// +kubebuilder:printcolumn:name="Current",type=string,JSONPath=`.status.currentVersion`
// +kubebuilder:printcolumn:name="Target",type=string,JSONPath=`.status.targetVersion`
// +kubebuilder:printcolumn:name="Phase",type=string,JSONPath=`.status.phase`
type OSUpgradeProgress struct {
	metav1.TypeMeta   `json:",inline" yaml:",inline"`
	metav1.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`

	// Specification of the desired behavior of the OSUpgradeProgress.
	Spec OSUpgradeProgressSpec `json:"spec,omitempty" yaml:"spec,omitempty"`

	// Most recently observed status of the OSUpgradeProgress.
	Status *OSUpgradeProgressStatus `json:"status,omitempty" yaml:"status,omitempty"`
}

// +kubebuilder:object:root=true
type OSUpgradeProgressList struct {
	metav1.TypeMeta `json:",inline" yaml:",inline"`
	metav1.ListMeta `json:"metadata,omitempty" yaml:"metadata,omitempty"`
	Items           []OSUpgradeProgress `json:"items" yaml:"items"`
}

type OSUpgradeProgressSpec struct {
	SourceRef OSUpgradeSourceRef `json:"sourceRef,omitempty" yaml:"sourceRef,omitempty"`

	// RetryNonce triggers a retry when its value changes.
	// Users can update this field (for example, set it to the current time)
	// to request a retry of a failed OS upgrade.
	RetryNonce string `json:"retryNonce,omitempty" yaml:"retryNonce,omitempty"`

	NodeName string `json:"nodeName,omitempty" yaml:"nodeName,omitempty"`
}

type OSUpgradeSourceRef struct {
	Name      string `json:"name,omitempty" yaml:"name,omitempty"`
	Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
}

type OSUpgradeProgressStatus struct {
	CurrentVersion    string                 `json:"currentVersion,omitempty" yaml:"currentVersion,omitempty"`
	TargetVersion     string                 `json:"targetVersion,omitempty" yaml:"targetVersion,omitempty"`
	Phase             OSUpgradeProgressPhase `json:"phase,omitempty" yaml:"phase,omitempty"`
	StartedAt         *metav1.Time           `json:"startedAt,omitempty" yaml:"startedAt,omitempty"`
	CompletedAt       *metav1.Time           `json:"completedAt,omitempty" yaml:"completedAt,omitempty"`
	LastUpdatedAt     *metav1.Time           `json:"lastUpdatedAt,omitempty" yaml:"lastUpdatedAt,omitempty"`
	RetryCount        int32                  `json:"retryCount,omitempty" yaml:"retryCount,omitempty"`
	InactivePartition string                 `json:"inactivePartition,omitempty" yaml:"inactivePartition,omitempty"`
	FailureReason     string                 `json:"failureReason,omitempty" yaml:"failureReason,omitempty"`
	Message           string                 `json:"message,omitempty" yaml:"message,omitempty"`
	PlannedPath       []string               `json:"plannedPath,omitempty" yaml:"plannedPath,omitempty"`
	CurrentStep       int32                  `json:"currentStep,omitempty" yaml:"currentStep,omitempty"`
	CurrentFrom       string                 `json:"currentFrom,omitempty" yaml:"currentFrom,omitempty"`
	CurrentTo         string                 `json:"currentTo,omitempty" yaml:"currentTo,omitempty"`

	// ObservedRetryNonce records the last retryNonce value the agent accepted.
	// When spec.retryNonce is changed by the user and differs from this value,
	// the agent may retry a failed upgrade.
	// +optional
	ObservedRetryNonce string `json:"observedRetryNonce,omitempty"`
}

func (osu OSUpgrade) StatusPhase() string {
	phase := ""
	if osu.Status != nil {
		phase = string(osu.Status.Phase)
	}
	return phase
}

func (osup OSUpgradeProgress) StatusPhase() string {
	phase := ""
	if osup.Status != nil {
		phase = string(osup.Status.Phase)
	}
	return phase
}