Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for custom packages #100

Merged
merged 7 commits into from
Dec 9, 2023
Merged

Conversation

nabuskey
Copy link
Collaborator

@nabuskey nabuskey commented Dec 5, 2023

This PR allows for end users to specify additional packages to be installed.

Example command:

./idpbuilder create --package-dir testDir --package-dir testDir2

The contents of testDir2:

1 directory, 2 files
ubuntu@ip-10-192-11-119:~/idpbuilder$ tree testDir2/
testDir2/
└── exampleApp.yaml

0 directories, 1 file

This contains a single manifest that defines an ArgoCD Application. This is passed directly to ArgoCD.

ubuntu@ip-10-192-11-119:~/idpbuilder$ head -n 9 testDir2/exampleApp.yaml
apiVersion: argoproj.io/v1alpha1
kind: Application
metadata:
  name: guestbook
  namespace: argocd
spec:
  project: default
  source:
    repoURL: https://github.com/argoproj/argocd-example-apps.git

image

In testDir, it contains app.yaml. This file is an ArgoCD application except for one field, spec.source.repoURL.

ubuntu@ip-10-192-11-119:~/idpbuilder$ tree testDir/
testDir/
├── app.yaml
└── busybox
    └── busybox.yaml

ubuntu@ip-10-192-11-119:~/idpbuilder$ grep repoURL -B 5 testDir/app.yaml
spec:
  destination:
    namespace: my-app
    server: "https://kubernetes.default.svc"
  source:
    repoURL: cnoe://busybox

The field above specifies the local path that contains manifests to be synced to Gitea repository. It will create a Gitea repository, fill it with contents from the busybox directory, then crates an ArgoCD application.

image

image

This will also continuously sync local file contents to the repository as long as the controller manager does not exit.

You can also add more ArgoCD application files to the specified directories, and the reconciler will pick them up.

Notes

I am not sure if the API is what we want. Initially I thought to do something like

type ExtraPackageConfigSpec struct {
       // Type specifies what kind of package this is. local means local files specified in the Directory field must be synced to a Git Repository
       Type: string `json:"type"`
	// Directory specifies the absolute path to the directory which contains raw manifests to be installed
	Directory string `json:"directory,omitempty"`
	// ArgoApplicationFile specifies the absolute path to the ArgoCD application file
	ArgoApplicationFile string `json:"argoApplicationFile"`
	ArgoCDName string
	ArgoCDNamespace string
}

This means Argo apps are defined in CLI and can't add more apps unless you exit the process and run the command again. Not a deal breaker imo but the other way is more user friendly? I don't personally have a preference so any suggestions here is welcome.

@nimakaviani
Copy link
Contributor

This means Argo apps are defined in CLI and can't add more apps unless you exit the process and run the command again. Not a deal breaker imo but the other way is more user friendly? I don't personally have a preference so any suggestions here is welcome.

I think we should enable both. ideally what would be effective is that the CLI entries for the package-dir get converted to a PackageConfigSpec and dropped into the kind cluster, to be picked up later on by Argo CD. it is important and helpful for folks to be able to add packages at runtime without having to stop the whole thing

@greghaynes
Copy link
Contributor

I would break out custom package to its own top level resource rather than being a field on local build. I'm less concerned with the CLI operation (we can change that later easier) but by having this as its own resource it should be much easier to add/delete packages while idpbuilder is running via CLI or programatically.

@greghaynes
Copy link
Contributor

I think we also need to add some docs for how to write these custom packages. It seems like we've got a good handle on the special keyword we're adding to argocd applications at this point.

@nabuskey
Copy link
Collaborator Author

nabuskey commented Dec 6, 2023

I would break out custom package to its own top level resource rather than being a field on local build. I'm less concerned with the CLI operation (we can change that later easier) but by having this as its own resource it should be much easier to add/delete packages while idpbuilder is running via CLI or programatically.

Yeah I thought about this too. It became a bit messy as I was working through it because of dependency on the local build resource, so I chose the faster way. I will make it a top level resource.

I think we also need to add some docs for how to write these custom packages. It seems like we've got a good handle on the special keyword we're adding to argocd applications at this point.

100%. Once we finalize this, we should document it, update the Readme, record demo, etc.

@nabuskey nabuskey linked an issue Dec 6, 2023 that may be closed by this pull request
Signed-off-by: Manabu Mccloskey <[email protected]>
Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey
Copy link
Collaborator Author

nabuskey commented Dec 8, 2023

