Skip to content

Commit

Permalink
Revert "[backport] feat: integrate gwctl with fsm cli (#380)"
Browse files Browse the repository at this point in the history
This reverts commit be94649.
  • Loading branch information
reaver-flomesh committed Oct 12, 2024
1 parent edc540a commit 38061f5
Show file tree
Hide file tree
Showing 52 changed files with 106 additions and 196 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ build: charts-tgz manifests go-fmt go-vet ## Build commands with release args, t

.PHONY: build-fsm
build-fsm: helm-update-dep cmd/cli/chart.tgz
CGO_ENABLED=1 go build -v -o ./bin/fsm -ldflags ${LDFLAGS} ./cmd/cli
CGO_ENABLED=0 go build -v -o ./bin/fsm -ldflags ${LDFLAGS} ./cmd/cli

cmd/cli/chart.tgz: scripts/generate_chart/generate_chart.go $(shell find charts/fsm)
go run $< --chart-name=fsm > $@
Expand Down Expand Up @@ -361,7 +361,7 @@ install-git-pre-push-hook:

.PHONY: build-cross
build-cross: helm-update-dep cmd/cli/chart.tgz
GO111MODULE=on CGO_ENABLED=1 $(GOX) -ldflags $(LDFLAGS) -parallel=5 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' ./cmd/cli
GO111MODULE=on CGO_ENABLED=0 $(GOX) -ldflags $(LDFLAGS) -parallel=5 -output="_dist/{{.OS}}-{{.Arch}}/$(BINNAME)" -osarch='$(TARGETS)' ./cmd/cli

