Skip to content

Commit

Permalink
Allow for fetching packages from remote git repositories (#255)
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey authored May 30, 2024
1 parent 08a1af6 commit f556285
Show file tree
Hide file tree
Showing 29 changed files with 1,417 additions and 279 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ Run the following commands for available flags and subcommands:

### Custom Packages

Idpbuilder supports specifying custom packages using the flag `--package-dir` flag. This flag expects a directory containing ArgoCD application files.
Idpbuilder supports specifying custom packages using the flag `--package-dir` flag.
This flag expects a directory (local or remote) containing ArgoCD application files.
In case of a remote directory, it must be a directory in a git repository,
and the URL format must be a [kustomize remote URL format](https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md).

Examples of using custom packages are available in the [example](./examples) directory.
Let's take a look at [this example](examples/basic). This defines two custom package directories to deploy to the cluster.
Expand All @@ -158,6 +161,12 @@ To deploy these packages, run the following commands from this repository's root
./idpbuilder create --package-dir examples/basic/package1 --package-dir examples/basic/package2
```

Alternatively, you can use the URL format:

```
./idpbuilder create --package-dir https://github.com/cnoe-io/idpbuilder//examples/basic/package1 --package-dir https://github.com/cnoe-io/idpbuilder//examples/basic/package2
```

Running this command should create three additional ArgoCD applications in your cluster.

```sh
Expand Down
17 changes: 16 additions & 1 deletion api/v1alpha1/custom_package_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const (
CNOEURIScheme = "cnoe://"
)

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
type CustomPackage struct {
Expand All @@ -30,12 +34,23 @@ type CustomPackageSpec struct {
GitServerAuthSecretRef SecretReference `json:"gitServerAuthSecretRef"`
// InternalGitServeURL specifies the base URL for the git server accessible within the cluster.
// for example, http://my-gitea-http.gitea.svc.cluster.local:3000
InternalGitServeURL string `json:"internalGitServeURL"`
InternalGitServeURL string `json:"internalGitServeURL"`
RemoteRepository RemoteRepositorySpec `json:"remoteRepository"`
// Replicate specifies whether to replicate remote or local contents to the local gitea server.
// +kubebuilder:default:=false
Replicate bool `json:"replicate"`
}

// RemoteRepositorySpec specifies information about remote repositories.
type RemoteRepositorySpec struct {
CloneSubmodules bool `json:"cloneSubmodules"`
Path string `json:"path"`
// Url specifies the url to the repository containing the ArgoCD application file
Url string `json:"url"`
// Ref specifies the specific ref supported by git fetch
Ref string `json:"ref"`
}

type ArgoCDPackageSpec struct {
// ApplicationFile specifies the absolute path to the ArgoCD application file
ApplicationFile string `json:"applicationFile"`
Expand Down
8 changes: 6 additions & 2 deletions api/v1alpha1/gitrepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ const (
GitProviderGitea = "gitea"
GitProviderGitHub = "github"
GiteaAdminUserName = "giteaAdmin"
SourceTypeLocal = "local"
SourceTypeRemote = "remote"
SourceTypeEmbedded = "embedded"
)

type GitRepositorySpec struct {
Expand All @@ -27,9 +30,10 @@ type GitRepositorySource struct {
// Path is the absolute path to directory that contains Kustomize structure or raw manifests.
// This is required when Type is set to local.
// +kubebuilder:validation:Optional
Path string `json:"path"`
Path string `json:"path"`
RemoteRepository RemoteRepositorySpec `json:"remoteRepository"`
// Type is the source type.
// +kubebuilder:validation:Enum:=local;embedded
// +kubebuilder:validation:Enum:=local;embedded;remote
// +kubebuilder:default:=embedded
Type string `json:"type"`
}
Expand Down
1 change: 1 addition & 0 deletions api/v1alpha1/localbuild_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type PackageConfigsSpec struct {
Argo ArgoPackageConfigSpec `json:"argoPackageConfigs,omitempty"`
EmbeddedArgoApplications EmbeddedArgoApplicationsPackageConfigSpec `json:"embeddedArgoApplicationsPackageConfigs,omitempty"`
CustomPackageDirs []string `json:"customPackageDirs,omitempty"`
CustomPackageUrls []string `json:"customPackageUrls,omitempty"`
}

type LocalbuildSpec struct {
Expand Down
22 changes: 22 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 6 additions & 9 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ module github.com/cnoe-io/idpbuilder

go 1.21.3

toolchain go1.21.5

require (
code.gitea.io/sdk/gitea v0.16.0
github.com/cnoe-io/argocd-api v0.0.0-20240125015729-416a35fe855d
github.com/docker/docker v24.0.7+incompatible
github.com/go-git/go-git/v5 v5.10.0
github.com/go-git/go-billy/v5 v5.5.0
github.com/go-git/go-git/v5 v5.12.0
github.com/go-logr/logr v1.4.1
github.com/google/go-cmp v0.6.0
github.com/google/go-github/v61 v61.0.0
Expand All @@ -29,12 +28,11 @@ require (
dario.cat/mergo v1.0.0 // indirect
github.com/BurntSushi/toml v1.3.2 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 // indirect
github.com/acomagu/bufpipe v1.0.4 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
github.com/alessio/shellescape v1.4.1 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/davidmz/go-pageant v1.0.2 // indirect
Expand All @@ -49,7 +47,6 @@ require (
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-fed/httpsig v1.1.0 // indirect
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect
github.com/go-git/go-billy/v5 v5.5.0 // indirect
github.com/go-openapi/jsonpointer v0.21.0 // indirect
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
Expand Down Expand Up @@ -90,9 +87,9 @@ require (
github.com/prometheus/client_model v0.5.0 // indirect
github.com/prometheus/common v0.45.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/skeema/knownhosts v1.2.0 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/stretchr/objx v0.5.2 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
Expand Down
27 changes: 12 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,8 @@ github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbi
github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
github.com/Microsoft/go-winio v0.6.1/go.mod h1:LRdKpFKfdobln8UmuiYcKPot9D2v6svN5+sAH+4kjUM=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371 h1:kkhsdkhsCvIsutKu5zLMgWtgh9YxGCNAw8Ad8hjwfYg=
github.com/ProtonMail/go-crypto v0.0.0-20230828082145-3c4c8a2d2371/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/acomagu/bufpipe v1.0.4 h1:e3H4WUzM3npvo5uv95QuJM3cQspFNtFBzvJ2oNjKIDQ=
github.com/acomagu/bufpipe v1.0.4/go.mod h1:mxdxdup/WdsKVreO5GpW4+M/1CE2sMG4jeGJ2sYmHc4=
github.com/ProtonMail/go-crypto v1.0.0 h1:LRuvITjQWX+WIfr930YHG2HNfjR1uOfyf5vE0kC2U78=
github.com/ProtonMail/go-crypto v1.0.0/go.mod h1:EjAoLdwvbIOoOQr3ihjnSoLZRtE8azugULFRteWMNc0=
github.com/alessio/shellescape v1.4.1 h1:V7yhSDDn8LP4lc4jS8pFkt0zCnzVJlG5JXy9BVKJUX0=
github.com/alessio/shellescape v1.4.1/go.mod h1:PZAiSCk0LJaZkiCSkPv8qIobYglO3FPpyFjDCtHLS30=
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8=
Expand All @@ -25,8 +23,9 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7NFEuV9ekS419A0=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU=
github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA=
github.com/cnoe-io/argocd-api v0.0.0-20240125015729-416a35fe855d h1:cmcSrS0OYTLlGsBFshaAG29qC+PC5LBtKRhnEknlzgU=
github.com/cnoe-io/argocd-api v0.0.0-20240125015729-416a35fe855d/go.mod h1:IXG3LiEAeckMfjdwJnt6qC0ee4J4U5bleMuk1HN82ZA=
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand Down Expand Up @@ -59,8 +58,8 @@ github.com/evanphx/json-patch/v5 v5.8.0 h1:lRj6N9Nci7MvzrXuX6HFzU8XjmhPiXPlsKEy1
github.com/evanphx/json-patch/v5 v5.8.0/go.mod h1:VNkHZ/282BpEyt/tObQO8s5CMPmYYq14uClGH4abBuQ=
github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nosvA=
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gliderlabs/ssh v0.3.5 h1:OcaySEmAQJgyYcArR+gGGTHCyE7nvhEMTlYY+Dp8CpY=
github.com/gliderlabs/ssh v0.3.5/go.mod h1:8XB4KraRrX39qHhT6yxPsHedjA08I/uBVwj4xC+/+z4=
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
Expand All @@ -71,8 +70,8 @@ github.com/go-git/go-billy/v5 v5.5.0 h1:yEY4yhzCDuMGSv83oGxiBotRzhwhNr8VZyphhiu+
github.com/go-git/go-billy/v5 v5.5.0/go.mod h1:hmexnoNsr2SJU1Ju67OaNz5ASJY3+sHgFRpCtpDCKow=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4=
github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII=
github.com/go-git/go-git/v5 v5.10.0 h1:F0x3xXrAWmhwtzoCokU4IMPcBdncG+HAAqi9FcOOjbQ=
github.com/go-git/go-git/v5 v5.10.0/go.mod h1:1FOZ/pQnqw24ghP2n7cunVl0ON55BsjPYvhWHvZGhoo=
github.com/go-git/go-git/v5 v5.12.0 h1:7Md+ndsjrzZxbddRDZjF14qK+NN56sy6wkqaVrjZtys=
github.com/go-git/go-git/v5 v5.12.0/go.mod h1:FTM9VKtnI2m65hNI/TenDDDnUf2Q9FHnXYjuz9i5OEY=
github.com/go-logr/logr v1.3.0/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
Expand Down Expand Up @@ -140,8 +139,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0=
github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJJLY9Nlc=
github.com/matryer/is v1.2.0 h1:92UTHpy8CDwaJ08GqLDzhhuixiBUUD1p3AU6PHddz4A=
github.com/matryer/is v1.2.0/go.mod h1:2fLPjFQM9rhQ15aVEtbuwhJinnOqrmgXPNdZsdwlWXA=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
Expand Down Expand Up @@ -190,13 +187,13 @@ github.com/prometheus/procfs v0.12.0/go.mod h1:pcuDEFsWDnvcgNzo4EEweacyhjeA9Zk3c
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0=
github.com/sergi/go-diff v1.1.0/go.mod h1:STckp+ISIX8hZLjrqAeVduY0gWCT9IjLuqbuNXdaHfM=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/skeema/knownhosts v1.2.0 h1:h9r9cf0+u7wSE+M183ZtMGgOJKiL96brpaz5ekfJCpM=
github.com/skeema/knownhosts v1.2.0/go.mod h1:g4fPeYpque7P0xefxtGzV81ihjC8sX2IqpAoNkjxbMo=
github.com/skeema/knownhosts v1.2.2 h1:Iug2P4fLmDw9f41PB6thxUkNUkJzB5i+1/exaj40L3A=
github.com/skeema/knownhosts v1.2.2/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo=
github.com/spf13/cobra v1.4.0/go.mod h1:Wo4iy3BUC+X2Fybo0PDqwJIv3dNRiZLHQymsfxlB84g=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0=
Expand Down
59 changes: 42 additions & 17 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package build
import (
"context"
"fmt"
"os"
"time"

"github.com/cnoe-io/idpbuilder/api/v1alpha1"
"github.com/cnoe-io/idpbuilder/globals"
"github.com/cnoe-io/idpbuilder/pkg/controllers"
"github.com/cnoe-io/idpbuilder/pkg/kind"
"github.com/cnoe-io/idpbuilder/pkg/util"
Expand All @@ -32,28 +34,42 @@ type Build struct {
kubeVersion string
extraPortsMapping string
customPackageDirs []string
customPackageUrls []string
packageCustomization map[string]v1alpha1.PackageCustomization
exitOnSync bool
scheme *runtime.Scheme
CancelFunc context.CancelFunc
}

func NewBuild(name, kubeVersion, kubeConfigPath, kindConfigPath, extraPortsMapping string, cfg util.CorePackageTemplateConfig,
customPackageDirs []string, exitOnSync bool, scheme *runtime.Scheme, ctxCancel context.CancelFunc,
packageCustomization map[string]v1alpha1.PackageCustomization) *Build {
type NewBuildOptions struct {
Name string
TemplateData util.CorePackageTemplateConfig
KindConfigPath string
KubeConfigPath string
KubeVersion string
ExtraPortsMapping string
CustomPackageDirs []string
CustomPackageUrls []string
PackageCustomization map[string]v1alpha1.PackageCustomization
ExitOnSync bool
Scheme *runtime.Scheme
CancelFunc context.CancelFunc
}

func NewBuild(opts NewBuildOptions) *Build {
return &Build{
name: name,
kindConfigPath: kindConfigPath,
kubeConfigPath: kubeConfigPath,
kubeVersion: kubeVersion,
extraPortsMapping: extraPortsMapping,
customPackageDirs: customPackageDirs,
packageCustomization: packageCustomization,
exitOnSync: exitOnSync,
scheme: scheme,
cfg: cfg,
CancelFunc: ctxCancel,
name: opts.Name,
kindConfigPath: opts.KindConfigPath,
kubeConfigPath: opts.KubeConfigPath,
kubeVersion: opts.KubeVersion,
extraPortsMapping: opts.ExtraPortsMapping,
customPackageDirs: opts.CustomPackageDirs,
customPackageUrls: opts.CustomPackageUrls,
packageCustomization: opts.PackageCustomization,
exitOnSync: opts.ExitOnSync,
scheme: opts.Scheme,
cfg: opts.TemplateData,
CancelFunc: opts.CancelFunc,
}
}

Expand Down Expand Up @@ -106,8 +122,8 @@ func (b *Build) ReconcileCRDs(ctx context.Context, kubeClient client.Client) err
return nil
}

func (b *Build) RunControllers(ctx context.Context, mgr manager.Manager, exitCh chan error) error {
return controllers.RunControllers(ctx, mgr, exitCh, b.CancelFunc, b.exitOnSync, b.cfg)
func (b *Build) RunControllers(ctx context.Context, mgr manager.Manager, exitCh chan error, tmpDir string) error {
return controllers.RunControllers(ctx, mgr, exitCh, b.CancelFunc, b.exitOnSync, b.cfg, tmpDir)
}

func (b *Build) Run(ctx context.Context, recreateCluster bool) error {
Expand Down Expand Up @@ -148,8 +164,16 @@ func (b *Build) Run(ctx context.Context, recreateCluster bool) error {
return err
}

dir, err := os.MkdirTemp("", fmt.Sprintf("%s-%s-", globals.ProjectName, b.name))
if err != nil {
setupLog.Error(err, "creating temp dir")
return err
}
defer os.RemoveAll(dir)
setupLog.V(1).Info("Created temp directory for cloning repositories", "dir", dir)

setupLog.V(1).Info("Running controllers")
if err := b.RunControllers(ctx, mgr, managerExit); err != nil {
if err := b.RunControllers(ctx, mgr, managerExit, dir); err != nil {
setupLog.Error(err, "Error running controllers")
return err
}
Expand Down Expand Up @@ -178,6 +202,7 @@ func (b *Build) Run(ctx context.Context, recreateCluster bool) error {
PackageCustomization: b.packageCustomization,
},
CustomPackageDirs: b.customPackageDirs,
CustomPackageUrls: b.customPackageUrls,
},
}

Expand Down
Loading

0 comments on commit f556285

Please sign in to comment.