Skip to content

Commit cb5a3a1

Browse files
committed
Issue certifcates for etcd-operator
This commit will add the capability to issue selfsigned certificates for etcd-operator. These certs are issued with the etcdcluster resouce name prepended and also reconciles these certs. Signed-off-by: ArkaSaha30 <[email protected]>
1 parent c2343a0 commit cb5a3a1

17 files changed

+260
-50
lines changed

api/v1alpha1/etcdcluster_types.go

+14-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,18 @@ import (
2323
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
2424
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
2525

26+
type MemberSecrets struct {
27+
PeerSecret string `json:"peerSecret"`
28+
ServerSecret string `json:"serverSecret"`
29+
}
30+
31+
// TLSCertificate defines the certificate issued by the certificate provider
32+
type TLSCertificate struct {
33+
Member MemberSecrets `json:"member"`
34+
OperatorSecret string `json:"operatorSecret"`
35+
Provider string `json:"provider"`
36+
}
37+
2638
// EtcdClusterSpec defines the desired state of EtcdCluster.
2739
type EtcdClusterSpec struct {
2840
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
@@ -31,7 +43,8 @@ type EtcdClusterSpec struct {
3143
// Size is the expected size of the etcd cluster.
3244
Size int `json:"size"`
3345
// Version is the expected version of the etcd container image.
34-
Version string `json:"version"`
46+
Version string `json:"version"`
47+
TLS *TLSCertificate `json:"tls,omitempty"`
3548
}
3649

3750
// EtcdClusterStatus defines the observed state of EtcdCluster.

cmd/main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
// to ensure that exec-entrypoint and run can make use of them.
2626
_ "k8s.io/client-go/plugin/pkg/client/auth"
2727

28+
certv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
2829
"k8s.io/apimachinery/pkg/runtime"
2930
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
3031
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
@@ -37,7 +38,6 @@ import (
3738

3839
operatorv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
3940
"go.etcd.io/etcd-operator/internal/controller"
40-
// +kubebuilder:scaffold:imports
4141
)
4242

4343
var (
@@ -49,6 +49,8 @@ func init() {
4949
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5050

5151
utilruntime.Must(operatorv1alpha1.AddToScheme(scheme))
52+
53+
utilruntime.Must(certv1.AddToScheme(scheme))
5254
// +kubebuilder:scaffold:scheme
5355
}
5456

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: ClusterIssuer
3+
metadata:
4+
name: selfsigned
5+
spec:
6+
selfSigned: {}

config/certmanager/kustomization.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
resources:
2+
- cert-manager_issuer.yaml

config/crd/bases/operator.etcd.io_etcdclusters.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ spec:
4242
size:
4343
description: Size is the expected size of the etcd cluster.
4444
type: integer
45+
tls:
46+
description: TLSCertificate defines the certificate issued by the
47+
certificate provider
48+
properties:
49+
member:
50+
properties:
51+
peerSecret:
52+
type: string
53+
serverSecret:
54+
type: string
55+
required:
56+
- peerSecret
57+
- serverSecret
58+
type: object
59+
operatorSecret:
60+
type: string
61+
provider:
62+
type: string
63+
required:
64+
- member
65+
- operatorSecret
66+
- provider
67+
type: object
4568
version:
4669
description: Version is the expected version of the etcd container
4770
image.

config/default/kustomization.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ resources:
2222
# crd/kustomization.yaml
2323
#- ../webhook
2424
# [CERTMANAGER] To enable cert-manager, uncomment all sections with 'CERTMANAGER'. 'WEBHOOK' components are required.
25-
#- ../certmanager
25+
- ../certmanager
2626
# [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'.
2727
#- ../prometheus
2828
# [METRICS] Expose the controller manager metrics service.

config/manager/kustomization.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
resources:
22
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1

config/rbac/role.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@ rules:
3939
- patch
4040
- update
4141
- watch
42+
- apiGroups:
43+
- cert-manager.io
44+
resources:
45+
- certificates
46+
verbs:
47+
- create
48+
- delete
49+
- get
50+
- list
51+
- update
52+
- watch
4253
- apiGroups:
4354
- operator.etcd.io
4455
resources:

config/samples/etcd-client-cert.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Certificate
3+
metadata:
4+
name: etcd-client-certificate
5+
spec:
6+
secretName: etcd-client-tls
7+
dnsNames:
8+
- etcd.etcd-operator-system
9+
issuerRef:
10+
name: etcd-operator-selfsigned
11+
kind: ClusterIssuer

config/samples/etcd-peer-cert.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Certificate
3+
metadata:
4+
name: etcd-peer-certificate
5+
spec:
6+
secretName: etcd-peer-tls
7+
dnsNames:
8+
- etcd.etcd-operator-system
9+
issuerRef:
10+
name: etcd-operator-selfsigned
11+
kind: ClusterIssuer

config/samples/etcd-server-cert.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: cert-manager.io/v1
2+
kind: Certificate
3+
metadata:
4+
name: etcd-server-certificate
5+
spec:
6+
secretName: etcd-server-tls
7+
dnsNames:
8+
- etcd.etcd-operator-system
9+
issuerRef:
10+
name: etcd-operator-selfsigned
11+
kind: ClusterIssuer

config/samples/operator_v1alpha1_etcdcluster.yaml

+9
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,12 @@ metadata:
77
name: etcdcluster-sample
88
spec:
99
# TODO(user): Add fields here
10+
size: 4
11+
version: "3.5.17"
12+
tls:
13+
member:
14+
peerSecret: etcd-peer-tls
15+
serverSecret: etcd-server-tls
16+
operatorSecret: etcd-client-tls
17+
provider: cert-manager
18+

go.mod

+16-13
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ toolchain go1.23.5
55
go 1.23.0
66

77
require (
8+
github.com/cert-manager/cert-manager v1.16.2
89
github.com/go-logr/logr v1.4.2
910
github.com/onsi/ginkgo/v2 v2.22.2
1011
github.com/onsi/gomega v1.36.2
@@ -25,7 +26,7 @@ require (
2526
require (
2627
cel.dev/expr v0.18.0 // indirect
2728
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
28-
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
29+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2930
github.com/beorn7/perks v1.0.1 // indirect
3031
github.com/blang/semver/v4 v4.0.0 // indirect
3132
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
@@ -34,15 +35,15 @@ require (
3435
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3536
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3637
github.com/dustin/go-humanize v1.0.1 // indirect
37-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
38+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
3839
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
3940
github.com/felixge/httpsnoop v1.0.4 // indirect
4041
github.com/fsnotify/fsnotify v1.7.0 // indirect
4142
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
4243
github.com/go-logr/stdr v1.2.2 // indirect
4344
github.com/go-logr/zapr v1.3.0 // indirect
4445
github.com/go-openapi/jsonpointer v0.21.0 // indirect
45-
github.com/go-openapi/jsonreference v0.20.2 // indirect
46+
github.com/go-openapi/jsonreference v0.21.0 // indirect
4647
github.com/go-openapi/swag v0.23.0 // indirect
4748
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
4849
github.com/gogo/protobuf v1.3.2 // indirect
@@ -55,7 +56,7 @@ require (
5556
github.com/google/gofuzz v1.2.0 // indirect
5657
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
5758
github.com/google/uuid v1.6.0 // indirect
58-
github.com/gorilla/websocket v1.5.0 // indirect
59+
github.com/gorilla/websocket v1.5.1 // indirect
5960
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
6061
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
6162
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
@@ -64,13 +65,14 @@ require (
6465
github.com/jonboulle/clockwork v0.4.0 // indirect
6566
github.com/josharian/intern v1.0.0 // indirect
6667
github.com/json-iterator/go v1.1.12 // indirect
68+
github.com/klauspost/compress v1.17.9 // indirect
6769
github.com/mailru/easyjson v0.7.7 // indirect
6870
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6971
github.com/modern-go/reflect2 v1.0.2 // indirect
7072
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
7173
github.com/pkg/errors v0.9.1 // indirect
7274
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
73-
github.com/prometheus/client_golang v1.19.1 // indirect
75+
github.com/prometheus/client_golang v1.20.4 // indirect
7476
github.com/prometheus/client_model v0.6.1 // indirect
7577
github.com/prometheus/common v0.55.0 // indirect
7678
github.com/prometheus/procfs v0.15.1 // indirect
@@ -86,14 +88,14 @@ require (
8688
go.etcd.io/etcd/client/v2 v2.305.17 // indirect
8789
go.etcd.io/etcd/pkg/v3 v3.5.17 // indirect
8890
go.etcd.io/etcd/raft/v3 v3.5.17 // indirect
89-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
90-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
91-
go.opentelemetry.io/otel v1.28.0 // indirect
91+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
92+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
93+
go.opentelemetry.io/otel v1.29.0 // indirect
9294
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
9395
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
94-
go.opentelemetry.io/otel/metric v1.28.0 // indirect
96+
go.opentelemetry.io/otel/metric v1.29.0 // indirect
9597
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
96-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
98+
go.opentelemetry.io/otel/trace v1.29.0 // indirect
9799
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
98100
go.uber.org/multierr v1.11.0 // indirect
99101
golang.org/x/crypto v0.31.0 // indirect
@@ -108,9 +110,9 @@ require (
108110
golang.org/x/tools v0.28.0 // indirect
109111
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
110112
google.golang.org/genproto v0.0.0-20240123012728-ef4313101c80 // indirect
111-
google.golang.org/genproto/googleapis/api v0.0.0-20240826202546-f6391c0de4c7 // indirect
112-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240826202546-f6391c0de4c7 // indirect
113-
google.golang.org/grpc v1.65.0 // indirect
113+
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
114+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
115+
google.golang.org/grpc v1.66.2 // indirect
114116
google.golang.org/protobuf v1.36.1 // indirect
115117
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
116118
gopkg.in/inf.v0 v0.9.1 // indirect
@@ -121,6 +123,7 @@ require (
121123
k8s.io/component-base v0.32.0 // indirect
122124
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
123125
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.31.0 // indirect
126+
sigs.k8s.io/gateway-api v1.1.0 // indirect
124127
sigs.k8s.io/json v0.0.0-20241010143419-9aa6b5e7a4b3 // indirect
125128
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
126129
sigs.k8s.io/yaml v1.4.0 // indirect

0 commit comments

Comments
 (0)