.PHONY: dist
dist:
Expand Down
4 changes: 2 additions & 2 deletions cmd/cli/dashboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func (d *dashboardCmd) run() error {
v1ClientSet := clientSet.CoreV1()

// Get Grafana service data
svc, err := v1ClientSet.Services(settings.FsmNamespace()).
svc, err := v1ClientSet.Services(settings.Namespace()).
Get(context.TODO(), grafanaServiceName, metav1.GetOptions{})

if err != nil {
Expand All @@ -86,7 +86,7 @@ func (d *dashboardCmd) run() error {
// Select pod/s given the service data available
set := labels.Set(svc.Spec.Selector)
listOptions := metav1.ListOptions{LabelSelector: set.AsSelector().String()}
pods, err := v1ClientSet.Pods(settings.FsmNamespace()).List(context.TODO(), listOptions)
pods, err := v1ClientSet.Pods(settings.Namespace()).List(context.TODO(), listOptions)
if err != nil {
return annotateErrorMessageWithFsmNamespace("Error listing pods: %s", err)
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/egressgateway_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (cmd *egressGatewayDisableCmd) run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/egressgateway_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (cmd *egressGatewayEnableCmd) run() error {
return fmt.Errorf("mode must be either http2tunnel or socks5")
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/flb_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func (cmd *flbDisableCmd) run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/flb_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (cmd *flbEnableCmd) run() error {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
40 changes: 9 additions & 31 deletions cmd/cli/fsm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,13 @@
package main

import (
goflag "flag"
"fmt"
"io"
"os"

cmdanalyze "sigs.k8s.io/gwctl/cmd/analyze"
cmdapply "sigs.k8s.io/gwctl/cmd/apply"
cmddelete "sigs.k8s.io/gwctl/cmd/delete"
cmdget "sigs.k8s.io/gwctl/cmd/get"

"github.com/spf13/pflag"

"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/action"
"k8s.io/cli-runtime/pkg/genericiooptions"

"github.com/flomesh-io/fsm/pkg/cli"
)
Expand All @@ -29,31 +23,26 @@ To install and configure FSM, run:

var settings = cli.New()

func newRootCmd(config *action.Configuration, ioStreams genericiooptions.IOStreams, args []string) *cobra.Command {
func newRootCmd(config *action.Configuration, stdin io.Reader, stdout io.Writer, stderr io.Writer, args []string) *cobra.Command {
cmd := &cobra.Command{
Use: "fsm",
Short: "Install and manage Flomesh Service Mesh",
Long: globalUsage,
SilenceUsage: true,
}

//cmd.PersistentFlags().AddGoFlagSet(goflag.CommandLine)
cmd.PersistentFlags().AddGoFlagSet(goflag.CommandLine)
flags := cmd.PersistentFlags()
settings.AddFlags(flags)

factory := settings.Factory()
stdin := ioStreams.In
stdout := ioStreams.Out
stderr := ioStreams.ErrOut

// Add subcommands here
cmd.AddCommand(
newMeshCmd(config, stdin, stdout),
newEnvCmd(stdout, stderr),
newNamespaceCmd(stdout),
newMetricsCmd(stdout),
newVersionCmd(stdout),
newProxyCmd(config, factory, stdout),
newProxyCmd(config, stdout),
newPolicyCmd(stdout, stderr),
newSupportCmd(config, stdout, stderr),
newUninstallCmd(config, stdin, stdout),
Expand All @@ -62,11 +51,6 @@ func newRootCmd(config *action.Configuration, ioStreams genericiooptions.IOStrea
newServiceLBCmd(stdout),
newFLBCmd(config, stdout),
newEgressGatewayCmd(config, stdout),
cmdapply.NewCmd(factory, ioStreams),
cmdget.NewCmd(factory, ioStreams, false),
cmdget.NewCmd(factory, ioStreams, true),
cmddelete.NewCmd(factory, ioStreams),
cmdanalyze.NewCmd(factory, ioStreams),
)

// Add subcommands related to unmanaged environments
Expand All @@ -77,25 +61,19 @@ func newRootCmd(config *action.Configuration, ioStreams genericiooptions.IOStrea
)
}

_ = cmd.PersistentFlags().Parse(args)
if settings.Verbose() {
cmd.PersistentFlags().VisitAll(func(flag *pflag.Flag) {
fmt.Fprintf(os.Stderr, "flag=%s, value=%s\n", flag.Name, flag.Value)
})
}
_ = flags.Parse(args)

return cmd
}

func initCommands() *cobra.Command {
actionConfig := new(action.Configuration)
cmd := newRootCmd(actionConfig, settings.IOStreams(), os.Args[1:])
_ = actionConfig.Init(settings.RESTClientGetter(), settings.FsmNamespace(), "secret", debug)
cmd := newRootCmd(actionConfig, os.Stdin, os.Stdout, os.Stderr, os.Args[1:])
_ = actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), "secret", debug)

// run when each command's execute method is called
cobra.OnInitialize(func() {
if err := actionConfig.Init(settings.RESTClientGetter(), settings.FsmNamespace(), "secret", debug); err != nil {
fmt.Fprintf(os.Stderr, "Failed to initialize action configuration: %v", err)
if err := actionConfig.Init(settings.RESTClientGetter(), settings.Namespace(), "secret", debug); err != nil {
os.Exit(1)
}
})
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/gateway_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (cmd *gatewayDisableCmd) run() error {
version.ServerVersion.String(), version.MinK8sVersionForGatewayAPI.String())
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/gateway_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (cmd *gatewayEnableCmd) run() error {
version.ServerVersion.String(), version.MinK8sVersionForGatewayAPI.String())
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/ingress_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (cmd *ingressDisableCmd) run() error {
version.ServerVersion.String(), version.MinK8sVersion.String())
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/ingress_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ func (cmd *ingressEnableCmd) run() error {
return fmt.Errorf("invalid service type, only support LoadBalancer or NodePort")
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/ingress_namespaced_disable.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (cmd *namespacedIngressDisableCmd) run() error {
version.ServerVersion.String(), version.MinK8sVersion.String())
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/ingress_namespaced_enable.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (cmd *namespacedIngressEnableCmd) run() error {
version.ServerVersion.String(), version.MinK8sVersion.String())
}

fsmNamespace := settings.FsmNamespace()
fsmNamespace := settings.Namespace()

debug("Getting mesh config ...")
// get mesh config
Expand Down
8 changes: 4 additions & 4 deletions cmd/cli/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (i *installCmd) run(config *helm.Configuration) error {

installClient := helm.NewInstall(config)
installClient.ReleaseName = i.meshName
installClient.Namespace = settings.FsmNamespace()
installClient.Namespace = settings.Namespace()
installClient.CreateNamespace = true
installClient.Wait = true
installClient.Atomic = i.atomic
Expand All @@ -168,7 +168,7 @@ func (i *installCmd) run(config *helm.Configuration) error {
return err
}

pods, _ := i.clientSet.CoreV1().Pods(settings.FsmNamespace()).List(context.Background(), metav1.ListOptions{})
pods, _ := i.clientSet.CoreV1().Pods(settings.Namespace()).List(context.Background(), metav1.ListOptions{})

for _, pod := range pods.Items {
fmt.Fprintf(i.out, "Status for pod %s in namespace %s:\n %v\n\n", pod.Name, pod.Namespace, pod.Status)
Expand All @@ -177,7 +177,7 @@ func (i *installCmd) run(config *helm.Configuration) error {
}
} else {
spinner := new(cli.Spinner)
spinner.Init(i.clientSet, settings.FsmNamespace(), values)
spinner.Init(i.clientSet, settings.Namespace(), values)
err = spinner.Run(func() error {
_, installErr := installClient.Run(i.chartRequested, values)
return installErr
Expand All @@ -188,7 +188,7 @@ func (i *installCmd) run(config *helm.Configuration) error {
}
}
}
fmt.Fprintf(i.out, "FSM installed successfully in namespace [%s] with mesh name [%s]\n", settings.FsmNamespace(), i.meshName)
fmt.Fprintf(i.out, "FSM installed successfully in namespace [%s] with mesh name [%s]\n", settings.Namespace(), i.meshName)
return nil
}

Expand Down
24 changes: 12 additions & 12 deletions cmd/cli/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var _ = Describe("Running the install command", func() {
out = new(bytes.Buffer)
store = storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down Expand Up @@ -115,7 +115,7 @@ var _ = Describe("Running the install command", func() {
})

It("should be installed in the correct namespace", func() {
Expect(rel.Namespace).To(Equal(settings.FsmNamespace()))
Expect(rel.Namespace).To(Equal(settings.Namespace()))
})
})
})
Expand All @@ -132,7 +132,7 @@ var _ = Describe("Running the install command", func() {
out = new(bytes.Buffer)
store = storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down Expand Up @@ -178,7 +178,7 @@ var _ = Describe("Running the install command", func() {
})

It("should be installed in the correct namespace", func() {
Expect(rel.Namespace).To(Equal(settings.FsmNamespace()))
Expect(rel.Namespace).To(Equal(settings.Namespace()))
})
})
})
Expand All @@ -195,7 +195,7 @@ var _ = Describe("Running the install command", func() {
out = new(bytes.Buffer)
store = storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down Expand Up @@ -255,7 +255,7 @@ var _ = Describe("Running the install command", func() {
})

It("should be installed in the correct namespace", func() {
Expect(rel.Namespace).To(Equal(settings.FsmNamespace()))
Expect(rel.Namespace).To(Equal(settings.Namespace()))
})
})
})
Expand All @@ -272,7 +272,7 @@ var _ = Describe("Running the install command", func() {
out = new(bytes.Buffer)
store = storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down Expand Up @@ -336,7 +336,7 @@ var _ = Describe("Running the install command", func() {
})

It("should be installed in the correct namespace", func() {
Expect(rel.Namespace).To(Equal(settings.FsmNamespace()))
Expect(rel.Namespace).To(Equal(settings.Namespace()))
})
})
})
Expand All @@ -351,7 +351,7 @@ var _ = Describe("Running the install command", func() {
out := new(bytes.Buffer)
store := storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down Expand Up @@ -416,7 +416,7 @@ var _ = Describe("Running the install command", func() {
out = new(bytes.Buffer)
store = storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down Expand Up @@ -471,7 +471,7 @@ var _ = Describe("Running the install command", func() {
})

It("should be installed in the correct namespace", func() {
Expect(rel.Namespace).To(Equal(settings.FsmNamespace()))
Expect(rel.Namespace).To(Equal(settings.Namespace()))
})
})
})
Expand All @@ -489,7 +489,7 @@ var _ = Describe("deployPrometheus is true", func() {
out = new(bytes.Buffer)
store = storage.Init(driver.NewMemory())
if mem, ok := store.Driver.(*driver.Memory); ok {
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
}

config = &helm.Configuration{
Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/mesh_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func (u *meshUpgradeCmd) run(config *helm.Configuration) error {
return err
}

fmt.Fprintf(u.out, "FSM successfully upgraded mesh [%s] in namespace [%s]\n", u.meshName, settings.FsmNamespace())
fmt.Fprintf(u.out, "FSM successfully upgraded mesh [%s] in namespace [%s]\n", u.meshName, settings.Namespace())
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/cli/mesh_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (

func meshUpgradeConfig() *action.Configuration {
mem := driver.NewMemory()
mem.SetNamespace(settings.FsmNamespace())
mem.SetNamespace(settings.Namespace())
store := storage.Init(mem)

return &action.Configuration{
Expand Down
Loading

0 comments on commit 38061f5

Please sign in to comment.