Rendering arrays of Components with React

React doesn’t support the use of a for() loop in it’s render method. If you need to render a list of components based on data, one approach is to build a var representing the list of components in a helper function as described here.

Another approach is to use .map() to build an array of Components from an array of values, like this:

this.state.grid.map( (cell, index) => (
<CellComponent key={index} value={this.state.grid[index]}
onChange={this.handleChangeForArrayFields.bind(this, index)}/>
)
)}

In this example, this.state.grid is an array containing values to map to each rendered value attribute on my Component. Each rendered element needs to be unique, so we add the key attribute, and set it to the index from each element that comes out of the map function.

I’ll look at the onChange handler in a followon post.

Kubernetes: installing helm tiller with RBAC role and service account

From here.

kubectl create namespace tiller-world
kubectl create serviceaccount tiller --namespace tiller-world

role-tiller.yml:

kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-manager
  namespace: tiller-world
rules:
- apiGroups: ["", "batch", "extensions", "apps"]
  resources: ["*"]
  verbs: ["*"]

rolebinding-tiller.yml:

kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
  name: tiller-binding
  namespace: tiller-world
subjects:
- kind: ServiceAccount
  name: tiller
  namespace: tiller-world
roleRef:
  kind: Role
  name: tiller-manager
  apiGroup: rbac.authorization.k8s.io

helm init with service account and namespace:

helm init --service-account tiller --tiller-namespace tiller-world

Combining with tls certs (from here):

helm init --tiller-tls --tiller-tls-cert ./tiller.cert.pem --tiller-tls-key ./tiller.key.pem --tiller-tls-verify --tls-ca-cert ca.cert.pem --service-account tiller --tiller-namespace tiller-world