@nimakaviani @greghaynes Review again when you get a chance please.

Some notes:
It's possible to replicate referenced remote repositories in ArgoCD Application spec to gitea. This however, means we are essentially cloning the remote repository three times. One locally during reconcile, another in the gitea repo, then another in argo repo server. Depending on the size of referenced repositories, we could end up using a lot of disk space. From end user perspective though, this could be really useful. I think we should consider this in another PR / issue as use cases come in.

Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey nabuskey force-pushed the feature/custom-pkgs branch from 33272e8 to 1aa1601 Compare December 8, 2023 17:59
Copy link
Contributor

@blakeromano blakeromano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

func (r *LocalbuildReconciler) reconcileCustomPkg(ctx context.Context, resource *v1alpha1.Localbuild, pkg v1alpha1.CustomPackageSpec) (ctrl.Result, error) {
logger := log.FromContext(ctx)

sc := runtime.NewScheme()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry I left this a bit ago and forgot to include it in a review - looks like this got fixed though?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah it's fixed :)

@greghaynes
Copy link
Contributor

greghaynes commented Dec 8, 2023

@nabuskey When I run this locally it exits before installing with:

./idpbuilder create --recreate

1.702074326016658e+09	INFO	setup	Getting Kube config
1.702074326017782e+09	INFO	setup	Getting Kube client
1.702074326037449e+09	INFO	setup	Adding CRDs to the cluster
1.7020743260752127e+09	INFO	crd not yet established, waiting.	{"crd name": "custompackages.idpbuilder.cnoe.io"}
1.7020743260786846e+09	INFO	crd not yet established, waiting.	{"crd name": "custompackages.idpbuilder.cnoe.io"}
1.702074326081224e+09	INFO	crd not yet established, waiting.	{"crd name": "custompackages.idpbuilder.cnoe.io"}
1.7020743261008396e+09	INFO	crd not yet established, waiting.	{"crd name": "gitrepositories.idpbuilder.cnoe.io"}
1.702074326107588e+09	INFO	crd not yet established, waiting.	{"crd name": "gitrepositories.idpbuilder.cnoe.io"}
1.7020743274453123e+09	INFO	setup	Creating controller manager
1.702074327468337e+09	INFO	controller-runtime.metrics	Metrics server is starting to listen	{"addr": ":8080"}
1.70207432746853e+09	INFO	setup	Running controllers
1.7020743274686532e+09	INFO	starting manager
1.7020743274686744e+09	INFO	setup	Creating localbuild resource
1.702074327469005e+09	INFO	Starting server	{"path": "/metrics", "kind": "metrics", "addr": "[::]:8080"}
1.7020743274692569e+09	INFO	controller.localbuild	Starting EventSource	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "Localbuild", "source": "kind source: *v1alpha1.Localbuild"}
1.7020743274692965e+09	INFO	controller.localbuild	Starting Controller	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "Localbuild"}
1.7020743274694698e+09	INFO	controller.custompackage	Starting EventSource	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "CustomPackage", "source": "kind source: *v1alpha1.CustomPackage"}
1.7020743274695013e+09	INFO	controller.custompackage	Starting Controller	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "CustomPackage"}
1.7020743274698658e+09	INFO	controller.gitrepository	Starting EventSource	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "GitRepository", "source": "kind source: *v1alpha1.GitRepository"}
1.7020743274699056e+09	INFO	controller.gitrepository	Starting Controller	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "GitRepository"}
1.702074327669879e+09	INFO	controller.custompackage	Starting workers	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "CustomPackage", "worker count": 1}
1.7020743276709957e+09	INFO	controller.gitrepository	Starting workers	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "GitRepository", "worker count": 1}
1.7020743276709957e+09	INFO	controller.localbuild	Starting workers	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "Localbuild", "worker count": 1}
Error: creating localbuild resource: Localbuild.idpbuilder.cnoe.io "localdev" is invalid: spec.packageConfigs.customPackageDirs: Required value

Are we now making packageDirs a required parameter? What do we think the default command to recommend to users should be?

Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey
Copy link
Collaborator Author

nabuskey commented Dec 8, 2023

@nabuskey When I run this locally it exits before installing with:

./idpbuilder create --recreate

