-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
618 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
FROM golang:1.21 as goBuilder | ||
WORKDIR /tmp/builder | ||
|
||
COPY go.mod ./go.mod | ||
COPY go.sum ./go.sum | ||
RUN go mod download | ||
|
||
COPY . ./ | ||
RUN CGO_ENABLED=0 GOOS=linux GOARCH=$(go env GOARCH) go build -ldflags="-s -w" ./cmd/gateway/tunnel/wireguard | ||
|
||
|
||
FROM alpine:3.18 | ||
|
||
RUN apk update && \ | ||
apk add iptables bash wireguard-tools tcpdump conntrack-tools curl && \ | ||
rm -rf /var/cache/apk/* | ||
|
||
COPY --from=goBuilder /tmp/builder/wireguard /usr/bin/liqo-wireguard | ||
|
||
CMD [ "/usr/bin/wireguard" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
// Copyright 2019-2023 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"flag" | ||
"os" | ||
|
||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/client-go/tools/leaderelection/resourcelock" | ||
"k8s.io/klog/v2" | ||
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/client/config" | ||
"sigs.k8s.io/controller-runtime/pkg/log" | ||
|
||
ipamv1alpha1 "github.com/liqotech/liqo/apis/ipam/v1alpha1" | ||
networkingv1alpha1 "github.com/liqotech/liqo/apis/networking/v1alpha1" | ||
"github.com/liqotech/liqo/pkg/gateway/tunnel/wireguard" | ||
"github.com/liqotech/liqo/pkg/utils/mapper" | ||
"github.com/liqotech/liqo/pkg/utils/restcfg" | ||
) | ||
|
||
// cluster-role | ||
// +kubebuilder:rbac:groups=core,resources=secrets,verbs=get;list;create;delete;update | ||
// +kubebuilder:rbac:groups=networking.liqo.io,resources=publickeys,verbs=get;list;create;delete;update | ||
|
||
var ( | ||
addToSchemeFunctions = []func(*runtime.Scheme) error{ | ||
networkingv1alpha1.AddToScheme, | ||
ipamv1alpha1.AddToScheme, | ||
} | ||
) | ||
|
||
func main() { | ||
var err error | ||
ctx := ctrl.SetupSignalHandler() | ||
options := wireguard.Options{} | ||
scheme := runtime.NewScheme() | ||
|
||
// Init flags and check mandatory ones. | ||
restcfg.InitFlags(nil) | ||
klog.InitFlags(nil) | ||
wireguard.InitFlags(&options) | ||
flag.Parse() | ||
if err = wireguard.CheckMandatoryFlags(wireguard.MandatoryFlags); err != nil { | ||
klog.Errorf("Mandatory flags: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Adds the APIs to the scheme. | ||
for _, addToScheme := range addToSchemeFunctions { | ||
if err = addToScheme(scheme); err != nil { | ||
klog.Errorf("unable to add scheme: %v", err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
// Set controller-runtime logger. | ||
log.SetLogger(klog.NewKlogr()) | ||
|
||
// Get the rest config. | ||
cfg := config.GetConfigOrDie() | ||
|
||
// Create the client. This cliend should be used only outside the reconciler. | ||
cl, err := client.New(cfg, client.Options{ | ||
Cache: nil, | ||
}) | ||
if err != nil { | ||
klog.Errorf("unable to create client: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create the manager. | ||
mgr, err := ctrl.NewManager(cfg, ctrl.Options{ | ||
MapperProvider: mapper.LiqoMapperProvider(scheme), | ||
Scheme: scheme, | ||
MetricsBindAddress: options.MetricsAddress, | ||
HealthProbeBindAddress: options.ProbeAddr, | ||
LeaderElection: options.LeaderElection, | ||
LeaderElectionID: "66cf253f.wgtunnel.liqo.io", | ||
LeaderElectionNamespace: options.Namespace, | ||
LeaderElectionReleaseOnCancel: true, | ||
LeaderElectionResourceLock: resourcelock.LeasesResourceLock, | ||
}) | ||
if err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Setup the controller. | ||
pkr, err := wireguard.NewPublicKeysReconciler( | ||
mgr.GetClient(), | ||
mgr.GetScheme(), | ||
mgr.GetEventRecorderFor("wireguard-controller"), | ||
) | ||
if err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Setup the controller. | ||
if err = pkr.SetupWithManager(mgr); err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Ensure presence of Secret with private and public keys. | ||
if err = wireguard.EnsureKeysSecret(ctx, cl, &options); err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
|
||
// Create the wg-liqo interface. | ||
err = wireguard.CreateLink(&options) | ||
if err != nil { | ||
klog.Errorf("unable to create wireguard interface: %v", err) | ||
os.Exit(1) | ||
} | ||
|
||
// Start the manager. | ||
if err = mgr.Start(ctx); err != nil { | ||
klog.Error(err) | ||
os.Exit(1) | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
deployments/liqo/charts/liqo-crds/crds/networking.liqo.io_publickeies.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
--- | ||
apiVersion: apiextensions.k8s.io/v1 | ||
kind: CustomResourceDefinition | ||
metadata: | ||
annotations: | ||
controller-gen.kubebuilder.io/version: v0.13.0 | ||
name: publickeies.networking.liqo.io | ||
spec: | ||
group: networking.liqo.io | ||
names: | ||
categories: | ||
- liqo | ||
kind: PublicKey | ||
listKind: PublicKeyList | ||
plural: publickeies | ||
singular: publickey | ||
scope: Namespaced | ||
versions: | ||
- name: v1alpha1 | ||
schema: | ||
openAPIV3Schema: | ||
description: PublicKey contains a public key data required by some interconnection | ||
technologies. | ||
properties: | ||
apiVersion: | ||
description: 'APIVersion defines the versioned schema of this representation | ||
of an object. Servers should convert recognized schemas to the latest | ||
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources' | ||
type: string | ||
kind: | ||
description: 'Kind is a string value representing the REST resource this | ||
object represents. Servers may infer this from the endpoint the client | ||
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds' | ||
type: string | ||
metadata: | ||
type: object | ||
spec: | ||
description: PublicKeySpec defines the desired state of PublicKey. | ||
properties: | ||
publicKey: | ||
description: PublicKey contains the public key. | ||
format: byte | ||
type: string | ||
type: object | ||
type: object | ||
served: true | ||
storage: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2019-2023 The Liqo Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
// Package wireguard contains the implementation of the wireguard tunnel. | ||
package wireguard |
Oops, something went wrong.