From ce564bc7cfc2e2a6d00804a0e48f60dd67b0a485 Mon Sep 17 00:00:00 2001 From: Fabricio Aguiar Date: Fri, 24 Nov 2023 15:47:06 +0000 Subject: [PATCH] Deduplicate related images Signed-off-by: Fabricio Aguiar --- cmd/csv-merger/csv-merger.go | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/cmd/csv-merger/csv-merger.go b/cmd/csv-merger/csv-merger.go index 10263cae5..b42404beb 100644 --- a/cmd/csv-merger/csv-merger.go +++ b/cmd/csv-merger/csv-merger.go @@ -27,6 +27,7 @@ import ( "github.com/ghodss/yaml" "github.com/imdario/mergo" "github.com/openstack-k8s-operators/openstack-operator/pkg/util" + "golang.org/x/exp/maps" semver "github.com/blang/semver/v4" "github.com/operator-framework/api/pkg/lib/version" @@ -163,6 +164,18 @@ func main() { envVarList = append(envVarList, getEnvsFromFile(filename)...) } } + uniqueEnv := make(map[string]v1.EnvVar) + for _, container := range csvBase.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers { + if container.Name == "manager" { + for _, env := range container.Env { + uniqueEnv[env.Name] = env + } + } + } + uniqueImages := make(map[string]csvv1alpha1.RelatedImage) + for _, img := range csvBase.Spec.RelatedImages { + uniqueImages[img.Name] = img + } for _, csvFile := range csvs { if csvFile != "" { csvBytes, err := os.ReadFile(csvFile) @@ -182,14 +195,22 @@ func main() { for _, container := range csvStruct.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.Containers { // Copy env vars from the Service Operator into the OpenStack Operator if container.Name == "manager" { - envVarList = append(envVarList, container.Env...) + for _, env := range container.Env { + uniqueEnv[env.Name] = env + } } } + envVarList = maps.Values(uniqueEnv) installStrategyBase.DeploymentSpecs = append(installStrategyBase.DeploymentSpecs, csvStruct.Spec.InstallStrategy.StrategySpec.DeploymentSpecs...) installStrategyBase.ClusterPermissions = append(installStrategyBase.ClusterPermissions, csvStruct.Spec.InstallStrategy.StrategySpec.ClusterPermissions...) installStrategyBase.Permissions = append(installStrategyBase.Permissions, csvStruct.Spec.InstallStrategy.StrategySpec.Permissions...) - csvNew.Spec.RelatedImages = append(csvNew.Spec.RelatedImages, csvStruct.Spec.RelatedImages...) + for _, img := range csvStruct.Spec.RelatedImages { + if img.Name != "manager" { + uniqueImages[img.Name] = img + } + } + csvNew.Spec.RelatedImages = maps.Values(uniqueImages) for _, owned := range csvStruct.Spec.CustomResourceDefinitions.Owned { csvNew.Spec.CustomResourceDefinitions.Owned = append(