|
| 1 | +// Copyright 2019-2025 The Liqo Authors |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package liqocontrollermanager |
| 16 | + |
| 17 | +import ( |
| 18 | + "time" |
| 19 | + |
| 20 | + "github.com/spf13/pflag" |
| 21 | + |
| 22 | + "github.com/liqotech/liqo/pkg/consts" |
| 23 | + "github.com/liqotech/liqo/pkg/utils/args" |
| 24 | +) |
| 25 | + |
| 26 | +// InitFlags adds all liqo-controller-manager flags to the given Options struct and parses them. |
| 27 | +func InitFlags(flagset *pflag.FlagSet, opts *Options) { |
| 28 | + // Set up default values for pointer fields |
| 29 | + opts.ClusterLabels = args.StringMap{} |
| 30 | + opts.IngressClasses = args.ClassNameList{} |
| 31 | + opts.LoadBalancerClasses = args.ClassNameList{} |
| 32 | + opts.DefaultNodeResources = args.ResourceMap{} |
| 33 | + opts.GatewayServerResources = args.StringList{} |
| 34 | + opts.GatewayClientResources = args.StringList{} |
| 35 | + opts.GlobalLabels = args.StringMap{} |
| 36 | + opts.GlobalAnnotations = args.StringMap{} |
| 37 | + opts.ClusterIDFlags = args.NewClusterIDFlags(true, nil) |
| 38 | + |
| 39 | + // Cluster-wide modules enable/disable flags |
| 40 | + flagset.BoolVar(&opts.NetworkingEnabled, "networking-enabled", true, "Enable/disable the networking module") |
| 41 | + flagset.BoolVar(&opts.AuthenticationEnabled, "authentication-enabled", true, "Enable/disable the authentication module") |
| 42 | + flagset.BoolVar(&opts.OffloadingEnabled, "offloading-enabled", true, "Enable/disable the offloading module") |
| 43 | + |
| 44 | + // Manager flags |
| 45 | + flagset.IntVar(&opts.WebhookPort, "webhook-port", 9443, "The port the webhook server binds to") |
| 46 | + flagset.StringVar(&opts.MetricsAddr, "metrics-address", ":8082", "The address the metric endpoint binds to") |
| 47 | + flagset.StringVar(&opts.ProbeAddr, "health-probe-address", ":8081", "The address the health probe endpoint binds to") |
| 48 | + flagset.BoolVar(&opts.LeaderElection, "enable-leader-election", false, "Enable leader election for controller manager") |
| 49 | + |
| 50 | + // Global parameters |
| 51 | + flagset.DurationVar(&opts.ResyncPeriod, "resync-period", 10*time.Hour, "The resync period for the informers") |
| 52 | + flagset.StringVar(&opts.LiqoNamespace, "liqo-namespace", consts.DefaultLiqoNamespace, "Name of the namespace where the liqo components are running") |
| 53 | + flagset.IntVar(&opts.ForeignClusterWorkers, "foreign-cluster-workers", 1, "The number of workers used to reconcile ForeignCluster resources.") |
| 54 | + flagset.DurationVar(&opts.ForeignClusterPingInterval, "foreign-cluster-ping-interval", 15*time.Second, |
| 55 | + "The frequency of the ForeignCluster API server readiness check. Set 0 to disable the check") |
| 56 | + flagset.DurationVar(&opts.ForeignClusterPingTimeout, "foreign-cluster-ping-timeout", 5*time.Second, |
| 57 | + "The timeout of the ForeignCluster API server readiness check") |
| 58 | + flagset.StringVar(&opts.DefaultLimitsEnforcement, "default-limits-enforcement", "none", |
| 59 | + "Defines how strict is the enforcement of the quota offered by the remote cluster. Possible values are: none, soft, hard") |
| 60 | + |
| 61 | + // Networking module |
| 62 | + flagset.StringVar(&opts.IPAMServer, "ipam-server", "", "The address of the IPAM server (set to empty string to disable IPAM)") |
| 63 | + flagset.Var(&opts.GatewayServerResources, "gateway-server-resources", |
| 64 | + "The list of resource types that implements the gateway server. They must be in the form <group>/<version>/<resource>") |
| 65 | + flagset.Var(&opts.GatewayClientResources, "gateway-client-resources", |
| 66 | + "The list of resource types that implements the gateway client. They must be in the form <group>/<version>/<resource>") |
| 67 | + flagset.StringVar(&opts.WgGatewayServerClusterRoleName, "wg-gateway-server-cluster-role-name", "liqo-gateway", |
| 68 | + "The name of the cluster role used by the wireguard gateway servers") |
| 69 | + flagset.StringVar(&opts.WgGatewayClientClusterRoleName, "wg-gateway-client-cluster-role-name", "liqo-gateway", |
| 70 | + "The name of the cluster role used by the wireguard gateway clients") |
| 71 | + flagset.BoolVar(&opts.FabricFullMasqueradeEnabled, "fabric-full-masquerade-enabled", false, |
| 72 | + "Enable the full masquerade on the fabric network") |
| 73 | + flagset.BoolVar(&opts.GwmasqbypassEnabled, "gateway-masquerade-bypass-enabled", false, |
| 74 | + "Enable the gateway masquerade bypass") |
| 75 | + flagset.IntVar(&opts.NetworkWorkers, "network-ctrl-workers", 1, |
| 76 | + "The number of workers used to reconcile Network resources.") |
| 77 | + flagset.IntVar(&opts.IPWorkers, "ip-ctrl-workers", 1, |
| 78 | + "The number of workers used to reconcile IP resources.") |
| 79 | + flagset.Uint16Var(&opts.GenevePort, "geneve-port", 6081, "The port used by the Geneve tunnel") |
| 80 | + |
| 81 | + // Authentication module |
| 82 | + flagset.StringVar(&opts.APIServerAddressOverride, "api-server-address-override", "", |
| 83 | + "Override the API server address where the Kuberentes APIServer is exposed") |
| 84 | + flagset.StringVar(&opts.CAOverride, "ca-override", "", "Override the CA certificate used by Kubernetes to sign certificates (base64 encoded)") |
| 85 | + flagset.BoolVar(&opts.TrustedCA, "trusted-ca", false, "Whether the Kubernetes APIServer certificate is issue by a trusted CA") |
| 86 | + flagset.StringVar(&opts.AWSConfig.AwsAccessKeyID, "aws-access-key-id", "", "AWS IAM AccessKeyID for the Liqo User") |
| 87 | + flagset.StringVar(&opts.AWSConfig.AwsSecretAccessKey, "aws-secret-access-key", "", "AWS IAM SecretAccessKey for the Liqo User") |
| 88 | + flagset.StringVar(&opts.AWSConfig.AwsRegion, "aws-region", "", "AWS region where the local cluster is running") |
| 89 | + flagset.StringVar(&opts.AWSConfig.AwsClusterName, "aws-cluster-name", "", "Name of the local EKS cluster") |
| 90 | + flagset.Var(&opts.ClusterLabels, consts.ClusterLabelsParameter, |
| 91 | + "The set of labels which characterizes the local cluster when exposed remotely as a virtual node") |
| 92 | + flagset.Var(&opts.IngressClasses, "ingress-classes", "List of ingress classes offered by the cluster. Example: \"nginx;default,traefik\"") |
| 93 | + flagset.Var(&opts.LoadBalancerClasses, "load-balancer-classes", "List of load balancer classes offered by the cluster. Example:\"metallb;default\"") |
| 94 | + flagset.Var(&opts.DefaultNodeResources, "default-node-resources", "Default resources assigned to the Virtual Node Pod") |
| 95 | + flagset.Var(&opts.GlobalLabels, "global-labels", "The set of labels that will be added to all resources created by Liqo controllers") |
| 96 | + flagset.Var(&opts.GlobalAnnotations, "global-annotations", "The set of annotations that will be added to all resources created by Liqo controllers") |
| 97 | + |
| 98 | + // Offloading module |
| 99 | + flagset.BoolVar(&opts.EnableStorage, "enable-storage", false, "enable the liqo virtual storage class") |
| 100 | + flagset.StringVar(&opts.VirtualStorageClassName, "virtual-storage-class-name", "liqo", "Name of the virtual storage class") |
| 101 | + flagset.StringVar(&opts.RealStorageClassName, "real-storage-class-name", "", "Name of the real storage class to use for the actual volumes") |
| 102 | + flagset.StringVar(&opts.StorageNamespace, "storage-namespace", "liqo-storage", "Namespace where the liqo storage-related resources are stored") |
| 103 | + flagset.BoolVar(&opts.EnableNodeFailureController, "enable-node-failure-controller", false, "Enable the node failure controller") |
| 104 | + flagset.IntVar(&opts.ShadowPodWorkers, "shadow-pod-ctrl-workers", 10, "The number of workers used to reconcile ShadowPod resources.") |
| 105 | + flagset.IntVar(&opts.ShadowEndpointSliceWorkers, "shadow-endpointslice-ctrl-workers", 10, |
| 106 | + "The number of workers used to reconcile ShadowEndpointSlice resources.") |
| 107 | + |
| 108 | + // Cross module |
| 109 | + flagset.BoolVar(&opts.EnableAPIServerIPRemapping, "enable-api-server-ip-remapping", true, "Enable the API server IP remapping") |
| 110 | +} |
0 commit comments