Skip to content

Commit

Permalink
Liqoctl: --service-type flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cheina97 authored and adamjensenbot committed May 19, 2023
1 parent 77d9f50 commit 60f21ff
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 10 deletions.
22 changes: 13 additions & 9 deletions cmd/liqoctl/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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
}
Expand Down
42 changes: 42 additions & 0 deletions docs/installation/install.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -323,6 +348,11 @@ This operation is necessary in case the default address (`https://<control-plane
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 **k3s** provider exposes *liqo-auth* and *liqo-gateway* with **NodePort** services.
To change this behavior, check the [network flags](NetworkFlags).
```
````
````{tab-item} KinD
Expand All @@ -337,6 +367,10 @@ liqoctl install kind
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 **kind** provider exposes *liqo-auth* and *liqo-gateway* with **NodePort** services.
To change this behavior, check the [network flags](NetworkFlags).
```
````
````{tab-item} Other
Expand All @@ -360,6 +394,11 @@ liqoctl install --api-server-url=<API-SERVER-URL> \
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).
```
````
`````

Expand Down Expand Up @@ -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)=

Expand Down
34 changes: 33 additions & 1 deletion pkg/liqoctl/install/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ 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"
"github.com/liqotech/liqo/pkg/liqoctl/factory"
"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.
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{}{
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/args/enum.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 60f21ff

Please sign in to comment.