From 1e7a5e741e11fb6b9198266786d2120b1e63b974 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Mon, 6 Dec 2021 16:46:17 +0000 Subject: [PATCH] hubble: Make UI version configurable Signed-off-by: Tom Payne --- defaults/defaults.go | 7 +++++-- hubble/hubble.go | 16 ++++++++++++---- hubble/ui.go | 14 +++++++++++--- internal/cli/cmd/hubble.go | 3 +++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/defaults/defaults.go b/defaults/defaults.go index cb3d6ca0b6..1572a3de3c 100644 --- a/defaults/defaults.go +++ b/defaults/defaults.go @@ -49,6 +49,8 @@ const ( HubbleUIServiceAccountName = "hubble-ui" HubbleUIConfigMapName = "hubble-ui-envoy" HubbleUIDeploymentName = "hubble-ui" + HubbleUIImage = "quay.io/cilium/hubble-ui" + HubbleUIBackendImage = "quay.io/cilium/hubble-ui-backend" ClusterMeshDeploymentName = "clustermesh-apiserver" ClusterMeshServiceAccountName = "clustermesh-apiserver" @@ -66,8 +68,9 @@ const ( ConnectivityCheckAlpineCurlImage = "quay.io/cilium/alpine-curl:v1.4.0@sha256:2550c747831ff575f2147149b088ea981c06f9b6bcd188756d1b82cc10997956" ConnectivityCheckJSONMockImage = "quay.io/cilium/json-mock:v1.3.0@sha256:2729064827fa9dbfface8d3df424feb6c792a0ba07117b844349635c93c06d2b" - ConfigMapName = "cilium-config" - Version = "v1.10.5" + ConfigMapName = "cilium-config" + Version = "v1.10.5" + HubbleUIVersion = "v0.8.3" TunnelType = "vxlan" diff --git a/hubble/hubble.go b/hubble/hubble.go index 99cf658c3b..d62f15f7e6 100644 --- a/hubble/hubble.go +++ b/hubble/hubble.go @@ -76,6 +76,9 @@ type Parameters struct { PortForward int CreateCA bool UI bool + UIImage string + UIBackendImage string + UIVersion string UIPortForward int Writer io.Writer Context string // Only for 'kubectl' pass-through commands @@ -88,10 +91,15 @@ func (p *Parameters) Log(format string, a ...interface{}) { } func (p *Parameters) validateParams() error { - if p.RelayImage != defaults.RelayImage { - return nil - } else if !utils.CheckVersion(p.RelayVersion) && p.RelayVersion != "" { - return fmt.Errorf("invalid syntax %q for image tag", p.RelayVersion) + if p.RelayImage == defaults.RelayImage { + if !utils.CheckVersion(p.RelayVersion) && p.RelayVersion != "" { + return fmt.Errorf("invalid syntax %q for image tag", p.RelayVersion) + } + } + if p.UIImage == defaults.HubbleUIImage || p.UIBackendImage == defaults.HubbleUIBackendImage { + if !utils.CheckVersion(p.UIVersion) && p.UIVersion != "" { + return fmt.Errorf("invalid syntax %q for image tag", p.UIVersion) + } } return nil } diff --git a/hubble/ui.go b/hubble/ui.go index 8ab3689e7a..4adbc22a77 100644 --- a/hubble/ui.go +++ b/hubble/ui.go @@ -188,7 +188,7 @@ func (k *K8sHubble) generateHubbleUIDeployment() *appsv1.Deployment { Containers: []corev1.Container{ { Name: "frontend", - Image: "quay.io/cilium/hubble-ui:v0.8.3@sha256:018ed122968de658d8874e2982fa6b3a8ae64b43d2356c05f977004176a89310", + Image: k.uiImage(), ImagePullPolicy: corev1.PullIfNotPresent, Ports: []corev1.ContainerPort{ { @@ -199,7 +199,7 @@ func (k *K8sHubble) generateHubbleUIDeployment() *appsv1.Deployment { }, { Name: "backend", - Image: "quay.io/cilium/hubble-ui-backend:v0.8.3@sha256:13a16ed3ae9749682c817d3b834b2f2de901da6fb41de7753d7dce16650982b3", + Image: k.uiBackendImage(), ImagePullPolicy: corev1.PullIfNotPresent, Env: []corev1.EnvVar{ {Name: "EVENTS_SERVER_PORT", Value: "8090"}, @@ -256,6 +256,14 @@ func (k *K8sHubble) generateHubbleUIDeployment() *appsv1.Deployment { return d } +func (k *K8sHubble) uiImage() string { + return utils.BuildImagePath(k.params.UIImage, defaults.HubbleUIImage, k.params.UIVersion, defaults.HubbleUIVersion) +} + +func (k *K8sHubble) uiBackendImage() string { + return utils.BuildImagePath(k.params.UIBackendImage, defaults.HubbleUIBackendImage, k.params.UIVersion, defaults.HubbleUIVersion) +} + func (k *K8sHubble) disableUI(ctx context.Context) error { k.Log("🔥 Deleting Hubble UI...") k.client.DeleteService(ctx, k.params.Namespace, defaults.HubbleUIServiceName, metav1.DeleteOptions{}) @@ -275,7 +283,7 @@ func (k *K8sHubble) enableUI(ctx context.Context) error { return nil } - k.Log("✨ Deploying Hubble UI...") + k.Log("✨ Deploying Hubble UI from %s and Hubble UI Backend from %s...", k.uiImage(), k.uiBackendImage()) if _, err := k.client.CreateConfigMap(ctx, k.params.Namespace, k.generateHubbleUIConfigMap(), metav1.CreateOptions{}); err != nil { return err } diff --git a/internal/cli/cmd/hubble.go b/internal/cli/cmd/hubble.go index 72b59decfb..7cae230d32 100644 --- a/internal/cli/cmd/hubble.go +++ b/internal/cli/cmd/hubble.go @@ -54,6 +54,9 @@ func newCmdHubbleEnable() *cobra.Command { cmd.Flags().StringVar(¶ms.RelayVersion, "relay-version", "", "Version of Relay to deploy") cmd.Flags().StringVar(¶ms.RelayServiceType, "relay-service-type", "ClusterIP", "Type of Kubernetes service to expose Hubble Relay") cmd.Flags().BoolVar(¶ms.UI, "ui", false, "Enable Hubble UI") + cmd.Flags().StringVar(¶ms.UIImage, "ui-image", "", "Image path to use for UI") + cmd.Flags().StringVar(¶ms.UIBackendImage, "ui-backend-image", "", "Image path to use for UI backend") + cmd.Flags().StringVar(¶ms.UIVersion, "ui-version", "", "Version of UI to deploy") cmd.Flags().BoolVar(¶ms.CreateCA, "create-ca", true, "Automatically create CA if needed") cmd.Flags().StringVar(&contextName, "context", "", "Kubernetes configuration context") cmd.Flags().BoolVar(¶ms.Wait, "wait", true, "Wait for status to report success (no errors)")