Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add kube-fluentd-operator #1086

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
| [ko](./images/ko) | `cgr.dev/chainguard/ko` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/ko.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/ko:latest) |
| [kube-bench](./images/kube-bench) | `cgr.dev/chainguard/kube-bench` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/kube-bench.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/kube-bench:latest) |
| [kube-downscaler](./images/kube-downscaler) | `cgr.dev/chainguard/kube-downscaler` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/kube-downscaler.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/kube-downscaler:latest) |
| [kube-fluentd-operator](./images/kube-fluentd-operator) | `cgr.dev/chainguard/kube-fluentd-operator` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/kube-fluentd-operator.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/kube-fluentd-operator:latest) |
| [kube-state-metrics](./images/kube-state-metrics) | `cgr.dev/chainguard/kube-state-metrics` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/kube-state-metrics.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/kube-state-metrics:latest) |
| [kubectl](./images/kubectl) | `cgr.dev/chainguard/kubectl` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/kubectl.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/kubectl:latest) |
| [kubernetes-csi-external-attacher](./images/kubernetes-csi-external-attacher) | `cgr.dev/chainguard/kubernetes-csi-external-attacher` | stable | [![](https://storage.googleapis.com/chainguard-images-build-outputs/badges/kubernetes-csi-external-attacher.build.status.latest.svg)](https://registry-ui.chainguard.app/?image=cgr.dev/chainguard/kubernetes-csi-external-attacher:latest) |
Expand Down
39 changes: 39 additions & 0 deletions images/kube-fluentd-operator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--monopod:start-->
# kube-fluentd-operator
| | |
| - | - |
| **Status** | stable |
| **OCI Reference** | `cgr.dev/chainguard/kube-fluentd-operator` |


* [View Image in Chainguard Academy](https://edu.chainguard.dev/chainguard/chainguard-images/reference/kube-fluentd-operator/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-->

This image is used for the [Kubernetes Fluentd Operator](https://github.com/vmware/kube-fluentd-operator)


## Get It!

The image is available on `cgr.dev`:

```
docker pull cgr.dev/chainguard/kube-fluentd-operator:latest
```

This image is a drop-in replacement for the Kubernetes Fluentd Operator available upstream at `vmware/kube-fluentd-operator`.

## Use It!

With helm:

```
git clone git@github.com:vmware/kube-fluentd-operator.git
helm install kfo ./kube-fluentd-operator/charts/log-router \
--set rbac.create=true \
--set image.tag=latest \
--set image.repository=cgr.dev/chainguard/kube-fluentd-operator
```
30 changes: 30 additions & 0 deletions images/kube-fluentd-operator/configs/latest.apko.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
contents:
packages:
- kube-fluentd-operator
- kube-fluentd-operator-oci-entrypoint
- kube-fluentd-operator-default-config
- kube-fluentd-operator-compat

entrypoint:
command: /fluentd/entrypoint.sh

environment:
FLUENTD_CONF: fluent.conf
LD_PRELOAD: /usr/lib/libjemalloc.so.2
GEM_PATH: /usr/lib/gem/home
GEM_HOME: /usr/lib/gem/home
PATH: /usr/lib/gem/home/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

accounts:
groups:
- groupname: nonroot
gid: 65532
users:
- username: nonroot
uid: 65532
gid: 65532
run-as: 0 # need to write to /var/log and hostPath volumes are mounted as root

annotations:
"org.opencontainers.image.url": https://edu.chainguard.dev/chainguard/chainguard-images/reference/kube-fluentd-operator
"org.opencontainers.image.source": https://github.com/chainguard-images/images/tree/main/images/kube-fluentd-operator
3 changes: 3 additions & 0 deletions images/kube-fluentd-operator/image.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
- apko:
config: configs/latest.apko.yaml
39 changes: 39 additions & 0 deletions images/kube-fluentd-operator/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
terraform {
required_providers {
apko = { source = "chainguard-dev/apko" }
}
}

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

module "latest" {
source = "../../tflib/publisher"

target_repository = var.target_repository
config = file("${path.module}/configs/latest.apko.yaml")
}

module "version-tags" {
source = "../../tflib/version-tags"
package = "kube-fluentd-operator"
config = module.latest.config
}

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

module "tagger" {
source = "../../tflib/tagger"

depends_on = [
module.test-latest,
]

tags = merge(
{ for t in toset(concat(["latest"], module.version-tags.tag_list)) : t => module.latest.image_ref },
)
}
41 changes: 41 additions & 0 deletions images/kube-fluentd-operator/tests/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_providers {
oci = { source = "chainguard-dev/oci" }
helm = { source = "hashicorp/helm" }
random = { source = "hashicorp/random" }
}
}

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

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

resource "helm_release" "kfo" {
name = "kfo"
namespace = "kfo"
chart = "https://github.com/vmware/kube-fluentd-operator/releases/download/v1.17.4/log-router-0.4.0.tgz" # not sure how we can get the correct version of the chart rather than hardcoding a version below
rawlingsj marked this conversation as resolved.
Show resolved Hide resolved
create_namespace = true
timeout = 120

values = [
<<EOF
rbac:
create: true
image:
repository: "${data.oci_string.ref.registry_repo}"
tag: "${data.oci_string.ref.pseudo_tag}"
EOF
]
}

data "oci_exec_test" "smoke" {
digest = var.digest # This doesn't actually matter here, just pass it something valid

# This script calls other files in the same relative directory
working_dir = path.module
script = "./smoke-test.sh"

depends_on = [helm_release.kfo]
}
32 changes: 32 additions & 0 deletions images/kube-fluentd-operator/tests/smoke-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env bash

set -o errexit -o nounset -o pipefail -x

sleep 5

# There are docs to test a deployment of the operator, but this is not
# working, same result with the upstream image. # https://github.com/vmware/kube-fluentd-operator#try-it-out

# Instead, we will test the operator by deploying the log-router helm chart
# + check the logs contain the expected text

# Define the timeout and delay variables
TIMEOUT=180
DELAY=5
TIMER=0

# Loop until the current time is greater than the end time
while [ $TIMER -lt $TIMEOUT ]; do
# Run the command and check for the text
if kubectl logs -n kfo -l app=log-router --tail -1 -c fluentd | grep "fluentd worker is now running"; then
echo "Worker is running"
exit 0
fi

# Sleep for the specified delay, then increment the timer
sleep $DELAY
TIMER=$(($TIMER + $DELAY))
done

echo "Worker failed to start within 3 minutes"
exit 1
5 changes: 5 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,11 @@ module "kubernetes-ingress-defaultbackend" {
target_repository = "${var.target_repository}/kubernetes-ingress-defaultbackend"
}

module "kube-fluentd-operator" {
source = "./images/kube-fluentd-operator"
target_repository = "${var.target_repository}/kube-fluentd-operator"
}

module "kubewatch" {
source = "./images/kubewatch"
target_repository = "${var.target_repository}/kubewatch"
Expand Down