Skip to content

Commit

Permalink
Added node-feature-discovery public image
Browse files Browse the repository at this point in the history
  • Loading branch information
Pyronewbic committed Apr 12, 2024
1 parent 020960f commit 81361eb
Show file tree
Hide file tree
Showing 8 changed files with 225 additions and 0 deletions.
54 changes: 54 additions & 0 deletions images/node-feature-discovery/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!--monopod:start-->
# node-feature-directory
| | |
| - | - |
| **OCI Reference** | `cgr.dev/chainguard/node-feature-directory` |


* [View Image in Chainguard Academy](https://edu.chainguard.dev/chainguard/chainguard-images/reference/node-feature-directory/overview/)
* [View Image Catalog](https://console.enforce.dev/images/catalog) for a full list of available tags.
* [Contact Chainguard](https://www.chainguard.dev/chainguard-images) for enterprise support, SLAs, and access to older tags.*

---
<!--monopod:end-->

<!--overview:start-->
A minimal wolfi-based image for node-feature-discovery, Node feature discovery for Kubernetes
<!--overview:end-->

<!--getting:start-->
## Download this Image
The image is available on `cgr.dev`:

```
docker pull cgr.dev/chainguard/node-feature-directory:latest
```
<!--getting:end-->

<!--body:start-->
## Upstream documentation
For more information on grafana, refer to the [node-feature-discovery documentation](https://kubernetes-sigs.github.io/node-feature-discovery/stable/get-started/index.html).
Additionally the node-feature-discovery GitHub reposiory can be [found here](https://github.com/kubernetes-sigs/node-feature-discovery).

## Helm
Node-feature-discovery can be deployed using the following helm chart:
- [https://artifacthub.io/packages/helm/node-feature-discovery/node-feature-discovery](https://artifacthub.io/packages/helm/node-feature-discovery/node-feature-discovery)

Follow the instructions in the link above to deploy node-feature-discovery using helm. Note you
will need to override the default image and tag used, replacing with the
chainguard image, example:

```bash
helm repo add node-feature-discovery https://kubernetes-sigs.github.io/node-feature-discovery/charts
helm repo update

export NFD_NS=node-feature-discovery
helm install nfd/node-feature-discovery --namespace $NFD_NS --create-namespace --generate-name \
--set image.repository=cgr.dev/chainguard/node-feature-discovery \
--set image.tag=latest
```

Refer to the [helm chart documentation](https://artifacthub.io/packages/helm/node-feature-discovery/node-feature-discovery)
for full instructions on how to use the helm chart.

<!--body:end-->
15 changes: 15 additions & 0 deletions images/node-feature-discovery/config/latest.apko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
contents:
packages:

accounts:
groups:
- groupname: nonroot
gid: 65532
users:
- username: nonroot
uid: 65532
gid: 65532
run-as: 65532

environment:
PATH: /usr/sbin:/sbin:/usr/bin:/bin
19 changes: 19 additions & 0 deletions images/node-feature-discovery/config/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_providers {
apko = { source = "chainguard-dev/apko" }
}
}

variable "extra_packages" {
description = "The additional packages to install"
default = ["node-feature-discovery"]
}

data "apko_config" "this" {
config_contents = file("${path.module}/latest.apko.yaml")
extra_packages = var.extra_packages
}

output "config" {
value = jsonencode(data.apko_config.this.config)
}
37 changes: 37 additions & 0 deletions images/node-feature-discovery/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
}
}

variable "target_repository" {
description = "The docker repo into which the image and attestations should be published."
}

module "latest-config" { source = "./config" }

module "latest" {
source = "../../tflib/publisher"
name = basename(path.module)
target_repository = var.target_repository
config = module.latest-config.config
build-dev = true
}

module "test-latest" {
source = "./tests"
digest = module.latest.image_ref
}

resource "oci_tag" "latest" {
depends_on = [module.test-latest]
digest_ref = module.latest.image_ref
tag = "latest"
}

resource "oci_tag" "latest-dev" {
depends_on = [module.test-latest]
digest_ref = module.latest.dev_ref
tag = "latest-dev"
}

13 changes: 13 additions & 0 deletions images/node-feature-discovery/metadata.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: node-feature-directory
image: cgr.dev/chainguard/node-feature-directory
logo: https://storage.googleapis.com/chainguard-academy/logos/grafana.svg
endoflife: ""
console_summary: ""
short_description: A minimal wolfi-based image for node-feature-discovery, Node feature discovery for Kubernetes
compatibility_notes: ""
readme_file: README.md
upstream_url: https://github.com/grafana/https://github.com/kubernetes-sigs/node-feature-discovery
keywords:
- kubernetes
- application
- node-discovery
69 changes: 69 additions & 0 deletions images/node-feature-discovery/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
helm = { source = "hashicorp/helm" }
imagetest = { source = "chainguard-dev/imagetest" }
}
}

variable "digest" {
description = "The image digest to run tests over."
}

data "oci_string" "ref" {
input = var.digest
}

data "imagetest_inventory" "this" {}

resource "imagetest_harness_k3s" "this" {
name = "node-feature-discovery"
inventory = data.imagetest_inventory.this

sandbox = {
mounts = [
{
source = path.module
destination = "/tests"
}
]
}
}

module "helm_node-feature-discovery" {
source = "../../../tflib/imagetest/helm"
chart = "node-feature-discovery"
repo = "https://kubernetes-sigs.github.io/node-feature-discovery/charts"
name = "node-feature-discovery"
values = {
image = {
repository = data.oci_string.ref.registry_repo
tag = data.oci_string.ref.pseudo_tag
pullPolicy = "Always"
}
}
}

resource "imagetest_feature" "test_labels" {
harness = imagetest_harness_k3s.this
name = "Test Labels"
description = "Basic functionality of the node-feature-discovery helm chart."

steps = [
{
name = "Helm install node-feature-discovery"
cmd = module.helm_node-feature-discovery.install_cmd
},
{
name = "Ensure it has the necessary labels For CPU, Kernel and Storage"
cmd = <<EOF
apk add jq bash
bash /tests/test-labels.sh
EOF
}
]

labels = {
type = "k8s"
}
}
13 changes: 13 additions & 0 deletions images/node-feature-discovery/tests/test-labels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
echo -e "Sleeping for 10 seconds"
sleep 10

cpu=`kubectl get no -o json | jq '.items[].metadata.labels' | grep 'feature.node.kubernetes.io/cpu-'`
kernel=`kubectl get no -o json | jq '.items[].metadata.labels' | grep 'feature.node.kubernetes.io/kernel-'`
storage=`kubectl get no -o json | jq '.items[].metadata.labels' | grep 'feature.node.kubernetes.io/storage-'`

if [[ ${#cpu} -ge 1 && ${#kernel} -ge 1 && ${#storage} -ge 1 ]]; then
exit 0
else
echo "Corresponding CPU or Kernel or storage labels have not been found"
exit 1
fi
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,11 @@ module "node" {
target_repository = "${var.target_repository}/node"
}

module "node-feature-discovery" {
source = "./images/node-feature-discovery"
target_repository = "${var.target_repository}/node-feature-discovery"
}

module "node-lts" {
source = "./images/node-lts"
target_repository = "${var.target_repository}/node-lts"
Expand Down

0 comments on commit 81361eb

Please sign in to comment.