Skip to content

Commit

Permalink
[installer]: add all combinations of images to the mirror function
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Emms committed Apr 13, 2022
1 parent 6b84807 commit 1bd1b95
Showing 1 changed file with 115 additions and 1 deletion.
116 changes: 115 additions & 1 deletion install/installer/cmd/mirror_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down

0 comments on commit 1bd1b95

Please sign in to comment.