Skip to content

Commit

Permalink
address review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Manabu McCloskey <[email protected]>
  • Loading branch information
nabuskey committed May 24, 2024
1 parent 774391a commit 3a6527d
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 137 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,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 [kustommize 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 @@ -153,6 +156,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
1 change: 1 addition & 0 deletions pkg/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ func (b *Build) Run(ctx context.Context, recreateCluster bool) error {
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, dir); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/cmd/create/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func init() {
CreateCmd.PersistentFlags().StringVar(&protocol, "protocol", "https", "Protocol to use to access web UIs. http or https.")
CreateCmd.PersistentFlags().StringVar(&port, "port", "8443", "Port number under which idpBuilder tools are accessible.")
CreateCmd.PersistentFlags().BoolVar(&pathRouting, "use-path-routing", false, "When set to true, web UIs are exposed under single domain name.")
CreateCmd.Flags().StringSliceVarP(&extraPackagesDirs, "package-dir", "p", []string{}, "Paths to custom packages")
CreateCmd.Flags().StringSliceVarP(&extraPackagesDirs, "package-dir", "p", []string{}, "Paths to directories containing custom packages")
CreateCmd.Flags().StringSliceVarP(&packageCustomizationFiles, "package-custom-file", "c", []string{}, "Name of the package and the path to file to customize the package with. e.g. argocd:/tmp/argocd.yaml")
// idpbuilder related flags
CreateCmd.Flags().BoolVarP(&noExit, "no-exit", "n", true, "When set, idpbuilder will not exit after all packages are synced. Useful for continuously syncing local directories.")
Expand Down
9 changes: 5 additions & 4 deletions pkg/cmd/get/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ func getSecretsE(cmd *cobra.Command, args []string) error {
defer ctxCancel()
kubeConfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config")

opts := build.NewBuildOptions{}
opts.KubeConfigPath = kubeConfigPath
opts.Scheme = k8s.GetScheme()
opts.CancelFunc = ctxCancel
opts := build.NewBuildOptions{
KubeConfigPath: kubeConfigPath,
Scheme: k8s.GetScheme(),
CancelFunc: ctxCancel,
}

b := build.NewBuild(opts)

Expand Down
3 changes: 1 addition & 2 deletions pkg/cmd/helpers/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ func ValidateKubernetesYamlFile(absPath string) error {
}

func ParsePackageStrings(pkgStrings []string) ([]string, []string, error) {
remote := make([]string, 0, 2)
local := make([]string, 0, 2)
remote, local := make([]string, 0, 2), make([]string, 0, 2)
for i := range pkgStrings {
loc := pkgStrings[i]
_, err := util.NewKustomizeRemote(loc)
Expand Down
22 changes: 11 additions & 11 deletions pkg/controllers/custompackage/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,19 +281,19 @@ func (r *Reconciler) SetupWithManager(mgr ctrl.Manager) error {
}

func (r *Reconciler) getArgoCDAppFile(ctx context.Context, resource *v1alpha1.CustomPackage) ([]byte, error) {
if resource.Spec.RemoteRepository.Url != "" {
cloneDir := util.RepoDir(resource.Spec.RemoteRepository.Url, r.TempDir)
st := r.RepoMap.LoadOrStore(resource.Spec.RemoteRepository.Url, cloneDir)
st.MU.Lock()
wt, _, err := util.CloneRemoteRepoToDir(ctx, resource.Spec.RemoteRepository, 1, false, cloneDir, "")
defer st.MU.Unlock()
if err != nil {
return nil, fmt.Errorf("cloning repo, %s: %w", resource.Spec.RemoteRepository.Url, err)
}
return util.ReadWorktreeFile(wt, resource.Spec.ArgoCD.ApplicationFile)
if resource.Spec.RemoteRepository.Url == "" {
return os.ReadFile(resource.Spec.ArgoCD.ApplicationFile)
}

return os.ReadFile(resource.Spec.ArgoCD.ApplicationFile)
cloneDir := util.RepoDir(resource.Spec.RemoteRepository.Url, r.TempDir)
st := r.RepoMap.LoadOrStore(resource.Spec.RemoteRepository.Url, cloneDir)
st.MU.Lock()
wt, _, err := util.CloneRemoteRepoToDir(ctx, resource.Spec.RemoteRepository, 1, false, cloneDir, "")
defer st.MU.Unlock()
if err != nil {
return nil, fmt.Errorf("cloning repo, %s: %w", resource.Spec.RemoteRepository.Url, err)
}
return util.ReadWorktreeFile(wt, resource.Spec.ArgoCD.ApplicationFile)
}

func localRepoName(appName, dir string) string {
Expand Down
1 change: 1 addition & 0 deletions pkg/controllers/gitrepository/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ func pushToRemote(ctx context.Context, remoteRepo *git.Repository, creds gitProv
func reconcileLocalRepoContent(ctx context.Context, repo *v1alpha1.GitRepository, tgtRepo repoInfo, creds gitProviderCredentials, scheme *runtime.Scheme, tmplConfig util.CorePackageTemplateConfig, tmpDir string, repoMap *util.RepoMap) error {
logger := log.FromContext(ctx)
tgtCloneDir := util.RepoDir(tgtRepo.cloneUrl, tmpDir)

st := repoMap.LoadOrStore(tgtRepo.cloneUrl, tgtCloneDir)
st.MU.Lock()
defer st.MU.Unlock()
Expand Down
9 changes: 8 additions & 1 deletion pkg/controllers/gitrepository/gitea.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ func (g *giteaProvider) getRepository(ctx context.Context, repo *v1alpha1.GitRep
}, nil
}

func (g *giteaProvider) updateRepoContent(ctx context.Context, repo *v1alpha1.GitRepository, repoInfo repoInfo, creds gitProviderCredentials, tmpDir string, repoMap *util.RepoMap) error {
func (g *giteaProvider) updateRepoContent(
ctx context.Context,
repo *v1alpha1.GitRepository,
repoInfo repoInfo,
creds gitProviderCredentials,
tmpDir string,
repoMap *util.RepoMap,
) error {
switch repo.Spec.Source.Type {
case v1alpha1.SourceTypeLocal, v1alpha1.SourceTypeEmbedded:
return reconcileLocalRepoContent(ctx, repo, repoInfo, creds, g.Scheme, g.config, tmpDir, repoMap)
Expand Down
9 changes: 8 additions & 1 deletion pkg/controllers/gitrepository/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,14 @@ func (g *gitHubProvider) setProviderCredentials(ctx context.Context, repo *v1alp
return g.gitHubClient.setToken(creds.accessToken)
}

func (g *gitHubProvider) updateRepoContent(ctx context.Context, repo *v1alpha1.GitRepository, repoInfo repoInfo, creds gitProviderCredentials, tmpDir string, repoMap *util.RepoMap) error {
func (g *gitHubProvider) updateRepoContent(
ctx context.Context,
repo *v1alpha1.GitRepository,
repoInfo repoInfo,
creds gitProviderCredentials,
tmpDir string,
repoMap *util.RepoMap,
) error {
return reconcileLocalRepoContent(ctx, repo, repoInfo, creds, g.Scheme, g.config, tmpDir, repoMap)
}

Expand Down
Loading

0 comments on commit 3a6527d

Please sign in to comment.