From b77301ae9e144f811d87a483be12abbd5b4283bd Mon Sep 17 00:00:00 2001 From: sdischer-sap <129972012+sdischer-sap@users.noreply.github.com> Date: Thu, 29 Feb 2024 10:09:58 +0100 Subject: [PATCH] Allow configuration of registry (#50) * feat: allow to configure registry in crossplane setup * fix: fix e2e tests and add comments for linter --- e2e/main_test.go | 6 +++--- go.sum | 2 -- pkg/setup/setup.go | 25 +++++++++++++++++++++++-- pkg/xpenvfuncs/xpenvfuncs.go | 21 +++++++++++++++++++-- 4 files changed, 45 insertions(+), 9 deletions(-) diff --git a/e2e/main_test.go b/e2e/main_test.go index 26fe6d7..071f249 100644 --- a/e2e/main_test.go +++ b/e2e/main_test.go @@ -39,9 +39,9 @@ func TestMain(m *testing.M) { // Enhance interface for one- based providers clusterSetup := setup.ClusterSetup{ - ProviderName: "provider-nop", - Images: imgs, - CrossplaneVersion: "1.14.0", + ProviderName: "provider-nop", + Images: imgs, + CrossplaneSetup: setup.CrossplaneSetup{}, ControllerConfig: &vendored.ControllerConfig{ Spec: vendored.ControllerConfigSpec{ Image: &imgs.Package, diff --git a/go.sum b/go.sum index 1033f97..bd347a5 100644 --- a/go.sum +++ b/go.sum @@ -83,8 +83,6 @@ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/go-containerregistry v0.17.0 h1:5p+zYs/R4VGHkhyvgWurWrpJ2hW4Vv9fQI+GzdcwXLk= -github.com/google/go-containerregistry v0.17.0/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= github.com/google/go-containerregistry v0.19.0 h1:uIsMRBV7m/HDkDxE/nXMnv1q+lOOSPlQ/ywc5JbB8Ic= github.com/google/go-containerregistry v0.19.0/go.mod h1:u0qB2l7mvtWVR5kNcbFIhFY1hLbf8eeGapA+vbFDCtQ= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= diff --git a/pkg/setup/setup.go b/pkg/setup/setup.go index 7c2bd24..1dbd2b1 100644 --- a/pkg/setup/setup.go +++ b/pkg/setup/setup.go @@ -24,6 +24,9 @@ const ( reuseClusterEnv = "E2E_REUSE_CLUSTER" clusterNameEnv = "E2E_CLUSTER_NAME" defaultPrefix = "e2e" + + // DockerRegistry is the default docker registry, which can be passed to the crossplane setup + DockerRegistry = "index.docker.io" ) // ProviderCredentials holds the data for a secret to be created in the crossplane namespace @@ -32,14 +35,32 @@ type ProviderCredentials struct { SecretName *string } +// CrossplaneSetup holds configuration specific to the crossplane installation +type CrossplaneSetup struct { + Version string + Registry string +} + +// Options returns configurtion as options pattern to be passed on to installation process step +func (c CrossplaneSetup) Options() []xpenvfuncs.CrossplaneOpt { + var opts []xpenvfuncs.CrossplaneOpt + if c.Version != "" { + opts = append(opts, xpenvfuncs.Version(c.Version)) + } + if c.Registry != "" { + opts = append(opts, xpenvfuncs.Registry(c.Registry)) + } + return opts +} + // ClusterSetup help with a default kind setup for crossplane, with crossplane and a provider type ClusterSetup struct { ProviderName string Images images.ProviderImages + CrossplaneSetup CrossplaneSetup ControllerConfig *vendored.ControllerConfig ProviderCredential *ProviderCredentials AddToSchemaFuncs []func(s *runtime.Scheme) error - CrossplaneVersion string postSetupFuncs []ClusterAwareFunc ProviderConfigDir *string } @@ -75,7 +96,7 @@ func (s *ClusterSetup) Configure(testEnv env.Environment, cluster *kind.Cluster) testEnv.Setup( xpenvfuncs.Conditional( xpenvfuncs.Compose( - xpenvfuncs.InstallCrossplane(name, s.CrossplaneVersion), + xpenvfuncs.InstallCrossplane(name, s.CrossplaneSetup.Options()...), xpenvfuncs.InstallCrossplaneProvider( name, xpenvfuncs.InstallCrossplaneProviderOptions{ Name: s.ProviderName, diff --git a/pkg/xpenvfuncs/xpenvfuncs.go b/pkg/xpenvfuncs/xpenvfuncs.go index 8c600ad..f30e95b 100644 --- a/pkg/xpenvfuncs/xpenvfuncs.go +++ b/pkg/xpenvfuncs/xpenvfuncs.go @@ -92,7 +92,7 @@ var ( ) // InstallCrossplane returns an env.Func that is used to install crossplane into the given cluster -func InstallCrossplane(clusterName string, crossplaneVersion string) env.Func { +func InstallCrossplane(clusterName string, opts ...CrossplaneOpt) env.Func { cacheName := "package-cache" return Compose( @@ -122,12 +122,12 @@ func InstallCrossplane(clusterName string, crossplaneVersion string) env.Func { helmInstallOpts := []helm.Option{ helm.WithName("crossplane"), helm.WithNamespace("crossplane-system"), - helm.WithVersion(crossplaneVersion), helm.WithReleaseName(helmRepoName + "/crossplane"), helm.WithArgs("--set", fmt.Sprintf("packageCache.pvc=%s", cacheName)), helm.WithTimeout("10m"), helm.WithWait(), } + helmInstallOpts = append(helmInstallOpts, opts...) if err := manager.RunInstall(helmInstallOpts...); err != nil { return ctx, errors.Wrap(err, "install crossplane func: failed to install crossplane Helm chart") @@ -529,3 +529,20 @@ func CreateTestNamespace(ctx context.Context, cfg *envconf.Config) (context.Cont func DeleteTestNamespace(ctx context.Context, cfg *envconf.Config) (context.Context, error) { return envfuncs.DeleteNamespace(cfg.Namespace())(ctx, cfg) } + +// CrossplaneOpt Option alias for configuring aspects of crossplane installation +type CrossplaneOpt = helm.Option + +// Version configures the version of crossplane to be installed +func Version(version string) CrossplaneOpt { + return func(opts *helm.Opts) { + opts.Version = version + } +} + +// Registry configures the registry crossplane uses by adding it to the args values +func Registry(registry string) CrossplaneOpt { + return func(opts *helm.Opts) { + opts.Args = append(opts.Args, "--set", fmt.Sprintf("args={--registry=%s}", registry)) + } +}