Skip to content

Commit

Permalink
[WIP] Run chaincode using jobs
Browse files Browse the repository at this point in the history
See #119

Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti committed May 10, 2024
1 parent 3c6f7a0 commit 7f60ab0
Show file tree
Hide file tree
Showing 4 changed files with 244 additions and 298 deletions.
16 changes: 11 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ We use [pull requests](http://help.github.com/pull-requests/) to deliver changes
1. [Fork the repository](https://guides.github.com/activities/forking/#fork) and create a new branch from `main`.
2. If you've added code that should be tested, add tests!
3. If you've added any new features or made breaking changes, update the documentation.
4. Ensure all the tests pass.
4. Ensure all the tests pass, using `go test -v ./...`.
5. Include a descriptive message, and the [Developer Certificate of Origin (DCO) sign-off](https://github.com/probot/dco#how-it-works) on all commit messages.
6. [Issue a pull request](https://guides.github.com/activities/forking/#making-a-pull-request)!
7. [GitHub Actions](https://github.com/hyperledger-labs/fabric-builder-k8s/actions) builds must succeed before the pull request can be reviewed and merged.
Expand All @@ -34,26 +34,32 @@ We use [pull requests](http://help.github.com/pull-requests/) to deliver changes

Please to try to be consistent with the rest of the code and conform to linting rules where they are provided.

To run the linter, use the following command.

```shell
golangci-lint run ./...
```

## Development environment

There is a [Visual Studio Code Dev Container](https://code.visualstudio.com/docs/devcontainers/containers) which should help develop and test the k8s builder in a consistent development environment.
It includes a preconfigured nano Fabric test network and minikube which can be used to run end to end tests.

Build your latest k8s builder changes.

```
```shell
GOBIN="${PWD}"/.fabric/builders/k8s_builder/bin go install ./cmd/...
```

[Configure kubernetes](./docs/KUBERNETES_CONFIG.md) and export the kubeconfig path.

```
```shell
export KUBECONFIG_PATH="${HOME}/.kube/config"
```

Start the Fabric test network in the `.fabric/test-network-nano-bash` directory.

```
```shell
./network.sh start
```

Expand All @@ -67,7 +73,7 @@ curl -fsSL \

Set up the environment for running peer commands and check everything is working.

```
```shell
. ./peer1admin.sh
peer channel list
```
Expand Down
18 changes: 10 additions & 8 deletions internal/builder/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (r *Run) Run(ctx context.Context) error {
return err
}

kubeObjectName := util.GetValidRfc1035LabelName(r.KubeNamePrefix, r.PeerID, chaincodeData)
kubeObjectName := util.GetValidRfc1035LabelName(r.KubeNamePrefix, r.PeerID, chaincodeData, util.ObjectNameSuffixLength+1)

clientset, err := util.GetKubeClientset(logger, r.KubeconfigPath)
if err != nil {
Expand Down Expand Up @@ -64,12 +64,12 @@ func (r *Run) Run(ctx context.Context) error {
)
}

podsClient := clientset.CoreV1().Pods(r.KubeNamespace)
jobsClient := clientset.BatchV1().Jobs(r.KubeNamespace)

pod, err := util.CreateChaincodePod(
job, err := util.CreateChaincodeJob(
ctx,
logger,
podsClient,
jobsClient,
kubeObjectName,
r.KubeNamespace,
r.KubeServiceAccount,
Expand All @@ -82,11 +82,13 @@ func (r *Run) Run(ctx context.Context) error {
}

logger.Printf(
"Running chaincode ID %s in kubernetes pod %s/%s",
"Running chaincode ID %s with kubernetes job %s/%s",
chaincodeData.ChaincodeID,
pod.Namespace,
pod.Name,
job.Namespace,
job.Name,
)

return util.WaitForChaincodePod(ctx, logger, podsClient, pod, chaincodeData.ChaincodeID)
batchClient := clientset.BatchV1().RESTClient()

return util.WaitForChaincodeJob(ctx, logger, batchClient, job, chaincodeData.ChaincodeID)
}
Loading

0 comments on commit 7f60ab0

Please sign in to comment.