Skip to content

Commit

Permalink
Fix some bugs in the e2e test suite when only one version mapping is …
Browse files Browse the repository at this point in the history
…provided and fix the setup of the data loader (#2141)

* Fix some bugs in the e2e test suite when only one version mapping is provided and fix the setup of the data loader

* Correct setup for custom sidecar image
  • Loading branch information
johscheuer authored Oct 7, 2024
1 parent 0dff9ad commit 8137bda
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 51 deletions.
44 changes: 4 additions & 40 deletions e2e/fixtures/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,62 +225,26 @@ func (factory *Factory) GetMainContainerOverrides(debugSymbols bool, unifiedImag
image = factory.GetUnifiedFoundationDBImage()
}

mainImage, mainTag := GetBaseImageAndTag(
mainImage, tag := GetBaseImageAndTag(
GetDebugImage(debugSymbols, image),
)

// If the version tag mapping is defined make use of that.
imageConfigs := factory.options.getImageVersionConfig(mainImage, false)
if len(imageConfigs) == 0 {
// The first entry is version specific e.g. this image + tag (if specified) will be used for the provided version
// the second entry ensures we set the base image for e.g. upgrades independent of the version.
imageConfigs = []fdbv1beta2.ImageConfig{
{
BaseImage: mainImage,
Tag: mainTag,
Version: factory.GetFDBVersionAsString(),
},
{
BaseImage: mainImage,
},
}
}

return fdbv1beta2.ContainerOverrides{
EnableTLS: false,
ImageConfigs: imageConfigs,
ImageConfigs: factory.options.getImageVersionConfig(mainImage, tag, false),
}
}

// GetSidecarContainerOverrides will return the sidecar container overrides. If the unified image should be used an empty
// container override will be returned.
func (factory *Factory) GetSidecarContainerOverrides(debugSymbols bool) fdbv1beta2.ContainerOverrides {
sidecarImage, sidecarTag := GetBaseImageAndTag(
image, tag := GetBaseImageAndTag(
GetDebugImage(debugSymbols, factory.GetSidecarImage()),
)

// If the version tag mapping is defined make use of that.
imageConfigs := factory.options.getImageVersionConfig(sidecarImage, true)
if len(imageConfigs) == 0 {
// The first entry is version specific e.g. this image + tag (if specified) will be used for the provided version
// the second entry ensures we set the base image for e.g. upgrades independent of the version.
imageConfigs = []fdbv1beta2.ImageConfig{
{
BaseImage: sidecarImage,
Tag: sidecarTag,
Version: factory.GetFDBVersionAsString(),
TagSuffix: "-1",
},
{
BaseImage: sidecarImage,
TagSuffix: "-1",
},
}
}

return fdbv1beta2.ContainerOverrides{
EnableTLS: false,
ImageConfigs: imageConfigs,
ImageConfigs: factory.options.getImageVersionConfig(image, tag, true),
}
}

Expand Down
2 changes: 1 addition & 1 deletion e2e/fixtures/fdb_data_loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ spec:
runAsUser: 0
runAsGroup: 0
# Install this library in a special location to force the operator to use it as the primary library.
{{ if eq .FDBVersion.Compact "7.1" }}
{{ if .CopyAsPrimary }}
- name: foundationdb-kubernetes-init-7-1-primary
image: {{ .Image }}
imagePullPolicy: {{ .ImagePullPolicy }}
Expand Down
51 changes: 41 additions & 10 deletions e2e/fixtures/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,58 @@ func (options *FactoryOptions) validateFDBVersionTagMapping() error {
return nil
}

func (options *FactoryOptions) getImageVersionConfig(baseImage string, isSidecar bool) []fdbv1beta2.ImageConfig {
// getTagSuffix returns "-1" if the tag suffix should be used for a sidecar image.
func getTagSuffix(isSidecar bool) string {
if isSidecar {
return "-1"
}

return ""
}

// getTagWithSuffix returns the tag with the required suffix if the image is needed for the sidecar image.
func getTagWithSuffix(tag string, isSidecar bool) string {
if tag != "" && isSidecar {
return tag + getTagSuffix(isSidecar)
}

return tag
}

func (options *FactoryOptions) getImageVersionConfig(baseImage string, versionTag string, isSidecar bool) []fdbv1beta2.ImageConfig {
if options.fdbVersionTagMapping == "" {
return nil
return []fdbv1beta2.ImageConfig{
{
BaseImage: baseImage,
Version: options.fdbVersion,
Tag: getTagWithSuffix(versionTag, isSidecar),
TagSuffix: getTagSuffix(isSidecar),
},
{
BaseImage: baseImage,
TagSuffix: getTagSuffix(isSidecar),
},
}
}

mappings := strings.Split(options.fdbVersionTagMapping, ",")
imageConfig := make([]fdbv1beta2.ImageConfig, len(mappings))

imageConfig := make([]fdbv1beta2.ImageConfig, len(mappings)+1)
for idx, mapping := range mappings {
versionMapping := strings.Split(mapping, ":")
tag := strings.TrimSpace(versionMapping[1])
// The sidecar requires the -1 prefix.
if isSidecar {
tag = tag + "-1"
}

imageConfig[idx] = fdbv1beta2.ImageConfig{
BaseImage: baseImage,
Version: strings.TrimSpace(versionMapping[0]),
Tag: tag,
Tag: getTagWithSuffix(strings.TrimSpace(versionMapping[1]), isSidecar),
}
}

// Always add the base image config to make sure that the default images can be used, even if only a subset
// of versions use a version tag mapping.
imageConfig[len(mappings)] = fdbv1beta2.ImageConfig{
BaseImage: baseImage,
TagSuffix: getTagSuffix(isSidecar),
}

return imageConfig
}

0 comments on commit 8137bda

Please sign in to comment.