|
| 1 | +package v1alpha1 |
| 2 | + |
| 3 | +import ( |
| 4 | + "github.com/RocketChat/airlock/internal/rules" |
| 5 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 6 | +) |
| 7 | + |
| 8 | +const ( |
| 9 | + MongoDBRestoreControllerName = "MongoDBRestore" |
| 10 | + |
| 11 | + RestoreConditionBucketStoreReady = "BucketStoreReady" |
| 12 | + RestoreConditionAccessRequestReady = "MongoDBAccessRequestReady" |
| 13 | + RestoreConditionJobScheduled = "JobScheduled" |
| 14 | + RestoreConditionJobCompleted = "JobCompleted" |
| 15 | + RestoreConditionJobFailed = "JobFailed" |
| 16 | + |
| 17 | + RestorePhasePending = "Pending" |
| 18 | + RestorePhaseRunning = "Running" |
| 19 | + RestorePhaseCompleted = "Completed" |
| 20 | + RestorePhaseFailed = "Failed" |
| 21 | + |
| 22 | + RestoreReasonRestoreNotStarted = "RestoreNotStarted" |
| 23 | + |
| 24 | + RestoreReasonBackupStoreNotFound = "BackupStoreNotFound" |
| 25 | + RestoreReasonAccessRequestNotFound = "AccessRequestNotFound" |
| 26 | + RestoreReasonAccessRequestNotReady = "AccessRequestNotReady" |
| 27 | + RestoreReasonAccessRequestReady = "AccessRequestReady" |
| 28 | + |
| 29 | + RestoreReasonBackupStoreReady = "BackupStoreReady" |
| 30 | + RestoreReasonJobScheduled = "JobScheduled" |
| 31 | + RestoreReasonJobCompleted = "JobCompleted" |
| 32 | + RestoreReasonJobFailed = "JobFailed" |
| 33 | +) |
| 34 | + |
| 35 | +var RestorePhaseRules = []rules.PhaseRule{ |
| 36 | + rules.NewPhaseRule( |
| 37 | + RestorePhaseFailed, |
| 38 | + rules.ConditionsAny( |
| 39 | + rules.ConditionEquals(RestoreConditionJobFailed, metav1.ConditionTrue), |
| 40 | + rules.ConditionEquals(RestoreConditionJobCompleted, metav1.ConditionFalse), |
| 41 | + rules.ConditionEquals(RestoreConditionJobScheduled, metav1.ConditionFalse), |
| 42 | + ), |
| 43 | + ), |
| 44 | + rules.NewPhaseRule( |
| 45 | + RestorePhasePending, |
| 46 | + rules.ConditionsAny( |
| 47 | + rules.ConditionEquals(RestoreConditionBucketStoreReady, metav1.ConditionUnknown, metav1.ConditionFalse), |
| 48 | + rules.ConditionEquals(RestoreConditionAccessRequestReady, metav1.ConditionUnknown, metav1.ConditionFalse), |
| 49 | + ), |
| 50 | + ), |
| 51 | + rules.NewPhaseRule( |
| 52 | + RestorePhaseRunning, |
| 53 | + rules.ConditionsAll( |
| 54 | + rules.ConditionEquals(RestoreConditionBucketStoreReady, metav1.ConditionTrue), |
| 55 | + rules.ConditionEquals(RestoreConditionAccessRequestReady, metav1.ConditionTrue), |
| 56 | + rules.ConditionEquals(RestoreConditionJobScheduled, metav1.ConditionTrue), |
| 57 | + rules.ConditionEquals(RestoreConditionJobCompleted, metav1.ConditionUnknown), |
| 58 | + ), |
| 59 | + ), |
| 60 | + rules.NewPhaseRule( |
| 61 | + RestorePhaseCompleted, |
| 62 | + rules.ConditionsAll( |
| 63 | + rules.ConditionEquals(RestoreConditionBucketStoreReady, metav1.ConditionTrue), |
| 64 | + rules.ConditionEquals(RestoreConditionAccessRequestReady, metav1.ConditionTrue), |
| 65 | + rules.ConditionEquals(RestoreConditionJobScheduled, metav1.ConditionTrue), |
| 66 | + rules.ConditionEquals(RestoreConditionJobCompleted, metav1.ConditionTrue), |
| 67 | + ), |
| 68 | + ), |
| 69 | +} |
| 70 | + |
| 71 | +// MongoDBRestoreSpec defines the desired state of MongoDBRestore |
| 72 | +// +kubebuilder:object:generate=true |
| 73 | +// +k8s:deepcopy-gen=true |
| 74 | +type MongoDBRestoreSpec struct { |
| 75 | + Cluster string `json:"cluster"` |
| 76 | + Database string `json:"database"` |
| 77 | + DropDatabase bool `json:"dropDatabase,omitempty"` |
| 78 | + S3Path string `json:"s3Path"` |
| 79 | + BackupStoreRef MongoDBBackupStoreRef `json:"backupStoreRef"` |
| 80 | +} |
| 81 | + |
| 82 | +// MongoDBRestoreStatus defines the observed state of MongoDBRestore |
| 83 | +// +kubebuilder:object:generate=true |
| 84 | +// +k8s:deepcopy-gen=true |
| 85 | +type MongoDBRestoreStatus struct { |
| 86 | + Phase string `json:"phase,omitempty"` |
| 87 | + ObservedGeneration *int64 `json:"observedGeneration,omitempty"` |
| 88 | + StartTime *metav1.Time `json:"startTime,omitempty"` |
| 89 | + CompletionTime *metav1.Time `json:"completionTime,omitempty"` |
| 90 | + Conditions []metav1.Condition `json:"conditions,omitempty"` |
| 91 | + Result *MongoDBRestoreStatusResult `json:"result,omitempty"` |
| 92 | +} |
| 93 | + |
| 94 | +// MongoDBRestoreStatusResult defines the result of a restore |
| 95 | +// +kubebuilder:object:generate=true |
| 96 | +// +k8s:deepcopy-gen=true |
| 97 | +type MongoDBRestoreStatusResult struct { |
| 98 | + Job *MongoDBRestoreStatusJob `json:"job,omitempty"` |
| 99 | +} |
| 100 | + |
| 101 | +// MongoDBRestoreStatusJob references the restore job |
| 102 | +// +kubebuilder:object:generate=true |
| 103 | +// +k8s:deepcopy-gen=true |
| 104 | +type MongoDBRestoreStatusJob struct { |
| 105 | + ID string `json:"id,omitempty"` |
| 106 | + Name string `json:"name,omitempty"` |
| 107 | +} |
| 108 | + |
| 109 | +// +kubebuilder:object:root=true |
| 110 | +// +kubebuilder:subresource:status |
| 111 | +// +kubebuilder:printcolumn:name="Phase",type="string",JSONPath=".status.phase" |
| 112 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 113 | +type MongoDBRestore struct { |
| 114 | + metav1.TypeMeta `json:",inline"` |
| 115 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 116 | + |
| 117 | + Spec MongoDBRestoreSpec `json:"spec,omitempty"` |
| 118 | + Status MongoDBRestoreStatus `json:"status,omitempty"` |
| 119 | +} |
| 120 | + |
| 121 | +// +kubebuilder:object:root=true |
| 122 | +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object |
| 123 | +type MongoDBRestoreList struct { |
| 124 | + metav1.TypeMeta `json:",inline"` |
| 125 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 126 | + Items []MongoDBRestore `json:"items"` |
| 127 | +} |
| 128 | + |
| 129 | +func init() { |
| 130 | + SchemeBuilder.Register(&MongoDBRestore{}, &MongoDBRestoreList{}) |
| 131 | +} |
| 132 | + |
| 133 | +func (o *MongoDBRestore) SetPhase(phase string) { |
| 134 | + o.Status.Phase = phase |
| 135 | +} |
| 136 | + |
| 137 | +func (o *MongoDBRestore) GetPhase() string { |
| 138 | + return o.Status.Phase |
| 139 | +} |
| 140 | + |
| 141 | +func (o *MongoDBRestore) SetObservedGeneration(generation int64) { |
| 142 | + o.Status.ObservedGeneration = &generation |
| 143 | +} |
0 commit comments