Skip to content

Commit

Permalink
Using flux install without export (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
luizbafilho authored Jun 7, 2021
1 parent c7393bc commit 190ade9
Show file tree
Hide file tree
Showing 8 changed files with 48 additions and 50 deletions.
4 changes: 1 addition & 3 deletions cmd/wego/install/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ func init() {
}

func runCmd(cmd *cobra.Command, args []string) {
manifests, err := cmdimpl.Install(params)
_, err := cmdimpl.Install(params)
checkError("failed outputing install manifests", err)

fmt.Println(string(manifests))
}
19 changes: 13 additions & 6 deletions cmd/wego/install/cmd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/weaveworks/weave-gitops/pkg/fluxops/fluxopsfakes"
"github.com/weaveworks/weave-gitops/pkg/override"
"github.com/weaveworks/weave-gitops/pkg/shims"
"github.com/weaveworks/weave-gitops/pkg/utils"
)

type localExitHandler struct {
Expand All @@ -38,13 +39,19 @@ var _ = Describe("Run Command Test", func() {
}
fluxops.SetFluxHandler(fakeHandler)

params = cmdimpl.InstallParamSet{
Namespace: "my-namespace",
}
runCmd(&cobra.Command{}, []string{})
_ = override.WithOverrides(
func() override.Result {
params = cmdimpl.InstallParamSet{
Namespace: "my-namespace",
}
runCmd(&cobra.Command{}, []string{})

args := fakeHandler.HandleArgsForCall(0)
Expect(args).To(Equal("install --namespace=my-namespace --export"))
args := fakeHandler.HandleArgsForCall(0)
Expect(args).To(Equal("install --namespace=my-namespace --components-extra=image-reflector-controller,image-automation-controller"))

return override.Result{}
},
utils.OverrideIgnore(utils.CallCommandForEffectWithInputPipeOp))
})
})
})
Expand Down
10 changes: 9 additions & 1 deletion pkg/cmdimpl/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cmdimpl

import (
_ "embed"
"fmt"

"github.com/weaveworks/weave-gitops/pkg/fluxops"
"github.com/weaveworks/weave-gitops/pkg/utils"
)

//go:embed manifests/app-crd.yaml
Expand All @@ -14,7 +16,13 @@ type InstallParamSet struct {
}

func Install(params InstallParamSet) ([]byte, error) {
manifests, err := fluxops.QuietInstall(params.Namespace)
kubectlApply := fmt.Sprintf("kubectl apply --namespace=%s -f -", params.Namespace)

if err := utils.CallCommandForEffectWithInputPipe(kubectlApply, string(appCRD)); err != nil {
return []byte(""), wrapError(err, "could not apply wego manifests")
}

manifests, err := fluxops.Install(params.Namespace)
if err != nil {
return nil, err
}
Expand Down
16 changes: 12 additions & 4 deletions pkg/cmdimpl/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (

"github.com/weaveworks/weave-gitops/pkg/fluxops"
"github.com/weaveworks/weave-gitops/pkg/fluxops/fluxopsfakes"
"github.com/weaveworks/weave-gitops/pkg/override"
"github.com/weaveworks/weave-gitops/pkg/utils"
)

var _ = Describe("Run Command Test", func() {
Expand All @@ -18,11 +20,17 @@ var _ = Describe("Run Command Test", func() {
}
fluxops.SetFluxHandler(fakeHandler)

_, err := Install(InstallParamSet{Namespace: "my-namespace"})
Expect(err).To(BeNil())
_ = override.WithOverrides(
func() override.Result {
_, err := Install(InstallParamSet{Namespace: "my-namespace"})
Expect(err).To(BeNil())

args := fakeHandler.HandleArgsForCall(0)
Expect(args).To(Equal("install --namespace=my-namespace --export"))
args := fakeHandler.HandleArgsForCall(0)
Expect(args).To(Equal("install --namespace=my-namespace --components-extra=image-reflector-controller,image-automation-controller"))

return override.Result{}
},
utils.OverrideIgnore(utils.CallCommandForEffectWithInputPipeOp))
})
})
})
32 changes: 5 additions & 27 deletions pkg/fluxops/fluxops.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,6 @@ import (
"sigs.k8s.io/yaml"
)

const fluxSystemNamespace = `apiVersion: v1
kind: Namespace
metadata:
name: flux-system
---
`

