Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support gRPC communication between primary and secondary mantle controllers #32

Merged
merged 3 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ Dockerfile.cross
*~

test/e2e/testdata/persistentvolumes.yaml
test/e2e/testdata/values-mantle-primary.yaml
include/
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ COPY main.go main.go
COPY cmd/ cmd/
COPY api/ api/
COPY internal/ internal/
COPY pkg/ pkg/

# Build
# the GOARCH has not a default value to allow the binary be built according to the host where the command
Expand Down
51 changes: 40 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
include versions.mk

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)

## Tool Binaries
KUBECTL ?= $(LOCALBIN)/kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
MOCKGEN ?= $(LOCALBIN)/mockgen
PROTOC ?= $(LOCALBIN)/protoc
PROTOC_RUN ?= PATH=$(LOCALBIN):$(PATH) $(PROTOC) -I=$(shell pwd)/include:.

# Files to be generated by protoc
PROTOBUF_GEN = pkg/controller/proto/controller.pb.go pkg/controller/proto/controller_grpc.pb.go docs/controller-protocol.md

# Image URL to use all building/pushing image targets
IMG ?= controller:latest

Expand Down Expand Up @@ -52,7 +69,7 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
cat config/rbac/role.yaml | yq '.metadata.name = "mantle-controller"' > charts/mantle-cluster-wide/templates/clusterrole.yaml

.PHONY: generate
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
generate: $(PROTOBUF_GEN) controller-gen ## Generate boilerplate code.
$(CONTROLLER_GEN) object paths="./..."

.PHONY: fmt
Expand Down Expand Up @@ -151,17 +168,29 @@ undeploy: kubectl ## Undeploy controller from the K8s cluster specified in ~/.ku

##@ Build Dependencies

## Location to install dependencies to
LOCALBIN ?= $(shell pwd)/bin
$(LOCALBIN):
mkdir -p $(LOCALBIN)
pkg/controller/proto/controller.pb.go: pkg/controller/proto/controller.proto $(PROTOC)
$(PROTOC_RUN) --go_out=module=github.com/cybozu-go/mantle:. $<

## Tool Binaries
KUBECTL ?= $(LOCALBIN)/kubectl
KUSTOMIZE ?= $(LOCALBIN)/kustomize
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest
MOCKGEN ?= $(LOCALBIN)/mockgen
pkg/controller/proto/controller_grpc.pb.go: pkg/controller/proto/controller.proto $(PROTOC)
$(PROTOC_RUN) --go-grpc_out=module=github.com/cybozu-go/mantle:. $<

docs/controller-protocol.md: pkg/controller/proto/controller.proto $(PROTOC)
$(PROTOC_RUN) --doc_out=./docs --doc_opt=markdown,$@ $<

.PHONY: $(PROTOC)
$(PROTOC): $(LOCALBIN)
[ -f $(PROTOC) ] || { \
set -e ;\
curl -Lo $(LOCALBIN)/protoc.zip https://github.com/protocolbuffers/protobuf/releases/download/v$(PROTOC_VERSION)/protoc-$(PROTOC_VERSION)-linux-x86_64.zip ;\
rm -rf $(LOCALBIN)/protoc.unzip ;\
unzip $(LOCALBIN)/protoc.zip -d $(LOCALBIN)/protoc.unzip ;\
cp -f $(LOCALBIN)/protoc.unzip/bin/protoc $(PROTOC) ;\
cp -r $(LOCALBIN)/protoc.unzip/include . ;\
rm -rf $(LOCALBIN)/protoc.unzip $(LOCALBIN)/protoc.zip ;\
GOBIN=$(LOCALBIN) go install google.golang.org/protobuf/cmd/protoc-gen-go@v$(PROTOC_GEN_GO_VERSION) ;\
GOBIN=$(LOCALBIN) go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v$(PROTOC_GEN_GO_GRPC_VERSION) ;\
GOBIN=$(LOCALBIN) go install github.com/pseudomuto/protoc-gen-doc/cmd/protoc-gen-doc@v$(PROTOC_GEN_DOC_VERSION) ;\
}

.PHONY: kustomize
kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. If wrong version is installed, it will be removed before downloading.
Expand Down
3 changes: 2 additions & 1 deletion api/v1/mantlebackup_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ type MantleBackupStatus struct {
}

const (
BackupConditionReadyToUse = "ReadyToUse"
BackupConditionReadyToUse = "ReadyToUse"
BackupConditionSyncedToRemote = "SyncedToRemote"

// Reasons for ConditionReadyToUse
BackupReasonNone = "NoProblem"
Expand Down
6 changes: 6 additions & 0 deletions charts/mantle/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ spec:
args:
- controller
- --leader-elect
- --role={{ .Values.controller.role }}
{{- with .Values.controller.mantleServiceEndpoint }}
- --mantle-service-endpoint={{ . }}
{{- end }}
{{- with .Values.controller.expireOffset }}
- --expire-offset={{ . }}
{{- end }}
Expand All @@ -75,6 +79,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
ports:
{{- toYaml .Values.controller.ports | nindent 12 }}
- command:
- /bin/bash
- -c
Expand Down
4 changes: 3 additions & 1 deletion charts/mantle/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ nodeSelector: {}
tolerations: []
affinity: {}

controller: {}
controller:
role: standalone
ports: []
Loading
Loading