forked from open-telemetry/opentelemetry-operator
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[chore] Change the E2E automation to run the tests in OpenShift (open…
…-telemetry#1254) * Run the E2E tests in OpenShift Signed-off-by: Israel Blancas <[email protected]> * Set version for GitHub Actions workflow Signed-off-by: Israel Blancas <[email protected]> * Fix CI Signed-off-by: Israel Blancas <[email protected]> * Apply some changes to simplify the upgrade E2E test Signed-off-by: Israel Blancas <[email protected]> * Fix CI Signed-off-by: Israel Blancas <[email protected]> * Fix CI Signed-off-by: Israel Blancas <[email protected]> * Install OpenShift routes only if needed Signed-off-by: Israel Blancas <[email protected]> * Trigger Build Signed-off-by: Israel Blancas <[email protected]> * Remove cert-manager installation from deployment step Signed-off-by: Israel Blancas <[email protected]> * Trigger Build Signed-off-by: Israel Blancas <[email protected]> * Ensure the webhook don't fail when kubectl apply Signed-off-by: Israel Blancas <[email protected]> * Fix coding standard issues Signed-off-by: Israel Blancas <[email protected]> * Fix coding standard issues Signed-off-by: Israel Blancas <[email protected]> * Increase timeout for golangci Signed-off-by: Israel Blancas <[email protected]> * Apply changes requested in CR Signed-off-by: Israel Blancas <[email protected]> * Change timeout to 500ms Signed-off-by: Israel Blancas <[email protected]> * Change program file name Signed-off-by: Israel Blancas <[email protected]> * Do the check without depending on a manifest file Signed-off-by: Israel Blancas <[email protected]> * Change program file name Signed-off-by: Israel Blancas <[email protected]> Signed-off-by: Israel Blancas <[email protected]>
- Loading branch information
Showing
10 changed files
with
185 additions
and
44 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
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,128 @@ | ||
// Copyright The OpenTelemetry 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 ( | ||
"context" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"time" | ||
|
||
appsv1 "k8s.io/api/apps/v1" | ||
k8sruntime "k8s.io/apimachinery/pkg/runtime" | ||
utilruntime "k8s.io/apimachinery/pkg/util/runtime" | ||
"k8s.io/apimachinery/pkg/util/wait" | ||
|
||
"github.com/spf13/pflag" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/client-go/tools/clientcmd" | ||
"k8s.io/client-go/util/homedir" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
otelv1alpha1 "github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1" | ||
) | ||
|
||
var scheme *k8sruntime.Scheme | ||
|
||
func init() { | ||
scheme = k8sruntime.NewScheme() | ||
utilruntime.Must(otelv1alpha1.AddToScheme(scheme)) | ||
utilruntime.Must(appsv1.AddToScheme(scheme)) | ||
} | ||
|
||
func main() { | ||
var timeout int | ||
var kubeconfigPath string | ||
|
||
defaultKubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config") | ||
|
||
pflag.IntVar(&timeout, "timeout", 300, "The timeout for the check.") | ||
pflag.StringVar(&kubeconfigPath, "kubeconfig-path", defaultKubeconfigPath, "Absolute path to the KubeconfigPath file") | ||
pflag.Parse() | ||
|
||
pollInterval := 500 * time.Millisecond | ||
timeoutPoll := time.Duration(timeout) * time.Second | ||
|
||
config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) | ||
if err != nil { | ||
println("Error reading the kubeconfig:", err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
clusterClient, err := client.New(config, client.Options{Scheme: scheme}) | ||
if err != nil { | ||
println("Creating the Kubernetes client", err) | ||
os.Exit(1) | ||
} | ||
|
||
fmt.Println("Waiting until the OTEL Collector Operator is deployed") | ||
operatorDeployment := &appsv1.Deployment{} | ||
|
||
err = wait.Poll(pollInterval, timeoutPoll, func() (done bool, err error) { | ||
err = clusterClient.Get( | ||
context.Background(), | ||
client.ObjectKey{ | ||
Name: "opentelemetry-operator-controller-manager", | ||
Namespace: "opentelemetry-operator-system", | ||
}, | ||
operatorDeployment, | ||
) | ||
if err != nil { | ||
fmt.Println(err) | ||
return false, nil | ||
} | ||
return true, nil | ||
}) | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
fmt.Println("OTEL Collector Operator is deployed properly!") | ||
|
||
// Sometimes, the deployment of the OTEL Operator is ready but, when | ||
// creating new instances of the OTEL Collector, the webhook is not reachable | ||
// and kubectl apply fails. This code deployes an OTEL Collector instance | ||
// until success (or timeout) | ||
collectorInstance := otelv1alpha1.OpenTelemetryCollector{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: "operator-check", | ||
Namespace: "default", | ||
}, | ||
} | ||
|
||
// Ensure the collector is not there before the check | ||
_ = clusterClient.Delete(context.Background(), &collectorInstance) | ||
|
||
fmt.Println("Ensure the creation of OTEL Collectors is available") | ||
err = wait.Poll(pollInterval, timeoutPoll, func() (done bool, err error) { | ||
err = clusterClient.Create( | ||
context.Background(), | ||
&collectorInstance, | ||
) | ||
if err != nil { | ||
fmt.Println(err) | ||
return false, nil | ||
} | ||
return true, nil | ||
}) | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
|
||
_ = clusterClient.Delete(context.Background(), &collectorInstance) | ||
} |
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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
#!/bin/bash | ||
|
||
# Install metrics-server on kind clusters for autoscale tests. Note: This is not needed for minikube, | ||
# Install metrics-server on kind clusters for autoscale tests. | ||
# Note: This is not needed for minikube, | ||
# you can just add --addons "metrics-server" to the start command. | ||
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml | ||
kubectl patch deployment -n kube-system metrics-server --type "json" -p '[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": --kubelet-insecure-tls}]' | ||
kubectl wait --for=condition=available deployment/metrics-server -n kube-system --timeout=5m | ||
|
||
|
||
if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then | ||
echo "Connected to an OpenShift cluster. metrics-server installation is not needed" | ||
elif [[ "$(kubectl get deployment metrics-server -n kube-system 2>&1 )" =~ "NotFound" ]]; then | ||
kubectl apply -f https://github.com/kubernetes-sigs/metrics-server/releases/latest/download/components.yaml | ||
kubectl patch deployment -n kube-system metrics-server --type "json" -p '[{"op": "add", "path": "/spec/template/spec/containers/0/args/-", "value": --kubelet-insecure-tls}]' | ||
kubectl wait --for=condition=available deployment/metrics-server -n kube-system --timeout=5m | ||
else | ||
echo "metrics-server is installed. Skipping installation" | ||
fi |
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
#!/bin/bash | ||
|
||
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/router_rbac.yaml | ||
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/route_crd.yaml | ||
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/router.yaml | ||
kubectl wait --for=condition=available deployment/ingress-router -n openshift-ingress --timeout=5m | ||
if [[ "$(kubectl api-resources)" =~ "openshift" ]]; then | ||
echo "Connected to an OpenShift cluster. OpenShift routes installation is not needed" | ||
else | ||
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/router_rbac.yaml | ||
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/route_crd.yaml | ||
kubectl apply -f https://raw.githubusercontent.com/openshift/router/release-4.12/deploy/router.yaml | ||
kubectl wait --for=condition=available deployment/ingress-router -n openshift-ingress --timeout=5m | ||
fi |
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,4 @@ | ||
#!/bin/bash | ||
|
||
sed -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/smoke-targetallocator/00-install.yaml | ||
sed -i "s#local/opentelemetry-operator-targetallocator:e2e#${TARGETALLOCATOR_IMG}#g" tests/e2e/targetallocator-features/00-install.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
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 |
---|---|---|
@@ -1,14 +1,6 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestSuite | ||
crdDir: ./tests/_build/crds/ | ||
artifactsDir: ./tests/_build/artifacts/ | ||
kindContainers: | ||
- local/opentelemetry-operator:e2e | ||
commands: | ||
- command: make cert-manager | ||
- command: kubectl apply -f ./tests/_build/manifests/01-opentelemetry-operator.yaml | ||
- command: kubectl wait --timeout=5m --for=condition=available deployment opentelemetry-operator-controller-manager -n opentelemetry-operator-system | ||
- command: sleep 5s | ||
testDirs: | ||
- ./tests/e2e/ | ||
timeout: 150 |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestStep | ||
commands: | ||
- command: kubectl apply -f ../../_build/manifests/01-opentelemetry-operator.yaml | ||
- command: kubectl rollout status -w deployment/opentelemetry-operator-controller-manager -n opentelemetry-operator-system | ||
- command: sleep 60s | ||
- script: cd ../../../ && make deploy VERSION=e2e |