From 945c7f155a33ee077dac67bb78db109934a0a1a1 Mon Sep 17 00:00:00 2001 From: iPraveenParihar Date: Sat, 13 May 2023 17:29:21 +0530 Subject: [PATCH] test: allow specifying custom nginx image for multus validation Allow overriding the nginx server image used for the web server and clients from CLI with --nginx-image flag. Set default image in flag as 'nginxinc/nginx-unprivileged:stable-alpine' Signed-off-by: iPraveenParihar (cherry picked from commit 78d65281539a0437d2b8a8cca755420a79e9259d) --- .../userfacing/multus/validation/validation.go | 7 +++++++ pkg/daemon/multus/client-daemonset.yaml | 2 +- pkg/daemon/multus/image-pull-daemonset.yaml | 2 +- pkg/daemon/multus/nginx-pod.yaml | 2 +- pkg/daemon/multus/templates.go | 16 ++++++++++++++-- pkg/daemon/multus/validation.go | 9 +++++++-- 6 files changed, 31 insertions(+), 7 deletions(-) diff --git a/cmd/rook/userfacing/multus/validation/validation.go b/cmd/rook/userfacing/multus/validation/validation.go index ce8b973b4..fdc2ce57e 100644 --- a/cmd/rook/userfacing/multus/validation/validation.go +++ b/cmd/rook/userfacing/multus/validation/validation.go @@ -131,6 +131,8 @@ func init() { "The default value is set to the worst-case value for a Rook Ceph cluster with 3 portable OSDs, 3 portable monitors, "+ "and where all optional child resources have been created with 1 daemon such that they all might run on a single node in a failure scenario. "+ "If you aren't sure what to choose for this value, add 1 for each additional OSD beyond 3.") + runCmd.Flags().StringVar(&validationConfig.NginxImage, "nginx-image", "nginxinc/nginx-unprivileged:stable-alpine", + "The Nginx image used for the validation server and clients.") // flags for 'validation cleanup' // none @@ -142,6 +144,11 @@ func runValidation(ctx context.Context) { os.Exit(22 /* EINVAL */) } + if validationConfig.NginxImage == "" { + fmt.Print(`--nginx-image must be specified`) + os.Exit(22 /* EINVAL */) + } + results, err := validationConfig.Run(ctx) report := results.SuggestedDebuggingReport() diff --git a/pkg/daemon/multus/client-daemonset.yaml b/pkg/daemon/multus/client-daemonset.yaml index f2a4951ca..e86311545 100644 --- a/pkg/daemon/multus/client-daemonset.yaml +++ b/pkg/daemon/multus/client-daemonset.yaml @@ -31,7 +31,7 @@ spec: {{ range $name, $address := .NetworkNamesAndAddresses }} - name: readiness-check-web-server-{{ $name }}-addr # use nginx image because it's already used for the web server pod and has a non-root user - image: nginxinc/nginx-unprivileged:stable-alpine + image: "{{ .NginxImage }}" command: - sleep - infinity diff --git a/pkg/daemon/multus/image-pull-daemonset.yaml b/pkg/daemon/multus/image-pull-daemonset.yaml index 917b8c914..683150d95 100644 --- a/pkg/daemon/multus/image-pull-daemonset.yaml +++ b/pkg/daemon/multus/image-pull-daemonset.yaml @@ -26,7 +26,7 @@ spec: containers: - name: sleep # use nginx image because it's already used for the web server pod and has a non-root user - image: nginxinc/nginx-unprivileged:stable-alpine + image: "{{ .NginxImage }}" command: - sleep - infinity diff --git a/pkg/daemon/multus/nginx-pod.yaml b/pkg/daemon/multus/nginx-pod.yaml index 64b271180..20466fbcb 100644 --- a/pkg/daemon/multus/nginx-pod.yaml +++ b/pkg/daemon/multus/nginx-pod.yaml @@ -22,7 +22,7 @@ spec: type: RuntimeDefault containers: - name: multus-validation-test-web-server - image: nginxinc/nginx-unprivileged:stable-alpine + image: "{{ .NginxImage }}" resources: {} ports: - containerPort: 8080 diff --git a/pkg/daemon/multus/templates.go b/pkg/daemon/multus/templates.go index 3532a7f07..44006635b 100644 --- a/pkg/daemon/multus/templates.go +++ b/pkg/daemon/multus/templates.go @@ -44,14 +44,18 @@ var ( type webServerTemplateConfig struct { NetworksAnnotationValue string + NginxImage string } -type imagePullTemplateConfig struct{} +type imagePullTemplateConfig struct { + NginxImage string +} type clientTemplateConfig struct { ClientID int NetworksAnnotationValue string NetworkNamesAndAddresses map[string]string + NginxImage string } func webServerPodName() string { @@ -74,6 +78,7 @@ const clientDaemonSetAppType = "client" func (vt *ValidationTest) generateWebServerTemplateConfig() webServerTemplateConfig { return webServerTemplateConfig{ NetworksAnnotationValue: vt.generateNetworksAnnotationValue(), + NginxImage: vt.NginxImage, } } @@ -89,6 +94,13 @@ func (vt *ValidationTest) generateClientTemplateConfig(clientID int, serverPubli ClientID: clientID, NetworksAnnotationValue: vt.generateNetworksAnnotationValue(), NetworkNamesAndAddresses: netNamesAndAddresses, + NginxImage: vt.NginxImage, + } +} + +func (vt *ValidationTest) generateImagePullTemplateConfig() imagePullTemplateConfig { + return imagePullTemplateConfig{ + NginxImage: vt.NginxImage, } } @@ -123,7 +135,7 @@ func (vt *ValidationTest) generateWebServerConfigMap() (*core.ConfigMap, error) } func (vt *ValidationTest) generateImagePullDaemonSet() (*apps.DaemonSet, error) { - t, err := loadTemplate("imagePullDaemonSet", imagePullDaemonSet, imagePullTemplateConfig{}) + t, err := loadTemplate("imagePullDaemonSet", imagePullDaemonSet, vt.generateImagePullTemplateConfig()) if err != nil { return nil, fmt.Errorf("failed to load image pull daemonset template: %w", err) } diff --git a/pkg/daemon/multus/validation.go b/pkg/daemon/multus/validation.go index 7f3b8a305..fe7edb21e 100644 --- a/pkg/daemon/multus/validation.go +++ b/pkg/daemon/multus/validation.go @@ -71,8 +71,8 @@ type ValidationTest struct { // Logger an instance of the basic log implementation used by this library. Logger Logger - // TODO: allow overriding the nginx server image from CLI, and set from default var that can be - // overridden at build time + //NginxImage is the Nginx image which will be used for the web server and clients. + NginxImage string } // ValidationTestResults contains results from a validation test. @@ -361,11 +361,16 @@ func (vt *ValidationTest) Run(ctx context.Context) (*ValidationTestResults, erro vt.Logger.Infof(" cluster network: %q", vt.ClusterNetwork) vt.Logger.Infof(" daemons per node: %d", vt.DaemonsPerNode) vt.Logger.Infof(" resource timeout: %v", vt.ResourceTimeout) + vt.Logger.Infof(" nginx image: %q", vt.NginxImage) if vt.PublicNetwork == "" && vt.ClusterNetwork == "" { return nil, fmt.Errorf("at least one of 'public network' and 'cluster network' must be specified") } + if vt.NginxImage == "" { + return nil, fmt.Errorf("'nginx-image' must be specified") + } + testResults := &ValidationTestResults{ suggestedDebugging: []string{}, }