1.702074326016658e+09	INFO	setup	Getting Kube config
1.702074326017782e+09	INFO	setup	Getting Kube client
1.702074326037449e+09	INFO	setup	Adding CRDs to the cluster
1.7020743260752127e+09	INFO	crd not yet established, waiting.	{"crd name": "custompackages.idpbuilder.cnoe.io"}
1.7020743260786846e+09	INFO	crd not yet established, waiting.	{"crd name": "custompackages.idpbuilder.cnoe.io"}
1.702074326081224e+09	INFO	crd not yet established, waiting.	{"crd name": "custompackages.idpbuilder.cnoe.io"}
1.7020743261008396e+09	INFO	crd not yet established, waiting.	{"crd name": "gitrepositories.idpbuilder.cnoe.io"}
1.702074326107588e+09	INFO	crd not yet established, waiting.	{"crd name": "gitrepositories.idpbuilder.cnoe.io"}
1.7020743274453123e+09	INFO	setup	Creating controller manager
1.702074327468337e+09	INFO	controller-runtime.metrics	Metrics server is starting to listen	{"addr": ":8080"}
1.70207432746853e+09	INFO	setup	Running controllers
1.7020743274686532e+09	INFO	starting manager
1.7020743274686744e+09	INFO	setup	Creating localbuild resource
1.702074327469005e+09	INFO	Starting server	{"path": "/metrics", "kind": "metrics", "addr": "[::]:8080"}
1.7020743274692569e+09	INFO	controller.localbuild	Starting EventSource	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "Localbuild", "source": "kind source: *v1alpha1.Localbuild"}
1.7020743274692965e+09	INFO	controller.localbuild	Starting Controller	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "Localbuild"}
1.7020743274694698e+09	INFO	controller.custompackage	Starting EventSource	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "CustomPackage", "source": "kind source: *v1alpha1.CustomPackage"}
1.7020743274695013e+09	INFO	controller.custompackage	Starting Controller	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "CustomPackage"}
1.7020743274698658e+09	INFO	controller.gitrepository	Starting EventSource	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "GitRepository", "source": "kind source: *v1alpha1.GitRepository"}
1.7020743274699056e+09	INFO	controller.gitrepository	Starting Controller	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "GitRepository"}
1.702074327669879e+09	INFO	controller.custompackage	Starting workers	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "CustomPackage", "worker count": 1}
1.7020743276709957e+09	INFO	controller.gitrepository	Starting workers	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "GitRepository", "worker count": 1}
1.7020743276709957e+09	INFO	controller.localbuild	Starting workers	{"reconciler group": "idpbuilder.cnoe.io", "reconciler kind": "Localbuild", "worker count": 1}
Error: creating localbuild resource: Localbuild.idpbuilder.cnoe.io "localdev" is invalid: spec.packageConfigs.customPackageDirs: Required value

Are we now making packageDirs a required parameter? What do we think the default command to recommend to users should be?

That was my bad. I did not mean to make that field a required command flag. Fixed now.

Copy link
Contributor

@nimakaviani nimakaviani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some minor changes, otherwise looks good

// CustomPackageSpec controls the installation of the custom applications.
type CustomPackageSpec struct {
// Replicate specifies whether to replicate remote or local contents to the local gitea server.
Replicate bool `json:"replicate"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this can be defaulted to something, no? I assume it is probably a no by default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it defaults to false via zero value. I'll add an annotation to be explicit.

InternalGitServeURL string `json:"internalGitServeURL"`
GitServerAuthSecretRef SecretReference `json:"gitServerAuthSecretRef"`

ArgoCD ArgoCDPackageSpec `json:"argoCD,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PackageSpec maybe? this leaves room for us to hook in other packaging tools later on too, without having to changeg the spec

}

type CustomPackageStatus struct {
Synced bool `json:"synced,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it contain the git repo for where the spec is pushed and tracked? particularly if it is in gitea?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

@@ -60,10 +62,40 @@ func create(cmd *cobra.Command, args []string) error {
os.Exit(1)
}

b := build.NewBuild(buildName, kubeVersion, kubeConfigPath, kindConfigPath, extraPortsMapping, k8s.GetScheme(), ctxCancel)
var absPaths []string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a more descriptive name? absDirPaths?

populate status field

Signed-off-by: Manabu Mccloskey <[email protected]>
@nabuskey nabuskey merged commit cfe5799 into cnoe-io:main Dec 9, 2023
2 checks passed
@cmoulliard
Copy link
Contributor

Next time, please update the README.md file too ! @nabuskey

@nimakaviani
Copy link
Contributor

There is an open issue for it with folks already showing interest #103

Manabu chose to let the community help there, if possible. We will pick it up if no traction from the community occurs soon-ish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement package directory flag
5 participants