Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support -ubi suffix starting 8.12.0 and 7.17.16 #7368

Merged
merged 5 commits into from
Dec 11, 2023

Conversation

thbkrkr
Copy link
Contributor

@thbkrkr thbkrkr commented Dec 7, 2023

This commit makes the operator use the -ubi suffix starting from 8.12.0 and 7.17.16 for the maps image, and for any image when the operator is configured with --ubi-only.

@thbkrkr thbkrkr added >enhancement Enhancement of existing functionality v2.11.0 labels Dec 7, 2023
pkg/controller/common/container/container.go Outdated Show resolved Hide resolved
image: MapsImage,
version: "8.11.0",
suffix: "-obi1",
want: testRegistry + "/elastic-maps-service/elastic-maps-server-ubi8-obi1:8.11.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is that not a behaviour change compared to the old logic where we would have had elastic-maps-server-obi1:8.11.0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was already the behavior but no unit test reflected it.

// don't double append suffix if already contained as e.g. the case for maps
if strings.HasSuffix(string(img), containerSuffix) {
return fmt.Sprintf("%s/%s:%s", containerRegistry, image, version)
}
return fmt.Sprintf("%s/%s%s:%s", containerRegistry, image, containerSuffix, version)

# in pseudo-code
if containerSuffix == ""               { img = "elastic-maps-server-ubi8:8.11.0" }
if containerSuffix == "-ubi8"          { img = "elastic-maps-server-ubi8:8.11.0" }
if containerSuffix == "-somethingelse" { img = "elastic-maps-server-ubi8-somethingelse:8.11.0" }

I checked out main, added this testcase:

{
	name:    "Maps old 8 image with custom suffix",
	image:   MapsImage,
	version: "8.11.0",
	suffix:  "-obi1",
	want:    testRegistry + "/elastic-maps-service/elastic-maps-server-ubi8-obi1:8.11.0",
},

The test passes:

--- PASS: TestImageRepository/Maps_old_8_image_with_custom_suffix (0.00s)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right I misread the old code.

want: testRegistry + "/elasticsearch/elasticsearch-ubi8:7.17.15",
},
{
name: "Maps 7 image with custom repository always uses -ubi suffix",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we know that maps is going to adopt the new convention? (If not we should push for it for consistency)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maps is going to adopt the new convention.


// getUBISuffix returns the UBI suffix to use depending on the given version
func getUBISuffix(v string) string {
ver := version.MustParse(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know the spec is supposed to be validated before we reach that part of the code, but version.MustParse panics if the version cannot be parsed, which seems like a "rough" way to handle an error 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree.

I don't know which is the best solution between these two ImageRepository signature updates:

  • ImageRepository(img Image, ver version.Version) string // implies that the caller does the version.Parse
  • ImageRepository(img Image, version string) (string, error) // does the version.Parse

I opted for the first option.

thbkrkr and others added 3 commits December 7, 2023 16:18
Co-authored-by: Michael Morello <michael.morello@gmail.com>
Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com>
Copy link
Contributor

@barkbay barkbay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

if strings.HasSuffix(string(img), containerSuffix) {
return fmt.Sprintf("%s/%s:%s", containerRegistry, image, version)
suffix := ""
UBIOnly := containerSuffix == UBISuffix
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: not a strong opinion but it feels to me that UBIOnly is the boolean flag that should be set by --ubi-only.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I renamed UBIOnly in useUBISuffix in dd2ff5a.

pkg/controller/common/container/container.go Outdated Show resolved Hide resolved
image: MapsImage,
version: "8.11.0",
suffix: "-obi1",
want: testRegistry + "/elastic-maps-service/elastic-maps-server-ubi8-obi1:8.11.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right I misread the old code.

@thbkrkr thbkrkr enabled auto-merge (squash) December 11, 2023 08:58
@thbkrkr thbkrkr merged commit 081f907 into elastic:main Dec 11, 2023
5 checks passed
robbavey pushed a commit to robbavey/cloud-on-k8s that referenced this pull request Dec 20, 2023
This commit makes the operator use the -ubi suffix starting from 8.12.0 and 7.17.16 for the maps image, and for any image when the operator is configured with --ubi-only.

---------
Co-authored-by: Michael Morello <michael.morello@gmail.com>
Co-authored-by: Peter Brachwitz <peter.brachwitz@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>enhancement Enhancement of existing functionality v2.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants