Skip to content

Commit

Permalink
Deduplicate related images
Browse files Browse the repository at this point in the history
Signed-off-by: Fabricio Aguiar <[email protected]>
  • Loading branch information
fao89 committed Nov 24, 2023
1 parent 585abc0 commit 468204a
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions cmd/csv-merger/csv-merger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -155,14 +156,19 @@ func main() {
Status: csvBase.Status}

installStrategyBase := csvBase.Spec.InstallStrategy.StrategySpec
csvNew.Spec.RelatedImages = csvBase.Spec.RelatedImages

envVarList := []v1.EnvVar{}
uniqueImages := make(map[string]csvv1alpha1.RelatedImage)
uniqueEnv := make(map[string]v1.EnvVar)
if len(*importEnvFiles) > 0 {
for _, filename := range strings.Split(*importEnvFiles, ",") {
envVarList = append(envVarList, getEnvsFromFile(filename)...)
envVarList := getEnvsFromFile(filename)
for _, env := range envVarList {
uniqueEnv[env.Name] = env
}

}
}

for _, csvFile := range csvs {
if csvFile != "" {
csvBytes, err := os.ReadFile(csvFile)
Expand All @@ -182,14 +188,20 @@ 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
}
}
}

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
}
}

for _, owned := range csvStruct.Spec.CustomResourceDefinitions.Owned {
csvNew.Spec.CustomResourceDefinitions.Owned = append(
Expand Down Expand Up @@ -227,14 +239,15 @@ func main() {
}

}
csvNew.Spec.RelatedImages = append(csvBase.Spec.RelatedImages, maps.Values(uniqueImages)...)
if len(*exportEnvFile) > 0 {
writeEnvToYaml(*exportEnvFile, envVarList)
writeEnvToYaml(*exportEnvFile, maps.Values(uniqueEnv))
} else {
installStrategyBase.DeploymentSpecs[0].Spec.Template.Spec.Containers[1].Env = append(
// OpenStack Operator controller-manager container env vars
installStrategyBase.DeploymentSpecs[0].Spec.Template.Spec.Containers[1].Env,
// Service Operator controller-manager container env vars
envVarList...,
maps.Values(uniqueEnv)...,
)
}

Expand Down

0 comments on commit 468204a

Please sign in to comment.