Skip to content

Commit

Permalink
Rename namespace variable
Browse files Browse the repository at this point in the history
Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti committed May 3, 2022
1 parent 333e57c commit fb0d51a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN apk add --no-cache \

RUN wget https://github.com/mikefarah/yq/releases/download/v4.23.1/yq_linux_amd64 -O /usr/bin/yq && chmod +x /usr/bin/yq

RUN yq 'del(.vm.endpoint) | .chaincode.externalBuilders += { "name": "k8s_builder", "path": "/opt/hyperledger/k8s_builder", "propagateEnvironment": [ "CORE_PEER_ID", "KUBE_NAMESPACE", "KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT" ] }' ${FABRIC_CFG_PATH}/core.yaml > core.yaml
RUN yq 'del(.vm.endpoint) | .chaincode.externalBuilders += { "name": "k8s_builder", "path": "/opt/hyperledger/k8s_builder", "propagateEnvironment": [ "CORE_PEER_ID", "KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT" ] }' ${FABRIC_CFG_PATH}/core.yaml > core.yaml

FROM hyperledger/fabric-peer:${HLF_VERSION}

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Status: it should just about work now but there are a few issues to iron out (an

The k8s builder can be run in cluster using the `KUBERNETES_SERVICE_HOST` and `KUBERNETES_SERVICE_PORT` environment variables, or it can connect using a `KUBECONFIG_PATH` environment variable.

An optional `KUBE_NAMESPACE` can be used to specify the namespace to deploy chaincode to.
An optional `FABRIC_CHAINCODE_NAMESPACE` can be used to specify the namespace to deploy chaincode to.

A `CORE_PEER_ID` environment variable is also currently required.

Expand All @@ -22,7 +22,7 @@ External builders are configured in the `core.yaml` file, for example:
path: /home/peer/ccbuilders/k8s_builder
propagateEnvironment:
- CORE_PEER_ID
- KUBE_NAMESPACE
- FABRIC_CHAINCODE_NAMESPACE
- KUBERNETES_SERVICE_HOST
- KUBERNETES_SERVICE_PORT
```
Expand Down
8 changes: 4 additions & 4 deletions cmd/run/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ func main() {
os.Exit(1)
}

peerID, err := util.GetRequiredEnv("CORE_PEER_ID")
peerID, err := util.GetRequiredEnv(util.PeerIdVariable)
if err != nil {
fmt.Fprintln(os.Stderr, "Expected CORE_PEER_ID environment variable")
fmt.Fprintf(os.Stderr, "Expected %s environment variable\n", util.PeerIdVariable)
os.Exit(1)
}

kubeconfigPath := util.GetOptionalEnv("KUBECONFIG_PATH", "")
kubeconfigPath := util.GetOptionalEnv(util.KubeconfigPathVariable, "")

kubeNamespace := util.GetOptionalEnv("KUBE_NAMESPACE", "")
kubeNamespace := util.GetOptionalEnv(util.ChaincodeNamespaceVariable, "")
if kubeNamespace == "" {
kubeNamespace, err = util.GetKubeNamespace()
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions docs/TEST_NETWORK_K8S.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ The org1 and org2 `core.yaml` files also need to be updated with the k8s builder
path: /opt/hyperledger/k8s_builder
propagateEnvironment:
- CORE_PEER_ID
- KUBE_NAMESPACE
- KUBERNETES_SERVICE_HOST
- KUBERNETES_SERVICE_PORT
```
Expand All @@ -28,8 +27,8 @@ You can use [yq](https://mikefarah.gitbook.io/yq/) to update the `core.yaml` fil
Make sure you are in the `fabric-samples/test-network-k8s` directory before running the following commands.

```shell
yq -i '.chaincode.externalBuilders += { "name": "k8s_builder", "path": "/opt/hyperledger/k8s_builder", "propagateEnvironment": [ "CORE_PEER_ID", "KUBE_NAMESPACE", "KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT" ] }' config/org1/core.yaml
yq -i '.chaincode.externalBuilders += { "name": "k8s_builder", "path": "/opt/hyperledger/k8s_builder", "propagateEnvironment": [ "CORE_PEER_ID", "KUBE_NAMESPACE", "KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT" ] }' config/org2/core.yaml
yq -i '.chaincode.externalBuilders += { "name": "k8s_builder", "path": "/opt/hyperledger/k8s_builder", "propagateEnvironment": [ "CORE_PEER_ID", "KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT" ] }' config/org1/core.yaml
yq -i '.chaincode.externalBuilders += { "name": "k8s_builder", "path": "/opt/hyperledger/k8s_builder", "propagateEnvironment": [ "CORE_PEER_ID", "KUBERNETES_SERVICE_HOST", "KUBERNETES_SERVICE_PORT" ] }' config/org2/core.yaml
```

## Kubernetes permissions
Expand Down
6 changes: 6 additions & 0 deletions internal/util/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ import (
"os"
)

const (
ChaincodeNamespaceVariable = "FABRIC_CHAINCODE_NAMESPACE"
KubeconfigPathVariable = "KUBECONFIG_PATH"
PeerIdVariable = "CORE_PEER_ID"
)

func GetOptionalEnv(key, defaultValue string) string {
if value, ok := os.LookupEnv(key); ok {
return value
Expand Down

0 comments on commit fb0d51a

Please sign in to comment.