diff --git a/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go b/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go index 053fff3..62a7db1 100644 --- a/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go +++ b/cmd/frigg/bootstrap/capd-controller/cluster/cluster.go @@ -35,13 +35,14 @@ import ( ) type flagpole struct { - Name string - Config string - ImageName string - Retain bool - Wait time.Duration - Kubeconfig string - GitopsTemplateRepo string + Name string + Config string + ImageName string + Retain bool + Wait time.Duration + Kubeconfig string + GitopsTemplateRepo string + GitopsWorkloadTemplate string } // NewCommand returns a new cobra.Command for cluster creation @@ -107,6 +108,12 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command { "", "add your custom gitops repo template url, like / or /", ) + c.Flags().StringVar( + &flags.GitopsWorkloadTemplate, + "gitops-workload-template-repo", + "", + "add your custom gitops repo template url, like / or /", + ) return c } @@ -138,6 +145,11 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { flags.GitopsTemplateRepo = vars.FriggMgmtTemplateName } + if flags.GitopsWorkloadTemplate == "" { + println(color.YellowString("No Gitops Template Repo specified, using default: %s ", vars.FriggWorkloadTemplateName)) + flags.GitopsWorkloadTemplate = vars.FriggWorkloadTemplateName + } + // Creating Working, tools and controllers directories directories.Create() @@ -202,7 +214,7 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { } // Rendering gitops repo - reporender.FullStage(flags.GitopsTemplateRepo) + reporender.FullStage(flags.GitopsTemplateRepo, flags.GitopsWorkloadTemplate) // Creating Namespaces println(color.GreenString("Creating Namespaces..")) diff --git a/cmd/frigg/bootstrap/capd/cluster/cluster.go b/cmd/frigg/bootstrap/capd/cluster/cluster.go index 56b342f..448bef7 100644 --- a/cmd/frigg/bootstrap/capd/cluster/cluster.go +++ b/cmd/frigg/bootstrap/capd/cluster/cluster.go @@ -32,13 +32,14 @@ import ( ) type flagpole struct { - Name string - Config string - ImageName string - Retain bool - Wait time.Duration - Kubeconfig string - GitopsTemplateRepo string + Name string + Config string + ImageName string + Retain bool + Wait time.Duration + Kubeconfig string + GitopsTemplateRepo string + GitopsWorkloadTemplate string } // NewCommand returns a new cobra.Command for cluster creation @@ -104,6 +105,12 @@ func NewCommand(logger log.Logger, streams cmd.IOStreams) *cobra.Command { "", "add your custom gitops repo template url, like / or /", ) + c.Flags().StringVar( + &flags.GitopsWorkloadTemplate, + "gitops-workload-template-repo", + "", + "add your custom gitops repo template url, like / or /", + ) return c } @@ -135,6 +142,11 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { flags.GitopsTemplateRepo = vars.FriggMgmtTemplateName } + if flags.GitopsWorkloadTemplate == "" { + println(color.YellowString("No Gitops Template Repo specified, using default: %s ", vars.FriggWorkloadTemplateName)) + flags.GitopsWorkloadTemplate = vars.FriggWorkloadTemplateName + } + // Creating Working, tools and controllers directories directories.Create() @@ -190,7 +202,7 @@ func runE(logger log.Logger, streams cmd.IOStreams, flags *flagpole) error { } // Rendering gitops repo - reporender.FullStage(flags.GitopsTemplateRepo) + reporender.FullStage(flags.GitopsTemplateRepo, flags.GitopsWorkloadTemplate) // Installs capi components on the bootstrap cluster. println(color.GreenString("Applying ClusterAPI and Cert-Manager Components and waiting for the 'Ready' condition..")) diff --git a/docs/README.md b/docs/README.md deleted file mode 100644 index f5413d4..0000000 --- a/docs/README.md +++ /dev/null @@ -1,48 +0,0 @@ -# Frigg documentation - -## Content - -- ./frigg -- ./providers - - ./capd - - ./capv - - ./capz - - ./harvester - -## How to get started - -You will need to have the following tools installed: - -(Currently, we are working on an implementation, -to download the needed binaries - so that you do not need to care about.) - -- [kind](https://formulae.brew.sh/formula/kind#default) -- [Docker](https://www.docker.com/products/docker-desktop/) -- [clusterctl](https://formulae.brew.sh/formula/clusterctl#default) -- [kubectl](https://formulae.brew.sh/formula/kubernetes-cli#default) -- [github cli](https://formulae.brew.sh/formula/gh#default) -- [jq](https://formulae.brew.sh/formula/jq#default) - -## Choose on of the providers you'd like to use - -We currently support the following ClusterAPI Providers: - -- CAPD (ClusterAPI Provider Docker) for local development -- CAPV (ClusterAPI Provider vSphere) -- CAPZ (ClusterAPI Provider Azure) -- CAPHV (ClusterAPI Provider Harvester) -- CAPVC (ClusterAPI Provider vCluster) -- CABPT (ClusterAPI Bootstrap Provider Talos) - -We will provide hands-on documentations, on each provider, so that -you can easily get started on using those. - -For now: You might want to get started with CAPD, in order to get a feeling how `frigg` -works. - -## Hardware recommendations - -Depending on your Provider, the hardware recommendations may vary. - -Please take a look inside the documentation on each provider. -We provide a minimum and a recommended hardware spec, for each of those. \ No newline at end of file diff --git a/docs/docsgenerator.go b/docs/docsgenerator.go deleted file mode 100644 index b953be6..0000000 --- a/docs/docsgenerator.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "github.com/PatrickLaabs/frigg/docs/providers/capd" - "github.com/PatrickLaabs/frigg/docs/providers/capd_controller" -) - -func CreateDocs() { - capd.MakeReadme("docs/providers/capd/README.md") - capd_controller.MakeReadme("docs/providers/capd_controller/README.md") -} - -func main() { - CreateDocs() -} diff --git a/docs/local_development.md b/docs/local_development.md new file mode 100644 index 0000000..80f2c39 --- /dev/null +++ b/docs/local_development.md @@ -0,0 +1,65 @@ +# Running Frigg for your local development + +## Get started + +You will need to set these Environment variables: + +```shell +export GITHUB_TOKEN= +export GITHUB_USERNAME= +export GITHUB_MAIL= +``` + +### Create your management cluster + +```shell +frigg bootstrap capd-controller cluster +``` + +### Create your workload cluster + +This will create a workload cluster ontop of your management cluster. + +```shell +frigg bootstrap capd-controller workloadcluster +``` + +--- + +## GitOps Repositories + +By default, you will use the standard template repositories for your management \ +and workload clusters. + +### Friggs Management-Cluster GitOps Template Repository +This Repository will the beating-heart for your management-cluster.\ +[friggs-mgmt-repo-template](https://github.com/PatrickLaabs/friggs-mgmt-repo-template) + +### Friggs Workload-Clusters GitOps Template Repository +This Repository is used to provide a good foundation for your workload clusters with various deployments.\ +[friggs-workload-repo-template](https://github.com/PatrickLaabs/friggs-workload-repo-template) + +### Use your custom GitOps Repo Template + +Frigg provides the ability to let you define your custom GitOps Repository Template URL +while bootstrapping your environment. + +You can either set your GitOps repo for your management cluster: +```shell +frigg bootstrap capd-controller cluster --gitops-template-repo +``` + +or for your Workload Clusters: +```shell +frigg bootstrap capd-controller cluster --gitops-workload-template-repo +``` + +If you want to set both, you are free to do so: +```shell +frigg bootstrap capd-controller cluster --gitops-template-repo --gitops-workload-template-repo +``` + +### Creating your custom GitOps Repositories + +This is currently under development.\ +PR: #128 \ No newline at end of file diff --git a/docs/providers/capd/capd_docs.go b/docs/providers/capd/capd_docs.go deleted file mode 100644 index a75d4ba..0000000 --- a/docs/providers/capd/capd_docs.go +++ /dev/null @@ -1,52 +0,0 @@ -package capd - -import ( - "fmt" - "io" - "os" - "time" -) - -func MakeReadme(filename string) { - date := time.Now().Format("2 Jan 2006") - - newLine := "\n" - doubleNewLine := "\n\n" - - header := "# CAPD (ClusterAPI Provider for Docker) Documentation" - body := "## Get started" + doubleNewLine + - "You will need to pass two Environment variables:" + newLine + - "- GITHUB_TOKEN" + newLine + - "- GITHUB_USERNAME" + newLine + - "- GITHUB_MAIL" + doubleNewLine + - "```" + newLine + - "export GITHUB_TOKEN=" + newLine + - "export GITHUB_USERNAME=" + newLine + - "export GITHUB_MAIL=" + newLine + - "```" + - doubleNewLine + - "## TL;DR:" + doubleNewLine + - "Create a Management Cluster:" + doubleNewLine + - "`frigg bootstrap capd cluster`" + doubleNewLine + - "Create a Workload Cluster:" + doubleNewLine + - "`frigg bootstrap capd workloadcluster`" + - doubleNewLine - footer := "Updated on: " + date - data := fmt.Sprintf("%s\n\n%s\n\n%s", header, body, footer) - - file, err := os.Create(filename) - if err != nil { - fmt.Printf("Error on creating file: %v\n", err) - } - defer func(file *os.File) { - err := file.Close() - if err != nil { - fmt.Printf("Error on closing file: %v\n", err) - } - }(file) - - _, err = io.WriteString(file, data) - if err != nil { - fmt.Printf("Error writing README file: %v\n", err) - } -} diff --git a/docs/providers/capd_controller/capd_controller_docs.go b/docs/providers/capd_controller/capd_controller_docs.go deleted file mode 100644 index 84f9291..0000000 --- a/docs/providers/capd_controller/capd_controller_docs.go +++ /dev/null @@ -1,51 +0,0 @@ -package capd_controller - -import ( - "fmt" - "io" - "os" - "time" -) - -func MakeReadme(filename string) { - date := time.Now().Format("2 Jan 2006") - - newLine := "\n" - doubleNewLine := "\n\n" - - header := "# CAPD (ClusterAPI Provider for Docker) Documentation" - body := "## Get started" + doubleNewLine + - "You will need to pass two Environment variables:" + newLine + - "- GITHUB_TOKEN" + newLine + - "- GITHUB_USERNAME" + newLine + - "- GITHUB_MAIL" + doubleNewLine + - "```" + newLine + - "export GITHUB_TOKEN=" + newLine + - "export GITHUB_USERNAME=" + newLine + - "export GITHUB_MAIL=" + newLine + - "```" + doubleNewLine + - "## TL;DR:" + doubleNewLine + - "Create a Management Cluster:" + doubleNewLine + - "`frigg bootstrap capd-controller cluster`" + doubleNewLine + - "Create a Workload Cluster:" + doubleNewLine + - "`frigg bootstrap capd-controller workloadcluster`" + - doubleNewLine - footer := "Updated on: " + date - data := fmt.Sprintf("%s\n\n%s\n\n%s", header, body, footer) - - file, err := os.Create(filename) - if err != nil { - fmt.Printf("Error on creating file: %v\n", err) - } - defer func(file *os.File) { - err := file.Close() - if err != nil { - fmt.Printf("Error on closing file: %v\n", err) - } - }(file) - - _, err = io.WriteString(file, data) - if err != nil { - fmt.Printf("Error writing README file: %v\n", err) - } -} diff --git a/docs/providers/capv/capv_docs.go b/docs/providers/capv/capv_docs.go deleted file mode 100644 index 1f4248c..0000000 --- a/docs/providers/capv/capv_docs.go +++ /dev/null @@ -1,9 +0,0 @@ -package capv - -import "fmt" - -// Docs generator for the capv provider usage - -func Docsgenerator() { - fmt.Println("Creating docs for capv..") -} diff --git a/docs/providers/capz/README.md b/docs/providers/capz/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/docs/providers/capz/capz_docs.go b/docs/providers/capz/capz_docs.go deleted file mode 100644 index 331914b..0000000 --- a/docs/providers/capz/capz_docs.go +++ /dev/null @@ -1,9 +0,0 @@ -package capz - -import "fmt" - -// Docs generator for the capz provider usage - -func Docsgenerator() { - fmt.Println("Creating docs for capz..") -} diff --git a/docs/providers/harvester/README.md b/docs/providers/harvester/README.md deleted file mode 100644 index e69de29..0000000 diff --git a/docs/providers/harvester/harvester_docs.go b/docs/providers/harvester/harvester_docs.go deleted file mode 100644 index cc06ab2..0000000 --- a/docs/providers/harvester/harvester_docs.go +++ /dev/null @@ -1,9 +0,0 @@ -package harvester - -import "fmt" - -// Docs generator for the capz provider usage - -func Docsgenerator() { - fmt.Println("Creating docs for Harvester..") -} diff --git a/internal/reporender/reporender.go b/internal/reporender/reporender.go index d922ec4..cc6a156 100644 --- a/internal/reporender/reporender.go +++ b/internal/reporender/reporender.go @@ -27,7 +27,7 @@ var ( ) // FullStage combines everything, that is needed, to fully prepare the gitops repo for the end-user -func FullStage(GitopsTemplate string) { +func FullStage(GitopsTemplate string, gitopsWorkloadTemplate string) { println(color.GreenString("Rendering the gitops template repo")) username, err := retrieveGithubUserEnv() @@ -44,7 +44,7 @@ func FullStage(GitopsTemplate string) { gitCreateFromTemplate(GitopsTemplate) wait.Wait(5 * time.Second) gitClone() - err = replaceStrings(localRepoStoragePath, username, usermail) + err = replaceStrings(localRepoStoragePath, username, usermail, gitopsWorkloadTemplate) if err != nil { return } @@ -102,7 +102,6 @@ func gitCreateFromTemplate(GitopsTemplate string) { cmd := exec.Command(ghCliPath, "repo", "create", targetRepoName, "--private", - //"--template="+vars.FriggMgmtTemplateName, "--template="+GitopsTemplate, ) @@ -158,7 +157,7 @@ func gitClone() { } // replaceStrings replaces the Placeholder strings inside all files in the gitops repo -func replaceStrings(dirPath string, username string, usermail string) error { +func replaceStrings(dirPath string, username string, usermail string, gitopsWorkloadTemplate string) error { err := filepath.Walk(dirPath, func(path string, info os.FileInfo, err error) error { if err != nil { println(color.RedString("Error on filepath walking: %v\n", err)) @@ -175,6 +174,7 @@ func replaceStrings(dirPath string, username string, usermail string) error { reGhUser := regexp.MustCompile(`GITHUB_USERNAME`) reGhUrl := regexp.MustCompile(`PLACEHOLDER`) reGhMail := regexp.MustCompile(`GITHUB_MAIL`) + reGitopsTemplate := regexp.MustCompile(`GITOPS_TEMPLATE_REPO`) url := "git@github.com:" + username + "/" + vars.RepoName + ".git" @@ -182,6 +182,7 @@ func replaceStrings(dirPath string, username string, usermail string) error { newdata := replaceInString(data, reGhUrl, url) newdata = replaceInString(newdata, reGhUser, username) newdata = replaceInString(newdata, reGhMail, usermail) + newdata = replaceInString(newdata, reGitopsTemplate, gitopsWorkloadTemplate) // Open the file for writing and replace content file, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0644) // Adjust permissions as needed diff --git a/internal/vars/vars.go b/internal/vars/vars.go index 6c2188f..8f94135 100644 --- a/internal/vars/vars.go +++ b/internal/vars/vars.go @@ -7,6 +7,7 @@ var FriggTools = "tools" var ControllerDir = "capi_controller" var FriggMgmtGitOpsName = "friggs-mgmt-repo" var FriggMgmtTemplateName = "PatrickLaabs/friggs-mgmt-repo-template" +var FriggWorkloadTemplateName = "PatrickLaabs/friggs-workload-repo-template" var PrivatekeyName = "frigg-sshkeypair_gen" var PublickeyName = "frigg-sshkeypair_gen.pub" var PublickeyNameOnGh = "frigg-generated-publickey"