1
0
Fork 0
mirror of https://github.com/kubernetes-sigs/node-feature-discovery.git synced 2024-12-14 11:57:51 +00:00

Automatically determine git version for labels.

- Added git version to published labels.
- Minor formatting fix in job template.
- Added .travis.yml and added build status image link to README.
- Added .gitignore.
This commit is contained in:
Connor Doyle 2016-07-14 14:17:27 -07:00
parent f9223bcb09
commit 4bd63cb7f3
6 changed files with 87 additions and 71 deletions

1
.gitignore vendored Normal file
View file

@ -0,0 +1 @@
dbi-iafeature-discovery-job.json

7
.travis.yml Normal file
View file

@ -0,0 +1,7 @@
sudo: required
services:
- docker
script:
- docker build -t intelsdi/dbi-iafeature-discovery .

View file

@ -12,17 +12,17 @@
#========================================================================
FROM golang:1.6
ADD ./main.go /go/src/github.com/intelsdi-x/dbi-iafeature-discovery/
ADD ./glide.yaml /go/src/github.com/intelsdi-x/dbi-iafeature-discovery/
ADD ./rdt-discovery /go/src/github.com/intelsdi-x/dbi-iafeature-discovery/rdt-discovery/
ADD . /go/src/github.com/intelsdi-x/dbi-iafeature-discovery
WORKDIR /go/src/github.com/intelsdi-x/dbi-iafeature-discovery
RUN git clone https://github.com/01org/intel-cmt-cat.git
RUN git clone --depth 1 https://github.com/01org/intel-cmt-cat.git
RUN cd intel-cmt-cat/lib; make install
RUN cd rdt-discovery; make
RUN go get github.com/Masterminds/glide
RUN glide install
RUN go install github.com/intelsdi-x/dbi-iafeature-discovery
RUN go install \
-ldflags "-X main.version=`git describe --tags --dirty --always`" \
github.com/intelsdi-x/dbi-iafeature-discovery
ENTRYPOINT /go/bin/dbi-iafeature-discovery

View file