var (
fluxHandler interface{} = DefaultFluxHandler{}
fluxBinary string
Expand Down Expand Up @@ -93,32 +86,17 @@ func QuietInstall(namespace string) ([]byte, error) {
}

func installFlux(namespace string, verbose bool) ([]byte, error) {
var extraManifest []byte
if namespace != "flux-system" { // we need to have this namespace created
extraManifest = []byte(fluxSystemNamespace)
}

args := []string{
"install",
fmt.Sprintf("--namespace=%s", namespace),
"--export",
"--components-extra=image-reflector-controller,image-automation-controller",
}

if verbose {
manifests, err := CallFlux(args...)
if err != nil {
return nil, err
}
return append(extraManifest, manifests...), nil
manifests, err := CallFlux(args...)
if err != nil {
return nil, err
}

return WithFluxHandler(quietFluxHandler{}, func() ([]byte, error) {
manifests, err := CallFlux(args...)
if err != nil {
return nil, err
}
return append(extraManifest, manifests...), nil
})
return manifests, nil
}

func GetAllResourcesStatus(appName string) ([]byte, error) {
Expand Down
5 changes: 2 additions & 3 deletions pkg/fluxops/fluxops_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,10 @@ var _ = Describe("Flux Install Test", func() {
Expect(err).To(BeNil())
Expect(string(output)).To(Equal("foo"))

output, err = fluxops.Install("my-namespace")
_, err = fluxops.Install("my-namespace")
Expect(err).To(BeNil())
Expect(string(output)).To(Equal("apiVersion: v1\nkind: Namespace\nmetadata:\n name: flux-system\n---\nfoo"))
args := fakeHandler.HandleArgsForCall(1)
Expect(args).To(Equal("install --namespace=my-namespace --export"))
Expect(args).To(Equal("install --namespace=my-namespace --components-extra=image-reflector-controller,image-automation-controller"))
})

By("Using a mock to fail verbose manifest generation", func() {
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/test/install_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ var _ = Describe("Weave GitOps Install Tests", func() {
})

By("When I run 'wego install' command with specified namespace", func() {
command := exec.Command("sh", "-c", fmt.Sprintf("%s install --namespace %s | kubectl apply -f -", WEGO_BIN_PATH, namespace))
command := exec.Command("sh", "-c", fmt.Sprintf("%s install --namespace %s", WEGO_BIN_PATH, namespace))
session, err = gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session).Should(gexec.Exit())
Expand Down
10 changes: 5 additions & 5 deletions test/acceptance/test/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func ResetOrCreateCluster(namespace string) (string, error) {

//For kubectl points to valid cluster, we will try to reset the namespace only
if namespace != "" && provider == "kubectl" {
err := runCommandPassThrough([]string{}, "sh", "-c", fmt.Sprintf("%s install --namespace %s| kubectl --ignore-not-found=true delete -f -", WEGO_BIN_PATH, namespace))
err := runCommandPassThrough([]string{}, "sh", "-c", fmt.Sprintf("%s flux uninstall --namespace %s --silent", WEGO_BIN_PATH, namespace))
if err != nil {
log.Infof("Failed to reset the namespace %s", namespace)
return clusterName, err
Expand Down Expand Up @@ -222,9 +222,9 @@ func initAndCreateEmptyRepo(appRepoName string, IsPrivateRepo bool) string {
privateRepo = "-p"
}
command := exec.Command("sh", "-c", fmt.Sprintf(`
mkdir %s &&
cd %s &&
git init &&
mkdir %s &&
cd %s &&
git init &&
hub create %s %s`, repoAbsolutePath, repoAbsolutePath, os.Getenv("GITHUB_ORG")+"/"+appRepoName, privateRepo))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Expand Down Expand Up @@ -268,7 +268,7 @@ func setupSSHKey(sshKeyPath string) {

func installAndVerifyWego(wegoNamespace string) {
By("And I run 'wego install' command with namespace "+wegoNamespace, func() {
command := exec.Command("sh", "-c", fmt.Sprintf("%s install --namespace=%s| kubectl apply -f -", WEGO_BIN_PATH, wegoNamespace))
command := exec.Command("sh", "-c", fmt.Sprintf("%s install --namespace=%s", WEGO_BIN_PATH, wegoNamespace))
session, err := gexec.Start(command, GinkgoWriter, GinkgoWriter)
Expect(err).ShouldNot(HaveOccurred())
Eventually(session).Should(gexec.Exit())
Expand Down

0 comments on commit 190ade9

Please sign in to comment.