Skip to content

Commit 11e1768

Browse files
authored
Merge pull request #143 from arangodb/feature/dc2dc-resource
`ArangoDeploymentReplication` resource
2 parents aa7e63e + aaf0596 commit 11e1768

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+6935
-94
lines changed

Makefile

+6-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ ifndef MANIFESTSUFFIX
5050
endif
5151
endif
5252
MANIFESTPATHDEPLOYMENT := manifests/arango-deployment$(MANIFESTSUFFIX).yaml
53+
MANIFESTPATHDEPLOYMENTREPLICATION := manifests/arango-deployment-replication$(MANIFESTSUFFIX).yaml
5354
MANIFESTPATHSTORAGE := manifests/arango-storage$(MANIFESTSUFFIX).yaml
5455
MANIFESTPATHTEST := manifests/arango-test$(MANIFESTSUFFIX).yaml
5556
ifndef DEPLOYMENTNAMESPACE
@@ -172,7 +173,7 @@ update-generated: $(GOBUILDDIR)
172173
"all" \
173174
"github.com/arangodb/kube-arangodb/pkg/generated" \
174175
"github.com/arangodb/kube-arangodb/pkg/apis" \
175-
"deployment:v1alpha storage:v1alpha" \
176+
"deployment:v1alpha replication:v1alpha storage:v1alpha" \
176177
--go-header-file "./tools/codegen/boilerplate.go.txt" \
177178
$(VERIFYARGS)
178179

@@ -230,6 +231,7 @@ run-unit-tests: $(GOBUILDDIR) $(SOURCES)
230231
golang:$(GOVERSION) \
231232
go test $(TESTVERBOSEOPTIONS) \
232233
$(REPOPATH)/pkg/apis/deployment/v1alpha \
234+
$(REPOPATH)/pkg/apis/replication/v1alpha \
233235
$(REPOPATH)/pkg/apis/storage/v1alpha \
234236
$(REPOPATH)/pkg/deployment/reconcile \
235237
$(REPOPATH)/pkg/deployment/resources \
@@ -270,6 +272,7 @@ endif
270272
kubectl apply -f manifests/crd.yaml
271273
kubectl apply -f $(MANIFESTPATHSTORAGE)
272274
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
275+
kubectl apply -f $(MANIFESTPATHDEPLOYMENTREPLICATION)
273276
kubectl apply -f $(MANIFESTPATHTEST)
274277
$(ROOTDIR)/scripts/kube_create_storage.sh $(DEPLOYMENTNAMESPACE)
275278
$(ROOTDIR)/scripts/kube_run_tests.sh $(DEPLOYMENTNAMESPACE) $(TESTIMAGE) "$(ENTERPRISEIMAGE)" $(TESTTIMEOUT) $(TESTLENGTHOPTIONS)
@@ -345,12 +348,14 @@ minikube-start:
345348
delete-operator:
346349
kubectl delete -f $(MANIFESTPATHTEST) --ignore-not-found
347350
kubectl delete -f $(MANIFESTPATHDEPLOYMENT) --ignore-not-found
351+
kubectl delete -f $(MANIFESTPATHDEPLOYMENTREPLICATION) --ignore-not-found
348352
kubectl delete -f $(MANIFESTPATHSTORAGE) --ignore-not-found
349353

350354
.PHONY: redeploy-operator
351355
redeploy-operator: delete-operator manifests
352356
kubectl apply -f manifests/crd.yaml
353357
kubectl apply -f $(MANIFESTPATHSTORAGE)
354358
kubectl apply -f $(MANIFESTPATHDEPLOYMENT)
359+
kubectl apply -f $(MANIFESTPATHDEPLOYMENTREPLICATION)
355360
kubectl apply -f $(MANIFESTPATHTEST)
356361
kubectl get pods

deps/github.com/arangodb-helper/go-certificates/keyfile.go

+64-13
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,13 @@ import (
3838
"strings"
3939
)
4040

