Skip to content

Commit

Permalink
version: Detect special running Cilium versions
Browse files Browse the repository at this point in the history
When cilium is installed with 'cilium install --version="-ci:1234"'
this version string is added to the standard image names. For the
Cilium agent this becomes "quay.io/cilium/cilium-ci:1234". Detect this
when decoding version from a running Cilium pod by finding the part
after the dash in the image reference, so that the detected version
becomes "-ci:1234". This allows hubble to be enabled without passing
--hubble-version parameter explicitly in this case.

Signed-off-by: Jarno Rajahalme <[email protected]>
  • Loading branch information
jrajahalme authored and tklauser committed Dec 9, 2021
1 parent 1fdd336 commit a7670ef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/k8s/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,14 @@ func (c *Client) GetRunningCiliumVersion(ctx context.Context, namespace string)
if digest := strings.Index(v, "@"); digest > 0 {
v = v[:digest]
}
// Add any part in the pod image separated by a '-` to the version,
// e.g., "quay.io/cilium/cilium-ci:1234" -> "-ci:1234"
base := strings.Split(version[0], "/")
last := base[len(base)-1]
dash := strings.Index(last, "-")
if dash >= 0 {
v = last[dash:] + ":" + v
}
return v, nil
}
return "", errors.New("unable to obtain cilium version: no cilium pods found")
Expand Down
4 changes: 4 additions & 0 deletions internal/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func BuildImagePath(userImage, defaultImage, userVersion, defaultVersion string)
if userImage == "" {
switch {
case userVersion == "":
// ':' in defaultVersion?
if strings.Contains(defaultVersion, ":") {
return defaultImage + defaultVersion
}
return defaultImage + ":" + defaultVersion
case strings.Contains(userVersion, ":"):
// userVersion already contains the colon. Useful for ":latest",
Expand Down

0 comments on commit a7670ef

Please sign in to comment.