Skip to content

Commit e38c096

Browse files
authored
Update Fabric CA deployment to support configurable replicas (#266)
* Update Fabric CA deployment to support configurable replicas - Modified the deployment template to use a dynamic `replicas` value from the Helm chart's values. - Added `replicas` field to the Fabric CA CRD and updated related types to ensure proper handling of replica counts. - Enhanced the CA controller to utilize the specified number of replicas when managing deployments. These changes improve the flexibility and scalability of the Fabric CA deployment by allowing users to configure the number of replicas as needed. Signed-off-by: dviejokfs <[email protected]> * Update Signed-off-by: dviejokfs <[email protected]> * Fix issue with replicas CA Signed-off-by: David VIEJO <[email protected]> * Enhance GitHub Actions test workflow to include additional Kubernetes diagnostics - Added commands to retrieve services, custom resource definitions (CRDs), and logs for specific pods. - Included detailed output for fabric main and follower channels, improving troubleshooting capabilities during test failures. These changes aim to provide more comprehensive information for debugging Kubernetes deployments in the CI pipeline.
1 parent a90370c commit e38c096

File tree

9 files changed

+60
-8
lines changed

9 files changed

+60
-8
lines changed

.github/workflows/test.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,27 @@ jobs:
3131
3232
- name: Test
3333
run: make test
34+
3435
- name: Show information
3536
if: ${{ failure() }}
3637
run: |
3738
kubectl get nodes -o=wide
3839
kubectl get pods -o=wide -A
40+
kubectl get service -o=wide -A
41+
kubectl get crds
3942
kubectl get fabricpeers.hlf.kungfusoftware.es -A -o=custom-columns='NAME:metadata.name,NAMESPACE:metadata.namespace,STATE:status.status,MESSAGE:status.message'
4043
kubectl get fabricorderernodes.hlf.kungfusoftware.es -A -o=custom-columns='NAME:metadata.name,NAMESPACE:metadata.namespace,STATE:status.status,MESSAGE:status.message'
4144
kubectl get fabriccas.hlf.kungfusoftware.es -A -o=custom-columns='NAME:metadata.name,NAMESPACE:metadata.namespace,STATE:status.status,MESSAGE:status.message'
45+
kubectl get fabricmainchannels.hlf.kungfusoftware.es -A -o=custom-columns='NAME:metadata.name,NAMESPACE:metadata.namespace,STATE:status.status,MESSAGE:status.message'
46+
kubectl get fabricfollowerchannels.hlf.kungfusoftware.es -A -o=custom-columns='NAME:metadata.name,NAMESPACE:metadata.namespace,STATE:status.status,MESSAGE:status.message'
47+
kubectl get configmap coredns -n kube-system -o yaml
48+
echo "Logs for hlf-operator deployment:"
49+
kubectl logs -l app.kubernetes.io/name=hlf-operator -c manager --tail 2500
50+
kubectl get fabricmainchannels -o yaml
51+
kubectl get fabricfollowerchannels -o yaml
52+
53+
POD=$(kubectl get pod -l 'release in (org1-peer0)' -o jsonpath="{.items[0].metadata.name}")
54+
kubectl logs $POD -c peer
55+
56+
POD=$(kubectl get pod -l 'release in (ord-node1)' -o jsonpath="{.items[0].metadata.name}")
57+
kubectl logs $POD

charts/hlf-ca/templates/deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ metadata:
55
labels:
66
{{ include "labels.standard" . | indent 4 }}
77
spec:
8-
replicas: 1
8+
replicas: {{ .Values.replicas }}
99
selector:
1010
matchLabels:
1111
app: {{ include "hlf-ca.name" . }}

config/crd/bases/hlf.kungfusoftware.es_fabriccas.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,6 +1048,9 @@ spec:
10481048
default: {}
10491049
nullable: true
10501050
type: object
1051+
replicas:
1052+
default: 1
1053+
type: integer
10511054
resources:
10521055
properties:
10531056
claims:
@@ -1555,6 +1558,7 @@ spec:
15551558
- hosts
15561559
- image
15571560
- metrics
1561+
- replicas
15581562
- resources
15591563
- rootCA
15601564
- service

controllers/ca/ca_controller.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ import (
1313
"encoding/json"
1414
"encoding/pem"
1515
"fmt"
16+
"sort"
17+
1618
"github.com/go-logr/logr"
1719
"github.com/kfsoftware/hlf-operator/controllers/hlfmetrics"
1820
"github.com/kfsoftware/hlf-operator/pkg/status"
1921
"helm.sh/helm/v3/pkg/cli"
2022
"helm.sh/helm/v3/pkg/release"
2123
"sigs.k8s.io/controller-runtime/pkg/controller"
22-
"sort"
2324

2425
"math/big"
2526
"net"
@@ -642,7 +643,12 @@ func GetConfig(conf *hlfv1alpha1.FabricCA, client *kubernetes.Clientset, chartNa
642643
Hosts: spec.Traefik.Hosts,
643644
}
644645
}
646+
replicas := 1
647+
if spec.Replicas != nil {
648+
replicas = *spec.Replicas
649+
}
645650
var c = FabricCAChart{
651+
Replicas: replicas,
646652
PodLabels: spec.PodLabels,
647653
PodAnnotations: spec.PodAnnotations,
648654
ImagePullSecrets: spec.ImagePullSecrets,
@@ -761,7 +767,11 @@ func GetCAState(clientSet *kubernetes.Clientset, ca *hlfv1alpha1.FabricCA, relea
761767
}
762768
}
763769
} else {
764-
if dep.Status.ReadyReplicas == *dep.Spec.Replicas {
770+
replicas := 1
771+
if ca.Spec.Replicas != nil {
772+
replicas = *ca.Spec.Replicas
773+
}
774+
if dep.Status.ReadyReplicas == int32(replicas) {
765775
r.Status = hlfv1alpha1.RunningStatus
766776
} else {
767777
r.Status = hlfv1alpha1.PendingStatus

controllers/ca/types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ type FabricCAChart struct {
2727
ServiceMonitor ServiceMonitor `json:"serviceMonitor"`
2828
EnvVars []corev1.EnvVar `json:"envVars"`
2929
ImagePullSecrets []corev1.LocalObjectReference `json:"imagePullSecrets"`
30+
// +kubebuilder:default:=1
31+
Replicas int `json:"replicas"`
3032
}
3133
type ServiceMonitor struct {
3234
Enabled bool `json:"enabled"`

controllers/tests/ca_controller_test.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,14 @@ import (
55
"context"
66
"encoding/base64"
77
"fmt"
8+
"strconv"
9+
"strings"
10+
"text/template"
11+
812
"github.com/kfsoftware/hlf-operator/controllers/ca"
913
operatorv1alpha1 "github.com/kfsoftware/hlf-operator/pkg/client/clientset/versioned"
1014
log "github.com/sirupsen/logrus"
1115
apierrors "k8s.io/apimachinery/pkg/api/errors"
12-
"strconv"
13-
"strings"
14-
"text/template"
1516

1617
"github.com/Masterminds/sprig"
1718
"github.com/hyperledger/fabric-sdk-go/pkg/client/resmgmt"
@@ -219,6 +220,7 @@ func randomFabricCA(releaseName string, namespace string) *hlfv1alpha1.FabricCA
219220
Expect(err).ToNot(HaveOccurred())
220221
k8sIP, err := utils.GetPublicIPKubernetes(ClientSet)
221222
Expect(err).ToNot(HaveOccurred())
223+
replicas := 1
222224

223225
fabricCa := &hlfv1alpha1.FabricCA{
224226
TypeMeta: NewTypeMeta("FabricCA"),
@@ -227,7 +229,7 @@ func randomFabricCA(releaseName string, namespace string) *hlfv1alpha1.FabricCA
227229
Namespace: namespace,
228230
},
229231
Spec: hlfv1alpha1.FabricCASpec{
230-
232+
Replicas: &replicas,
231233
Istio: &hlfv1alpha1.FabricIstio{
232234
Hosts: []string{},
233235
},
@@ -808,14 +810,15 @@ var _ = Describe("Fabric Controllers", func() {
808810
Expect(err).ToNot(HaveOccurred())
809811
k8sIP, err := utils.GetPublicIPKubernetes(ClientSet)
810812
Expect(err).ToNot(HaveOccurred())
811-
813+
replicas := 1
812814
fabricCa := &hlfv1alpha1.FabricCA{
813815
TypeMeta: NewTypeMeta("FabricCA"),
814816
ObjectMeta: v1.ObjectMeta{
815817
Name: objName,
816818
Namespace: FabricNamespace,
817819
},
818820
Spec: hlfv1alpha1.FabricCASpec{
821+
Replicas: &replicas,
819822
Istio: &hlfv1alpha1.FabricIstio{
820823
Hosts: []string{},
821824
},

kubectl-hlf/cmd/ca/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ func (c *createCmd) run(_ []string) error {
130130
if err != nil {
131131
return err
132132
}
133+
replicas := 1
133134
fabricCA := &v1alpha1.FabricCA{
134135
TypeMeta: v1.TypeMeta{
135136
Kind: "FabricCA",
@@ -140,6 +141,7 @@ func (c *createCmd) run(_ []string) error {
140141
Namespace: c.caOpts.NS,
141142
},
142143
Spec: v1alpha1.FabricCASpec{
144+
Replicas: &replicas,
143145
Database: v1alpha1.FabricCADatabase{
144146
Type: c.caOpts.DBType,
145147
Datasource: c.caOpts.DBDataSource,

pkg/apis/hlf.kungfusoftware.es/v1alpha1/hlf_types.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,11 @@ type FabricCASpec struct {
801801
// +optional
802802
// +kubebuilder:validation:Default={}
803803
Env []corev1.EnvVar `json:"env"`
804+
805+
// +kubebuilder:default:=1
806+
// +optional
807+
// +nullable
808+
Replicas *int `json:"replicas"`
804809
}
805810

806811
type FabricCATLSConf struct {

pkg/apis/hlf.kungfusoftware.es/v1alpha1/zz_generated.deepcopy.go

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)