Skip to content

Commit 068d414

Browse files
authored
Set default CredentialStore to "kubernetes" in multiple controllers (#271)
* Set default CredentialStore to "kubernetes" in multiple controllers - Updated the Reconcile functions in the CA, identity, ordnode, and peer controllers to set the CredentialStore to "kubernetes" if it is not already specified. - This change ensures a consistent default configuration across different components, enhancing usability and reducing potential misconfigurations. Signed-off-by: dviejokfs <[email protected]> * Add Prometheus metrics documentation and update sidebar - Added a new documentation file for Prometheus metrics, detailing available metrics for monitoring Hyperledger Fabric, including certificate expiration and current time metrics. - Updated the sidebar configuration to include a link to the new Prometheus metrics documentation, enhancing navigation for users. These changes improve the documentation and usability of monitoring features within the Hyperledger Fabric operator. Signed-off-by: dviejokfs <[email protected]> --------- Signed-off-by: dviejokfs <[email protected]>
1 parent 1e7a4ab commit 068d414

File tree

6 files changed

+169
-38
lines changed

6 files changed

+169
-38
lines changed

controllers/ca/ca_controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,9 @@ func Reconcile(
11081108
if err != nil {
11091109
return ctrl.Result{}, err
11101110
}
1111-
1111+
if hlf.Spec.CredentialStore == "" {
1112+
hlf.Spec.CredentialStore = "kubernetes"
1113+
}
11121114
if exists {
11131115
// update
11141116
log.Debugf("Release %s exists, updating", releaseName)

controllers/identity/identity_controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,9 @@ func (r *FabricIdentityReconciler) Reconcile(ctx context.Context, req ctrl.Reque
121121
return ctrl.Result{}, err
122122
}
123123
}
124+
if fabricIdentity.Spec.CredentialStore == "" {
125+
fabricIdentity.Spec.CredentialStore = "kubernetes"
126+
}
124127
clientSet, err := utils.GetClientKubeWithConf(r.Config)
125128
if err != nil {
126129
r.setConditionStatus(ctx, fabricIdentity, hlfv1alpha1.FailedStatus, false, err, false)

controllers/ordnode/ordnode_controller.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,9 @@ func (r *FabricOrdererNodeReconciler) Reconcile(ctx context.Context, req ctrl.Re
144144
return ctrl.Result{}, err
145145
}
146146
}
147+
if fabricOrdererNode.Spec.CredentialStore == "" {
148+
fabricOrdererNode.Spec.CredentialStore = "kubernetes"
149+
}
147150
cmdStatus := action.NewStatus(cfg)
148151
exists := true
149152
helmStatus, err := cmdStatus.Run(releaseName)
@@ -757,7 +760,7 @@ func ReenrollTLSCryptoMaterial(
757760
return nil, nil, nil, err
758761
}
759762
return tlsCert, tlsKey, tlsRootCert, nil
760-
} else if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreKubernetes {
763+
} else {
761764
reenrollRequest, err := getReenrollRequestForFabricCATLS(client, enrollment, &conf.Spec, "tls")
762765
if err != nil {
763766
return nil, nil, nil, err
@@ -771,8 +774,6 @@ func ReenrollTLSCryptoMaterial(
771774
return nil, nil, nil, err
772775
}
773776
return tlsCert, tlsKey, tlsRootCert, nil
774-
} else {
775-
return nil, nil, nil, errors.New(fmt.Sprintf("not implemented for credential store %s", conf.Spec.CredentialStore))
776777
}
777778
}
778779

controllers/peer/peer_controller.go

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,9 @@ func (r *FabricPeerReconciler) Reconcile(ctx context.Context, req ctrl.Request)
359359
return r.updateCRStatusOrFailReconcile(ctx, r.Log, fabricPeer)
360360
}
361361
}
362-
362+
if fabricPeer.Spec.CredentialStore == "" {
363+
fabricPeer.Spec.CredentialStore = "kubernetes"
364+
}
363365
cmdStatus := action.NewStatus(cfg)
364366
exists := true
365367
helmStatus, err := cmdStatus.Run(releaseName)
@@ -921,17 +923,7 @@ func getEnrollRequestForVaultTLS(tls *hlfv1alpha1.TLSComponent, conf *hlfv1alpha
921923
}
922924

