Skip to content

Commit 221e984

Browse files
committed
...
1 parent d9c4240 commit 221e984

18 files changed

+978
-72
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ jobs:
2727
cache: false
2828
- uses: RocketChat/k3d-with-registry@main
2929
- name: Build binary
30+
env:
31+
CI: true
3032
run: |
3133
cd $__W_SRC_REL
3234
go mod tidy

Makefile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ vet: ## Run go vet against code.
108108

109109
.PHONY: test
110110
test: manifests generate fmt vet ## Run tests (Ginkgo suite only).
111-
go test ./internal/... -v
112111
go test ./tests/ -v -ginkgo.v -coverprofile cover.out
113112

114113
.PHONY: test-unit
@@ -297,6 +296,8 @@ k3d-deploy-minio: k3d-cluster k3d-add-storageclass
297296
$(KUBECTL_WITH_CONFIG) apply -k "github.com/minio/operator?ref=v6.0.4"
298297
$(KUBECTL_WITH_CONFIG) rollout status deployment/minio-operator -n minio-operator
299298
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/minio
299+
# ensures minio is ready
300+
$(KUBECTL_WITH_CONFIG) wait --for=condition=complete job/create-minio-buckets -n minio-tenant --timeout=5m
300301

301302
.PHONY: docker-build-backup-image
302303
docker-build-backup-image:
@@ -311,10 +312,12 @@ k3d-run-backup-pod: k3d-cluster k3d-load-backup-image
311312
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/backup-pod.yaml
312313

313314
.PHONY: k3d-load-mongo-data
314-
k3d-load-mongo-data: k3d-deploy-mongo
315+
k3d-load-mongo-data: k3d-deploy-mongo k3d-add-storageclass k3d-deploy-minio k3d-load-backup-image
315316
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/mongo-restore-job.yaml
316317
# wait for the job to complete
317-
# $(KUBECTL_WITH_CONFIG) wait --for=condition=complete job/restore-job -n mongo --timeout=5m
318+
# weird hack for me to fix dns for one term
319+
[ "$CI" = "true" ] || sudo systemctl restart NetworkManager
320+
$(KUBECTL_WITH_CONFIG) wait --for=condition=complete job/restore-job -n mongo --timeout=5m
318321

319322
# subject to change as more matures
320323
.PHONY: k3d-setup-all
@@ -334,4 +337,5 @@ k3d-add-backup-store: k3d-cluster
334337

335338
.PHONY: k3d-add-age-secret
336339
k3d-add-age-secret: k3d-cluster
337-
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/age-secret.yaml
340+
$(KUBECTL_WITH_CONFIG) apply -f ./tests/assets/local-tests/age-secret.yaml
341+

api/v1alpha1/mongodbbackup_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ type MongoDBBackupSpec struct {
105105
IncludedCollections []string `json:"includedCollections,omitempty"`
106106
BackupStoreRef MongoDBBackupStoreRef `json:"backupStoreRef"`
107107
Prefix string `json:"prefix,omitempty"`
108-
Encrypt MongoDBBackupEncryption `json:"encrypt,omitempty"`
108+
Encryption MongoDBBackupEncryption `json:"encryption,omitempty"`
109109
}
110110

111111
type MongoDBBackupStoreRef struct {
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
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+
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 151 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)