-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add cli commands to enable/disable ingress, gateway, egress-gat…
…eway, flb and service-lb (#39) * feat: enable fsm-ingress by cli cmd Signed-off-by: Lin Yang <[email protected]> * feat: add --dry-run flag for install command Signed-off-by: Lin Yang <[email protected]> feat: add --dry-run flag for install command Signed-off-by: Lin Yang <[email protected]> * feat: add commands for enable/disable ingress Signed-off-by: Lin Yang <[email protected]> * fix: command description Signed-off-by: Lin Yang <[email protected]> * fix: golang lint Signed-off-by: Lin Yang <[email protected]> * feat: support enable/disable gateway & NamespacedIngress Signed-off-by: Lin Yang <[email protected]> * feat: cleanup resources upon uninstallation Signed-off-by: Lin Yang <[email protected]> * feat: support enable/disable egress-gateway Signed-off-by: Lin Yang <[email protected]> * #32 rollback change for balance algorithm shortening (#33) * feat: support enable/disable service-lb Signed-off-by: Lin Yang <[email protected]> * fix: comments Signed-off-by: Lin Yang <[email protected]> * feat: waiting for fsm-controller pods to be ready Signed-off-by: Lin Yang <[email protected]> * fix: a typo Signed-off-by: Lin Yang <[email protected]> * feat: waiting for fsm-controller to ready Signed-off-by: Lin Yang <[email protected]> * fix: golang lint Signed-off-by: Lin Yang <[email protected]> * feat: wait for deployment rolled out Signed-off-by: Lin Yang <[email protected]> * ci: watch branch release/v* to trigger GitHub actions (#38) Signed-off-by: Lin Yang <[email protected]> * fix: make codegen Signed-off-by: Lin Yang <[email protected]> * fix: remove cluster argument Signed-off-by: Lin Yang <[email protected]> --------- Signed-off-by: Lin Yang <[email protected]> Co-authored-by: Addo.Zhang <[email protected]>
- Loading branch information
1 parent
5ab21e7
commit ab6feec
Showing
46 changed files
with
2,926 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package main | ||
|
||
import ( | ||
"io" | ||
|
||
"helm.sh/helm/v3/pkg/action" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
const egressGatewayDescription = ` | ||
This command consists of multiple subcommands related to managing egress gateway | ||
associated with fsm installations. | ||
` | ||
|
||
var ( | ||
egressGatewayManifestFiles = []string{ | ||
"templates/egress-gateway-configmap.yaml", | ||
"templates/egress-gateway-deployment.yaml", | ||
"templates/egress-gateway-service.yaml", | ||
} | ||
) | ||
|
||
func newEgressGatewayCmd(config *action.Configuration, out io.Writer) *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "egressgateway", | ||
Short: "manage fsm egress-gateway", | ||
Aliases: []string{"egw"}, | ||
Long: egressGatewayDescription, | ||
Args: cobra.NoArgs, | ||
} | ||
cmd.AddCommand(newEgressGatewayEnable(config, out)) | ||
cmd.AddCommand(newEgressGatewayDisable(out)) | ||
|
||
return cmd | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"io" | ||
|
||
"github.com/spf13/cobra" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/kubernetes" | ||
|
||
configClientset "github.com/flomesh-io/fsm/pkg/gen/client/config/clientset/versioned" | ||
) | ||
|
||
const egressGatewayDisableDescription = ` | ||
This command will disable FSM egress-gateway, make sure --mesh-name and --fsm-namespace matches | ||
the release name and namespace of installed FSM, otherwise it doesn't work. | ||
` | ||
|
||
type egressGatewayDisableCmd struct { | ||
out io.Writer | ||
kubeClient kubernetes.Interface | ||
configClient configClientset.Interface | ||
meshName string | ||
} | ||
|
||
func newEgressGatewayDisable(out io.Writer) *cobra.Command { | ||
disableCmd := &egressGatewayDisableCmd{ | ||
out: out, | ||
} | ||
|
||
cmd := &cobra.Command{ | ||
Use: "disable", | ||
Short: "disable fsm egress-gateway", | ||
Long: egressGatewayDisableDescription, | ||
Args: cobra.ExactArgs(0), | ||
RunE: func(_ *cobra.Command, args []string) error { | ||
config, err := settings.RESTClientGetter().ToRESTConfig() | ||
if err != nil { | ||
return fmt.Errorf("error fetching kubeconfig: %w", err) | ||
} | ||
|
||
kubeClient, err := kubernetes.NewForConfig(config) | ||
if err != nil { | ||
return fmt.Errorf("could not access Kubernetes cluster, check kubeconfig: %w", err) | ||
} | ||
disableCmd.kubeClient = kubeClient | ||
|
||
configClient, err := configClientset.NewForConfig(config) | ||
if err != nil { | ||
return fmt.Errorf("could not access Kubernetes cluster, check kubeconfig: %w", err) | ||
} | ||
disableCmd.configClient = configClient | ||
|
||
return disableCmd.run() | ||
}, | ||
} | ||
|
||
f := cmd.Flags() | ||
f.StringVar(&disableCmd.meshName, "mesh-name", defaultMeshName, "name for the control plane instance") | ||
//utilruntime.Must(cmd.MarkFlagRequired("mesh-name")) | ||
|
||
return cmd | ||
} | ||
|
||
func (cmd *egressGatewayDisableCmd) run() error { | ||
ctx, cancel := context.WithCancel(context.Background()) | ||
defer cancel() | ||
|
||
fsmNamespace := settings.Namespace() | ||
|
||
debug("Getting mesh config ...") | ||
// get mesh config | ||
mc, err := cmd.configClient.ConfigV1alpha3().MeshConfigs(fsmNamespace).Get(ctx, defaultFsmMeshConfigName, metav1.GetOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if !mc.Spec.EgressGateway.Enabled { | ||
fmt.Fprintf(cmd.out, "egress-gateway is disabled already, no action needed\n") | ||
return nil | ||
} | ||
|
||
debug("Deleting FSM egress-gateway resources ...") | ||
err = deleteEgressGatewayResources(ctx, cmd.kubeClient, fsmNamespace, cmd.meshName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = updatePresetMeshConfigMap(ctx, cmd.kubeClient, fsmNamespace, map[string]interface{}{ | ||
"egressGateway.enabled": false, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
debug("Updating mesh config ...") | ||
// update mesh config, fsm-mesh-config | ||
mc.Spec.EgressGateway.Enabled = false | ||
_, err = cmd.configClient.ConfigV1alpha3().MeshConfigs(fsmNamespace).Update(ctx, mc, metav1.UpdateOptions{}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
fmt.Fprintf(cmd.out, "egress-gateway is disabled successfully\n") | ||
|
||
return nil | ||
} |
Oops, something went wrong.