Skip to content

Commit

Permalink
bootstrap directory feature
Browse files Browse the repository at this point in the history
  • Loading branch information
pthomison committed Apr 7, 2024
1 parent 195c92d commit 0ed7b0e
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 2 additions & 2 deletions cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,13 @@ func k3AutoCreate(cmd *cobra.Command, args []string) {
if !MinimalFlag {

logrus.Info("Injecting Default Deployments")
err = Deploy(ctx, "default", defaults.DefaultDeploymentsFolder, afero.FromIOFS{FS: defaults.DefaultDeployments})
err = Deploy(ctx, "default", defaults.DefaultDeploymentsFolder, "/", afero.FromIOFS{FS: defaults.DefaultDeployments})
checkError(err)
logrus.Info("Default Deployments Injected")

if DeploymentDirectoryFlag != "" {
logrus.Info("Injecting Directory Deployments")
err = Deploy(ctx, "deployments", DeploymentDirectoryFlag, afero.NewOsFs())
err = Deploy(ctx, "deployments", DeploymentDirectoryFlag, BootstrapDirectoryFlag, afero.NewOsFs())
checkError(err)

logrus.Info("Directory Deployments Injected")
Expand Down
8 changes: 4 additions & 4 deletions cmd/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
sourcev1beta2 "github.com/fluxcd/source-controller/api/v1beta2"
)

func ensureDeployment(ctx context.Context, k8sC client.Client, name string, namespace string, repository string, image string, tag string) error {
func ensureDeployment(ctx context.Context, k8sC client.Client, name string, namespace string, repository string, image string, tag string, path string) error {
oci := sourcev1beta2.OCIRepository{}
err := k8sC.Get(ctx, client.ObjectKey{
Name: name,
Expand Down Expand Up @@ -55,7 +55,7 @@ func ensureDeployment(ctx context.Context, k8sC client.Client, name string, name
if err != nil && !errors.IsNotFound(err) {
return err
} else if err != nil {
kustomization = flux.NewOCIKustomizationObject(name, namespace)
kustomization = flux.NewOCIKustomizationObject(name, namespace, path)
err = k8sC.Create(ctx, &kustomization)
if err != nil {
return err
Expand All @@ -73,7 +73,7 @@ func ensureDeployment(ctx context.Context, k8sC client.Client, name string, name
return nil
}

func Deploy(ctx context.Context, name string, directory string, filesystem afero.Fs) error {
func Deploy(ctx context.Context, name string, directory string, bootstrap string, filesystem afero.Fs) error {

k8sC, err := k8s.NewClient()
if err != nil {
Expand Down Expand Up @@ -131,7 +131,7 @@ func Deploy(ctx context.Context, name string, directory string, filesystem afero

close(closeChan)

err = ensureDeployment(ctx, k8sC, name, namespace, repository, image, tag)
err = ensureDeployment(ctx, k8sC, name, namespace, repository, image, tag, bootstrap)
if err != nil {
return err
}
Expand Down
2 changes: 2 additions & 0 deletions cmd/k3auto.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ var (
ClusterConfigFileFlag string
SecretConfigFileFlag string
DeploymentDirectoryFlag string
BootstrapDirectoryFlag string
MinimalFlag bool
)

func init() {
K3AutoCmd.PersistentFlags().StringVarP(&ClusterConfigFileFlag, "cluster-config", "c", "", "Override Cluster Config File")
K3AutoCmd.PersistentFlags().StringVarP(&SecretConfigFileFlag, "secret-config", "s", "", "Inject Secrets To the Cluster on Creation")
K3AutoCmd.PersistentFlags().StringVarP(&DeploymentDirectoryFlag, "deployment-directory", "d", "", "Deployment Directory")
K3AutoCmd.PersistentFlags().StringVarP(&BootstrapDirectoryFlag, "bootstrap-directory", "b", "/", "Folder Within The Deployment Directory To Bootstrap From")
K3AutoCmd.PersistentFlags().BoolVarP(&MinimalFlag, "minimal", "m", false, "Only deploy the k3d cluster & flux controllers")

K3AutoCmd.AddCommand(VersionCmd)
Expand Down
4 changes: 2 additions & 2 deletions cmd/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func k3AutoUpdate(cmd *cobra.Command, args []string) {
if !MinimalFlag {

logrus.Info("Injecting Default Deployments")
err = Deploy(ctx, "default", defaults.DefaultDeploymentsFolder, afero.FromIOFS{FS: defaults.DefaultDeployments})
err = Deploy(ctx, "default", defaults.DefaultDeploymentsFolder, "/", afero.FromIOFS{FS: defaults.DefaultDeployments})
checkError(err)
logrus.Info("Default Deployments Injected")

Expand All @@ -35,7 +35,7 @@ func k3AutoUpdate(cmd *cobra.Command, args []string) {
if DeploymentDirectoryFlag != "" {

logrus.Info("Injecting Directory Deployments")
err = Deploy(ctx, "deployments", DeploymentDirectoryFlag, afero.NewOsFs())
err = Deploy(ctx, "deployments", DeploymentDirectoryFlag, BootstrapDirectoryFlag, afero.NewOsFs())
checkError(err)

logrus.Info("Directory Deployments Injected")
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
func SetupEnvironment(ctx context.Context) (func(ctx context.Context) error, error) {
// go cmd.CreateCmd.ExecuteContext(ctx)

cmd.K3AutoCmd.SetArgs([]string{"create", "-d", "./e2e_deployments", "-s", "./e2e_secrets.yaml"})
cmd.K3AutoCmd.SetArgs([]string{"create", "-d", "./e2e_deployments", "-b", "./e2e_deployments/bootstrap/", "-s", "./e2e_secrets.yaml"})
go cmd.K3AutoCmd.ExecuteContext(ctx)

cleanupFn := func(ctx context.Context) error {
Expand Down
4 changes: 2 additions & 2 deletions internal/flux/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewOCIRepoObject(name string, namespace string, repository string, image st
}
}

func NewOCIKustomizationObject(name string, namespace string) kustomizev1.Kustomization {
func NewOCIKustomizationObject(name string, namespace string, path string) kustomizev1.Kustomization {
return kustomizev1.Kustomization{
ObjectMeta: v1.ObjectMeta{
Name: name,
Expand All @@ -65,7 +65,7 @@ func NewOCIKustomizationObject(name string, namespace string) kustomizev1.Kustom
Interval: v1.Duration{
Duration: time.Minute * 10,
},
Path: "/",
Path: path,
Prune: true,
SourceRef: kustomizev1.CrossNamespaceSourceReference{
Kind: "OCIRepository",
Expand Down

0 comments on commit 0ed7b0e

Please sign in to comment.