Skip to content

Commit

Permalink
Modify the template based on input
Browse files Browse the repository at this point in the history
Modifies the value from clusterRoleBinding to RoleBinding
if the permissions are anything other than clusterAdmin.

Signed-off-by: John Schnake <jschnake@vmware.com>
Signed-off-by: Nikhil Sharma <nikhilsharma230303@gmail.com>
  • Loading branch information
johnSchnake authored and NikhilSharmaWe committed Nov 18, 2021
1 parent bfce3a9 commit cdf69c8
Show file tree
Hide file tree
Showing 51 changed files with 545 additions and 72 deletions.
38 changes: 19 additions & 19 deletions cmd/sonobuoy/app/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,23 @@ import (
)

const (
namespaceFlag = "namespace"
sonobuoyImageFlag = "sonobuoy-image"
imagePullPolicyFlag = "image-pull-policy"
pluginFlag = "plugin"
timeoutFlag = "timeout"
waitOutputFlag = "wait-output"
customRegistryFlag = "custom-registry"
kubeconfig = "kubeconfig"
kubecontext = "context"
e2eFocusFlag = "e2e-focus"
e2eSkipFlag = "e2e-skip"
e2eParallelFlag = "e2e-parallel"
e2eRegistryConfigFlag = "e2e-repo-config"
pluginImageFlag = "plugin-image"
filenameFlag = "filename"
retrievePathFlag = "retrieve-path"
securityContextModeFlag = "security-context-mode"
namespaceFlag = "namespace"
sonobuoyImageFlag = "sonobuoy-image"
imagePullPolicyFlag = "image-pull-policy"
pluginFlag = "plugin"
timeoutFlag = "timeout"
waitOutputFlag = "wait-output"
customRegistryFlag = "custom-registry"
kubeconfig = "kubeconfig"
kubecontext = "context"
e2eFocusFlag = "e2e-focus"
e2eSkipFlag = "e2e-skip"
e2eParallelFlag = "e2e-parallel"
e2eRegistryConfigFlag = "e2e-repo-config"
pluginImageFlag = "plugin-image"
filenameFlag = "filename"
retrievePathFlag = "retrieve-path"
securityContextModeFlag = "security-context-mode"
aggregatorPermissionsFlag = "aggregator-permissions"

// Quick runs a single E2E test and the systemd log tests.
Expand Down Expand Up @@ -178,10 +178,10 @@ func AddSecurityContextMode(mode *string, flags *pflag.FlagSet) {
)
}

