Skip to content

Commit b671739

Browse files
cheina97adamjensenbot
authored andcommitted
Telemetry: E2E tests + VirtualNode scheme
1 parent 3715d0d commit b671739

File tree

5 files changed

+81
-1
lines changed

5 files changed

+81
-1
lines changed

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ E2E_TARGETS = e2e-dir \
200200
ctl \
201201
e2e-infra \
202202
installer/liqoctl/setup \
203+
telemetry \
203204
installer/liqoctl/peer \
204205
e2e/postinstall \
205206
e2e/cruise \
@@ -239,5 +240,8 @@ e2e-infra:
239240
installer/%:
240241
${PWD}/test/e2e/pipeline/$@.sh
241242

243+
telemetry:
244+
${PWD}/test/e2e/pipeline/telemetry/telemetry.sh
245+
242246
e2e/%:
243247
go test ${PWD}/test/$@/... -count=1 -timeout=20m

cmd/telemetry/main.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package main
1717
import (
1818
"context"
1919
"flag"
20+
"fmt"
2021
"os"
2122
"os/signal"
2223
"syscall"
@@ -30,12 +31,14 @@ import (
3031
"sigs.k8s.io/controller-runtime/pkg/log"
3132

3233
discoveryv1alpha1 "github.com/liqotech/liqo/apis/discovery/v1alpha1"
33-
netv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
34+
virtualkubeletv1alpha1 "github.com/liqotech/liqo/apis/net/v1alpha1"
3435
offloadingv1alpha1 "github.com/liqotech/liqo/apis/offloading/v1alpha1"
3536
sharingv1alpha1 "github.com/liqotech/liqo/apis/sharing/v1alpha1"
37+
netv1alpha1 "github.com/liqotech/liqo/apis/virtualkubelet/v1alpha1"
3638
"github.com/liqotech/liqo/pkg/consts"
3739
"github.com/liqotech/liqo/pkg/telemetry"
3840
argsutils "github.com/liqotech/liqo/pkg/utils/args"
41+
"github.com/liqotech/liqo/pkg/utils/json"
3942
"github.com/liqotech/liqo/pkg/utils/mapper"
4043
"github.com/liqotech/liqo/pkg/utils/restcfg"
4144
)
@@ -48,6 +51,7 @@ func init() {
4851
_ = offloadingv1alpha1.AddToScheme(scheme)
4952
_ = sharingv1alpha1.AddToScheme(scheme)
5053
_ = netv1alpha1.AddToScheme(scheme)
54+
_ = virtualkubeletv1alpha1.AddToScheme(scheme)
5155
}
5256

5357
// cluster-role
@@ -65,6 +69,7 @@ func main() {
6569
namespace := flag.String("namespace", "liqo", "the namespace where liqo is deployed")
6670
liqoVersion := flag.String("liqo-version", "", "the liqo version")
6771
kubernetesVersion := flag.String("kubernetes-version", "", "the kubernetes version")
72+
dryRun := flag.Bool("dry-run", false, "if true, do not send the telemetry item and print it on stdout")
6873
flag.Var(&clusterLabels, consts.ClusterLabelsParameter,
6974
"The set of labels which characterizes the local cluster when exposed remotely as a virtual node")
7075

@@ -104,6 +109,11 @@ func main() {
104109
os.Exit(1)
105110
}
106111

112+
if *dryRun {
113+
klog.Infof("dry-run enabled, telemetry item:")
114+
fmt.Println(json.Pretty(telemetryItem))
115+
return
116+
}
107117
err = telemetry.Send(ctx, *telemetryEndpoint, telemetryItem, *timeout)
108118
if err != nil {
109119
klog.Errorf("failed to send telemetry item: %v", err)

pkg/utils/json/doc.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2019-2023 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 json contains some utilities to work with JSON.
16+
package json

pkg/utils/json/json.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2019-2023 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 json
16+
17+
import "encoding/json"
18+
19+
// Pretty returns an indented JSON string to print.
20+
func Pretty(data interface{}) (string, error) {
21+
val, err := json.MarshalIndent(data, "", " ")
22+
if err != nil {
23+
return "", err
24+
}
25+
return string(val), nil
26+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
# This scripts expects the following variables to be set:
4+
# CLUSTER_NUMBER -> the number of liqo clusters
5+
# NAMESPACE -> the namespace where liqo is running
6+
# LIQO_VERSION -> the liqo version to test
7+
# K8S_VERSION -> the Kubernetes version
8+
9+
set -e # Fail in case of error
10+
set -o nounset # Fail if undefined variables are used
11+
set -o pipefail # Fail if one of the piped commands fails
12+
13+
error() {
14+
local sourcefile=$1
15+
local lineno=$2
16+
echo "An error occurred at $sourcefile:$lineno."
17+
}
18+
trap 'error "${BASH_SOURCE}" "${LINENO}"' ERR
19+
20+
for i in $(seq 1 "${CLUSTER_NUMBER}")
21+
do
22+
export KUBECONFIG="${TMPDIR2}/kubeconfigs/liqo_kubeconf_${i}"
23+
go run ./cmd/telemetry/main.go --liqo-version "${LIQO_VERSION}" --kubernetes-version "${K8S_VERSION}" --dry-run
24+
done

0 commit comments

Comments
 (0)