41-
// LoadKeyFile loads a SSL keyfile formatted for the arangod server.
42-
func LoadKeyFile(keyFile string) (tls.Certificate, error) {
43-
raw, err := ioutil.ReadFile(keyFile)
44-
if err != nil {
45-
return tls.Certificate{}, maskAny(err)
46-
}
41+
// Keyfile contains 1 or more certificates and a private key.
42+
type Keyfile tls.Certificate
4743

48-
result := tls.Certificate{}
44+
// NewKeyfile creates a keyfile from given content.
45+
func NewKeyfile(content string) (Keyfile, error) {
46+
raw := []byte(content)
47+
result := Keyfile{}
4948
for {
5049
var derBlock *pem.Block
5150
derBlock, raw = pem.Decode(raw)
@@ -56,22 +55,74 @@ func LoadKeyFile(keyFile string) (tls.Certificate, error) {
5655
result.Certificate = append(result.Certificate, derBlock.Bytes)
5756
} else if derBlock.Type == "PRIVATE KEY" || strings.HasSuffix(derBlock.Type, " PRIVATE KEY") {
5857
if result.PrivateKey == nil {
58+
var err error
5959
result.PrivateKey, err = parsePrivateKey(derBlock.Bytes)
6060
if err != nil {
61-
return tls.Certificate{}, maskAny(err)
61+
return Keyfile{}, maskAny(err)
6262
}
6363
}
6464
}
6565
}
66+
return result, nil
67+
}
6668

67-
if len(result.Certificate) == 0 {
68-
return tls.Certificate{}, maskAny(fmt.Errorf("No certificates found in %s", keyFile))
69+
// Validate the contents of the keyfile
70+
func (kf Keyfile) Validate() error {
71+
if len(kf.Certificate) == 0 {
72+
return maskAny(fmt.Errorf("No certificates found in keyfile"))
6973
}
70-
if result.PrivateKey == nil {
71-
return tls.Certificate{}, maskAny(fmt.Errorf("No private key found in %s", keyFile))
74+
if kf.PrivateKey == nil {
75+
return maskAny(fmt.Errorf("No private key found in keyfile"))
7276
}
7377

74-
return result, nil
78+
return nil
79+
}
80+
81+
// EncodeCACertificates extracts the CA certificate(s) from the given keyfile (if any).
82+
func (kf Keyfile) EncodeCACertificates() (string, error) {
83+
buf := &bytes.Buffer{}
84+
for _, derBytes := range kf.Certificate {
85+
c, err := x509.ParseCertificate(derBytes)
86+
if err != nil {
87+
return "", maskAny(err)
88+
}
89+
if c.IsCA {
90+
pem.Encode(buf, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
91+
}
92+
}
93+
94+
return buf.String(), nil
95+
}
96+
97+
// EncodeCertificates extracts all certificates from the given keyfile and encodes them as PEM blocks.
98+
func (kf Keyfile) EncodeCertificates() string {
99+
buf := &bytes.Buffer{}
100+
for _, derBytes := range kf.Certificate {
101+
pem.Encode(buf, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
102+
}
103+
104+
return buf.String()
105+
}
106+
107+
// EncodePrivateKey extract the private key from the given keyfile and encodes is as PEM block.
108+
func (kf Keyfile) EncodePrivateKey() string {
109+
buf := &bytes.Buffer{}
110+
pem.Encode(buf, pemBlockForKey(kf.PrivateKey))
111+
return buf.String()
112+
}
113+
114+
// LoadKeyFile loads a SSL keyfile formatted for the arangod server.
115+
func LoadKeyFile(keyFile string) (tls.Certificate, error) {
116+
raw, err := ioutil.ReadFile(keyFile)
117+
if err != nil {
118+
return tls.Certificate{}, maskAny(err)
119+
}
120+
121+
kf, err := NewKeyfile(string(raw))
122+
if err != nil {
123+
return tls.Certificate{}, maskAny(err)
124+
}
125+
return tls.Certificate(kf), nil
75126
}
76127

77128
// ExtractCACertificateFromKeyFile loads a SSL keyfile formatted for the arangod server and

0 commit comments

Comments
 (0)