Skip to content
This repository has been archived by the owner on Mar 31, 2023. It is now read-only.

allow specifying version with --controller-version or --dependency-file #129

Merged
merged 4 commits into from
Feb 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
23 changes: 22 additions & 1 deletion cmd/wksctl/init/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"regexp"
"strings"

"github.com/pelletier/go-toml"
"github.com/spf13/cobra"
"github.com/weaveworks/wksctl/pkg/utilities/manifest"
"github.com/weaveworks/wksctl/pkg/version"
Expand All @@ -18,6 +19,7 @@ import (
// updated git information for flux manifests.

type initOptionType struct {
dependencyPath string
footlooseIP string
footlooseBackend string
gitURL string
Expand Down Expand Up @@ -60,6 +62,8 @@ var (
updates = []manifestUpdate{
{selector: equal("wks-controller.yaml"), updater: updateControllerManifests},
{selector: and(prefix("flux"), extension("yaml")), updater: updateFluxManifests}}

dependencies = &toml.Tree{}
)

func multiLineRegexp(pattern string) *regexp.Regexp {
Expand All @@ -82,6 +86,8 @@ func init() {
&initOptions.namespace, "namespace", manifest.DefaultNamespace, "namespace portion of kubeconfig path")
Cmd.Flags().StringVar(
&initOptions.version, "controller-version", version.Version, "version of wks-controller to use")
Cmd.Flags().StringVar(
&initOptions.dependencyPath, "dependency-file", "./dependencies.toml", "path to file containing version information for all dependencies")
Cmd.MarkPersistentFlagRequired("git-url")
}

Expand Down Expand Up @@ -119,7 +125,11 @@ func updatedArg(item string) []byte {
}

func updateControllerManifests(contents []byte, options initOptionType) ([]byte, error) {
withVersion := controllerImageSegment.ReplaceAll(contents, []byte(`$1:`+options.version))
controllerVersion, ok := dependencies.Get("controller.version").(string)
if !ok {
controllerVersion = options.version
}
withVersion := controllerImageSegment.ReplaceAll(contents, []byte(`$1:`+controllerVersion))
if controllerFootlooseEnvEntry.Find(withVersion) == nil {
return controllerFootlooseAddrLocation.ReplaceAll(withVersion,
// We want to add to the matched entry so we start with $0 (the entire match) and use $1 to get the indentation correct.
Expand Down Expand Up @@ -173,5 +183,16 @@ func updateManifests(options initOptionType) error {
}

func initRun(cmd *cobra.Command, args []string) error {
if initOptions.version == "" {
initOptions.version = version.Version // from main command
}
bytes, err := ioutil.ReadFile(initOptions.dependencyPath)
if err != nil {
return err
}
dependencies, err = toml.Load(string(bytes))
if err != nil {
return err
}
return updateManifests(initOptions)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/hashicorp/golang-lru v0.5.3 // indirect
github.com/imdario/mergo v0.3.7 // indirect
github.com/oleiade/reflections v1.0.0 // indirect
github.com/pelletier/go-toml v1.2.0
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
github.com/pkg/errors v0.8.1
github.com/shurcooL/httpfs v0.0.0-20190707220628-8d4bc4ba7749 // indirect
Expand Down