func AddAggregatorPermissions(mode *string, flags *pflag.FlagSet){
func AddAggregatorPermissionsFlag(mode *string, flags *pflag.FlagSet) {
flags.StringVar(
mode, aggregatorPermissionsFlag, "clusterAdmin",
"Type of aggregator permission to use in the cluster. Allowable values are [namespaced, clusterAdmin]"
"Type of aggregator permission to use in the cluster. Allowable values are [namespaced, clusterAdmin]",
)
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/client/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ type templateValues struct {
CustomAnnotations map[string]string
SSHKey string

AggregatorPermissions string
ClusterAdmin bool

NodeSelectors map[string]string

Expand Down Expand Up @@ -226,7 +226,7 @@ func (*SonobuoyClient) GenerateManifestAndPlugins(cfg *GenConfig) ([]byte, []*ma
ImagePullSecrets: cfg.Config.ImagePullSecrets,
CustomAnnotations: cfg.Config.CustomAnnotations,
SSHKey: base64.StdEncoding.EncodeToString(sshKeyData),
AggregatorPermissions: cfg.Config.AggregatorPermissions,
ClusterAdmin: cfg.Config.AggregatorPermissions == config.AggregatorPermissionsClusterAdmin,

Plugins: pluginYAML,

Expand Down
4 changes: 4 additions & 0 deletions pkg/client/gen.tmpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ metadata:
{{- if .EnableRBAC }}
---
apiVersion: rbac.authorization.k8s.io/v1
{{- if .ClusterAdmin }}
kind: ClusterRoleBinding
{{- else }}
kind: RoleBinding
{{- end }}
metadata:
labels:
component: sonobuoy
Expand Down
10 changes: 10 additions & 0 deletions pkg/client/gen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,16 @@ func TestGenerateManifestGolden(t *testing.T) {
},
},
goldenFile: filepath.Join("testdata", "imagePullPolicy-all-plugins.golden"),
}, {
name: "AggregatorPermissions for non-cluster admin",
inputcm: &client.GenConfig{
Config: fromConfig(func(c *config.Config) *config.Config {
c.AggregatorPermissions = "somethingelse"
return c
}),
KubeVersion: "v99+static.testing",
},
goldenFile: filepath.Join("testdata", "aggregatorpermissions-noncluster-admin.golden"),
},
}

Expand Down
202 changes: 202 additions & 0 deletions pkg/client/testdata/aggregatorpermissions-noncluster-admin.golden
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
---
apiVersion: v1
kind: Namespace
metadata:
name: sonobuoy
---
apiVersion: v1
kind: ServiceAccount
metadata:
labels:
component: sonobuoy
name: sonobuoy-serviceaccount
namespace: sonobuoy
---
apiVersion: v1
data:
config.json: |
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","AggregatorPermissions":"somethingelse","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot"}
kind: ConfigMap
metadata:
labels:
component: sonobuoy
name: sonobuoy-config-cm
namespace: sonobuoy
---
apiVersion: v1
data:
plugin-0.yaml: |
podSpec:
containers: []
nodeSelector:
kubernetes.io/os: linux
restartPolicy: Never
serviceAccountName: sonobuoy-serviceaccount
tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master
operator: Exists
- key: CriticalAddonsOnly
operator: Exists
- key: kubernetes.io/e2e-evict-taint-key
operator: Exists
sonobuoy-config:
driver: Job
plugin-name: e2e
result-format: junit
spec:
command:
- /run_e2e.sh
env:
- name: E2E_EXTRA_ARGS
value: --progress-report-url=http://localhost:8099/progress
- name: E2E_FOCUS
- name: E2E_PARALLEL
- name: E2E_SKIP
- name: E2E_USE_GO_RUNNER
value: "true"
- name: RESULTS_DIR
value: /tmp/sonobuoy/results
- name: SONOBUOY
value: "true"
- name: SONOBUOY_CONFIG_DIR
value: /tmp/sonobuoy/config
- name: SONOBUOY_K8S_VERSION
value: v99+static.testing
- name: SONOBUOY_PROGRESS_PORT
value: "8099"
- name: SONOBUOY_RESULTS_DIR
value: /tmp/sonobuoy/results
image: k8s.gcr.io/conformance:v99+static.testing
imagePullPolicy: IfNotPresent
name: e2e
resources: {}
volumeMounts:
- mountPath: /tmp/sonobuoy/results
name: results
plugin-1.yaml: |
podSpec:
containers: []
dnsPolicy: ClusterFirstWithHostNet
hostIPC: true
hostNetwork: true
hostPID: true
nodeSelector:
kubernetes.io/os: linux
serviceAccountName: sonobuoy-serviceaccount
tolerations:
- operator: Exists
volumes:
- hostPath:
path: /
name: root
sonobuoy-config:
driver: DaemonSet
plugin-name: systemd-logs
result-format: raw
spec:
command:
- /bin/sh
- -c
- /get_systemd_logs.sh; while true; do echo "Plugin is complete. Sleeping indefinitely
to avoid container exit and automatic restarts from Kubernetes"; sleep 3600; done
env:
- name: CHROOT_DIR
value: /node
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
- name: RESULTS_DIR
value: /tmp/sonobuoy/results
- name: SONOBUOY
value: "true"
- name: SONOBUOY_CONFIG_DIR
value: /tmp/sonobuoy/config
- name: SONOBUOY_K8S_VERSION
value: v99+static.testing
- name: SONOBUOY_PROGRESS_PORT
value: "8099"
- name: SONOBUOY_RESULTS_DIR
value: /tmp/sonobuoy/results
image: sonobuoy/systemd-logs:v0.4
imagePullPolicy: IfNotPresent
name: systemd-logs
resources: {}
securityContext:
privileged: true
volumeMounts:
- mountPath: /node
name: root
- mountPath: /tmp/sonobuoy/results
name: results
kind: ConfigMap
metadata:
labels:
component: sonobuoy
name: sonobuoy-plugins-cm
namespace: sonobuoy
---
apiVersion: v1
kind: Pod
metadata:
labels:
component: sonobuoy
sonobuoy-component: aggregator
tier: analysis
name: sonobuoy
namespace: sonobuoy
spec:
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
containers:
- env:
- name: SONOBUOY_ADVERTISE_IP
valueFrom:
fieldRef:
fieldPath: status.podIP
image: sonobuoy/sonobuoy:static-version-for-testing
imagePullPolicy: IfNotPresent
name: kube-sonobuoy
command: ["/sonobuoy"]
args: ["aggregator", "--no-exit", "--level=info", "-v=4", "--alsologtostderr"]
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
sonobuoy-component: aggregator
name: sonobuoy-aggregator
namespace: sonobuoy
spec:
ports:
- port: 8080
protocol: TCP
targetPort: 8080
selector:
sonobuoy-component: aggregator
type: ClusterIP
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
apiVersion: v1
data:
config.json: |
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot","AggregatorPermissions":"clusterAdmin"}
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","AggregatorPermissions":"clusterAdmin","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot"}
kind: ConfigMap
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/testdata/default-plugins-via-selection.golden
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
apiVersion: v1
data:
config.json: |
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":[],"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot","AggregatorPermissions":"clusterAdmin"}
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":[],"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","AggregatorPermissions":"clusterAdmin","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot"}
kind: ConfigMap
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/testdata/default-pod-spec.golden
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
apiVersion: v1
data:
config.json: |
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot","AggregatorPermissions":"clusterAdmin"}
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","AggregatorPermissions":"clusterAdmin","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot"}
kind: ConfigMap
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/testdata/default.golden
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
apiVersion: v1
data:
config.json: |
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot","AggregatorPermissions":"clusterAdmin"}
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":null,"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","AggregatorPermissions":"clusterAdmin","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot"}
kind: ConfigMap
metadata:
labels:
Expand Down
2 changes: 1 addition & 1 deletion pkg/client/testdata/e2e-default.golden
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ metadata:
apiVersion: v1
data:
config.json: |
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":[{"name":"e2e"}],"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot","AggregatorPermissions":"clusterAdmin"}
{"Description":"DEFAULT","UUID":"","Version":"static-version-for-testing","ResultsDir":"/tmp/sonobuoy/results","Resources":null,"Filters":{"Namespaces":".*","LabelSelector":""},"Limits":{"PodLogs":{"Namespaces":"kube-system","SonobuoyNamespace":true,"FieldSelectors":[],"LabelSelector":"","Previous":false,"SinceSeconds":null,"SinceTime":null,"Timestamps":false,"TailLines":null,"LimitBytes":null}},"QPS":30,"Burst":50,"Server":{"bindaddress":"0.0.0.0","bindport":8080,"advertiseaddress":"","timeoutseconds":21600},"Plugins":[{"name":"e2e"}],"PluginSearchPath":["./plugins.d","/etc/sonobuoy/plugins.d","~/sonobuoy/plugins.d"],"Namespace":"sonobuoy","WorkerImage":"sonobuoy/sonobuoy:static-version-for-testing","ImagePullPolicy":"IfNotPresent","ImagePullSecrets":"","AggregatorPermissions":"clusterAdmin","ProgressUpdatesPort":"8099","SecurityContextMode":"nonroot"}
kind: ConfigMap
metadata:
labels:
Expand Down
Loading

0 comments on commit cdf69c8

Please sign in to comment.