diff --git a/tests/e2e-autoscale/autoscale/03-install.yaml b/tests/e2e-autoscale/autoscale/03-install.yaml index 0c2ee6249a..d4401cae3d 100644 --- a/tests/e2e-autoscale/autoscale/03-install.yaml +++ b/tests/e2e-autoscale/autoscale/03-install.yaml @@ -18,4 +18,4 @@ spec: - -duration=1m - -workers=20 restartPolicy: Never - backoffLimit: 4 \ No newline at end of file + backoffLimit: 4 diff --git a/tests/e2e-autoscale/autoscale/05-assert.yaml b/tests/e2e-autoscale/autoscale/05-assert.yaml index dac0c9e105..d67919fa37 100644 --- a/tests/e2e-autoscale/autoscale/05-assert.yaml +++ b/tests/e2e-autoscale/autoscale/05-assert.yaml @@ -4,4 +4,4 @@ metadata: name: simplest-set-utilization status: scale: - replicas: 1 \ No newline at end of file + replicas: 1 diff --git a/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go b/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go index 65b1e7bd53..9126b3295c 100644 --- a/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go +++ b/tests/e2e-autoscale/autoscale/cmd/verify/wait-and-validate-metrics.go @@ -34,17 +34,13 @@ func main() { var hpaName string var timeout time.Duration var numMetrics int - var kubeconfigPath string var cpuValue int var memoryValue int var scaleDownWindow int var scaleUpWindow int - defaultKubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config") - pflag.DurationVar(&timeout, "timeout", 5*time.Minute, "The timeout for the check.") pflag.StringVar(&hpaName, "hpa", "", "HPA to check") - pflag.StringVar(&kubeconfigPath, "kubeconfig-path", defaultKubeconfigPath, "Absolute path to the KubeconfigPath file") pflag.IntVar(&numMetrics, "num-metrics", 1, "number of expected metrics in Spec") pflag.IntVar(&cpuValue, "cpu-value", -1, "value for target CPU utilization") pflag.IntVar(&memoryValue, "memory-value", -1, "value for target memory utilization") @@ -57,7 +53,14 @@ func main() { os.Exit(1) } - config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) + kubeconfigPath := getKubeconfigPath() + + configLoader := clientcmd.NewNonInteractiveDeferredLoadingClientConfig( + &clientcmd.ClientConfigLoadingRules{ExplicitPath: kubeconfigPath}, + &clientcmd.ConfigOverrides{}, + ) + + config, err := configLoader.ClientConfig() if err != nil { fmt.Printf("Error reading the kubeconfig: %s\n", err) os.Exit(1) @@ -170,3 +173,15 @@ func main() { fmt.Printf("%s is ready!\n", hpaName) } + +func getKubeconfigPath() string { + kubeconfigEnv := os.Getenv("KUBECONFIG") + if kubeconfigEnv != "" { + if _, err := os.Stat(kubeconfigEnv); err == nil { + return kubeconfigEnv + } + } + + homeDir := homedir.HomeDir() + return filepath.Join(homeDir, ".kube", "config") +} diff --git a/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go b/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go index 3b74418dd7..51bc7328da 100644 --- a/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go +++ b/tests/e2e-autoscale/autoscale/wait-until-hpa-ready.go @@ -22,7 +22,7 @@ import ( "time" "github.com/spf13/pflag" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" "k8s.io/client-go/kubernetes" "k8s.io/client-go/tools/clientcmd" @@ -37,19 +37,13 @@ func main() { pflag.StringVar(&hpaName, "hpa", "", "HPA to check") pflag.Parse() - kubeconfigEnv := os.Getenv("KUBECONFIG") - kubeconfigPath := filepath.Join(homedir.HomeDir(), ".kube", "config") - if kubeconfigEnv != "" { - if _, err := os.Stat(kubeconfigEnv); err != nil { - kubeconfigPath = kubeconfigEnv - } - } - if len(hpaName) == 0 { fmt.Println("hpa flag is mandatory") os.Exit(1) } + kubeconfigPath := getKubeconfigPath() + config, err := clientcmd.BuildConfigFromFlags("", kubeconfigPath) if err != nil { fmt.Printf("Error reading the kubeconfig: %s\n", err) @@ -62,7 +56,7 @@ func main() { os.Exit(1) } - namespace, err := client.CoreV1().Namespaces().Get(context.Background(), os.Getenv("NAMESPACE"), metav1.GetOptions{}) + namespace, err := client.CoreV1().Namespaces().Get(context.Background(), os.Getenv("NAMESPACE"), v1.GetOptions{}) if err != nil { fmt.Println(err) os.Exit(1) @@ -80,13 +74,13 @@ func main() { hpav2, err := hpaClientV2.Get( c, hpaName, - metav1.GetOptions{}, + v1.GetOptions{}, ) if err != nil { hpav1, err := hpaClientV1.Get( c, hpaName, - metav1.GetOptions{}, + v1.GetOptions{}, ) if err != nil { fmt.Printf("HPA %s not found\n", hpaName) @@ -113,3 +107,15 @@ func main() { fmt.Printf("%s is ready!\n", hpaName) } + +func getKubeconfigPath() string { + kubeconfigEnv := os.Getenv("KUBECONFIG") + if kubeconfigEnv != "" { + if _, err := os.Stat(kubeconfigEnv); err == nil { + return kubeconfigEnv + } + } + + homeDir := homedir.HomeDir() + return filepath.Join(homeDir, ".kube", "config") +} diff --git a/tests/e2e-openshift/Dockerfile b/tests/e2e-openshift/Dockerfile index 715598a539..17e9b46e4b 100644 --- a/tests/e2e-openshift/Dockerfile +++ b/tests/e2e-openshift/Dockerfile @@ -7,15 +7,28 @@ COPY . /tmp/opentelemetry-operator WORKDIR /tmp +# Set the Go path and Go cache environment variables +ENV GOPATH=/tmp/go +ENV GOBIN=/tmp/go/bin +ENV GOCACHE=/tmp/.cache/go-build +ENV PATH=$PATH:$GOBIN + +# Create the /tmp/go/bin and build cache directories, and grant read and write permissions to all users +RUN mkdir -p /tmp/go/bin $GOCACHE \ + && chmod -R 777 /tmp/go/bin $GOPATH $GOCACHE + +# Install dependencies required by test cases and debugging +RUN apt-get update && apt-get install -y jq vim libreadline-dev + # Install kuttl -RUN curl -L -o kuttl https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64 \ - && chmod +x kuttl \ - && mv kuttl /usr/local/bin/kuttl +RUN curl -LO https://github.com/kudobuilder/kuttl/releases/download/v0.15.0/kubectl-kuttl_0.15.0_linux_x86_64 \ + && chmod +x kubectl-kuttl_0.15.0_linux_x86_64 \ + && mv kubectl-kuttl_0.15.0_linux_x86_64 /usr/local/bin/kuttl # Install kubectl and oc -RUN curl -L -o oc.tar.gz https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz \ - && tar -xvzf oc.tar.gz \ - && chmod +x kubectl oc \ +RUN curl -LO https://mirror.openshift.com/pub/openshift-v4/x86_64/clients/ocp/latest/openshift-client-linux.tar.gz \ + && tar -xzf openshift-client-linux.tar.gz \ + && chmod +x oc kubectl \ && mv oc kubectl /usr/local/bin/ # Set the working directory