Skip to content

Commit b5d2321

Browse files
Merge pull request #9 from cybozu-go/implement-restore-2
Implement the reconciler for MantleRestore
2 parents 968dae7 + 502be7a commit b5d2321

37 files changed

+2333
-71
lines changed

Diff for: Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ RUN go mod download
1313
COPY main.go main.go
1414
COPY cmd/ cmd/
1515
COPY api/ api/
16-
COPY internal/controller/ internal/controller/
16+
COPY internal/ internal/
1717

1818
# Build
1919
# the GOARCH has not a default value to allow the binary be built according to the host where the command

Diff for: Makefile

+12-1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ help: ## Display this help.
4747
manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
4848
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4949
cp -a config/crd/bases/mantle.cybozu.io_mantlebackups.yaml charts/mantle-cluster-wide/templates/
50+
cp -a config/crd/bases/mantle.cybozu.io_mantlerestores.yaml charts/mantle-cluster-wide/templates/
5051
cat config/rbac/role.yaml | yq '.metadata.name = "mantle-controller"' > charts/mantle-cluster-wide/templates/clusterrole.yaml
5152

5253
.PHONY: generate
@@ -61,8 +62,12 @@ fmt: ## Run go fmt against code.
6162
vet: ## Run go vet against code.
6263
go vet ./...
6364

65+
.PHONY: mock
66+
mock: mockgen
67+
$(MOCKGEN) -source=internal/ceph/command.go -destination=internal/ceph/command_mock.go -package=ceph
68+
6469
.PHONY: test
65-
test: manifests generate fmt vet envtest ## Run tests.
70+
test: manifests generate fmt vet envtest mock ## Run tests.
6671
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_KUBERNETES_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
6772

6873
GOLANGCI_LINT = $(shell pwd)/bin/golangci-lint
@@ -155,6 +160,7 @@ KUBECTL ?= $(LOCALBIN)/kubectl
155160
KUSTOMIZE ?= $(LOCALBIN)/kustomize
156161
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
157162
ENVTEST ?= $(LOCALBIN)/setup-envtest
163+
MOCKGEN ?= $(LOCALBIN)/mockgen
158164

159165
.PHONY: kustomize
160166
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
@@ -181,3 +187,8 @@ kubectl: $(KUBECTL) # Download kubectl if necessary.
181187
$(KUBECTL): $(LOCALBIN)
182188
curl https://storage.googleapis.com/kubernetes-release/release/v$(KUBERNETES_VERSION)/bin/linux/amd64/kubectl -o $(KUBECTL)
183189
chmod 755 $(KUBECTL)
190+
191+
.PHONY: mockgen
192+
mockgen: $(MOCKGEN) ## Download mockgen locally if necessary.
193+
$(MOCKGEN): $(LOCALBIN)
194+
GOBIN=$(LOCALBIN) go install go.uber.org/mock/mockgen@$(MOCKGEN_VERSION)

Diff for: PROJECT

+9
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,13 @@ resources:
1717
kind: MantleBackup
1818
path: github.com/cybozu-go/mantle/api/v1
1919
version: v1
20+
- api:
21+
crdVersion: v1
22+
namespaced: true
23+
controller: true
24+
domain: cybozu.io
25+
group: backup
26+
kind: MantleRestore
27+
path: github.com/cybozu-go/mantle/api/v1
28+
version: v1
2029
version: "3"

Diff for: api/v1/mantlebackup_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ type MantleBackupStatus struct {
3131

3232
// 'conditions' specifies current backup conditions
3333
Conditions []metav1.Condition `json:"conditions,omitempty"`
34+
35+
// 'pvcManifest' saving backup target PVC manifests
36+
PVCManifest string `json:"pvcManifest,omitempty"`
37+
// 'pvManifest' saving backup target PV manifest
38+
PVManifest string `json:"pvManifest,omitempty"`
3439
}
3540

