diff --git a/.goreleaser.yml b/.goreleaser.yml index 2daed7a..71848fd 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -3,7 +3,6 @@ project_name: kubebuilder-initializer-plugin before: hooks: - go mod download - - builds: - <<: &build_defaults diff --git a/Makefile b/Makefile index b00494d..d8e2f04 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ GO_CMD ?= go PROJECT_NAME := kubebuilder-initializer-plugin UNAME := $(shell uname) -all: init fmt test lint compile +all: init fmt test lint build help: ## Display this help screen @echo "Makefile targets:" @@ -23,5 +23,4 @@ include build/code.mk include build/test.mk include build/compile.mk include build/release.mk -include build/docker.mk include build/install.mk diff --git a/README.md b/README.md index 1e25951..1188c77 100644 --- a/README.md +++ b/README.md @@ -8,19 +8,48 @@ # Kubebuilder Initializer Plugin -A powerful Kubebuilder plugin to initialize dynamically the structure of your kubebuilder operator repositories. +A powerful Kubebuilder plugin to initialize dynamically the structure of your kubebuilder operator project. -### Prerequisites +## Prerequisites -This is a plugin for the kubebuilder tool. In case of you haven't installed the tool yet, please visit the -[kubebuilder documentation](https://github.com/kubernetes-sigs/kubebuilder) and follow the instructions to get -kuberbuilder properly installed in your computer. +This is a plugin for the kubebuilder cli tool If you don't have the Kubebuilder cli installed in your computer, please +visit the official documentation, [kubebuilder documentation](https://github.com/kubernetes-sigs/kubebuilder). -### Installation +## Installation -#### Homebrew +We provide you a variety of alternatives to install the plugin in your computer, take the onw that best fits your needs. + +### Download the executable + +1. Visit the latest release at [Release page](https://github.com/astrokube/kubebuilder-initializer-plugin/releases) +2. Download the version that works for you +3. Extract the tarball +4. Copy the executable file to the path used by Kubebuilder to read the external plugins + - OSX: ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer/v1-alpha + - Linux: $HOME/.config/kubebuilder/plugins/kubebuilder-initializer/v1-alpha + +### From the code + +To compile the code from your own computer, you just need to run the following commands -1. Add the Astrokube repo +```bash +git clone https://github.com/astrokube/kubebuilder-initializer-plugin.git +cd kubebuilder-initializer-plugin +make build install +``` + +To check that the installation was success, verify that the executable was copied to the below path (depending on the +operating system) + +- OSX: ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer/v1-alpha +- Linux: $HOME/.config/kubebuilder/plugins/kubebuilder-initializer/v1-alpha + + +### Homebrew + +Additionally, you could download the executable from our Astrokube Brew repository. + +1. Add the Astrokube Brew repository ```bash brew tap astrokube/tools ``` @@ -30,7 +59,7 @@ brew tap astrokube/tools brew install kubebuilder-initializer-plugin ``` -3. Please, create a symbolic link (this is required as the Kubebuilder cli will look at that folder to load the external plugins) +3. You will need to create a symbolic link to the path used by Kubebuilder to read the external plugins. ```bash mkdir -p ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer-plugin/v1-alpha/ @@ -38,72 +67,85 @@ ln -s /usr/local/Cellar/kubebuilder-initializer-plugin/0.1.0/bin/kubebuilder-ini ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer-plugin/v1-alpha/kubebuilder-initializer-plugin ``` -#### Download the executable files +### Verify the installation -1. Visit the latest release at [Release page](https://github.com/astrokube/kubebuilder-initializer-plugin/releases) -2. Download the version that works for you -3. Extract the files in the tarball that you downloaded in the previous step -4. Copy the executable file to the path used by Kubebuilder to read the external plugins - - OSX: ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer/v1-alpha - - Linux: $HOME/.config/kubebuilder/plugins/kubebuilder-initializer/v1-alpha +Once the plugin is installed in your computer, a new plugin is available for you to be used when running the Kubebuilder +cli tool, you can run `kubebuilder help` to check it. -#### Build from the code +The `kubebuilder-initializer-plugin/v1-alpha` appears in the list of available plugins. -```bash -git clone https://github.com/astrokube/kubebuilder-initializer-plugin.git -cd kubebuilder-initializer-plugin -make build install -``` -To check that installation was success, please check that the executable file was copied to the folder used by Kubebuilder -to read the plugins -- OSX: ~/Library/Application\ Support/kubebuilder/plugins/kubebuilder-initializer/v1-alpha -- Linux: $HOME/.config/kubebuilder/plugins/kubebuilder-initializer/v1-alpha +![Kubebuilder pLugins](docs/assets/plugins.png) -## Getting started +## Define your own template -To deep dive into how Kubebuilder deals with external plugins you can visit the following article -[Extensible CLI and Scaffolding Plugins - Phase 2](https://github.com/kubernetes-sigs/kubebuilder/blob/master/designs/extensible-cli-and-scaffolding-plugins-phase-2.md) +The Kubebuilder Initializer plugin understand a template like a Git repository in which the name of the elements in the repository +(both folders and files) and the content of the files can contain variables. -Once you have installed the plugin you can use the Kubebuilder cli as usual. +The plugin takes advantage of Go templates to process the templates; that provides us with a very flexible way to define templates. +That implies that we could not only to define variables -1. Check that the plugin has been installed correctly +[go.mod](https://github.com/astrokube/kubebuilder-operator-template/blob/main/go.mod#L1) +```text +module {{.repository.server}}/{{.repository.owner}}/{{.repository.name}} +``` -```bash -kubebuilder help +but also add some logic to our own templates + +[OWNERS_ALIASES](https://github.com/astrokube/kubebuilder-operator-template/blob/main/OWNERS_ALIASES#L4-L9) +```text +# See the OWNERS docs: https://git.k8s.io/community/contributors/guide/owners.md + +aliases: +{{- range .owners}} + {{.alias}}: +{{- range .members}} + - [{{.}}](https://github.com/{{.}}) +{{- end}} +{{- end}} ``` -And the `kubebuilder-initializer-plugin/v1-alpha` is displayed as part of the list of available plugins. +You can find some examples of templates in [AWESOME_TEMPLATES.md](AWESOME_TEMPLATES.md), and we encourage you to contribute +with your own templates, so please, feel free to open a pull request with an entry in this file if you want to share a +template with others. -![Kubebuilder pLugins](docs/assets/plugins.png) +**TODO** +We ask you to share an example files with the variables that need to be passed in order to customize the templates, +See an example [here](). Only yaml files are supported (JSON could be supported for futures release If this was required +by the community ) + +*For upcoming releases, the plugin will inspect the files in the templates and It will be able to generate the yaml file for you* + +## Getting started + +This plugin is used exclusively in the initial scaffolding (`kubebuilder init`) and It's compatible with any other plugin. +When we run the `init` command, the Kubebuilder cli creates the PROJECT file, this is the main piece for Kubebuilder +to create consistency and being able to inject code when we run other commands such as `kubebuildfer create api` or +`kubebuilder create webhook` +On the other hand, the `Kubebuilder Initializer plugin` must be used in conjunction with other plugins that will +take the control once we need to create a Webhook or an API. -2. Choose the template for scaffolding the initial structure of our Kubebuilder operator. You can -create your own template as described (here]() or alternatively you could take advantage of some of the well-known templates -that you can find in [AWESOME_TEMPLATES.md](AWESOME_TEMPLATES.md) +To take advantage of the Initializer plugin, we just need a repository, that will be used as a template, and the +variables file that will allow us to customize the template. By the default, the plugin read the variables from a +named file `.kubebuilder-initializer.yaml`, but this can be customized If required. -3. Once we have chosen the template that we want to use, we just need to write the yaml file that contains the values that -will make us to customize the template. By default, the plugin will take a file named `.kubebuilder-layout.yaml`, otherwise -you will need to pass an extra argument with the path to the file. +To sum up, to initialize our project we just need to pass the argument `--from` and we could additionally pass the argument +`--vars` in case of we don't want to use the default `.kubebuilder-initializer.yaml`. -4. Initialize your project. Keep in mind that this plugin is used exclusively to initialize our project structure, so we should -use also a plugin that supports the APIs and webhooks creation,for instance the `go.kubebuilder.io/v3` that is prpvided out ->>>>>>> main -of the box by Kubbebuilder. +In the below example, we would use our plugin in conjunction with the `go.kubebuilder.io/v3` that help us to work with +implementation of operators in Go. ```bash -kubebuilder init --plugins go.kubebuilder.io/v3,kubebuilder-layout/v1-alpha \ - --from "github.com/astrokube/kubebuilder-operator-template" \ - --domain astrokube \ - --owner astrokube \ - --repo github.com/astrokube/k8s-testing-operator +kubebuilder init --plugins go.kubebuilder.io/v3,kubebuilder-initializer-plugin/v1-alpha \ + --domain astrokube --owner astrokube --repo github.com/astrokube/k8s-testing-operator \ + --from "https://github.com/astrokube/kubebuilder-operator-template" ``` -The only argument that needs to be passed is the `from` - -*In the above example, the args `domain`, `repo` and `owner` are required by the plugin `go.kubebuilder.io/v3`.* +Be aware that, in the above example, the arguments `domain`, `repo` and `owner` are required by the plugin +`go.kubebuilder.io/v3`. **Non default branches** -By default, the plugin will fetch the code in the default branch, buy we can specify a branch: +By default, the plugin will fetch the code in the default branch, but we can specify another branch: ```bash --from "github.com/astrokube/kubebuilder-operator-template#" @@ -121,6 +163,11 @@ the below ``` +## Kubebuilder + +To deep dive into how Kubebuilder deals with external plugins you can visit the following article +[Extensible CLI and Scaffolding Plugins - Phase 2](https://github.com/kubernetes-sigs/kubebuilder/blob/master/designs/extensible-cli-and-scaffolding-plugins-phase-2.md) + ## Contributing diff --git a/build/compile.mk b/build/compile.mk index 756de0b..c4fb3c5 100644 --- a/build/compile.mk +++ b/build/compile.mk @@ -5,11 +5,7 @@ BUILD_DATE = $(shell date -u +%Y-%m-%dT%H:%M:%SZ) VERSION ?= $(shell git describe --tags --always --dirty | sed -e '/^v/s/^v\(.*\)$$/\1/g') VERSION_TAG := $(shell git describe --tags --always --abbrev=0 | sed -e '/^v/s/^v\(.*\)$$/\1/g') -LDFLAGS = -s -w \ - -X github.com/astrokube/kubebuilder-initializer-plugin/internal/info.Commit=$(COMMIT) \ - -X github.com/astrokube/kubebuilder-initializer-plugin/internal/info.Version=$(VERSION) \ - -X github.com/astrokube/kubebuilder-initializer-plugin/internal/info.BuildDate=$(BUILD_DATE) \ - -X github.com/astrokube/kubebuilder-initializer-plugin/internal/info.Compiler=$(GOLANG_VERSION) +LDFLAGS = -s -w .PHONY: build build: ## build executable for the current os diff --git a/build/docker.mk b/build/docker.mk deleted file mode 100644 index db11aa4..0000000 --- a/build/docker.mk +++ /dev/null @@ -1,4 +0,0 @@ -.PHONY: docker-% -docker-%: ## Run commands inside a docker container - docker run --rm --workdir /app -v $(CURDIR):/app golang:$(GO_VERSION) \ - make $* \ No newline at end of file diff --git a/internal/command/command.go b/internal/command/command.go index 0e42e1d..aa3dd21 100644 --- a/internal/command/command.go +++ b/internal/command/command.go @@ -2,20 +2,17 @@ package command import ( "fmt" + "strings" "github.com/spf13/pflag" "sigs.k8s.io/kubebuilder/v3/pkg/plugin/external" ) const ( - flagVars = "vars" - - flagDomain = "domain" - flagRepo = "repo" - flagProjectName = "project-name" - flagFrom = "from" - flagSource = "source" - flagInit = "init" + flagVars = "vars" + flagFrom = "from" + flagSource = "source" + flagInit = "init" ) const ( @@ -33,16 +30,26 @@ func Run(request *external.PluginRequest) external.PluginResponse { } var err error + var flagSet *pflag.FlagSet switch request.Command { case ActionInit: - flagSet := processFlags(request, initFlags) + flagSet, err = processFlags(request, initFlags) + if err != nil { + break + } response.Universe, err = runInit(flagSet) case ActionFlags: - flagSet := processFlags(request, flagsFlags) + flagSet, err = processFlags(request, flagsFlags) + if err != nil { + break + } response.Flags, err = runFlags(flagSet) case ActionMetadata: - flagSet := processFlags(request, metadataFlags) + flagSet, err = processFlags(request, metadataFlags) + if err != nil { + break + } response.Metadata, err = runMetadata(flagSet) case ActionCreateAPI: break @@ -53,7 +60,6 @@ func Run(request *external.PluginRequest) external.PluginResponse { default: err = fmt.Errorf("unknown command '%s'", request.Command) } - if err != nil { response.Error = true response.ErrorMsgs = []string{err.Error()} @@ -61,7 +67,7 @@ func Run(request *external.PluginRequest) external.PluginResponse { return response } -func processFlags(request *external.PluginRequest, flags []external.Flag) *pflag.FlagSet { +func processFlags(request *external.PluginRequest, flags []external.Flag) (*pflag.FlagSet, error) { flagsSet := pflag.NewFlagSet(fmt.Sprintf("%sFlags", request.Command), pflag.ContinueOnError) for _, f := range flags { switch f.Type { @@ -69,13 +75,32 @@ func processFlags(request *external.PluginRequest, flags []external.Flag) *pflag flagsSet.String(f.Name, f.Default, f.Usage) case "boolean": flagsSet.Bool(f.Name, f.Default == "true", f.Usage) - case "array": - flagsSet.StringArray(f.Name, []string{}, f.Usage) default: flagsSet.String(f.Name, f.Default, f.Usage) } } - _ = flagsSet.Parse(request.Args) + args := filterProvidedArgs(request.Args, flags) + if err := flagsSet.Parse(args); err != nil { + return nil, err + } + return flagsSet, nil +} - return flagsSet +func filterProvidedArgs(args []string, supportedFlags []external.Flag) (out []string) { + supportedFlagsMap := make(map[string]struct{}, len(supportedFlags)) + for i := range supportedFlags { + key := fmt.Sprintf("--%s", supportedFlags[i].Name) + supportedFlagsMap[key] = struct{}{} + } + expectArgValue := false + for i := range args { + arg := args[i] + if expectArgValue { + out = append(out, arg) + } else if _, ok := supportedFlagsMap[args[i]]; ok { + out = append(out, arg) + } + expectArgValue = strings.HasPrefix(arg, "--") + } + return } diff --git a/internal/command/init.go b/internal/command/init.go index 0fa4111..d29d1a7 100644 --- a/internal/command/init.go +++ b/internal/command/init.go @@ -12,7 +12,13 @@ import ( var initFlags = []external.Flag{ { - Name: "vars", + Name: flagSource, + Type: "string", + Default: "git", + Usage: "Type of source. The only supported value is 'git'", + }, + { + Name: flagVars, Type: "string", Default: ".kubebuilder-initializer.yaml", Usage: "path to the file that contains the variables to be used. By default the plugin uses the file in path ." + @@ -22,30 +28,46 @@ var initFlags = []external.Flag{ Name: flagFrom, Type: "string", Default: "", - Usage: "repository path (e.g., github.com/my-organization/my-repo). We can pass a specific branch " + - "after the repository path (e.g., github.com/my-organization/my-repo#develop) or the credentials If " + - "required (e.g., username:password@github.com/my-organization/my-repo#develop)", + Usage: "repository path (e.g., github.com/my-organization/my-repo).", }, /** { - Name: flagDomain, + Name: "component-config", + Type: "boolean", + Default: "false", + Usage: "create a versioned ComponentConfig file, may be 'true' or 'false'", + }, + { + Name: "domain", Type: "string", - Default: "", - Usage: "store the domain of the project. ", + Default: "my.domain", + Usage: "domain for groups (default \"my.domain\")", + }, + { + Name: "fetch-deps", + Type: "boolean", + Default: "true", + Usage: "ensure dependencies are downloaded (default true)", }, { - Name: flagRepo, + Name: "license", Type: "string", Default: "", - Usage: "name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current " + - "working directory.", + Usage: "license to use to boilerplate, may be one of 'apache2', 'none' (default \"apache2\")", }, { - Name: flagProjectName, + Name: "owner", Type: "string", Default: "", - Usage: "the name of the project. This will be used to scaffold the manager data", + Usage: "owner to add to the copyright", }, + **/ + + /** + --project-name string name of this project + --project-version string project version (default "3") + --repo string name to use for go module (e.g., github.com/user/repo), defaults to the go package of the current working directory. + --skip-go-version-check if specified, skip checking the Go versio */ } @@ -54,23 +76,30 @@ var initMetadata = plugin.SubcommandMetadata{ "It scaffolds a repository with a previously created layout", Examples: ` Scaffold with the defaults: - $ kubebuilder init --plugins astrokube-layout/v1 + $ kubebuilder init --plugins kubebuilder-initializer-plugin/v1-alpha \ + --from https://github.com/astronetes/operator-template - Scaffold with a specific layout: - $ kubebuilder init --plugins astrokube-layout/v1 --layout github.com/astronetes/operator-template - --vars custom-vars.yml + Scaffold overwriting the default file for the variables: + $ kubebuilder init --plugins kubebuilder-initializer-plugin/v1-alpha \ + --from https://github.com/astronetes/operator-template \ + --vars path-to-my-custom-variables.yml + `, } func runInit(flags *pflag.FlagSet) (map[string]string, error) { - source, _ := flags.GetString(flagSource) - from, _ := flags.GetString(flagFrom) - vars, _ := flags.GetString(flagVars) - /** - domain, _ := flags.GetString(flagDomain) - projectName, _ := flags.GetString(flagProjectName) - repo, _ := flags.GetString(flagRepo) - **/ + source, err := flags.GetString(flagSource) + if err != nil { + return nil, err + } + from, err := flags.GetString(flagFrom) + if err != nil { + return nil, err + } + vars, err := flags.GetString(flagVars) + if err != nil { + return nil, err + } content, err := templatizer.Templatize(source, from, vars) if err != nil { return content, err diff --git a/internal/info/plugin.go b/internal/info/plugin.go deleted file mode 100644 index 79aeef9..0000000 --- a/internal/info/plugin.go +++ /dev/null @@ -1,12 +0,0 @@ -package info - -var ( - Commit string - Version string - BuildDate string - GolangVersion string -) - -func Author() string { - return "The Astrokube Team " -} diff --git a/internal/info/plugin_test.go b/internal/info/plugin_test.go deleted file mode 100644 index eca8837..0000000 --- a/internal/info/plugin_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package info - -import "testing" - -func TestAuthor(t *testing.T) { - tests := []struct { - name string - want string - }{ - { - name: "simple test", - want: "The Astrokube Team ", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if got := Author(); got != tt.want { - t.Errorf("Author() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/pkg/templatizer/internal/source/git.go b/pkg/templatizer/internal/source/git.go index c7f336e..971c061 100644 --- a/pkg/templatizer/internal/source/git.go +++ b/pkg/templatizer/internal/source/git.go @@ -1,3 +1,6 @@ +/* +Package source provides us with the implementations that can be used to fetch the source code in the templates. +*/ package source import ( @@ -14,8 +17,10 @@ import ( "github.com/go-git/go-git/v5/storage/memory" ) -var repoRegex = regexp.MustCompile(`((?P(.*))(@))?(?P([a-zA-Z0-9./\-_]+))(#(?P(.*)))?`) +//nolint:lll +var repoRegex = regexp.MustCompile(`(?P(https|ssh))://((?P(.*))(@))?(?P([a-zA-Z0-9./\-_]+))(#(?P(.*)))?`) +// A GitSource struct is used to fetch the template from a Git repository. type GitSource struct { url string branch string @@ -24,6 +29,21 @@ type GitSource struct { refOrigin string } +// NewGitSource returns a pointer of a new instance of GitSource. +// +// The function receives a parameter, named conn, that contains the details of the Git connection. The function +// uses the below regular expression to extract the details in the parameter. +// +// (?P(https|ssh))://((?P(.*))(@))?(?P([a-zA-Z0-9./\-_]+))(#(?P(.*)))? +// +// The connection url is composed by the following parts +// protocol: It's required a must be https or ssh depending on the chosen mechanism to establish the connection with the +// remote repository. +// auth: It's an optional param (not required for public repositories) and we can provide both user credentials or +// a token. If we pass the credentials the format must be username:password +// path: The repository url. For instance, github.com/astrokube/kubebuilder-initializer-plugin if we use the https +// protocol, or github.com/astrokube/kubebuilder-initializer-plugin.git if we use the ssh protocol +// branch: Optional param, we can use a specific branch by passing the name of the desired branch after symbol `#` func NewGitSource(conn string) *GitSource { match := repoRegex.FindStringSubmatch(conn) @@ -49,10 +69,13 @@ func NewGitSource(conn string) *GitSource { } s.refOrigin = "origin" s.branch = paramsMap["branch"] - s.url = fmt.Sprintf("https://%s", paramsMap["path"]) + s.url = fmt.Sprintf("%s://%s", paramsMap["protocol"], paramsMap["path"]) + return s } +// GetTemplateContent returns a map with an entry per each file in the repository. The key of this map +// is the absolute path to the file from the root of the repository and the value is the content of the file. func (s *GitSource) GetTemplateContent() (map[string]string, error) { if err := s.loadFileSystem(); err != nil { return nil, err @@ -64,14 +87,12 @@ func (s *GitSource) GetTemplateContent() (map[string]string, error) { func (s *GitSource) loadFileSystem() error { repo, err := git.Clone(memory.NewStorage(), memfs.New(), &git.CloneOptions{ - URL: s.url, - Auth: s.auth, - //Progress: os.Stdout, - // InsecureSkipTLS: true, + URL: s.url, + Auth: s.auth, SingleBranch: true, }) if err != nil { - return fmt.Errorf("error cloning the repository '%w'", err) + return fmt.Errorf("error cloning the repository from %s '%w'", s.url, err) } w, err := repo.Worktree() if err != nil { diff --git a/pkg/templatizer/internal/source/git_test.go b/pkg/templatizer/internal/source/git_test.go new file mode 100644 index 0000000..2cc0d33 --- /dev/null +++ b/pkg/templatizer/internal/source/git_test.go @@ -0,0 +1,33 @@ +package source + +import ( + "reflect" + "testing" +) + +func TestNewGitSource(t *testing.T) { + type args struct { + conn string + } + tests := []struct { + name string + args args + want *GitSource + }{ + { + name: "Basic test", + args: args{conn: "https://github.com/astrokube/kubebuilder-operator-template"}, + want: &GitSource{ + url: "https://github.com/astrokube/kubebuilder-operator-template", + refOrigin: "origin", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := NewGitSource(tt.args.conn); !reflect.DeepEqual(got, tt.want) { + t.Errorf("NewGitSource() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/pkg/templatizer/internal/variables/replacer.go b/pkg/templatizer/internal/variables/replacer.go index 83b5c9f..e544652 100644 --- a/pkg/templatizer/internal/variables/replacer.go +++ b/pkg/templatizer/internal/variables/replacer.go @@ -1,3 +1,4 @@ +// Package variables is used to deal with variables and the replacement of values in Go templates package variables import ( @@ -6,6 +7,8 @@ import ( "text/template" ) +// ReplaceVariables is a function that create a Go text template from the given content and replace the provided +// variables in the map. func ReplaceVariables(name string, content string, variables map[string]interface{}) (string, error) { t, err := template.New(name).Parse(content) if err != nil { diff --git a/pkg/templatizer/templatizer.go b/pkg/templatizer/templatizer.go index 16b1b73..c558fab 100644 --- a/pkg/templatizer/templatizer.go +++ b/pkg/templatizer/templatizer.go @@ -1,3 +1,5 @@ +// Package templatizer is an isolated package that could be used from other repositories as a library. That's the main +// reason this package is under `pkg`. package templatizer import ( @@ -10,6 +12,12 @@ import ( "gopkg.in/yaml.v3" ) +// Templatize fetch the content in a remote source and replace the variables with the provided values in a file. +// This function receives the below three parameters: +// - sourceType: So far only `git` is supported +// - connString: url used to establish the connection with the remote source +// - varsFile: Path to the file that contains the variables that will be used to replace values + func Templatize(sourceType string, connString string, varsFile string) (map[string]string, error) { var content map[string]string var err error