923925
func CreateTLSCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.FabricPeer, enrollment *hlfv1alpha1.TLSComponent) (*x509.Certificate, *ecdsa.PrivateKey, *x509.Certificate, error) {
924-
if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreKubernetes {
925-
enrollRequest, err := getEnrollRequestForFabricCATLS(client, enrollment, conf, "tls")
926-
if err != nil {
927-
return nil, nil, nil, err
928-
}
929-
tlsCert, tlsKey, tlsRootCert, err := certs.EnrollUser(enrollRequest)
930-
if err != nil {
931-
return nil, nil, nil, err
932-
}
933-
return tlsCert, tlsKey, tlsRootCert, nil
934-
} else if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreVault {
926+
if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreVault {
935927
enrollRequest, err := getEnrollRequestForVaultTLS(enrollment, conf, "tls")
936928
if err != nil {
937929
return nil, nil, nil, err
@@ -947,12 +939,6 @@ func CreateTLSCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.Fab
947939
}
948940
return tlsCert, tlsKey, tlsRootCert, nil
949941
} else {
950-
return nil, nil, nil, errors.New("not implemented")
951-
}
952-
}
953-
954-
func CreateTLSOPSCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.FabricPeer, enrollment *hlfv1alpha1.TLSComponent) (*x509.Certificate, *ecdsa.PrivateKey, *x509.Certificate, error) {
955-
if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreKubernetes {
956942
enrollRequest, err := getEnrollRequestForFabricCATLS(client, enrollment, conf, "tls")
957943
if err != nil {
958944
return nil, nil, nil, err
@@ -962,7 +948,11 @@ func CreateTLSOPSCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.
962948
return nil, nil, nil, err
963949
}
964950
return tlsCert, tlsKey, tlsRootCert, nil
965-
} else if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreVault {
951+
}
952+
}
953+
954+
func CreateTLSOPSCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.FabricPeer, enrollment *hlfv1alpha1.TLSComponent) (*x509.Certificate, *ecdsa.PrivateKey, *x509.Certificate, error) {
955+
if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreVault {
966956
enrollRequest, err := getEnrollRequestForVaultTLS(enrollment, conf, "tls")
967957
if err != nil {
968958
return nil, nil, nil, err
@@ -978,14 +968,7 @@ func CreateTLSOPSCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.
978968
}
979969
return tlsCert, tlsKey, tlsRootCert, nil
980970
} else {
981-
return nil, nil, nil, errors.New(fmt.Sprintf("not implemented for credential store %s", conf.Spec.CredentialStore))
982-
}
983-
}
984-
985-
func CreateSignCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.FabricPeer, enrollment *hlfv1alpha1.Component) (*x509.Certificate, *ecdsa.PrivateKey, *x509.Certificate, error) {
986-
switch conf.Spec.CredentialStore {
987-
case hlfv1alpha1.CredentialStoreKubernetes:
988-
enrollRequest, err := getEnrollRequestForFabricCA(client, enrollment, conf, "tls")
971+
enrollRequest, err := getEnrollRequestForFabricCATLS(client, enrollment, conf, "tls")
989972
if err != nil {
990973
return nil, nil, nil, err
991974
}
@@ -994,6 +977,12 @@ func CreateSignCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.Fa
994977
return nil, nil, nil, err
995978
}
996979
return tlsCert, tlsKey, tlsRootCert, nil
980+
}
981+
}
982+
983+
func CreateSignCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.FabricPeer, enrollment *hlfv1alpha1.Component) (*x509.Certificate, *ecdsa.PrivateKey, *x509.Certificate, error) {
984+
switch conf.Spec.CredentialStore {
985+
997986
case hlfv1alpha1.CredentialStoreVault:
998987
enrollRequest, err := getEnrollRequestForVault(enrollment, conf, "tls")
999988
if err != nil {
@@ -1010,7 +999,15 @@ func CreateSignCryptoMaterial(client *kubernetes.Clientset, conf *hlfv1alpha1.Fa
1010999
}
10111000
return tlsCert, tlsKey, tlsRootCert, nil
10121001
default:
1013-
return nil, nil, nil, errors.New(fmt.Sprintf("not implemented for credential store %s", conf.Spec.CredentialStore))
1002+
enrollRequest, err := getEnrollRequestForFabricCA(client, enrollment, conf, "tls")
1003+
if err != nil {
1004+
return nil, nil, nil, err
1005+
}
1006+
tlsCert, tlsKey, tlsRootCert, err := certs.EnrollUser(enrollRequest)
1007+
if err != nil {
1008+
return nil, nil, nil, err
1009+
}
1010+
return tlsCert, tlsKey, tlsRootCert, nil
10141011
}
10151012
}
10161013

@@ -1100,7 +1097,7 @@ func ReenrollSignCryptoMaterial(
11001097
return nil, nil, nil, err
11011098
}
11021099
return signCert, privateKey, signRootCert, nil
1103-
} else if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreKubernetes {
1100+
} else {
11041101
reenrollRequest, err := getReenrollRequestForFabricCA(client, enrollment, &conf.Spec, "tls")
11051102
if err != nil {
11061103
return nil, nil, nil, err
@@ -1114,8 +1111,6 @@ func ReenrollSignCryptoMaterial(
11141111
return nil, nil, nil, err
11151112
}
11161113
return signCert, privateKey, signRootCert, nil
1117-
} else {
1118-
return nil, nil, nil, errors.New(fmt.Sprintf("not implemented for credential store %s", conf.Spec.CredentialStore))
11191114
}
11201115
}
11211116

