Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Signed-off-by: David VIEJO <[email protected]>
  • Loading branch information
dviejokfs committed Oct 14, 2024
1 parent fd043ca commit cf4c151
Show file tree
Hide file tree
Showing 10 changed files with 58 additions and 27 deletions.
28 changes: 14 additions & 14 deletions .github/workflows/test-kubectl-plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ jobs:
make generate manifests install
- name: Install Istio
run: |
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.20.0 TARGET_ARCH=x86_64 sh -
export PATH="$PATH:$PWD/istio-1.20.0/bin"
curl -L https://istio.io/downloadIstio | ISTIO_VERSION=1.23.2 TARGET_ARCH=x86_64 sh -
export PATH="$PATH:$PWD/istio-1.23.2/bin"
kubectl create namespace istio-system
istioctl operator init
Expand Down Expand Up @@ -123,7 +123,7 @@ jobs:

sleep 2

kubectl wait --timeout=180s --for=jsonpath='{.status.status}'=HEALTHY istiooperator istio-gateway --namespace=istio-system
kubectl wait --timeout=240s --for=jsonpath='{.status.status}'=HEALTHY istiooperator istio-gateway --namespace=istio-system

- name: Configure DNS in Kubernetes
run: |
Expand Down Expand Up @@ -169,14 +169,14 @@ jobs:
- name: Create Peer org
run: |
export PEER_IMAGE=hyperledger/fabric-peer
export PEER_VERSION=2.5.5
export PEER_VERSION=2.5.10
export CA_IMAGE=hyperledger/fabric-ca
export CA_VERSION=1.5.7
export CA_VERSION=1.5.13
kubectl hlf ca create --image=$CA_IMAGE --version=$CA_VERSION --storage-class=standard --capacity=2Gi --name=org1-ca \
--enroll-id=enroll --hosts=org1-ca.localho.st --enroll-pw=enrollpw
kubectl wait --timeout=180s --for=condition=Running fabriccas.hlf.kungfusoftware.es --all
kubectl wait --timeout=240s --for=condition=Running fabriccas.hlf.kungfusoftware.es --all
# register user for the peers
kubectl hlf ca register --name=org1-ca --user=peer --secret=peerpw --type=peer \
Expand All @@ -186,26 +186,26 @@ jobs:
kubectl hlf peer create --statedb=couchdb --image=$PEER_IMAGE --version=$PEER_VERSION \
--storage-class=standard --enroll-id=peer --mspid=Org1MSP \
--enroll-pw=peerpw --hosts=peer0-org1.localho.st --capacity=5Gi --name=org1-peer0 --ca-name=org1-ca.default
kubectl wait --timeout=180s --for=condition=Running fabricpeers.hlf.kungfusoftware.es --all
kubectl wait --timeout=240s --for=condition=Running fabricpeers.hlf.kungfusoftware.es --all
- name: Create Orderer Org
run: |
export ORDERER_IMAGE=hyperledger/fabric-orderer
export ORDERER_VERSION=2.5.5
export ORDERER_VERSION=2.5.10
export CA_IMAGE=hyperledger/fabric-ca
export CA_VERSION=1.5.7
export CA_VERSION=1.5.13
kubectl hlf ca create --image=$CA_IMAGE --version=$CA_VERSION --storage-class=standard --capacity=2Gi --name=ord-ca \
--enroll-id=enroll --enroll-pw=enrollpw --hosts=ord-ca.localho.st
kubectl wait --timeout=180s --for=condition=Running fabriccas.hlf.kungfusoftware.es --all
kubectl wait --timeout=240s --for=condition=Running fabriccas.hlf.kungfusoftware.es --all
kubectl hlf ca register --name=ord-ca --user=orderer --secret=ordererpw \
--type=orderer --enroll-id enroll --enroll-secret=enrollpw --mspid=OrdererMSP
kubectl hlf ordnode create --image=$ORDERER_IMAGE --version=$ORDERER_VERSION \
--storage-class=standard --enroll-id=orderer --mspid=OrdererMSP --hosts=orderer0-ord.localho.st --admin-hosts=admin-orderer0-ord.localho.st \
--enroll-pw=ordererpw --capacity=2Gi --name=ord-node1 --ca-name=ord-ca.default
kubectl wait --timeout=180s --for=condition=Running fabricorderernodes.hlf.kungfusoftware.es --all
kubectl wait --timeout=240s --for=condition=Running fabricorderernodes.hlf.kungfusoftware.es --all
- name: Prepare Connection string for Orderer Node
run: |
kubectl hlf inspect --output ordservice.yaml -o OrdererMSP
Expand Down Expand Up @@ -258,7 +258,7 @@ jobs:
--identities="OrdererMSP;admin-tls-ordservice.yaml" \
--identities="Org1MSP;peer-org1.yaml"
kubectl wait --timeout=180s --for=condition=RUNNING fabricmainchannels.hlf.kungfusoftware.es --all
kubectl wait --timeout=240s --for=condition=RUNNING fabricmainchannels.hlf.kungfusoftware.es --all
- name: Join peers to channel
Expand All @@ -276,7 +276,7 @@ jobs:
--secret-ns=default \
--secret-key="peer-org1.yaml"
kubectl wait --timeout=180s --for=condition=RUNNING fabricfollowerchannels.hlf.kungfusoftware.es --all
kubectl wait --timeout=240s --for=condition=RUNNING fabricfollowerchannels.hlf.kungfusoftware.es --all
- name: Get channel
run: |
sleep 3
Expand Down Expand Up @@ -334,7 +334,7 @@ jobs:
run: |
sleep 10
echo "waiting for deployment to be ready"
kubectl wait --timeout=180s --for=condition=Available deployment asset --namespace=default
kubectl wait --timeout=240s --for=condition=Available deployment asset --namespace=default
kubectl hlf chaincode invoke --config=org1.yaml \
--user=admin --peer=org1-peer0.default \
--chaincode=asset --channel=demo \
Expand Down
3 changes: 1 addition & 2 deletions controllers/ca/ca_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"github.com/kfsoftware/hlf-operator/pkg/status"
"helm.sh/helm/v3/pkg/cli"
"helm.sh/helm/v3/pkg/release"
"k8s.io/kubernetes/pkg/api/v1/pod"
"sigs.k8s.io/controller-runtime/pkg/controller"
"sort"

