Skip to content

Commit 0195d74

Browse files
cheina97adamjensenbot
authored andcommitted
refactor: liqo-controller-manager flags
1 parent 708f51c commit 0195d74

File tree

7 files changed

+349
-231
lines changed

7 files changed

+349
-231
lines changed

cmd/liqo-controller-manager/main.go

Lines changed: 83 additions & 229 deletions
Large diffs are not rendered by default.

cmd/liqo-controller-manager/modules/authentication.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1"
2626
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
27+
liqocontrollermanager "github.com/liqotech/liqo/pkg/liqo-controller-manager"
2728
"github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication"
2829
identitycontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication/identity-controller"
2930
identitycreatorcontroller "github.com/liqotech/liqo/pkg/liqo-controller-manager/authentication/identitycreator-controller"
@@ -49,6 +50,28 @@ type AuthOption struct {
4950
SliceStatusOptions *remoteresourceslicecontroller.SliceStatusOptions
5051
}
5152

53+
// NewAuthOption creates a new AuthOption with the given parameters.
54+
func NewAuthOption(identityProvider identitymanager.IdentityProvider, namespaceManager tenantnamespace.Manager,
55+
clusterID liqov1beta1.ClusterID, opts *liqocontrollermanager.Options) *AuthOption {
56+
return &AuthOption{
57+
IdentityProvider: identityProvider,
58+
NamespaceManager: namespaceManager,
59+
LocalClusterID: clusterID,
60+
LiqoNamespace: opts.LiqoNamespace,
61+
APIServerAddressOverride: opts.APIServerAddressOverride,
62+
CAOverrideB64: opts.CAOverride,
63+
TrustedCA: opts.TrustedCA,
64+
SliceStatusOptions: &remoteresourceslicecontroller.SliceStatusOptions{
65+
EnableStorage: opts.EnableStorage,
66+
LocalRealStorageClassName: opts.RealStorageClassName,
67+
IngressClasses: opts.IngressClasses,
68+
LoadBalancerClasses: opts.LoadBalancerClasses,
69+
ClusterLabels: opts.ClusterLabels.StringMap,
70+
DefaultResourceQuantity: opts.DefaultNodeResources.ToResourceList(),
71+
},
72+
}
73+
}
74+
5275
// SetupAuthenticationModule setup the authentication module and initializes its controllers .
5376
func SetupAuthenticationModule(ctx context.Context, mgr manager.Manager, uncachedClient client.Client,
5477
opts *AuthOption) error {

cmd/liqo-controller-manager/modules/networking.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626

2727
ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1"
2828
"github.com/liqotech/liqo/pkg/ipam"
29+
liqocontrollermanager "github.com/liqotech/liqo/pkg/liqo-controller-manager"
2930
clientoperator "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/client-operator"
3031
configuration "github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/configuration"
3132
"github.com/liqotech/liqo/pkg/liqo-controller-manager/networking/external-network/remapping"
@@ -65,6 +66,29 @@ type NetworkingOption struct {
6566
GenevePort uint16
6667
}
6768

69+
// NewNetworkingOption creates a new NetworkingOption with the provided parameters.
70+
func NewNetworkingOption(factory *dynamicutils.RunnableFactory, dynClient dynamic.Interface,
71+
ipamClient ipam.IPAMClient, opts *liqocontrollermanager.Options) *NetworkingOption {
72+
return &NetworkingOption{
73+
DynClient: dynClient,
74+
Factory: factory,
75+
76+
LiqoNamespace: opts.LiqoNamespace,
77+
IpamClient: ipamClient,
78+
79+
GatewayServerResources: opts.GatewayServerResources.StringList,
80+
GatewayClientResources: opts.GatewayClientResources.StringList,
81+
WgGatewayServerClusterRoleName: opts.WgGatewayServerClusterRoleName,
82+
WgGatewayClientClusterRoleName: opts.WgGatewayClientClusterRoleName,
83+
NetworkWorkers: opts.NetworkWorkers,
84+
IPWorkers: opts.IPWorkers,
85+
FabricFullMasquerade: opts.FabricFullMasqueradeEnabled,
86+
GwmasqbypassEnabled: opts.GwmasqbypassEnabled,
87+
88+
GenevePort: opts.GenevePort,
89+
}
90+
}
91+
6892
// SetupNetworkingModule setup the networking module and initializes its controllers .
6993
func SetupNetworkingModule(ctx context.Context, mgr manager.Manager, uncachedClient client.Client, opts *NetworkingOption) error {
7094
// Initialize reserved networks

cmd/liqo-controller-manager/modules/offloading.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030

3131
liqov1beta1 "github.com/liqotech/liqo/apis/core/v1beta1"
3232
"github.com/liqotech/liqo/pkg/consts"
33+
liqocontrollermanager "github.com/liqotech/liqo/pkg/liqo-controller-manager"
3334
mapsctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/offloading/namespacemap-controller"
3435
nsoffctrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/offloading/namespaceoffloading-controller"
3536
nodefailurectrl "github.com/liqotech/liqo/pkg/liqo-controller-manager/offloading/nodefailure-controller"
@@ -57,6 +58,24 @@ type OffloadingOption struct {
5758
ResyncPeriod time.Duration
5859
}
5960

61+
// NewOffloadingOption creates a new OffloadingOption with the given parameters.
62+
func NewOffloadingOption(clientset *kubernetes.Clientset, localClusterID liqov1beta1.ClusterID,
63+
namespaceManager tenantnamespace.Manager, opts *liqocontrollermanager.Options) *OffloadingOption {
64+
return &OffloadingOption{
65+
Clientset: clientset,
66+
LocalClusterID: localClusterID,
67+
NamespaceManager: namespaceManager,
68+
EnableStorage: opts.EnableStorage,
69+
VirtualStorageClassName: opts.VirtualStorageClassName,
70+
RealStorageClassName: opts.RealStorageClassName,
71+
StorageNamespace: opts.StorageNamespace,
72+
EnableNodeFailureController: opts.EnableNodeFailureController,
73+
ShadowPodWorkers: opts.ShadowPodWorkers,
74+
ShadowEndpointSliceWorkers: opts.ShadowEndpointSliceWorkers,
75+
ResyncPeriod: opts.ResyncPeriod,
76+
}
77+
}
78+
6079
// SetupOffloadingModule setup the offloading module and initializes its controllers.
6180
func SetupOffloadingModule(ctx context.Context, mgr manager.Manager, opts *OffloadingOption) error {
6281
virtualNodeReconciler, err := virtualnodectrl.NewVirtualNodeReconciler(
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
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+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
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+
identitymanager "github.com/liqotech/liqo/pkg/identityManager"
21+
"github.com/liqotech/liqo/pkg/utils/args"
22+
)
23+
24+
// Options holds all configuration flags for the liqo-controller-manager.
25+
type Options struct {
26+
// Cluster-wide modules enable/disable flags
27+
NetworkingEnabled bool
28+
AuthenticationEnabled bool
29+
OffloadingEnabled bool
30+
31+
// Manager flags
32+
WebhookPort int
33+
MetricsAddr string
34+
ProbeAddr string
35+
LeaderElection bool
36+
37+
// Global parameters
38+
ResyncPeriod time.Duration
39+
ClusterIDFlags *args.ClusterIDFlags
40+
LiqoNamespace string
41+
ForeignClusterWorkers int
42+
ForeignClusterPingInterval time.Duration
43+
ForeignClusterPingTimeout time.Duration
44+
DefaultLimitsEnforcement string
45+
46+
// Networking module
47+
IPAMServer string
48+
GatewayServerResources args.StringList
49+
GatewayClientResources args.StringList
50+
WgGatewayServerClusterRoleName string
51+
WgGatewayClientClusterRoleName string
52+
FabricFullMasqueradeEnabled bool
53+
GwmasqbypassEnabled bool
54+
NetworkWorkers int
55+
IPWorkers int
56+
GenevePort uint16
57+
58+
// Authentication module
59+
APIServerAddressOverride string
60+
CAOverride string
61+
TrustedCA bool
62+
AWSConfig *identitymanager.LocalAwsConfig
63+
ClusterLabels args.StringMap
64+
IngressClasses args.ClassNameList
65+
LoadBalancerClasses args.ClassNameList
66+
DefaultNodeResources args.ResourceMap
67+
GlobalLabels args.StringMap
68+
GlobalAnnotations args.StringMap
69+
70+
// Offloading module
71+
EnableStorage bool
72+
VirtualStorageClassName string
73+
RealStorageClassName string
74+
StorageNamespace string
75+
EnableNodeFailureController bool
76+
ShadowPodWorkers int
77+
ShadowEndpointSliceWorkers int
78+
79+
// Cross module
80+
EnableAPIServerIPRemapping bool
81+
}
82+
83+
// NewOptions creates a new Options struct with default values.
84+
func NewOptions() *Options {
85+
return &Options{
86+
AWSConfig: &identitymanager.LocalAwsConfig{},
87+
}
88+
}

pkg/utils/args/cluster-identity.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ var _ flag.Value = &ClusterIDFlags{}
4343
// fcFlags := NewClusterIDFlags(false, nil)
4444
// flag.Parse()
4545
// foreignClusterID := fcFlags.Read()
46-
func NewClusterIDFlags(local bool, flags *pflag.FlagSet) ClusterIDFlags {
46+
func NewClusterIDFlags(local bool, flags *pflag.FlagSet) *ClusterIDFlags {
4747
var prefix, description string
4848
if local {
4949
prefix = "cluster" //nolint:goconst // No need to make the word "cluster" a const...
@@ -55,7 +55,7 @@ func NewClusterIDFlags(local bool, flags *pflag.FlagSet) ClusterIDFlags {
5555
if flags == nil {
5656
flags = pflag.CommandLine
5757
}
58-
return ClusterIDFlags{
58+
return &ClusterIDFlags{
5959
local: local,
6060
ClusterID: flags.String(fmt.Sprintf("%s-id", prefix), "", fmt.Sprintf(description, "ID")),
6161
}

0 commit comments

Comments
 (0)