From 6e1f7ee96621e868966fb917c91d2884bb3ce560 Mon Sep 17 00:00:00 2001 From: Lorenzo Moro Date: Sat, 12 Oct 2024 17:37:52 +0200 Subject: [PATCH] Reformatted following linting --- cmd/network-manager/doc.go | 2 +- cmd/network-manager/main.go | 3 +-- pkg/network-manager/doc.go | 2 +- pkg/network-manager/network-controller.go | 7 ++++--- pkg/utils/namings/namings.go | 6 +++--- pkg/utils/resourceforge/forge.go | 6 +++--- tools/scripts/environment.sh | 24 +++++++++++------------ 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cmd/network-manager/doc.go b/cmd/network-manager/doc.go index 6f37ab0..c5e3f0b 100644 --- a/cmd/network-manager/doc.go +++ b/cmd/network-manager/doc.go @@ -1,4 +1,4 @@ -// Copyright 2022-2023 FLUIDOS Project +// Copyright 2022-2024 FLUIDOS Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/cmd/network-manager/main.go b/cmd/network-manager/main.go index a75deb2..ffdb0ef 100644 --- a/cmd/network-manager/main.go +++ b/cmd/network-manager/main.go @@ -1,4 +1,4 @@ -// Copyright 2022-2023 FLUIDOS Project +// Copyright 2022-2024 FLUIDOS Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -83,7 +83,6 @@ func main() { setupLog.Error(err, "Unable to start NetworkManager") os.Exit(1) } - } func healthHandler(w http.ResponseWriter, _ *http.Request) { diff --git a/pkg/network-manager/doc.go b/pkg/network-manager/doc.go index 83a3ce9..8560764 100644 --- a/pkg/network-manager/doc.go +++ b/pkg/network-manager/doc.go @@ -1,4 +1,4 @@ -// Copyright 2022-2023 FLUIDOS Project +// Copyright 2022-2024 FLUIDOS Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. diff --git a/pkg/network-manager/network-controller.go b/pkg/network-manager/network-controller.go index ecf6c72..8d3ec31 100644 --- a/pkg/network-manager/network-controller.go +++ b/pkg/network-manager/network-controller.go @@ -33,10 +33,12 @@ import ( // +kubebuilder:rbac:groups=network.fluidos.eu,resources=clusters,verbs=get;list;watch;create;update;patch;delete // +kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch +// ClusterInfo keeps the address of the discovered cluster type ClusterInfo struct { Address string `json:"address"` } +// NetworkManager keeps all the necessary class data type NetworkManager struct { context context.Context client client.Client @@ -46,7 +48,6 @@ type NetworkManager struct { } func (nm *NetworkManager) sendMulticastMessage(multicastAddress string) error { - info := ClusterInfo{ Address: nm.address, } @@ -79,7 +80,6 @@ func (nm *NetworkManager) sendMulticastMessage(multicastAddress string) error { } func (nm *NetworkManager) receiveMulticastMessage(multicastAddress string) error { - addr, err := net.ResolveUDPAddr("udp", multicastAddress) if err != nil { return err @@ -128,6 +128,7 @@ func (nm *NetworkManager) receiveMulticastMessage(multicastAddress string) error } } +// This is the entrypoint of the Network Manager func Start(ctx context.Context, cl client.Client) error { fmt.Println("Starting Kubernetes cluster discovery") @@ -179,7 +180,7 @@ func Start(ctx context.Context, cl client.Client) error { } }() - // Block until context is cancelled + // Block until context is canceled <-ctx.Done() return nil } diff --git a/pkg/utils/namings/namings.go b/pkg/utils/namings/namings.go index 7b97a3b..c86f88a 100644 --- a/pkg/utils/namings/namings.go +++ b/pkg/utils/namings/namings.go @@ -125,9 +125,9 @@ func RetrieveFlavorNameFromPC(pcName string) string { } // ForgeClusterName generates a name for the Cluster. -func ForgeClusterName(IPaddress string) string { - hash := ForgeHashString(IPaddress, 4) - return fmt.Sprintf("cluster-%s-%s", strings.Replace(strings.Replace(IPaddress, ":", "-", -1), ".", "-", -1), hash) +func ForgeClusterName(address string) string { + hash := ForgeHashString(address, 4) + return fmt.Sprintf("cluster-%s-%s", strings.ReplaceAll(strings.ReplaceAll(address, ":", "-"), ".", "-"), hash) } // ForgeRandomString generates a random string of 16 bytes. diff --git a/pkg/utils/resourceforge/forge.go b/pkg/utils/resourceforge/forge.go index 0cf72ff..b8d4849 100644 --- a/pkg/utils/resourceforge/forge.go +++ b/pkg/utils/resourceforge/forge.go @@ -1433,12 +1433,12 @@ func ForgeSecretForService(contract *reservationv1alpha1.Contract, } // ForgeCluster creates a Cluster from a String. -func ForgeCluster(IPaddress string) *networkv1alpha1.Cluster { +func ForgeCluster(address string) *networkv1alpha1.Cluster { return &networkv1alpha1.Cluster{ ObjectMeta: metav1.ObjectMeta{ - Name: namings.ForgeClusterName(IPaddress), + Name: namings.ForgeClusterName(address), Namespace: flags.FluidosNamespace, }, - Address: IPaddress, + Address: address, } } diff --git a/tools/scripts/environment.sh b/tools/scripts/environment.sh index 6622339..297be9d 100644 --- a/tools/scripts/environment.sh +++ b/tools/scripts/environment.sh @@ -74,14 +74,14 @@ create_kind_clusters() { kind create cluster --name "$name" --config "$SCRIPT_DIR"/../../quickstart/kind/configs/standard.yaml --kubeconfig "$SCRIPT_DIR"/"$name"-config -q # Install macvlan plugin to enable multicast node discovery, if required if [ "$6" == "true" ]; then - num_workers=$(kind get nodes --name fluidos-consumer-1 | grep worker | wc -l) + num_workers=$(kind get nodes --name fluidos-consumer-1 | grep worker -c) for j in $(seq 1 "$num_workers"); do ( - docker exec --workdir /tmp "$name"-worker$([ $j = 1 ] && echo "" || echo $j) mkdir -p cni-plugins - docker exec --workdir /tmp/cni-plugins "$name"-worker$([ $j = 1 ] && echo "" || echo $j) curl -LO https://github.com/containernetworking/plugins/releases/download/v1.5.1/cni-plugins-linux-amd64-v1.5.1.tgz - docker exec --workdir /tmp/cni-plugins "$name"-worker$([ $j = 1 ] && echo "" || echo $j) tar xvfz cni-plugins-linux-amd64-v1.5.1.tgz - docker exec --workdir /tmp/cni-plugins "$name"-worker$([ $j = 1 ] && echo "" || echo $j) cp macvlan /opt/cni/bin - docker exec --workdir /tmp "$name"-worker$([ $j = 1 ] && echo "" || echo $j) rm -r cni-plugins + docker exec --workdir /tmp "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" mkdir -p cni-plugins + docker exec --workdir /tmp/cni-plugins "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" curl -LO https://github.com/containernetworking/plugins/releases/download/v1.5.1/cni-plugins-linux-amd64-v1.5.1.tgz + docker exec --workdir /tmp/cni-plugins "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" tar xvfz cni-plugins-linux-amd64-v1.5.1.tgz + docker exec --workdir /tmp/cni-plugins "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" cp macvlan /opt/cni/bin + docker exec --workdir /tmp "$name"-worker"$([ $j = 1 ] && echo "" || echo $j)" rm -r cni-plugins ) done fi @@ -106,14 +106,14 @@ create_kind_clusters() { kind create cluster --name "$name" --config "$SCRIPT_DIR"/../../quickstart/kind/configs/standard.yaml --kubeconfig "$SCRIPT_DIR"/"$name"-config -q # Install macvlan plugin to enable multicast node discovery, if required if [ "$6" == "true" ]; then - num_workers=$(kind get nodes --name fluidos-provider-1 | grep worker | wc -l) + num_workers=$(kind get nodes --name fluidos-provider-1 | grep worker -c) for j in $(seq 1 "$num_workers"); do ( - docker exec --workdir /tmp "$name"-worker$([ $j = 1 ] && echo "" || echo $j) mkdir -p cni-plugins - docker exec --workdir /tmp/cni-plugins "$name"-worker$([ $j = 1 ] && echo "" || echo $j) curl -LO https://github.com/containernetworking/plugins/releases/download/v1.5.1/cni-plugins-linux-amd64-v1.5.1.tgz - docker exec --workdir /tmp/cni-plugins "$name"-worker$([ $j = 1 ] && echo "" || echo $j) tar xvfz cni-plugins-linux-amd64-v1.5.1.tgz - docker exec --workdir /tmp/cni-plugins "$name"-worker$([ $j = 1 ] && echo "" || echo $j) cp macvlan /opt/cni/bin - docker exec --workdir /tmp "$name"-worker$([ $j = 1 ] && echo "" || echo $j) rm -r cni-plugins + docker exec --workdir /tmp "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" mkdir -p cni-plugins + docker exec --workdir /tmp/cni-plugins "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" curl -LO https://github.com/containernetworking/plugins/releases/download/v1.5.1/cni-plugins-linux-amd64-v1.5.1.tgz + docker exec --workdir /tmp/cni-plugins "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" tar xvfz cni-plugins-linux-amd64-v1.5.1.tgz + docker exec --workdir /tmp/cni-plugins "$name"-worker"$([ "$j" = 1 ] && echo "" || echo "$j")" cp macvlan /opt/cni/bin + docker exec --workdir /tmp "$name"-worker"$([ $j = 1 ] && echo "" || echo $j)" rm -r cni-plugins ) done fi