@ -1,5 +1,7 @@
# CPU Feature Discovery for Kubernetes
[![Build Status](https://travis-ci.com/intelsdi-x/dbi-iafeature-discovery.svg?token=ajyZ5osyX5HNjsUu5muj&branch=master)](https://travis-ci.com/intelsdi-x/dbi-iafeature-discovery)
- [Overview](#overview)
- [Getting Started](#getting-started)
* [System Requirements](#system-requirements)
@ -41,8 +43,10 @@ The published node labels encode a few pieces of information:
- A "namespace" to denote vendor-specific information
(`node.alpha.intel.com`).
- The version of this discovery code (e.g. `v0.1.0`) that wrote the
label.
- The version of this discovery code that wrote the label, for example
`"node.alpha.intel.com/dbi-iafeature-discovery.version": "v0.1.0"`.
The value of this label corresponds to the output from
`git describe --tags --dirty --always`.
- The relevant hardware component each label describes (e.g. `cpu`).
- The name of the discovered feature as it appears in the underlying
source, mostly `cpuid` (e.g. `AESNI`).

View file

@ -1,54 +1,54 @@
{
"apiVersion": "extensions/v1beta1",
"kind": "Job",
"metadata": {
"labels": {
"app": "dbi-iafeature-discovery"
},
"name": "dbi-iafeature-discovery"
"apiVersion": "extensions/v1beta1",
"kind": "Job",
"metadata": {
"labels": {
"app": "dbi-iafeature-discovery"
},
"spec": {
"completions": COMPLETION_COUNT,
"parallelism": PARALLELISM_COUNT,
"template": {
"metadata": {
"labels": {
"app": "dbi-nodelabel"
}
},
"spec": {
"containers": [
{
"env": [
{
"name": "POD_NAME",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.name"
}
}
},
{
"name": "POD_NAMESPACE",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.namespace"
}
}
}
],
"image": "intelsdi/nodelabels",
"name": "nodelabeler",
"ports": [
{
"containerPort": 2233,
"hostPort": 7156
}
]
}
],
"restartPolicy": "Never"
}
"name": "dbi-iafeature-discovery"
},
"spec": {
"completions": COMPLETION_COUNT,
"parallelism": PARALLELISM_COUNT,
"template": {
"metadata": {
"labels": {
"app": "dbi-nodelabel"
}
},
"spec": {
"containers": [
{
"env": [
{
"name": "POD_NAME",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.name"
}
}
},
{
"name": "POD_NAMESPACE",
"valueFrom": {
"fieldRef": {
"fieldPath": "metadata.namespace"
}
}
}
],
"image": "intelsdi/nodelabels",
"name": "nodelabeler",
"ports": [
{
"containerPort": 2233,
"hostPort": 7156
}
]
}
],
"restartPolicy": "Never"
}
}
}
}

34
main.go
View file

@ -14,6 +14,7 @@ limitations under the License.
package main
import (
"fmt"
"log"
"os"
"os/exec"
@ -22,18 +23,18 @@ import (
client "k8s.io/kubernetes/pkg/client/unversioned"
)
const (
version = "0.1.0"
)
const namespace = "node.alpha.intel.com"
var version = "" // Must not be const, set using ldflags at build time
var prefix = fmt.Sprintf("%s/%s", namespace, version)
func main() {
// Setting-up a logger file
fd, err := os.OpenFile("dbi-iafeature-discovery.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Can't Open File for Logging: %v", err)
// Assert that the version is known
if version == "" {
log.Fatalf("`main.version` not set! Set -ldflags '-X main.version `git describe --tags --dirty --always`' during build or run.")
}
defer fd.Close()
log.SetOutput(fd)
log.Printf("Version: [%s]", version)
log.Printf("Label prefix: [%s]", prefix)
// Setting-up K8S client
cli, err := client.NewInCluster()
@ -59,12 +60,15 @@ func main() {
log.Fatalf("Can't Get Node: %v", err)
}
// Add the version of this discovery code as a node label
node.Labels[fmt.Sprintf("%s/dbi-ia-feature-discovery.version", prefix)] = version
// Get the cpu features as strings
features := cpuid.CPU.Features.Strings()
log.Printf("CPU Features Detected from cpuid: %s\n", features)
// Add each of the cpu feature as the node label
for _, feature := range features {
node.Labels["node.alpha.intel.com/v"+version+"-cpu-"+feature] = "true"
node.Labels[fmt.Sprintf("%s-cpu-%s", prefix, feature)] = "true"
}
// If supported, add CMT, MBM and CAT features as a node label
@ -76,7 +80,7 @@ func main() {
outString := string(out[:])
if outString == "DETECTED" {
node.Labels["node.alpha.intel.com/v"+version+"-cpu-RDTMON"] = "true"
node.Labels[fmt.Sprintf("%s-cpu-RDTMON", prefix)] = "true"
log.Printf("RDT Monitoring Detected\n")
}
@ -88,10 +92,10 @@ func main() {
outString = string(out[:])
if outString == "DETECTED" {
node.Labels["node.alpha.intel.com/v"+version+"-cpu-RDTL3CA"] = "true"
node.Labels[fmt.Sprintf("%s-cpu-RDTL3CA", prefix)] = "true"
log.Printf("RDT L3 Cache Allocation Detected\n")
}
cmd = "/go/src/github.com/intelsdi-x/dbi-iafeature-discovery/rdt-discovery/l2-alloc-discovery"
out, err = exec.Command("bash", "-c", cmd).Output()
if err != nil {
@ -100,7 +104,7 @@ func main() {
outString = string(out[:])
if outString == "DETECTED" {
node.Labels["node.alpha.intel.com/v"+version+"-cpu-RDTL2CA"] = "true"
node.Labels[fmt.Sprintf("%s-cpu-RDTL2CA", prefix)] = "true"
log.Printf("RDT L2 Cache Allocation Detected\n")
}
@ -113,7 +117,7 @@ func main() {
outString = string(out[:])
if outString == "0\n" {
node.Labels["node.alpha.intel.com/v"+version+"-cpu-turbo"] = "true"
node.Labels[fmt.Sprintf("%s-cpu-turbo", prefix)] = "true"
log.Printf("Turbo Boost is Enabled\n")
}