mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-15 04:57:56 +00:00
Merge pull request #256 from askervin/make-yamls
Makefile: create default yamls, configurable namespace, docker-push
This commit is contained in:
commit
9df0daef99
7 changed files with 72 additions and 29 deletions
19
Makefile
19
Makefile
|
@ -1,4 +1,5 @@
|
||||||
.PHONY: all test
|
.PHONY: all test yamls
|
||||||
|
.FORCE:
|
||||||
|
|
||||||
IMAGE_BUILD_CMD := docker build
|
IMAGE_BUILD_CMD := docker build
|
||||||
|
|
||||||
|
@ -9,14 +10,28 @@ IMAGE_NAME := node-feature-discovery
|
||||||
IMAGE_TAG_NAME := $(VERSION)
|
IMAGE_TAG_NAME := $(VERSION)
|
||||||
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
|
IMAGE_REPO := $(IMAGE_REGISTRY)/$(IMAGE_NAME)
|
||||||
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)
|
IMAGE_TAG := $(IMAGE_REPO):$(IMAGE_TAG_NAME)
|
||||||
|
K8S_NAMESPACE := kube-system
|
||||||
|
|
||||||
|
yaml_templates := $(wildcard *.yaml.template)
|
||||||
|
yaml_instances := $(patsubst %.yaml.template,%.yaml,$(yaml_templates))
|
||||||
|
|
||||||
all: image
|
all: image
|
||||||
|
|
||||||
image:
|
image: yamls
|
||||||
$(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \
|
$(IMAGE_BUILD_CMD) --build-arg NFD_VERSION=$(VERSION) \
|
||||||
-t $(IMAGE_TAG) ./
|
-t $(IMAGE_TAG) ./
|
||||||
|
|
||||||
|
yamls: $(yaml_instances)
|
||||||
|
|
||||||
|
%.yaml: %.yaml.template .FORCE
|
||||||
|
@echo "$@: namespace: ${K8S_NAMESPACE}"
|
||||||
|
@echo "$@: image: ${IMAGE_TAG}"
|
||||||
|
@sed -E \
|
||||||
|
-e s',^(\s*)name: node-feature-discovery # NFD namespace,\1name: ${K8S_NAMESPACE},' \
|
||||||
|
-e s',^(\s*)image:.+$$,\1image: ${IMAGE_TAG},' \
|
||||||
|
-e s',^(\s*)namespace:.+$$,\1namespace: ${K8S_NAMESPACE},' \
|
||||||
|
$< > $@
|
||||||
|
|
||||||
mock:
|
mock:
|
||||||
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
|
mockery --name=FeatureSource --dir=source --inpkg --note="Re-generate by running 'make mock'"
|
||||||
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"
|
mockery --name=APIHelpers --dir=pkg/apihelper --inpkg --note="Re-generate by running 'make mock'"
|
||||||
|
|
31
README.md
31
README.md
|
@ -436,16 +436,18 @@ If you want to use the latest development version (master branch) you need to
|
||||||
|
|
||||||
#### nfd-master
|
#### nfd-master
|
||||||
|
|
||||||
Nfd-master runs as a DaemonSet, by default in the master node(s) only. You can
|
Nfd-master runs as a DaemonSet, by default in the master node(s)
|
||||||
use the template spec provided to deploy nfd-master. If deploying a custom
|
only. You can use the template spec provided to deploy nfd-master, or
|
||||||
image, you need to update the template to use the correct image (for the latest
|
use `nfd-master.yaml` generated by `Makefile`. The latter includes
|
||||||
released version, omit the `sed` part):
|
`image:` and `namespace:` definitions that match the latest built
|
||||||
|
image. Example:
|
||||||
```
|
```
|
||||||
sed -E s',^(\s*)image:.+$,\1image: <YOUR_IMAGE_REPO>:<YOUR_IMAGE_TAG>,' nfd-master.yaml.template > nfd-master.yaml
|
make IMAGE_TAG=<IMAGE_TAG>
|
||||||
|
docker push <IMAGE_TAG>
|
||||||
kubectl create -f nfd-master.yaml
|
kubectl create -f nfd-master.yaml
|
||||||
```
|
```
|
||||||
Nfd-master listens for connections from nfd-worker(s) and connects to the
|
Nfd-master listens for connections from nfd-worker(s) and connects to the
|
||||||
Kubernetes API server to adds node labels advertised by them.
|
Kubernetes API server to add node labels advertised by them.
|
||||||
|
|
||||||
If you have RBAC authorization enabled (as is the default e.g. with clusters
|
If you have RBAC authorization enabled (as is the default e.g. with clusters
|
||||||
initialized with kubeadm) you need to configure the appropriate ClusterRoles,
|
initialized with kubeadm) you need to configure the appropriate ClusterRoles,
|
||||||
|
@ -456,12 +458,14 @@ labels. The provided template will configure these for you.
|
||||||
#### nfd-worker
|
#### nfd-worker
|
||||||
|
|
||||||
Nfd-worker is preferably run as a Kubernetes DaemonSet. There is an
|
Nfd-worker is preferably run as a Kubernetes DaemonSet. There is an
|
||||||
example spec that can be used as a template, or, as is when just trying out the
|
example spec (`nfd-worker-daemonset.yaml.template`) that can be used
|
||||||
service. Similarly to nfd-master above, if using a custom-built image you need
|
as a template, or, as is when just trying out the service. Similarly
|
||||||
to update the template with the correct image (for the latest release, omit the
|
to nfd-master above, the `Makefile` also generates
|
||||||
`sed` part):
|
`nfd-worker-daemonset.yaml` from the template that you can use to
|
||||||
|
deploy the latest image. Example:
|
||||||
```
|
```
|
||||||
sed -E s',^(\s*)image:.+$,\1image: <YOUR_IMAGE_REPO>:<YOUR_IMAGE_TAG>,' nfd-worker-daemonset.yaml.template > nfd-worker-daemonset.yaml
|
make IMAGE_TAG=<IMAGE_TAG>
|
||||||
|
docker push <IMAGE_TAG>
|
||||||
kubectl create -f nfd-worker-daemonset.yaml
|
kubectl create -f nfd-worker-daemonset.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -475,7 +479,7 @@ Feature discovery can alternatively be configured as a one-shot job. There is
|
||||||
an example script in this repo that demonstrates how to deploy the job in the cluster.
|
an example script in this repo that demonstrates how to deploy the job in the cluster.
|
||||||
|
|
||||||
```
|
```
|
||||||
./label-nodes.sh [<YOUR_IMAGE_REPO>:<YOUR_IMAGE_TAG>]
|
./label-nodes.sh [<IMAGE_TAG>]
|
||||||
```
|
```
|
||||||
|
|
||||||
The label-nodes.sh script tries to launch as many jobs as there are Ready nodes.
|
The label-nodes.sh script tries to launch as many jobs as there are Ready nodes.
|
||||||
|
@ -592,7 +596,7 @@ make
|
||||||
Optional, this example with Docker.
|
Optional, this example with Docker.
|
||||||
|
|
||||||
```
|
```
|
||||||
docker push <image registry>/<image-name>:<version>
|
docker push <IMAGE_TAG>
|
||||||
```
|
```
|
||||||
|
|
||||||
**Change the job spec to use your custom image (optional):**
|
**Change the job spec to use your custom image (optional):**
|
||||||
|
@ -614,6 +618,7 @@ name of the resulting container image.
|
||||||
| IMAGE_TAG_NAME | Container image tag name | <nfd version>
|
| IMAGE_TAG_NAME | Container image tag name | <nfd version>
|
||||||
| IMAGE_REPO | Container image repository to use | <IMAGE_REGISTRY>/<IMAGE_NAME>
|
| IMAGE_REPO | Container image repository to use | <IMAGE_REGISTRY>/<IMAGE_NAME>
|
||||||
| IMAGE_TAG | Full image:tag to tag the image with | <IMAGE_REPO>/<IMAGE_NAME>
|
| IMAGE_TAG | Full image:tag to tag the image with | <IMAGE_REPO>/<IMAGE_NAME>
|
||||||
|
| K8S_NAMESPACE | nfd-master and nfd-worker namespace | kube-system
|
||||||
|
|
||||||
For example, to use a custom registry:
|
For example, to use a custom registry:
|
||||||
```
|
```
|
||||||
|
|
|
@ -1,23 +1,36 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
this=`basename $0`
|
this=`basename $0`
|
||||||
if [ $# -gt 1 ]; then
|
if [ $# -gt 1 ] || [ "$1" == "-h" ] || [ "$1" == "--help" ]; then
|
||||||
echo Usage: $this [IMAGE[:TAG]]
|
echo Usage: $this [IMAGE[:TAG]]
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
IMAGE=$1
|
||||||
|
if [ -n "$IMAGE" ]; then
|
||||||
|
if [ ! -f nfd-worker-job.yaml ]; then
|
||||||
|
make IMAGE_TAG=$IMAGE nfd-worker-job.yaml
|
||||||
|
else
|
||||||
|
# Keep existing nfd-worker-job.yaml, only update image.
|
||||||
|
sed -E "s,^(\s*)image:.+$,\1image: $IMAGE," -i nfd-worker-job.yaml
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ! -f nfd-worker-job.yaml ]; then
|
||||||
|
# Missing image info for the labeling job.
|
||||||
|
echo "nfd-worker-job.yaml missing."
|
||||||
|
echo "Run 'make nfd-worker-job.yaml', use the template or provide IMAGE (see --help)."
|
||||||
|
exit 2
|
||||||
|
fi
|
||||||
|
|
||||||
# Get the number of nodes in Ready state in the Kubernetes cluster
|
# Get the number of nodes in Ready state in the Kubernetes cluster
|
||||||
NumNodes=$(kubectl get nodes | grep -i ' ready ' | wc -l)
|
NumNodes=$(kubectl get nodes | grep -i ' ready ' | wc -l)
|
||||||
|
|
||||||
# We set the .spec.completions and .spec.parallelism to the node count
|
# We set the .spec.completions and .spec.parallelism to the node count
|
||||||
# We request a specific hostPort in the job spec to limit the number of pods
|
# We request a specific hostPort in the job spec to limit the number of pods
|
||||||
# that run on a node to one. As a result, one pod runs on each node in parallel
|
# that run on a node to one. As a result, one pod runs on each node in parallel
|
||||||
# We set the NODE_NAME environemnt variable to get the Kubernetes node object.
|
# We set the NODE_NAME environment variable to get the Kubernetes node object.
|
||||||
sed -e "s/COMPLETION_COUNT/$NumNodes/" \
|
sed -e "s/completions:.*$/completions: $NumNodes/" \
|
||||||
-e "s/PARALLELISM_COUNT/$NumNodes/" \
|
-e "s/parallelism:.*$/parallelism: $NumNodes/" \
|
||||||
nfd-worker-job.yaml.template > nfd-worker-job.yaml
|
-i nfd-worker-job.yaml
|
||||||
|
|
||||||
if [ -n "$1" ]; then
|
|
||||||
sed -E "s,^(\s*)image:.+$,\1image: $1," -i nfd-worker-job.yaml
|
|
||||||
fi
|
|
||||||
|
|
||||||
kubectl create -f nfd-worker-job.yaml
|
kubectl create -f nfd-worker-job.yaml
|
||||||
|
|
|
@ -5,7 +5,7 @@ apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
name: nfd-master
|
name: nfd-master
|
||||||
namespace: default
|
namespace: node-feature-discovery
|
||||||
---
|
---
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
|
@ -32,7 +32,7 @@ roleRef:
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: nfd-master
|
name: nfd-master
|
||||||
namespace: default
|
namespace: node-feature-discovery
|
||||||
---
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: DaemonSet
|
kind: DaemonSet
|
||||||
|
@ -40,6 +40,7 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
app: nfd
|
app: nfd
|
||||||
name: nfd
|
name: nfd
|
||||||
|
namespace: node-feature-discovery
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
|
|
@ -1,8 +1,13 @@
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: node-feature-discovery # NFD namespace
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
kind: ServiceAccount
|
kind: ServiceAccount
|
||||||
metadata:
|
metadata:
|
||||||
name: nfd-master
|
name: nfd-master
|
||||||
namespace: default
|
namespace: node-feature-discovery
|
||||||
---
|
---
|
||||||
apiVersion: rbac.authorization.k8s.io/v1
|
apiVersion: rbac.authorization.k8s.io/v1
|
||||||
kind: ClusterRole
|
kind: ClusterRole
|
||||||
|
@ -29,7 +34,7 @@ roleRef:
|
||||||
subjects:
|
subjects:
|
||||||
- kind: ServiceAccount
|
- kind: ServiceAccount
|
||||||
name: nfd-master
|
name: nfd-master
|
||||||
namespace: default
|
namespace: node-feature-discovery
|
||||||
---
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: DaemonSet
|
kind: DaemonSet
|
||||||
|
@ -37,6 +42,7 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
app: nfd-master
|
app: nfd-master
|
||||||
name: nfd-master
|
name: nfd-master
|
||||||
|
namespace: node-feature-discovery
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
@ -94,6 +100,7 @@ apiVersion: v1
|
||||||
kind: Service
|
kind: Service
|
||||||
metadata:
|
metadata:
|
||||||
name: nfd-master
|
name: nfd-master
|
||||||
|
namespace: node-feature-discovery
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
app: nfd-master
|
app: nfd-master
|
||||||
|
|
|
@ -4,6 +4,7 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
app: nfd-worker
|
app: nfd-worker
|
||||||
name: nfd-worker
|
name: nfd-worker
|
||||||
|
namespace: node-feature-discovery
|
||||||
spec:
|
spec:
|
||||||
selector:
|
selector:
|
||||||
matchLabels:
|
matchLabels:
|
||||||
|
|
|
@ -4,6 +4,7 @@ metadata:
|
||||||
labels:
|
labels:
|
||||||
app: node-feature-discovery
|
app: node-feature-discovery
|
||||||
name: nfd-worker
|
name: nfd-worker
|
||||||
|
namespace: node-feature-discovery
|
||||||
spec:
|
spec:
|
||||||
completions: COMPLETION_COUNT
|
completions: COMPLETION_COUNT
|
||||||
parallelism: PARALLELISM_COUNT
|
parallelism: PARALLELISM_COUNT
|
||||||
|
|
Loading…
Add table
Reference in a new issue