From 1bd1b955d5e1372f6cc0d874c7c15e81dcc00b2e Mon Sep 17 00:00:00 2001 From: Simon Emms Date: Wed, 13 Apr 2022 21:42:19 +0000 Subject: [PATCH] [installer]: add all combinations of images to the mirror function --- install/installer/cmd/mirror_list.go | 116 ++++++++++++++++++++++++++- 1 file changed, 115 insertions(+), 1 deletion(-) diff --git a/install/installer/cmd/mirror_list.go b/install/installer/cmd/mirror_list.go index b5ba93dced44db..0955007c05eb70 100644 --- a/install/installer/cmd/mirror_list.go +++ b/install/installer/cmd/mirror_list.go @@ -15,6 +15,7 @@ import ( "github.com/gitpod-io/gitpod/installer/pkg/common" configv1 "github.com/gitpod-io/gitpod/installer/pkg/config/v1" "github.com/spf13/cobra" + "k8s.io/utils/pointer" ) type mirrorListRepo struct { @@ -85,6 +86,119 @@ func init() { mirrorListCmd.Flags().StringVarP(&mirrorListOpts.ConfigFN, "config", "c", os.Getenv("GITPOD_INSTALLER_CONFIG"), "path to the config file") } +func renderAllKubernetesObject(cfgVersion string, cfg *configv1.Config) ([]string, error) { + fns := []func() ([]string, error){ + func() ([]string, error) { + // Render for in-cluster dependencies + return renderKubernetesObjects(cfgVersion, cfg) + }, + func() ([]string, error) { + // Render for external depedencies - AWS + cfg.Database = configv1.Database{ + InCluster: pointer.Bool(false), + External: &configv1.DatabaseExternal{ + Certificate: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + cfg.ContainerRegistry = configv1.ContainerRegistry{ + InCluster: pointer.Bool(false), + External: &configv1.ContainerRegistryExternal{ + URL: "some-url", + Certificate: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + S3Storage: &configv1.S3Storage{ + Bucket: "some-bucket", + Certificate: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + cfg.ObjectStorage = configv1.ObjectStorage{ + InCluster: pointer.Bool(false), + S3: &configv1.ObjectStorageS3{ + Endpoint: "endpoint", + Credentials: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + return renderKubernetesObjects(cfgVersion, cfg) + }, + func() ([]string, error) { + // Render for external depedencies - Azure + cfg.Database.CloudSQL = nil + cfg.ContainerRegistry = configv1.ContainerRegistry{ + InCluster: pointer.Bool(false), + External: &configv1.ContainerRegistryExternal{ + URL: "some-url", + Certificate: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + cfg.ObjectStorage = configv1.ObjectStorage{ + InCluster: pointer.Bool(false), + Azure: &configv1.ObjectStorageAzure{ + Credentials: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + + return renderKubernetesObjects(cfgVersion, cfg) + }, + func() ([]string, error) { + // Render for external depedencies - GCP + cfg.Database = configv1.Database{ + InCluster: pointer.Bool(false), + CloudSQL: &configv1.DatabaseCloudSQL{ + Instance: "value", + ServiceAccount: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + cfg.ObjectStorage = configv1.ObjectStorage{ + InCluster: pointer.Bool(false), + CloudStorage: &configv1.ObjectStorageCloudStorage{ + Project: "project", + ServiceAccount: configv1.ObjectRef{ + Kind: configv1.ObjectRefSecret, + Name: "value", + }, + }, + } + + return renderKubernetesObjects(cfgVersion, cfg) + }, + } + + var k8s []string + for _, fn := range fns { + data, err := fn() + if err != nil { + return nil, err + } + + for _, item := range data { + k8s = append(k8s, item) + } + } + + return k8s, nil +} + func generateMirrorList(cfgVersion string, cfg *configv1.Config) ([]mirrorListRepo, error) { // Throw error if set to the default Gitpod repository if cfg.Repository == common.GitpodContainerRegistry { @@ -97,7 +211,7 @@ func generateMirrorList(cfgVersion string, cfg *configv1.Config) ([]mirrorListRe // Use the default Gitpod registry to pull from cfg.Repository = common.GitpodContainerRegistry - k8s, err := renderKubernetesObjects(cfgVersion, cfg) + k8s, err := renderAllKubernetesObject(cfgVersion, cfg) if err != nil { return nil, err }