Skip to content

Commit 1b46537

Browse files
committed
fabric: node ips
1 parent 583c4cc commit 1b46537

26 files changed

+567
-36
lines changed

apis/networking/v1alpha1/internalnode_types.go

+19-3
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,28 @@ type InternalNodeSpecInterface struct {
5151
type InternalNodeSpec struct {
5252
// Interface contains the information about network interfaces.
5353
Interface InternalNodeSpecInterface `json:"interface"`
54+
}
55+
56+
// InternalNodeStatusNodeIP defines the observed state of InternalNode.
57+
// It contains the IPs used by an host network pod (scheduled on that node) as src IPs to contact a pod.
58+
type InternalNodeStatusNodeIP struct {
59+
// Local is the src IP used to contact a pod on the same node.
60+
Local *IP `json:"local,omitempty"`
61+
// Remote is the src IP used to contact a pod on another node.
62+
Remote *IP `json:"remote,omitempty"`
63+
}
64+
65+
// InternalNodeStatus defines the observed state of InternalNode.
66+
type InternalNodeStatus struct {
5467
// NodeAddress is the address of the node.
55-
NodeAddress string `json:"nodeAddress"`
68+
NodeIP InternalNodeStatusNodeIP `json:"nodeIP"`
5669
}
5770

5871
// +kubebuilder:object:root=true
5972
// +kubebuilder:resource:scope=Cluster,categories=liqo
60-
// +kubebuilder:printcolumn:name="Node Address",type=string,JSONPath=`.spec.nodeAddress`
73+
// +kubebuilder:subresource:status
74+
// +kubebuilder:printcolumn:name="Node IP Local",type=string,JSONPath=`.status.nodeIP.local`
75+
// +kubebuilder:printcolumn:name="Node IP Remote",type=string,JSONPath=`.status.nodeIP.remote`
6176
// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp`
6277

6378
// InternalNode contains the network internalnode settings.
@@ -66,7 +81,8 @@ type InternalNode struct {
6681
metav1.TypeMeta `json:",inline"`
6782
metav1.ObjectMeta `json:"metadata,omitempty"`
6883

69-
Spec InternalNodeSpec `json:"spec,omitempty"`
84+
Spec InternalNodeSpec `json:"spec,omitempty"`
85+
Status InternalNodeStatus `json:"status,omitempty"`
7086
}
7187

7288
// +kubebuilder:object:root=true

apis/networking/v1alpha1/zz_generated.deepcopy.go

+42
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/fabric/main.go

+39
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,25 @@ import (
2121
"os"
2222

2323
"github.com/spf13/cobra"
24+
corev1 "k8s.io/api/core/v1"
25+
"k8s.io/apimachinery/pkg/labels"
2426
"k8s.io/apimachinery/pkg/runtime"
27+
"k8s.io/apimachinery/pkg/selection"
2528
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
29+
"k8s.io/client-go/rest"
2630
"k8s.io/klog/v2"
2731
ctrl "sigs.k8s.io/controller-runtime"
32+
"sigs.k8s.io/controller-runtime/pkg/cache"
33+
"sigs.k8s.io/controller-runtime/pkg/client"
2834
"sigs.k8s.io/controller-runtime/pkg/client/config"
2935
"sigs.k8s.io/controller-runtime/pkg/log"
3036
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
3137

3238
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1"
3339
"github.com/liqotech/liqo/pkg/fabric"
40+
"github.com/liqotech/liqo/pkg/fabric/sourcedetector"
3441
"github.com/liqotech/liqo/pkg/firewall"
42+
"github.com/liqotech/liqo/pkg/gateway"
3543
"github.com/liqotech/liqo/pkg/route"
3644
flagsutils "github.com/liqotech/liqo/pkg/utils/flags"
3745
"github.com/liqotech/liqo/pkg/utils/mapper"
@@ -45,6 +53,7 @@ var (
4553

4654
func init() {
4755
utilruntime.Must(networkingv1alpha1.AddToScheme(scheme))
56+
utilruntime.Must(corev1.AddToScheme(scheme))
4857
}
4958

5059
func main() {
@@ -79,6 +88,14 @@ func run(cmd *cobra.Command, _ []string) error {
7988
// Get the rest config.
8089
cfg := config.GetConfigOrDie()
8190

91+
// Create a label selector to filter only the events for gateway pods
92+
reqGatewayPods, err := labels.NewRequirement(
93+
gateway.GatewayComponentKey,
94+
selection.Equals,
95+
[]string{gateway.GatewayComponentGateway},
96+
)
97+
utilruntime.Must(err)
98+
8299
// Create the manager.
83100
mgr, err := ctrl.NewManager(cfg, ctrl.Options{
84101
MapperProvider: mapper.LiqoMapperProvider(scheme),
@@ -88,11 +105,33 @@ func run(cmd *cobra.Command, _ []string) error {
88105
},
89106
HealthProbeBindAddress: options.ProbeAddr,
90107
LeaderElection: false,
108+
NewCache: func(config *rest.Config, opts cache.Options) (cache.Cache, error) {
109+
opts.ByObject = map[client.Object]cache.ByObject{
110+
&corev1.Pod{}: {
111+
Label: labels.NewSelector().Add(*reqGatewayPods),
112+
},
113+
}
114+
return cache.New(config, opts)
115+
},
91116
})
92117
if err != nil {
93118
return fmt.Errorf("unable to create manager: %w", err)
94119
}
95120

121+
gwr, err := sourcedetector.NewGatewayReconciler(
122+
mgr.GetClient(),
123+
mgr.GetScheme(),
124+
mgr.GetEventRecorderFor("gateway-controller"),
125+
options,
126+
)
127+
if err != nil {
128+
return fmt.Errorf("unable to create gateway reconciler: %w", err)
129+
}
130+
131+
if err := gwr.SetupWithManager(mgr); err != nil {
132+
return fmt.Errorf("unable to setup gateway reconciler: %w", err)
133+
}
134+
96135
// Setup the firewall configuration controller.
97136
fwcr, err := firewall.NewFirewallConfigurationReconcilerWithFinalizer(
98137
mgr.GetClient(),

cmd/gateway/geneve/main.go

+6
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ func main() {
6262
klog.InitFlags(legacyflags)
6363
flagsutils.FromFlagToPflag(legacyflags, cmd.Flags())
6464

65+
geneve.InitFlags(cmd.Flags(), options)
66+
if err := geneve.MarkFlagsRequired(&cmd); err != nil {
67+
klog.Error(err)
68+
os.Exit(1)
69+
}
70+
6571
gateway.InitFlags(cmd.Flags(), options.GwOptions)
6672
if err := gateway.MarkFlagsRequired(&cmd); err != nil {
6773
klog.Error(err)

cmd/gateway/main.go

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func init() {
5454
}
5555

5656
// +kubebuilder:rbac:groups=coordination.k8s.io,resources=leases,verbs=get;create;update;delete
57-
// +kubebuilder:rbac:groups=core,resources=events,verbs=get;list;watch;create;update;patch;delete
5857

5958
func main() {
6059
var cmd = cobra.Command{

deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_internalnodes.yaml

+27-7
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ spec:
1717
scope: Cluster
1818
versions:
1919
- additionalPrinterColumns:
20-
- jsonPath: .spec.nodeAddress
21-
name: Node Address
20+
- jsonPath: .status.nodeIP.local
21+
name: Node IP Local
22+
type: string
23+
- jsonPath: .status.nodeIP.remote
24+
name: Node IP Remote
2225
type: string
2326
- jsonPath: .metadata.creationTimestamp
2427
name: Age
@@ -62,14 +65,31 @@ spec:
6265
required:
6366
- gateway
6467
type: object
65-
nodeAddress:
66-
description: NodeAddress is the address of the node.
67-
type: string
6868
required:
6969
- interface
70-
- nodeAddress
70+
type: object
71+
status:
72+
description: InternalNodeStatus defines the observed state of InternalNode.
73+
properties:
74+
nodeIP:
75+
description: NodeAddress is the address of the node.
76+
properties:
77+
local:
78+
description: Local is the src IP used to contact a pod on the
79+
same node.
80+
pattern: ^(([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])$
81+
type: string
82+
remote:
83+
description: Remote is the src IP used to contact a pod on another
84+
node.
85+
pattern: ^(([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])\.){3}([1-9]{0,1}[0-9]{0,2}|2[0-4][0-9]|25[0-5])$
86+
type: string
87+
type: object
88+
required:
89+
- nodeIP
7190
type: object
7291
type: object
7392
served: true
7493
storage: true
75-
subresources: {}
94+
subresources:
95+
status: {}

deployments/liqo/files/liqo-fabric-ClusterRole.yaml

+40
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,24 @@
11
rules:
2+
- apiGroups:
3+
- ""
4+
resources:
5+
- events
6+
verbs:
7+
- create
8+
- delete
9+
- get
10+
- list
11+
- patch
12+
- update
13+
- watch
14+
- apiGroups:
15+
- ""
16+
resources:
17+
- pods
18+
verbs:
19+
- get
20+
- list
21+
- watch
222
- apiGroups:
323
- networking.liqo.io
424
resources:
@@ -45,6 +65,26 @@ rules:
4565
- patch
4666
- update
4767
- watch
68+
- apiGroups:
69+
- networking.liqo.io
70+
resources:
71+
- internalnodes
72+
verbs:
73+
- get
74+
- list
75+
- patch
76+
- update
77+
- watch
78+
- apiGroups:
79+
- networking.liqo.io
80+
resources:
81+
- internalnodes/status
82+
verbs:
83+
- get
84+
- list
85+
- patch
86+
- update
87+
- watch
4888
- apiGroups:
4989
- networking.liqo.io
5090
resources:

deployments/liqo/templates/_helpers.tpl

+3-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ app.kubernetes.io/part-of: {{ quote (include "liqo.name" .) }}
7979
{{- end }}
8080

8181
{{/*
82-
Common metadata for Templates
82+
Common metadata for Gateway Templates
8383
*/}}
8484
{{- define "liqo.metadataTemplate" -}}
8585
name: {{ quote "{{ .Name }}" }}
@@ -89,13 +89,14 @@ labels:
8989
{{- end }}
9090

9191
{{/*
92-
Common Labels for Templates
92+
Common Labels for Gateway Templates
9393
*/}}
9494
{{- define "liqo.labelsTemplate" -}}
9595
{{ include "liqo.selectorLabelsTemplate" . }}
9696
helm.sh/chart: {{ quote (include "liqo.chart" .) }}
9797
app.kubernetes.io/version: {{ quote (include "liqo.version" .) }}
9898
app.kubernetes.io/managed-by: {{ quote .Release.Service }}
99+
networking.liqo.io/component: "gateway"
99100
{{- end }}
100101

101102
{{/*

deployments/liqo/templates/liqo-wireguard-gateway-client-template.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,15 @@ spec:
8484
- --namespace={{"{{ .Namespace }}"}}
8585
- --remote-cluster-id={{"{{ .ClusterID }}"}}
8686
- --gateway-uid={{"{{ .GatewayUID }}"}}
87+
- --node-name={{"$(NODE_NAME)"}}
8788
- --mode=server
8889
- --metrics-address=:8084
8990
- --health-probe-bind-address=:8085
91+
env:
92+
- name: NODE_NAME
93+
valueFrom:
94+
fieldRef:
95+
fieldPath: spec.nodeName
9096
securityContext:
9197
capabilities:
9298
add:

deployments/liqo/templates/liqo-wireguard-gateway-server-template.yaml

+6
Original file line numberDiff line numberDiff line change
@@ -96,10 +96,16 @@ spec:
9696
- --name={{"{{ .Name }}"}}
9797
- --namespace={{"{{ .Namespace }}"}}
9898
- --remote-cluster-id={{"{{ .ClusterID }}"}}
99+
- --node-name={{"$(NODE_NAME)"}}
99100
- --gateway-uid={{"{{ .GatewayUID }}"}}
100101
- --mode=server
101102
- --metrics-address=:8084
102103
- --health-probe-bind-address=:8085
104+
env:
105+
- name: NODE_NAME
106+
valueFrom:
107+
fieldRef:
108+
fieldPath: spec.nodeName
103109
securityContext:
104110
capabilities:
105111
add:

0 commit comments

Comments
 (0)