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

feat: new field for image suffix in installation #2988

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions api/v1/installation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type InstallationSpec struct {
// supported to explicitly specify the default registries will be used.
//
// Image format:
// `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
// `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
//
// This option allows configuring the `<registry>` portion of the above format.
// +optional
Expand All @@ -53,7 +53,7 @@ type InstallationSpec struct {
// image path will be used for each image.
//
// Image format:
// `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
// `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
//
// This option allows configuring the `<imagePath>` portion of the above format.
// +optional
Expand All @@ -66,12 +66,25 @@ type InstallationSpec struct {
// image prefix will be used for each image.
//
// Image format:
// `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
// `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
//
// This option allows configuring the `<imagePrefix>` portion of the above format.
// +optional
ImagePrefix string `json:"imagePrefix,omitempty"`

// ImageSuffix allows for the suffix part of an image to be specified. If specified
// then the given value will be appended to each image name. If not specified, or if
// specified value is empty, no suffix will be appended.
// A special case value, UseDefault, is supported to explicitly specify the default
// image suffix will be used for each image.
//
// Image format:
// `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
//
// This option allows configuring the `<imageSuffix>` portion of the above format.
// +optional
ImageSuffix string `json:"imageSuffix,omitempty"`

// ImagePullSecrets is an array of references to container registry pull secrets to use. These are
// applied to all images to be pulled.
// +optional
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func main() {
cmpnts = append(cmpnts, components.CommonImages...)

for _, x := range cmpnts {
ref, _ := components.GetReference(x, "", "", "", nil)
ref, _ := components.GetReference(x, "", "", "", "", nil)
fmt.Println(ref)
}
os.Exit(0)
Expand Down
16 changes: 8 additions & 8 deletions pkg/components/images_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2019 Tigera, Inc. All rights reserved.
// Copyright (c) 2019,2023 Tigera, Inc. All rights reserved.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,7 +28,7 @@ var _ = Describe("test GetReference", func() {
Context("No registry override", func() {
DescribeTable("should render",
func(c component, registry, image string) {
Expect(GetReference(c, "", "", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", registry, image, c.Version)))
Expect(GetReference(c, "", "", "", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", registry, image, c.Version)))
},
Entry("a calico image correctly", ComponentCalicoNode, CalicoRegistry, "calico/node"),
Entry("a tigera image correctly", ComponentTigeraNode, TigeraRegistry, "tigera/cnx-node"),
Expand All @@ -42,7 +42,7 @@ var _ = Describe("test GetReference", func() {
DescribeTable("should render",
func(c component, registry, image string) {
ud := "UseDefault"
Expect(GetReference(c, ud, ud, "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", registry, image, c.Version)))
Expect(GetReference(c, ud, ud, "", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", registry, image, c.Version)))
},
Entry("a calico image correctly", ComponentCalicoNode, CalicoRegistry, "calico/node"),
Entry("a tigera image correctly", ComponentTigeraNode, TigeraRegistry, "tigera/cnx-node"),
Expand All @@ -55,7 +55,7 @@ var _ = Describe("test GetReference", func() {
Context("registry override", func() {
DescribeTable("should render",
func(c component, image string) {
Expect(GetReference(c, "quay.io/", "", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", "quay.io/", image, c.Version)))
Expect(GetReference(c, "quay.io/", "", "", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", "quay.io/", image, c.Version)))
},
Entry("a calico image correctly", ComponentCalicoNode, "calico/node"),
Entry("a tigera image correctly", ComponentTigeraNode, "tigera/cnx-node"),
Expand All @@ -68,7 +68,7 @@ var _ = Describe("test GetReference", func() {
Context("image prefix override", func() {
DescribeTable("should render",
func(c component, image string) {
Expect(GetReference(c, "quay.io/", "", "pref", nil)).To(Equal(fmt.Sprintf("quay.io/%s:%s", image, c.Version)))
Expect(GetReference(c, "quay.io/", "", "pref", "", nil)).To(Equal(fmt.Sprintf("quay.io/%s:%s", image, c.Version)))
},
Entry("a calico image correctly", ComponentCalicoNode, "calico/prefnode"),
Entry("a tigera image correctly", ComponentTigeraNode, "tigera/prefcnx-node"),
Expand All @@ -81,7 +81,7 @@ var _ = Describe("test GetReference", func() {
Context("imagepath override", func() {
DescribeTable("should render",
func(c component, registry, image string) {
Expect(GetReference(c, "", "userpath", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", registry, image, c.Version)))
Expect(GetReference(c, "", "userpath", "", "", nil)).To(Equal(fmt.Sprintf("%s%s:%s", registry, image, c.Version)))
},
Entry("a calico image correctly", ComponentCalicoNode, CalicoRegistry, "userpath/node"),
Entry("a tigera image correctly", ComponentTigeraNode, TigeraRegistry, "userpath/cnx-node"),
Expand All @@ -93,7 +93,7 @@ var _ = Describe("test GetReference", func() {
Context("registry and imagepath override", func() {
DescribeTable("should render",
func(c component, image string) {
Expect(GetReference(c, "quay.io/extra/", "userpath", "", nil)).To(Equal(fmt.Sprintf("quay.io/extra/%s:%s", image, c.Version)))
Expect(GetReference(c, "quay.io/extra/", "userpath", "", "", nil)).To(Equal(fmt.Sprintf("quay.io/extra/%s:%s", image, c.Version)))
},
Entry("a calico image correctly", ComponentCalicoNode, "userpath/node"),
Entry("a tigera image correctly", ComponentTigeraNode, "userpath/cnx-node"),
Expand All @@ -116,7 +116,7 @@ var _ = Describe("test GetReference", func() {
},
},
}
Expect(GetReference(c, "quay.io/extra/", "userpath", "", is)).To(Equal(fmt.Sprintf("quay.io/extra/%s%s", image, hash)))
Expect(GetReference(c, "quay.io/extra/", "userpath", "", "", is)).To(Equal(fmt.Sprintf("quay.io/extra/%s%s", image, hash)))
},
Entry("a calico image correctly", ComponentCalicoNode, "userpath/node", "@sha256:caliconodehash"),
Entry("a tigera image correctly", ComponentTigeraNode, "userpath/cnx-node", "@sha256:tigeracnxnodehash"),
Expand Down
9 changes: 8 additions & 1 deletion pkg/components/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ type component struct {
const UseDefault = "UseDefault"

// GetReference returns the fully qualified image to use, including registry and version.
func GetReference(c component, registry, imagePath, imagePrefix string, is *operator.ImageSet) (string, error) {
func GetReference(c component, registry, imagePath, imagePrefix, imageSuffix string, is *operator.ImageSet) (string, error) {
// If a user did not supply a registry, use the default registry
// based on component
if registry == "" || registry == UseDefault {
Expand Down Expand Up @@ -80,6 +80,9 @@ func GetReference(c component, registry, imagePath, imagePrefix string, is *oper
if imagePath != "" && imagePath != UseDefault {
image = ReplaceImagePath(image, imagePath)
}
if imageSuffix != "" && imageSuffix != UseDefault {
image = appendSuffix(image, imageSuffix)
}

if is == nil {
return fmt.Sprintf("%s%s:%s", registry, image, c.Version), nil
Expand Down Expand Up @@ -111,3 +114,7 @@ func insertPrefix(image, prefix string) string {
subs = append(subs[:len(subs)-1], fmt.Sprintf("%s%s", prefix, subs[len(subs)-1]))
return strings.Join(subs, "/")
}

func appendSuffix(image, suffix string) string {
return fmt.Sprintf("%s%s", image, suffix)
}
1 change: 1 addition & 0 deletions pkg/controller/certificatemanager/certificatemanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func Create(cli client.Client, installation *operatorv1.InstallationSpec, cluste
installation.Registry,
installation.ImagePath,
installation.ImagePrefix,
installation.ImageSuffix,
imageSet,
)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,7 @@ var _ = Describe("Test CertificateManagement suite", func() {
installation.Registry,
installation.ImagePath,
installation.ImagePrefix,
installation.ImageSuffix,
imageSet,
)
Expect(err).NotTo(HaveOccurred())
Expand Down
28 changes: 22 additions & 6 deletions pkg/crds/operator/operator.tigera.io_installations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6974,7 +6974,7 @@ spec:
the image path for each image. If not specified or empty, the default
for each image will be used. A special case value, UseDefault, is
supported to explicitly specify the default image path will be used
for each image. \n Image format: `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
for each image. \n Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<imagePath>` portion of the
above format."
type: string
Expand All @@ -6984,7 +6984,7 @@ spec:
a prefix on each image. If not specified or empty, no prefix will
be used. A special case value, UseDefault, is supported to explicitly
specify the default image prefix will be used for each image. \n
Image format: `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<imagePrefix>` portion of
the above format."
type: string
Expand All @@ -7003,6 +7003,14 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
imageSuffix:
description: "ImageSuffix allows for the suffix part of an image to
be specified. If specified then the given value will be appended
to each image name. If not specified, or if specified value is empty,
no suffix will be appended. \n Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<imageSuffix>` portion of
the above format."
type: string
kubeletVolumePluginPath:
description: 'KubeletVolumePluginPath optionally specifies enablement
of Calico CSI plugin. If not specified, CSI will be enabled by default.
Expand Down Expand Up @@ -7136,7 +7144,7 @@ spec:
slash character (`/`) and all images will be pulled from this registry.
If not specified then the default registries will be used. A special
case value, UseDefault, is supported to explicitly specify the default
registries will be used. \n Image format: `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
registries will be used. \n Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<registry>` portion of the
above format."
type: string
Expand Down Expand Up @@ -16481,7 +16489,7 @@ spec:
used as the image path for each image. If not specified or empty,
the default for each image will be used. A special case value,
UseDefault, is supported to explicitly specify the default image
path will be used for each image. \n Image format: `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
path will be used for each image. \n Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<imagePath>` portion
of the above format."
type: string
Expand All @@ -16491,7 +16499,7 @@ spec:
as a prefix on each image. If not specified or empty, no prefix
will be used. A special case value, UseDefault, is supported
to explicitly specify the default image prefix will be used
for each image. \n Image format: `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
for each image. \n Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<imagePrefix>` portion
of the above format."
type: string
Expand All @@ -16510,6 +16518,14 @@ spec:
type: object
x-kubernetes-map-type: atomic
type: array
imageSuffix:
description: "ImageSuffix allows for the suffix part of an image
to be specified. If specified then the given value will be appended
to each image name. If not specified, or if specified value
is empty, no suffix will be appended. \n Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<imageSuffix>` portion
of the above format."
type: string
kubeletVolumePluginPath:
description: 'KubeletVolumePluginPath optionally specifies enablement
of Calico CSI plugin. If not specified, CSI will be enabled
Expand Down Expand Up @@ -16649,7 +16665,7 @@ spec:
from this registry. If not specified then the default registries
will be used. A special case value, UseDefault, is supported
to explicitly specify the default registries will be used. \n
Image format: `<registry><imagePath>/<imagePrefix><imageName>:<image-tag>`
Image format: `<registry><imagePath>/<imagePrefix><imageName><imageSuffix>:<image-tag>`
\n This option allows configuring the `<registry>` portion of
the above format."
type: string
Expand Down
3 changes: 2 additions & 1 deletion pkg/render/amazoncloudintegration.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ func (c *amazonCloudIntegrationComponent) ResolveImages(is *operatorv1.ImageSet)
reg := c.cfg.Installation.Registry
path := c.cfg.Installation.ImagePath
prefix := c.cfg.Installation.ImagePrefix
suffix := c.cfg.Installation.ImageSuffix
var err error
c.image, err = components.GetReference(components.ComponentCloudControllers, reg, path, prefix, is)
c.image, err = components.GetReference(components.ComponentCloudControllers, reg, path, prefix, suffix, is)
return err
}

Expand Down
9 changes: 5 additions & 4 deletions pkg/render/apiserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,26 +133,27 @@ func (c *apiServerComponent) ResolveImages(is *operatorv1.ImageSet) error {
reg := c.cfg.Installation.Registry
path := c.cfg.Installation.ImagePath
prefix := c.cfg.Installation.ImagePrefix
suffix := c.cfg.Installation.ImageSuffix
var err error
errMsgs := []string{}

if c.cfg.Installation.Variant == operatorv1.TigeraSecureEnterprise {
c.apiServerImage, err = components.GetReference(components.ComponentAPIServer, reg, path, prefix, is)
c.apiServerImage, err = components.GetReference(components.ComponentAPIServer, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
c.queryServerImage, err = components.GetReference(components.ComponentQueryServer, reg, path, prefix, is)
c.queryServerImage, err = components.GetReference(components.ComponentQueryServer, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
} else {
if operatorv1.IsFIPSModeEnabled(c.cfg.Installation.FIPSMode) {
c.apiServerImage, err = components.GetReference(components.ComponentCalicoAPIServerFIPS, reg, path, prefix, is)
c.apiServerImage, err = components.GetReference(components.ComponentCalicoAPIServerFIPS, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
} else {
c.apiServerImage, err = components.GetReference(components.ComponentCalicoAPIServer, reg, path, prefix, is)
c.apiServerImage, err = components.GetReference(components.ComponentCalicoAPIServer, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/render/applicationlayer/applicationlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func (c *component) ResolveImages(is *operatorv1.ImageSet) error {
reg := c.config.Installation.Registry
path := c.config.Installation.ImagePath
prefix := c.config.Installation.ImagePrefix
suffix := c.config.Installation.ImageSuffix

if c.config.OsType != c.SupportedOSType() {
return fmt.Errorf("layer 7 features are supported only on %s", c.SupportedOSType())
Expand All @@ -122,17 +123,17 @@ func (c *component) ResolveImages(is *operatorv1.ImageSet) error {
var err error
var errMsgs []string

c.config.proxyImage, err = components.GetReference(components.ComponentEnvoyProxy, reg, path, prefix, is)
c.config.proxyImage, err = components.GetReference(components.ComponentEnvoyProxy, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}

c.config.collectorImage, err = components.GetReference(components.ComponentL7Collector, reg, path, prefix, is)
c.config.collectorImage, err = components.GetReference(components.ComponentL7Collector, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}

c.config.dikastesImage, err = components.GetReference(components.ComponentDikastes, reg, path, prefix, is)
c.config.dikastesImage, err = components.GetReference(components.ComponentDikastes, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/render/aws-securitygroup-setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,9 @@ func (c *awsSGSetupComponent) ResolveImages(is *operatorv1.ImageSet) error {
reg := c.cfg.Installation.Registry
path := c.cfg.Installation.ImagePath
prefix := c.cfg.Installation.ImagePrefix
suffix := c.cfg.Installation.ImageSuffix
var err error
c.image, err = components.GetReference(components.ComponentOperatorInit, reg, path, prefix, is)
c.image, err = components.GetReference(components.ComponentOperatorInit, reg, path, prefix, suffix, is)
return err
}

Expand Down
11 changes: 6 additions & 5 deletions pkg/render/compliance.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,30 +141,31 @@ func (c *complianceComponent) ResolveImages(is *operatorv1.ImageSet) error {
reg := c.cfg.Installation.Registry
path := c.cfg.Installation.ImagePath
prefix := c.cfg.Installation.ImagePrefix
suffix := c.cfg.Installation.ImageSuffix
var err error
c.benchmarkerImage, err = components.GetReference(components.ComponentComplianceBenchmarker, reg, path, prefix, is)
c.benchmarkerImage, err = components.GetReference(components.ComponentComplianceBenchmarker, reg, path, prefix, suffix, is)

errMsgs := []string{}
if err != nil {
errMsgs = append(errMsgs, err.Error())
}

c.snapshotterImage, err = components.GetReference(components.ComponentComplianceSnapshotter, reg, path, prefix, is)
c.snapshotterImage, err = components.GetReference(components.ComponentComplianceSnapshotter, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}

c.serverImage, err = components.GetReference(components.ComponentComplianceServer, reg, path, prefix, is)
c.serverImage, err = components.GetReference(components.ComponentComplianceServer, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}

c.controllerImage, err = components.GetReference(components.ComponentComplianceController, reg, path, prefix, is)
c.controllerImage, err = components.GetReference(components.ComponentComplianceController, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}

c.reporterImage, err = components.GetReference(components.ComponentComplianceReporter, reg, path, prefix, is)
c.reporterImage, err = components.GetReference(components.ComponentComplianceReporter, reg, path, prefix, suffix, is)
if err != nil {
errMsgs = append(errMsgs, err.Error())
}
Expand Down
Loading