Skip to content

Commit

Permalink
Allow configuration of registry (#50)
Browse files Browse the repository at this point in the history
* feat: allow to configure registry in crossplane setup

* fix: fix e2e tests and add comments for linter
  • Loading branch information
sdischer-sap authored Feb 29, 2024
1 parent 13cfc02 commit b77301a
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
6 changes: 3 additions & 3 deletions e2e/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
25 changes: 23 additions & 2 deletions pkg/setup/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
21 changes: 19 additions & 2 deletions pkg/xpenvfuncs/xpenvfuncs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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))
}
}

0 comments on commit b77301a

Please sign in to comment.