3641
const (

Diff for: api/v1/mantlerestore_types.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package v1
2+
3+
import (
4+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
5+
)
6+
7+
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
8+
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
9+
10+
// MantleRestoreSpec defines the desired state of MantleRestore
11+
type MantleRestoreSpec struct {
12+
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
13+
// Important: Run "make" to regenerate code after modifying this file
14+
15+
// 'backup' specifies restore target backup resource name
16+
// +kubebuilder:validation:Required
17+
Backup string `json:"backup,omitempty"`
18+
}
19+
20+
// MantleRestoreStatus defines the observed state of MantleRestore
21+
type MantleRestoreStatus struct {
22+
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
23+
// Important: Run "make" to regenerate code after modifying this file
24+
25+
// 'conditions' specifies current restore conditions
26+
Conditions []metav1.Condition `json:"conditions,omitempty"`
27+
28+
// 'clusterID' specifies the Ceph cluster ID the source PV/PVC belongs to
29+
ClusterID string `json:"clusterID,omitempty"`
30+
31+
// 'pool' specifies pool name the volumes are restored to
32+
Pool string `json:"pool,omitempty"`
33+
}
34+
35+
const (
36+
RestoreConditionReadyToUse = "ReadyToUse"
37+
)
38+
39+
// +kubebuilder:object:root=true
40+
// +kubebuilder:subresource:status
41+
42+
// MantleRestore is the Schema for the mantlerestores API
43+
type MantleRestore struct {
44+
metav1.TypeMeta `json:",inline"`
45+
metav1.ObjectMeta `json:"metadata,omitempty"`
46+
47+
Spec MantleRestoreSpec `json:"spec,omitempty"`
48+
Status MantleRestoreStatus `json:"status,omitempty"`
49+
}
50+
51+
// +kubebuilder:object:root=true
52+
53+
// MantleRestoreList contains a list of MantleRestore
54+
type MantleRestoreList struct {
55+
metav1.TypeMeta `json:",inline"`
56+
metav1.ListMeta `json:"metadata,omitempty"`
57+
Items []MantleRestore `json:"items"`
58+
}
59+
60+
func init() {
61+
SchemeBuilder.Register(&MantleRestore{}, &MantleRestoreList{})
62+
}

Diff for: api/v1/zz_generated.deepcopy.go

+96
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: charts/mantle-cluster-wide/templates/clusterrole.yaml

+42
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ rules:
99
resources:
1010
- persistentvolumeclaims
1111
verbs:
12+
- create
13+
- delete
1214
- get
1315
- list
16+
- patch
17+
- update
1418
- watch
1519
- apiGroups:
1620
- ""
1721
resources:
1822
- persistentvolumes
1923
verbs:
24+
- create
25+
- delete
2026
- get
2127
- list
28+
- patch
29+
- update
2230
- watch
2331
- apiGroups:
2432
- ""
@@ -62,6 +70,40 @@ rules:
6270
- get
6371
- patch
6472
- update
73+
- apiGroups:
74+
- mantle.cybozu.io
75+
resources:
76+
- mantlerbackup
77+
verbs:
78+
- get
79+
- list
80+
- watch
81+
- apiGroups:
82+
- mantle.cybozu.io
83+
resources:
84+
- mantlerestores
85+
verbs:
86+
- create
87+
- delete
88+
- get
89+
- list
90+
- patch
91+
- update
92+
- watch
93+
- apiGroups:
94+
- mantle.cybozu.io
95+
resources:
96+
- mantlerestores/finalizers
97+
verbs:
98+
- update
99+
- apiGroups:
100+
- mantle.cybozu.io
101+
resources:
102+
- mantlerestores/status
103+
verbs:
104+
- get
105+
- patch
106+
- update
65107
- apiGroups:
66108
- storage.k8s.io
67109
resources:

Diff for: charts/mantle-cluster-wide/templates/mantle.cybozu.io_mantlebackups.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,12 @@ spec:
123123
description: '''createdAt'' specifies the creation date and time'
124124
format: date-time
125125
type: string
126+
pvManifest:
127+
description: '''pvManifest'' saving backup target PV manifest'
128+
type: string
129+
pvcManifest:
130+
description: '''pvcManifest'' saving backup target PVC manifests'
131+
type: string
126132
type: object
127133
type: object
128134
served: true

0 commit comments

Comments
 (0)