diff --git a/cmd/liqoctl/cmd/install.go b/cmd/liqoctl/cmd/install.go index ed4b15da3e..d73fe04aa4 100644 --- a/cmd/liqoctl/cmd/install.go +++ b/cmd/liqoctl/cmd/install.go @@ -21,6 +21,7 @@ import ( "github.com/spf13/cobra" + "github.com/liqotech/liqo/pkg/liqoctl/completion" "github.com/liqotech/liqo/pkg/liqoctl/factory" "github.com/liqotech/liqo/pkg/liqoctl/install" "github.com/liqotech/liqo/pkg/liqoctl/install/aks" @@ -91,8 +92,8 @@ information and examples concerning its behavior and the common flags. ` func newInstallCommand(ctx context.Context, f *factory.Factory) *cobra.Command { - options := install.Options{Factory: f, CommandName: liqoctl} - base := generic.New(&options) + options := install.NewOptions(f, liqoctl) + base := generic.New(options) clusterLabels := args.StringMap{StringMap: map[string]string{}} sharingPercentage := args.Percentage{Val: 90} reservedSubnets := args.CIDRList{} @@ -166,16 +167,19 @@ func newInstallCommand(ctx context.Context, f *factory.Factory) *cobra.Command { cmd.PersistentFlags().BoolVar(&options.EnableMetrics, "enable-metrics", false, "Enable metrics exposition through prometheus (default false)") cmd.PersistentFlags().BoolVar(&options.DisableTelemetry, "disable-telemetry", false, "Disable the anonymous and aggregated Liqo telemetry collection (default false)") + cmd.PersistentFlags().Var(options.ExtServiceType, "service-type", "Override the used service type for liqo-auth and liqo-gateway") + f.Printer.CheckErr(cmd.RegisterFlagCompletionFunc("service-type", completion.Enumeration(options.ExtServiceType.Allowed))) + f.AddLiqoNamespaceFlag(cmd.PersistentFlags()) base.RegisterFlags(cmd) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, aks.New)) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, eks.New)) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, gke.New)) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, k3s.New)) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, kind.New)) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, kubeadm.New)) - cmd.AddCommand(newInstallProviderCommand(ctx, &options, openshift.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, aks.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, eks.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, gke.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, k3s.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, kind.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, kubeadm.New)) + cmd.AddCommand(newInstallProviderCommand(ctx, options, openshift.New)) return cmd } diff --git a/docs/installation/install.md b/docs/installation/install.md index f4d3b88442..d2479d1b43 100644 --- a/docs/installation/install.md +++ b/docs/installation/install.md @@ -47,6 +47,11 @@ liqoctl install kubeadm By default, the cluster is assigned an automatically generated name, then leveraged during the peering and offloading processes. Alternatively, you can manually specify a desired name with the `--cluster-name` flag. + +```{admonition} Service Type +By default, the **kubeadm** provider exposes *liqo-auth* and *liqo-gateway* with **LoadBalancer** services. +To change this behavior, check the [network flags](NetworkFlags). +``` ```` ````{tab-item} OpenShift @@ -65,6 +70,11 @@ liqoctl install openshift By default, the cluster is assigned an automatically generated name, then leveraged during the peering and offloading processes. Alternatively, you can manually specify a desired name with the `--cluster-name` flag. + +```{admonition} Service Type +By default, the **openshift** provider exposes *liqo-auth* and *liqo-gateway* with **LoadBalancer** services. +To change this behavior, check the [network flags](NetworkFlags). +``` ```` ````{tab-item} AKS @@ -114,6 +124,11 @@ If you are running an [AKS private cluster](https://learn.microsoft.com/en-us/az Additionally, since your API Server is not accessible from the public Internet, you shall leverage the [in-band peering approach](FeaturesPeeringInBandControlPlane) towards the clusters not attached to the same Azure Virtual Network. ``` + +```{admonition} Service Type +By default, the **AKS** provider exposes *liqo-auth* and *liqo-gateway* with **LoadBalancer** services. +To change this behavior, check the [network flags](NetworkFlags). +``` ```` ````{tab-item} EKS @@ -199,6 +214,11 @@ liqoctl install eks --eks-cluster-region=${EKS_CLUSTER_REGION} \ By default, the cluster is assigned the same name as that specified through the `--eks-cluster-name` parameter. Alternatively, you can manually specify a different name with the `--cluster-name` *liqoctl* flag. + +```{admonition} Service Type +By default, the **EKS** provider exposes *liqo-auth* and *liqo-gateway* with **LoadBalancer** services. +To change this behavior, check the [network flags](NetworkFlags). +``` ```` ````{tab-item} GKE @@ -301,6 +321,11 @@ liqoctl install gke --project-id ${GKE_PROJECT_ID} \ By default, the cluster is assigned the same name as that assigned in GCP. Alternatively, you can manually specify a different name with the `--cluster-name` *liqoctl* flag. + +```{admonition} Service Type +By default, the **GKE** provider exposes *liqo-auth* and *liqo-gateway* with **LoadBalancer** services. +To change this behavior, check the [network flags](NetworkFlags). +``` ```` ````{tab-item} K3s @@ -323,6 +348,11 @@ This operation is necessary in case the default address (`https:// \ By default, the cluster is assigned an automatically generated name, then leveraged during the peering and offloading processes. Alternatively, you can manually specify a desired name with the `--cluster-name` flag. + +```{admonition} Service Type +By default, liqoctl exposes *liqo-auth* and *liqo-gateway* with **LoadBalancer** services. +To change this behavior, check the [network flags](NetworkFlags). +``` ```` ````` @@ -396,12 +435,15 @@ These labels can be used later to **restrict workload offloading to a subset of * `--sharing-percentage`: the maximum percentage of available **cluster resources** that could be shared with remote clusters. This is the Liqo's default behavior, which can be changed by deploying a custom [resource plugin](https://github.com/liqotech/liqo-resource-plugins). **Note**: the `--sharing-percentage` can be updated (e.g., via helm) dynamically, without reinstalling Liqo. +(NetworkFlags)= + ### Networking The main networking flags include: * `--reserved-subnets`: the list of **private CIDRs to be excluded** from the ones used by Liqo to remap remote clusters in case of address conflicts, as already in use (e.g., the subnet of the cluster nodes). The Pod CIDR and the Service CIDR shall not be manually specified, as automatically included in the reserved list. +* `--service-type`: overrides the service type used by **liqo-gateway** and **liqo-auth** services. Possible values are: `LoadBalancer`, `NodePort`, and `ClusterIP`. By default, the service type is the one specified by the selected provider (check the provider's specific installation) or `LoadBalancer`. (InstallationHelm)= diff --git a/pkg/liqoctl/install/handler.go b/pkg/liqoctl/install/handler.go index c30d97d220..e27f534170 100644 --- a/pkg/liqoctl/install/handler.go +++ b/pkg/liqoctl/install/handler.go @@ -30,6 +30,7 @@ import ( "helm.sh/helm/v3/pkg/action" "helm.sh/helm/v3/pkg/repo" "helm.sh/helm/v3/pkg/strvals" + corev1 "k8s.io/api/core/v1" "sigs.k8s.io/controller-runtime/pkg/client" "github.com/liqotech/liqo/pkg/consts" @@ -37,6 +38,7 @@ import ( "github.com/liqotech/liqo/pkg/liqoctl/install/util" "github.com/liqotech/liqo/pkg/liqoctl/output" "github.com/liqotech/liqo/pkg/utils" + "github.com/liqotech/liqo/pkg/utils/args" ) // Provider defines the interface for an install provider. @@ -87,11 +89,25 @@ type Options struct { ServiceCIDR string ReservedSubnets []string + ExtServiceType *args.StringEnum + DisableAPIServerSanityChecks bool DisableAPIServerDefaulting bool SkipValidation bool } +// NewOptions returns a new Options struct. +func NewOptions(f *factory.Factory, commandName string) *Options { + return &Options{ + CommandName: commandName, + Factory: f, + ExtServiceType: args.NewEnumWithVoidDefault([]string{ + string(corev1.ServiceTypeClusterIP), + string(corev1.ServiceTypeNodePort), + string(corev1.ServiceTypeLoadBalancer)}), + } +} + // Run implements the install command. func (o *Options) Run(ctx context.Context, provider Provider) error { ctx, cancel := context.WithTimeout(ctx, o.Timeout) @@ -295,7 +311,7 @@ func (o *Options) values() map[string]interface{} { replicas = 2 } - return map[string]interface{}{ + values := map[string]interface{}{ "tag": o.Version, "apiServer": map[string]interface{}{ @@ -348,6 +364,22 @@ func (o *Options) values() map[string]interface{} { "enable": !o.DisableTelemetry, }, } + + if o.ExtServiceType.Value != "" { + values["gateway"] = map[string]interface{}{ + "service": map[string]interface{}{ + "type": o.ExtServiceType.Value, + }, + } + + values["auth"] = map[string]interface{}{ + "service": map[string]interface{}{ + "type": o.ExtServiceType.Value, + }, + } + } + + return values } func (o *Options) cleanup() error { diff --git a/pkg/utils/args/enum.go b/pkg/utils/args/enum.go index 8b9f561368..75fb934838 100644 --- a/pkg/utils/args/enum.go +++ b/pkg/utils/args/enum.go @@ -33,6 +33,14 @@ func NewEnum(allowed []string, d string) *StringEnum { } } +// NewEnumWithVoidDefault give a list of allowed flag parameters, where the default is a void string. +func NewEnumWithVoidDefault(allowed []string) *StringEnum { + return &StringEnum{ + Allowed: allowed, + Value: "", + } +} + // String returns the stringified value. func (a StringEnum) String() string { return a.Value