Expand Down Expand Up @@ -746,7 +745,7 @@ func GetCAState(clientSet *kubernetes.Clientset, ca *hlfv1alpha1.FabricCA, relea
}
if len(pods.Items) > 0 {
for _, item := range pods.Items {
if pod.IsPodReadyConditionTrue(item.Status) {
if utils.IsPodReadyConditionTrue(item.Status) {
r.Status = hlfv1alpha1.RunningStatus
} else {
switch item.Status.Phase {
Expand Down
3 changes: 1 addition & 2 deletions controllers/console/console_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/cli"
"k8s.io/kubernetes/pkg/api/v1/pod"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -98,7 +97,7 @@ func GetConsoleState(conf *action.Configuration, config *rest.Config, releaseNam
}
if len(pods.Items) > 0 {
for _, item := range pods.Items {
if pod.IsPodReadyConditionTrue(item.Status) {
if utils.IsPodReadyConditionTrue(item.Status) {
r.Status = hlfv1alpha1.RunningStatus
} else {
switch item.Status.Phase {
Expand Down
3 changes: 1 addition & 2 deletions controllers/operatorapi/operatorapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/cli"
"k8s.io/kubernetes/pkg/api/v1/pod"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -98,7 +97,7 @@ func GetConsoleState(conf *action.Configuration, config *rest.Config, releaseNam
}
if len(pods.Items) > 0 {
for _, item := range pods.Items {
if pod.IsPodReadyConditionTrue(item.Status) {
if utils.IsPodReadyConditionTrue(item.Status) {
r.Status = hlfv1alpha1.RunningStatus
} else {
switch item.Status.Phase {
Expand Down
3 changes: 1 addition & 2 deletions controllers/operatorui/operatorui.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/pkg/errors"
log "github.com/sirupsen/logrus"
"helm.sh/helm/v3/pkg/cli"
"k8s.io/kubernetes/pkg/api/v1/pod"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -98,7 +97,7 @@ func GetOperatorUIState(conf *action.Configuration, config *rest.Config, release
}
if len(pods.Items) > 0 {
for _, item := range pods.Items {
if pod.IsPodReadyConditionTrue(item.Status) {
if utils.IsPodReadyConditionTrue(item.Status) {
r.Status = hlfv1alpha1.RunningStatus
} else {
switch item.Status.Phase {
Expand Down
3 changes: 1 addition & 2 deletions controllers/ordnode/ordnode_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"k8s.io/kubernetes/pkg/api/v1/pod"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/controller"
Expand Down Expand Up @@ -1398,7 +1397,7 @@ func GetOrdererState(conf *action.Configuration, config *rest.Config, releaseNam
}
if len(pods.Items) > 0 {
for _, item := range pods.Items {
if pod.IsPodReadyConditionTrue(item.Status) {
if utils.IsPodReadyConditionTrue(item.Status) {
r.Status = hlfv1alpha1.RunningStatus
} else {
switch item.Status.Phase {
Expand Down
3 changes: 1 addition & 2 deletions controllers/peer/peer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"helm.sh/helm/v3/pkg/cli"
apiv1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/kubernetes/pkg/api/v1/pod"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

Expand Down Expand Up @@ -180,7 +179,7 @@ func GetPeerState(conf *action.Configuration, config *rest.Config, releaseName s
}
if len(pods.Items) > 0 {
for _, item := range pods.Items {
if pod.IsPodReadyConditionTrue(item.Status) {
if utils.IsPodReadyConditionTrue(item.Status) {
r.Status = hlfv1alpha1.RunningStatus
} else {
switch item.Status.Phase {
Expand Down
37 changes: 37 additions & 0 deletions controllers/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"strings"
"time"

corev1 "k8s.io/api/core/v1"
v12 "k8s.io/api/core/v1"
apiextv1beta1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1beta1"
v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down Expand Up @@ -197,3 +198,39 @@ func GetFreeNodeports(host string, n int) ([]int, error) {
}
return []int{}, errors.New("no ports are free")
}

// IsPodReadyConditionTrue returns true if a pod is ready; false otherwise.
func IsPodReadyConditionTrue(status corev1.PodStatus) bool {
condition := GetPodReadyCondition(status)
return condition != nil && condition.Status == corev1.ConditionTrue
}

// GetPodReadyCondition extracts the pod ready condition from the given status and returns that.
// Returns nil if the condition is not present.
func GetPodReadyCondition(status corev1.PodStatus) *corev1.PodCondition {
_, condition := GetPodCondition(&status, corev1.PodReady)
return condition
}

// GetPodCondition extracts the provided condition from the given status and returns that.
// Returns nil and -1 if the condition is not present, and the index of the located condition.
func GetPodCondition(status *corev1.PodStatus, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) {
if status == nil {
return -1, nil
}
return GetPodConditionFromList(status.Conditions, conditionType)
}

// GetPodConditionFromList extracts the provided condition from the given list of condition and
// returns the index of the condition and the condition. Returns -1 and nil if the condition is not present.
func GetPodConditionFromList(conditions []corev1.PodCondition, conditionType corev1.PodConditionType) (int, *corev1.PodCondition) {
if conditions == nil {
return -1, nil
}
for i := range conditions {
if conditions[i].Type == conditionType {
return i, &conditions[i]
}
}
return -1, nil
}
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ require (
k8s.io/cli-runtime v0.29.0
k8s.io/client-go v0.31.1
k8s.io/code-generator v0.31.1
k8s.io/kubernetes v1.13.0
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8
sigs.k8s.io/controller-runtime v0.19.0
sigs.k8s.io/yaml v1.4.0
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1354,6 +1354,7 @@ k8s.io/kubectl v0.29.0 h1:Oqi48gXjikDhrBF67AYuZRTcJV4lg2l42GmvsP7FmYI=
k8s.io/kubectl v0.29.0/go.mod h1:0jMjGWIcMIQzmUaMgAzhSELv5WtHo2a8pq67DtviAJs=
k8s.io/kubernetes v1.13.0 h1:qTfB+u5M92k2fCCCVP2iuhgwwSOv1EkAkvQY1tQODD8=
k8s.io/kubernetes v1.13.0/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
k8s.io/kubernetes v1.31.1/go.mod h1:/YGPL//Fb9mdv5vukvAQ7Xon+Bqwry52bmjTdORAw+Q=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 h1:pUdcCO1Lk/tbT5ztQWOBi5HBgbBP1J8+AsQnQCKsi8A=
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo=
Expand Down

0 comments on commit cf4c151

Please sign in to comment.