@@ -1143,7 +1138,7 @@ func ReenrollTLSCryptoMaterial(
11431138
return nil, nil, nil, err
11441139
}
11451140
return tlsCert, tlsKey, tlsRootCert, nil
1146-
} else if conf.Spec.CredentialStore == hlfv1alpha1.CredentialStoreKubernetes {
1141+
} else {
11471142
reenrollRequest, err := getReenrollRequestForFabricCATLS(client, enrollment, &conf.Spec, "tls")
11481143
if err != nil {
11491144
return nil, nil, nil, err
@@ -1157,8 +1152,6 @@ func ReenrollTLSCryptoMaterial(
11571152
return nil, nil, nil, err
11581153
}
11591154
return tlsCert, tlsKey, tlsRootCert, nil
1160-
} else {
1161-
return nil, nil, nil, errors.New(fmt.Sprintf("not implemented for credential store %s", conf.Spec.CredentialStore))
11621155
}
11631156
}
11641157

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
id: prometheus-metrics
3+
title: Prometheus Metrics
4+
---
5+
6+
# Prometheus Metrics
7+
8+
The HLF Operator exposes several Prometheus metrics that can be used for monitoring and alerting on your Hyperledger Fabric network. These metrics provide insights into certificate expiration times and current system time.
9+
10+
## Available Metrics
11+
12+
### Certificate Expiration Metrics
13+
14+
#### `hlf_operator_certificate_expiration_timestamp_seconds`
15+
16+
**Type:** Gauge Vector
17+
**Description:** The date after which the certificate expires, expressed as a Unix Epoch Time.
18+
19+
**Labels:**
20+
- `node_type`: Type of the Fabric node (e.g., "peer", "orderer", "ca")
21+
- `crt_type`: Type of certificate (e.g., "tls", "signcert", "cacert")
22+
- `namespace`: Kubernetes namespace where the resource is deployed
23+
- `name`: Name of the Fabric resource
24+
25+
**Example:**
26+
```
27+
hlf_operator_certificate_expiration_timestamp_seconds{node_type="peer",crt_type="tls",namespace="hlf-network",name="peer0-org1"} 1735689600
28+
```
29+
30+
### System Time Metrics
31+
32+
#### `hlf_operator_current_time_seconds`
33+
34+
**Type:** Gauge
35+
**Description:** The current time in Unix Epoch Time.
36+
37+
**Example:**
38+
```
39+
hlf_operator_current_time_seconds 1735689600
40+
```
41+
42+
## Usage Examples
43+
44+
### Monitoring Certificate Expiration
45+
46+
You can create Prometheus queries to monitor certificate expiration:
47+
48+
```promql
49+
# Get all certificates expiring within the next 30 days
50+
hlf_operator_certificate_expiration_timestamp_seconds - hlf_operator_current_time_seconds < 2592000
51+
52+
# Get certificates expiring within the next 7 days
53+
hlf_operator_certificate_expiration_timestamp_seconds - hlf_operator_current_time_seconds < 604800
54+
55+
# Get certificates by node type
56+
hlf_operator_certificate_expiration_timestamp_seconds{node_type="peer"}
57+
58+
# Get TLS certificates specifically
59+
hlf_operator_certificate_expiration_timestamp_seconds{crt_type="tls"}
60+
```
61+
62+
### Alerting Rules
63+
64+
Here are some example Prometheus alerting rules you can use:
65+
66+
```yaml
67+
groups:
68+
- name: hlf-certificate-alerts
69+
rules:
70+
- alert: CertificateExpiringSoon
71+
expr: (hlf_operator_certificate_expiration_timestamp_seconds - hlf_operator_current_time_seconds) < 604800
72+
for: 5m
73+
labels:
74+
severity: warning
75+
annotations:
76+
summary: "Certificate expiring soon"
77+
description: "Certificate for {{ $labels.node_type }} {{ $labels.name }} in namespace {{ $labels.namespace }} will expire in less than 7 days"
78+
79+
- alert: CertificateExpiringVerySoon
80+
expr: (hlf_operator_certificate_expiration_timestamp_seconds - hlf_operator_current_time_seconds) < 86400
81+
for: 5m
82+
labels:
83+
severity: critical
84+
annotations:
85+
summary: "Certificate expiring very soon"
86+
description: "Certificate for {{ $labels.node_type }} {{ $labels.name }} in namespace {{ $labels.namespace }} will expire in less than 24 hours"
87+
```
88+
89+
### Grafana Dashboard Queries
90+
91+
For Grafana dashboards, you can use these queries:
92+
93+
**Certificate Expiration Timeline:**
94+
```promql
95+
hlf_operator_certificate_expiration_timestamp_seconds
96+
```
97+
98+
**Days Until Expiration:**
99+
```promql
100+
(hlf_operator_certificate_expiration_timestamp_seconds - hlf_operator_current_time_seconds) / 86400
101+
```
102+
103+
**Certificates by Node Type:**
104+
```promql
105+
count by (node_type) (hlf_operator_certificate_expiration_timestamp_seconds)
106+
```
107+
108+
## Enabling Metrics Collection
109+
110+
To collect these metrics, ensure that:
111+
112+
1. **ServiceMonitor is enabled** in your Fabric resources:
113+
```yaml
114+
serviceMonitor:
115+
enabled: true
116+
interval: 10s
117+
labels: {}
118+
sampleLimit: 0
119+
scrapeTimeout: 10s
120+
```
121+
122+
2. **Prometheus Operator is installed** in your cluster to automatically discover and scrape the metrics.
123+
124+
3. **Metrics endpoint is accessible** on the HLF Operator service.
125+
126+
## Metric Updates
127+
128+
- **Certificate expiration metrics** are updated whenever certificates are processed or renewed
129+
- **Current time metric** is updated regularly to provide a reference point for time-based calculations
130+
131+
These metrics help you maintain visibility into your Hyperledger Fabric network's certificate lifecycle and ensure timely certificate renewals to prevent service disruptions.

website-docs/sidebars.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const sidebars: SidebarsConfig = {
2222
"operator-guide/increase-resources",
2323
"operator-guide/increase-storage",
2424
"operator-guide/renew-certificates",
25+
"operator-guide/prometheus-metrics",
2526
"operator-guide/istio",
2627
"operator-guide/upgrade-hlf-operator",
2728
"operator-guide/auto-renew-certificates",

0 commit comments

Comments
 (0)