Skip to content
This repository was archived by the owner on Nov 1, 2022. It is now read-only.

Add fluxctl install command #2287

Merged
merged 19 commits into from
Jul 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update arguments and implement command
The templates haven't been implemented yet
  • Loading branch information
2opremio committed Jul 26, 2019
commit cc6e2deafb00a73480c527992c885652e6cdf77c
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ $(GOBIN)/helm-operator: $(HELM_OPERATOR_DEPS)
integration-test: all
test/bin/test-flux

cmd/fluxctl/install/generated_templates.gogen.go: cmd/fluxctl/install/templates/*
cmd/fluxctl/install/generated_templates.gogen.go: cmd/fluxctl/install/templates/* cmd/fluxctl/install/generate.go
cd cmd/fluxctl/install && go run generate.go

check-generated: cmd/fluxctl/install/generated_templates.gogen.go
Expand Down
2 changes: 1 addition & 1 deletion cmd/fluxctl/install/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func main() {
err := vfsgen.Generate(fs, vfsgen.Options{
Filename: "generated_templates.gogen.go",
PackageName: "install",
VariableName: "Templates",
VariableName: "templates",
})
if err != nil {
log.Fatalln(err)
Expand Down
4 changes: 2 additions & 2 deletions cmd/fluxctl/install/generated_templates.gogen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions cmd/fluxctl/install/install.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package install

import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"text/template"

"github.com/shurcooL/httpfs/vfsutil"
)

type TemplateParameters struct {
GitURL string
GitBranch string
GitPaths []string
GitLabel string
GitUser string
GitEmail string
Namespace string
AdditionalFluxArgs []string
}

func FillInInstallTemplates(opts TemplateParameters) (io.Reader, error) {
result := bytes.NewBuffer(nil)
err := vfsutil.WalkFiles(templates, "/", func(path string, info os.FileInfo, rs io.ReadSeeker, err error) error {
if err != nil {
return fmt.Errorf("cannot walk embedded files: %s", err)
}
if info.IsDir() {
return nil
}
templateBytes, err := ioutil.ReadAll(rs)
if err != nil {
return fmt.Errorf("cannot read embedded file %q: %s", info.Name(), err)
}
template, err := template.New(info.Name()).Parse(string(templateBytes))
if err != nil {
return fmt.Errorf("cannot parse embedded file %q: %s", info.Name(), err)
}
if err := template.Execute(result, opts); err != nil {
return fmt.Errorf("cannot execute template for embedded file %q: %s", info.Name(), err)
}
return nil
})
if err != nil {
return nil, fmt.Errorf("internal error filling embedded installation templates: %s", err)
}
return result, nil
}
39 changes: 19 additions & 20 deletions cmd/fluxctl/install_cmd.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package main

import (
"io"
"os"

"github.com/spf13/cobra"

"github.com/weaveworks/flux/cmd/fluxctl/install"
)

type installOpts struct {
gitURL string
gitBranch string
gitPaths []string
gitLabel string
gitUser string
gitEmail string
namespace string
additionalFluxArgs []string
}
type installOpts install.TemplateParameters

func newInstall() *installOpts {
return &installOpts{}
Expand All @@ -27,27 +23,30 @@ func (opts *installOpts) Command() *cobra.Command {
fluxctl install --git-url '[email protected]:<your username>/flux-get-started' | kubectl -f -`,
RunE: opts.RunE,
}
cmd.Flags().StringVarP(&opts.gitURL, "git-url", "", "",
cmd.Flags().StringVarP(&opts.GitURL, "git-url", "", "",
"URL of the Git repository to be used by Flux, e.g. [email protected]:<your username>/flux-get-started")
cmd.Flags().StringVarP(&opts.gitBranch, "git-branch", "", "master",
cmd.Flags().StringVarP(&opts.GitBranch, "git-branch", "", "master",
"Git branch to be used by Flux")
cmd.Flags().StringVarP(&opts.gitLabel, "git-label", "", "flux",
cmd.Flags().StringVarP(&opts.GitLabel, "git-label", "", "flux",
"Git label to keep track of Flux's sync progress; overrides both --git-sync-tag and --git-notes-ref")
cmd.Flags().StringVarP(&opts.gitUser, "git-user", "", "Flux",
cmd.Flags().StringVarP(&opts.GitUser, "git-user", "", "Flux",
"Username to use as git committer")
cmd.Flags().StringVarP(&opts.gitEmail, "git-email", "", "[email protected]",
cmd.Flags().StringVarP(&opts.GitEmail, "git-email", "", "[email protected]",
"Email to use as git committer")
cmd.Flags().StringVarP(&opts.namespace, "namespace", "", "flux",
cmd.Flags().StringVarP(&opts.Namespace, "namespace", "", "flux",
"Cluster namespace where to install flux")
cmd.Flags().StringSliceVarP(&opts.additionalFluxArgs, "extra-flux-args", "", []string{},
cmd.Flags().StringSliceVarP(&opts.AdditionalFluxArgs, "extra-flux-args", "", []string{},
"Additional arguments for Flux as CSVs, e.g. --extra-flux-arg='--manifest-generation=true,--sync-garbage-collection=true'")
return cmd
}

func (opts *installOpts) RunE(cmd *cobra.Command, args []string) error {
//0. Read and patch embedded templates manifests with what was passed to as options

//1. Print them
templates, err := install.FillInInstallTemplates(install.TemplateParameters(*opts))
if err != nil {
return err
}
_, err = io.Copy(os.Stdout, templates)
return err

return nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ require (
github.com/prometheus/common v0.3.0 // indirect
github.com/prometheus/procfs v0.0.0-20190412120340-e22ddced7142 // indirect
github.com/ryanuber/go-glob v1.0.0
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749
github.com/shurcooL/vfsgen v0.0.0-20181202132449-6a9ea43bcacd
github.com/sirupsen/logrus v1.4.1 // indirect
github.com/spf13/cobra v0.0.3
Expand Down