Skip to content

Commit

Permalink
Allow systemd-logs to be configured via CLI
Browse files Browse the repository at this point in the history
This adds a new flag `--systemd-logs-image` to the gen flags so that it
can be customized via the CLI rather than needing to modify the output
of gen.

Signed-off-by: Bridget McErlean <bmcerlean@vmware.com>
  • Loading branch information
zubron authored and johnSchnake committed Dec 19, 2019
1 parent 30365d1 commit 3f6547e
Show file tree
Hide file tree
Showing 13 changed files with 152 additions and 14 deletions.
8 changes: 8 additions & 0 deletions cmd/sonobuoy/app/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ func AddKubeConformanceImage(image *string, flags *pflag.FlagSet) {
)
}

// AddSystemdLogsImage initialises the systemd-logs-image flag.
func AddSystemdLogsImage(image *string, flags *pflag.FlagSet) {
flags.StringVar(
image, "systemd-logs-flag", config.DefaultSystemdLogsImage,
"Container image override for the systemd-logs plugin image.",
)
}

// AddKubeConformanceImageVersion initialises an image version flag.
func AddKubeConformanceImageVersion(imageVersion *image.ConformanceImageVersion, flags *pflag.FlagSet) {
help := "Use default Conformance image, but override the version. "
Expand Down
3 changes: 3 additions & 0 deletions cmd/sonobuoy/app/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type genFlags struct {
dnsPodLabels []string
sonobuoyImage string
kubeConformanceImage string
systemdLogsImage string
sshKeyPath string
sshUser string
kubeConformanceImageVersion imagepkg.ConformanceImageVersion
Expand Down Expand Up @@ -88,6 +89,7 @@ func GenFlagSet(cfg *genFlags, rbac RBACMode) *pflag.FlagSet {
AddDNSPodLabelsFlag(&cfg.dnsPodLabels, genset)
AddSonobuoyImage(&cfg.sonobuoyImage, genset)
AddKubeConformanceImage(&cfg.kubeConformanceImage, genset)
AddSystemdLogsImage(&cfg.systemdLogsImage, genset)
AddKubeConformanceImageVersion(&cfg.kubeConformanceImageVersion, genset)
AddSSHKeyPathFlag(&cfg.sshKeyPath, genset)
AddSSHUserFlag(&cfg.sshUser, genset)
Expand Down Expand Up @@ -153,6 +155,7 @@ func (g *genFlags) Config() (*client.GenConfig, error) {
Config: g.resolveConfig(),
EnableRBAC: rbacEnabled,
KubeConformanceImage: image,
SystemdLogsImage: g.systemdLogsImage,
ImagePullPolicy: g.imagePullPolicy.String(),
SSHKeyPath: g.sshKeyPath,
SSHUser: g.sshUser,
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ func SystemdLogsManifest(cfg *GenConfig) *manifest.Manifest {
Spec: manifest.Container{
Container: corev1.Container{
Name: "systemd-logs",
Image: "gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest",
Image: cfg.SystemdLogsImage,
Command: []string{"/bin/sh", "-c", `/get_systemd_logs.sh && while true; do echo "Sleeping for 1h to avoid daemonset restart"; sleep 3600; done`},
ImagePullPolicy: corev1.PullPolicy(cfg.ImagePullPolicy),
Env: []corev1.EnvVar{
Expand Down
8 changes: 8 additions & 0 deletions pkg/client/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,14 @@ func TestGenerateManifestGolden(t *testing.T) {
},
},
goldenFile: filepath.Join("testdata", "e2e-progress-vs-user-defined.golden"),
}, {
name: "Custom systemd-logs image is used if specified",
inputcm: &client.GenConfig{
E2EConfig: &client.E2EConfig{},
DynamicPlugins: []string{"systemd-logs"},
SystemdLogsImage: "custom-systemd-logs:v1.0.0",
},
goldenFile: filepath.Join("testdata", "custom-systemd-logs-image.golden"),
},
}

Expand Down
1 change: 1 addition & 0 deletions pkg/client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ type GenConfig struct {
EnableRBAC bool
ImagePullPolicy string
KubeConformanceImage string
SystemdLogsImage string
SSHKeyPath string
SSHUser string

Expand Down
126 changes: 126 additions & 0 deletions pkg/client/testdata/custom-systemd-logs-image.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

---
apiVersion: v1
kind: Namespace
metadata:
name:
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
component: sonobuoy
name: sonobuoy-serviceaccount
namespace:
---
apiVersion: v1
data:
config.json: |
{"Description":"","UUID":"","Version":"","ResultsDir":"","Resources":null,"Filters":{"Namespaces":"","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"","SonobuoyNamespace":null,"FieldSelectors":null,"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null,"LimitSize":"","LimitTime":""}},"Server":{"bindaddress":"","bindport":0,"advertiseaddress":"","timeoutseconds":0},"Plugins":null,"PluginSearchPath":null,"Namespace":"","WorkerImage":"","ImagePullPolicy":"","ImagePullSecrets":""}
kind: ConfigMap
metadata:
labels:
component: sonobuoy
name: sonobuoy-config-cm
namespace:
---
apiVersion: v1
data:
plugin-0.yaml: |
sonobuoy-config:
driver: DaemonSet
plugin-name: systemd-logs
result-format: raw
spec:
command:
- /bin/sh
- -c
- /get_systemd_logs.sh && while true; do echo "Sleeping for 1h to avoid daemonset
restart"; sleep 3600; done
env:
- name: CHROOT_DIR
value: /node
- name: RESULTS_DIR
value: /tmp/results
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: custom-systemd-logs:v1.0.0
name: systemd-logs
resources: {}
securityContext:
privileged: true
volumeMounts:
- mountPath: /tmp/results
name: results
- mountPath: /node
name: root
kind: ConfigMap
metadata:
labels:
component: sonobuoy
name: sonobuoy-plugins-cm
namespace:
---
apiVersion: v1
kind: Pod
metadata:
labels:
component: sonobuoy
run: sonobuoy-master
tier: analysis
name: sonobuoy
namespace:
spec:
containers:
- command:
- /bin/bash
- -c
- /sonobuoy master --no-exit=true -v 3 --logtostderr
env:
- name: SONOBUOY_ADVERTISE_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
image:
imagePullPolicy:
name: kube-sonobuoy
volumeMounts:
- mountPath: /etc/sonobuoy
name: sonobuoy-config-volume
- mountPath: /plugins.d
name: sonobuoy-plugins-volume
- mountPath: /tmp/sonobuoy
name: output-volume
restartPolicy: Never
serviceAccountName: sonobuoy-serviceaccount
tolerations:
- key: "kubernetes.io/e2e-evict-taint-key"
operator: "Exists"
volumes:
- configMap:
name: sonobuoy-config-cm
name: sonobuoy-config-volume
- configMap:
name: sonobuoy-plugins-cm
name: sonobuoy-plugins-volume
- emptyDir: {}
name: output-volume
---
apiVersion: v1
kind: Service
metadata:
labels:
component: sonobuoy
run: sonobuoy-master
name: sonobuoy-master
namespace:
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
run: sonobuoy-master
type: ClusterIP
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ data:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
name: systemd-logs
resources: {}
securityContext:
Expand Down
1 change: 0 additions & 1 deletion pkg/client/testdata/default-pod-spec.golden
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ data:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
name: systemd-logs
resources: {}
securityContext:
Expand Down
1 change: 0 additions & 1 deletion pkg/client/testdata/default.golden
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ data:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
name: systemd-logs
resources: {}
securityContext:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ data:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
name: systemd-logs
resources: {}
securityContext:
Expand Down
1 change: 0 additions & 1 deletion pkg/client/testdata/systemd-logs-default.golden
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ data:
valueFrom:
fieldRef:
fieldPath: spec.nodeName
image: gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest
name: systemd-logs
resources: {}
securityContext:
Expand Down
3 changes: 3 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ const (

// DefaultDNSNamespace is the namespace where the DNS pods for the cluster are found.
DefaultDNSNamespace = "kube-system"

// DefaultSystemdLogsImage is the URL for the docker image used by the systemd-logs plugin
DefaultSystemdLogsImage = "gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest"
)

var (
Expand Down
10 changes: 2 additions & 8 deletions site/docs/master/airgap.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,16 +114,10 @@ docker tag gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest $PRIVATE_REG
docker push $PRIVATE_REG/sonobuoy-plugin-systemd-logs:latest
```

Unlike the `e2e` plugin, there is no command line flag to specify which image to use for this plugin.

To do that, you will have to manually specify the image you want to use by saving and modifying the Sonobuoy manifest generated by `sonobuoy gen`.
Within this manifest, you will find the definition of the `systemd-logs` plugin within the `sonobuoy-plugins-cm` ConfigMap.
Modify the `image` value from the default (`gcr.io/heptio-images/sonobuoy-plugin-systemd-logs:latest`) to your image (`$PRIVATE_REG/sonobuoy-plugin-systemd-logs:latest`).

To use this modified manifest, you can pass the file directly when running Sonobuoy:
To use the image in your own registry, you will need to override the default when using the `gen` or `run` commands with the `--systemd-logs-image` flag as follows:

```
sonobuoy run -f <path/to/modified-manifest.yaml>
sonobuoy run --systemd-logs-image $PRIVATE_REG/sonobuoy-plugin-systemd-logs:latest
```

If you do not wish to run this plugin, you can remove it from the list of [plugins][plugins] to be run within the manifest, or you can explicitly specify which plugin you with to run with the `--plugin` flag.
Expand Down

0 comments on commit 3f6547e

Please sign in to comment.