Skip to content

Commit b5e719e

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 719fb8d commit b5e719e

17 files changed

+277
-65
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
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"
3636
"sigs.k8s.io/controller-runtime/pkg/webhook"
3737

38+
certv1 "github.com/cert-manager/cert-manager/pkg/apis/certmanager/v1"
3839
operatorv1alpha1 "go.etcd.io/etcd-operator/api/v1alpha1"
3940
"go.etcd.io/etcd-operator/internal/controller"
4041
// +kubebuilder:scaffold:imports
@@ -49,6 +50,8 @@ func init() {
4950
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
5051

5152
utilruntime.Must(operatorv1alpha1.AddToScheme(scheme))
53+
54+
utilruntime.Must(certv1.AddToScheme(scheme))
5255
// +kubebuilder:scaffold:scheme
5356
}
5457

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

+6
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
11
resources:
22
- manager.yaml
3+
apiVersion: kustomize.config.k8s.io/v1beta1
4+
kind: Kustomization
5+
images:
6+
- name: controller
7+
newName: arkasaha30/etcd-operator
8+
newTag: cert4

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

+21-18
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ toolchain go1.23.4
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
@@ -24,7 +25,7 @@ require (
2425

2526
require (
2627
github.com/antlr4-go/antlr/v4 v4.13.0 // indirect
27-
github.com/asaskevich/govalidator v0.0.0-20190424111038-f61b66f89f4a // indirect
28+
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
2829
github.com/beorn7/perks v1.0.1 // indirect
2930
github.com/blang/semver/v4 v4.0.0 // indirect
3031
github.com/cenkalti/backoff/v4 v4.3.0 // indirect
@@ -33,15 +34,15 @@ require (
3334
github.com/coreos/go-systemd/v22 v22.5.0 // indirect
3435
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
3536
github.com/dustin/go-humanize v1.0.1 // indirect
36-
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
37+
github.com/emicklei/go-restful/v3 v3.12.1 // indirect
3738
github.com/evanphx/json-patch/v5 v5.9.0 // indirect
3839
github.com/felixge/httpsnoop v1.0.4 // indirect
3940
github.com/fsnotify/fsnotify v1.7.0 // indirect
4041
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
4142
github.com/go-logr/stdr v1.2.2 // indirect
4243
github.com/go-logr/zapr v1.3.0 // indirect
4344
github.com/go-openapi/jsonpointer v0.21.0 // indirect
44-
github.com/go-openapi/jsonreference v0.20.2 // indirect
45+
github.com/go-openapi/jsonreference v0.21.0 // indirect
4546
github.com/go-openapi/swag v0.23.0 // indirect
4647
github.com/go-task/slim-sprig/v3 v3.0.0 // indirect
4748
github.com/gogo/protobuf v1.3.2 // indirect
@@ -54,7 +55,7 @@ require (
5455
github.com/google/gofuzz v1.2.0 // indirect
5556
github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect
5657
github.com/google/uuid v1.6.0 // indirect
57-
github.com/gorilla/websocket v1.5.0 // indirect
58+
github.com/gorilla/websocket v1.5.1 // indirect
5859
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
5960
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
6061
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
@@ -63,40 +64,41 @@ require (
6364
github.com/jonboulle/clockwork v0.2.2 // indirect
6465
github.com/josharian/intern v1.0.0 // indirect
6566
github.com/json-iterator/go v1.1.12 // indirect
67+
github.com/klauspost/compress v1.17.9 // indirect
6668
github.com/mailru/easyjson v0.7.7 // indirect
6769
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
6870
github.com/modern-go/reflect2 v1.0.2 // indirect
6971
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
7072
github.com/pkg/errors v0.9.1 // indirect
7173
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
72-
github.com/prometheus/client_golang v1.19.1 // indirect
74+
github.com/prometheus/client_golang v1.20.4 // indirect
7375
github.com/prometheus/client_model v0.6.1 // indirect
7476
github.com/prometheus/common v0.55.0 // indirect
7577
github.com/prometheus/procfs v0.15.1 // indirect
7678
github.com/sirupsen/logrus v1.9.3 // indirect
7779
github.com/soheilhy/cmux v0.1.5 // indirect
7880
github.com/spf13/cobra v1.8.1 // indirect
7981
github.com/spf13/pflag v1.0.5 // indirect
80-
github.com/stoewer/go-strcase v1.2.0 // indirect
82+
github.com/stoewer/go-strcase v1.3.0 // indirect
8183
github.com/tmc/grpc-websocket-proxy v0.0.0-20220101234140-673ab2c3ae75 // indirect
8284
github.com/x448/float16 v0.8.4 // indirect
8385
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
8486
go.etcd.io/bbolt v1.3.11 // indirect
8587
go.etcd.io/etcd/client/v2 v2.305.17 // indirect
8688
go.etcd.io/etcd/pkg/v3 v3.5.17 // indirect
8789
go.etcd.io/etcd/raft/v3 v3.5.17 // indirect
88-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect
89-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect
90-
go.opentelemetry.io/otel v1.28.0 // indirect
90+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.54.0 // indirect
91+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
92+
go.opentelemetry.io/otel v1.29.0 // indirect
9193
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 // indirect
9294
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 // indirect
93-
go.opentelemetry.io/otel/metric v1.28.0 // indirect
95+
go.opentelemetry.io/otel/metric v1.29.0 // indirect
9496
go.opentelemetry.io/otel/sdk v1.28.0 // indirect
95-
go.opentelemetry.io/otel/trace v1.28.0 // indirect
97+
go.opentelemetry.io/otel/trace v1.29.0 // indirect
9698
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
9799
go.uber.org/multierr v1.11.0 // indirect
98100
golang.org/x/crypto v0.31.0 // indirect
99-
golang.org/x/exp v0.0.0-20230515195305-f3d0a9c9a5cc // indirect
101+
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
100102
golang.org/x/net v0.33.0 // indirect
101103
golang.org/x/oauth2 v0.23.0 // indirect
102104
golang.org/x/sync v0.10.0 // indirect
@@ -107,20 +109,21 @@ require (
107109
golang.org/x/tools v0.28.0 // indirect
108110
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
109111
google.golang.org/genproto v0.0.0-20230822172742-b8732ec3820d // indirect
110-
google.golang.org/genproto/googleapis/api v0.0.0-20240528184218-531527333157 // indirect
111-
google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect
112-
google.golang.org/grpc v1.65.0 // indirect
112+
google.golang.org/genproto/googleapis/api v0.0.0-20240827150818-7e3bb234dfed // indirect
113+
google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect
114+
google.golang.org/grpc v1.66.2 // indirect
113115
google.golang.org/protobuf v1.36.1 // indirect
114116
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
115117
gopkg.in/inf.v0 v0.9.1 // indirect
116118
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
117119
gopkg.in/yaml.v2 v2.4.0 // indirect
118120
gopkg.in/yaml.v3 v3.0.1 // indirect
119-
k8s.io/apiextensions-apiserver v0.31.0 // indirect
120-
k8s.io/apiserver v0.31.0 // indirect
121-
k8s.io/component-base v0.31.0 // indirect
121+
k8s.io/apiextensions-apiserver v0.31.1 // indirect
122+
k8s.io/apiserver v0.31.1 // indirect
123+
k8s.io/component-base v0.31.1 // indirect
122124
k8s.io/kube-openapi v0.0.0-20241105132330-32ad38e42d3f // indirect
123125
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.30.3 // 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)