diff --git a/.circleci/config.yml b/.circleci/config.yml index ed251193c544..8422e4ff799a 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -10,6 +10,7 @@ aliases: - &release-regex /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/ - &release-branch-regex /^release-\d+\.\d+$/ - &docker-login echo "$DOCKER_PASS" | docker login -u "$DOCKER_USER" --password-stdin + - &install-cli curl https://get.okteto.com -sSfL | sh parameters: # The following parameters are filled by GH Actions to run CircleCI jobs @@ -155,6 +156,8 @@ jobs: - v4-pkg-cache-{{ checksum "go.sum" }} - attach_workspace: at: ./artifacts + # Install the latest CLI public available, as the actions tests uses the installed version to checkout the action branch to test + - run: *install-cli - run: name: Run actions integration tests command: | diff --git a/integration/k8s-client.go b/integration/k8s-client.go index 5bd8b0f41d16..ad406caab18d 100644 --- a/integration/k8s-client.go +++ b/integration/k8s-client.go @@ -22,45 +22,12 @@ import ( "time" "github.com/okteto/okteto/integration/commands" - "github.com/okteto/okteto/pkg/config" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" - "k8s.io/client-go/rest" - "k8s.io/client-go/tools/clientcmd" - clientcmdapi "k8s.io/client-go/tools/clientcmd/api" ) -// K8sClient returns a kubernetes client for current KUBECONFIG -func K8sClient() (*kubernetes.Clientset, *rest.Config, error) { - clientConfig := getClientConfig(config.GetKubeconfigPath(), "") - - config, err := clientConfig.ClientConfig() - if err != nil { - return nil, nil, err - } - - client, err := kubernetes.NewForConfig(config) - if err != nil { - return nil, nil, err - } - return client, config, nil -} - -func getClientConfig(kubeconfigPaths []string, kubeContext string) clientcmd.ClientConfig { - loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() - loadingRules.DefaultClientConfig = &clientcmd.DefaultClientConfig - loadingRules.Precedence = kubeconfigPaths - return clientcmd.NewNonInteractiveDeferredLoadingClientConfig( - loadingRules, - &clientcmd.ConfigOverrides{ - CurrentContext: kubeContext, - ClusterInfo: clientcmdapi.Cluster{Server: ""}, - }, - ) -} - func GetPodsBySelector(ctx context.Context, ns, selector string, client kubernetes.Interface) (*corev1.PodList, error) { return client.CoreV1().Pods(ns).List(ctx, metav1.ListOptions{LabelSelector: selector}) } diff --git a/integration/okteto.go b/integration/okteto.go index a56f67658ad0..8e9cadc5f16e 100644 --- a/integration/okteto.go +++ b/integration/okteto.go @@ -14,6 +14,7 @@ package integration import ( + "crypto/sha256" "fmt" "io" "log" @@ -26,8 +27,6 @@ import ( "testing" "time" - "github.com/okteto/okteto/pkg/config" - "github.com/okteto/okteto/pkg/k8s/kubeconfig" "github.com/okteto/okteto/pkg/model" "github.com/okteto/okteto/pkg/okteto" ) @@ -79,16 +78,6 @@ func RunOktetoVersion(oktetoPath string) (string, error) { return string(o), nil } -func reduceName(s string) string { - return strings.Map(func(r rune) rune { - switch r { - case 'a', 'e', 'i', 'o', 'u', '_': - return -1 - } - return r - }, s) -} - // GetTestNamespace returns the name for a namespace func GetTestNamespace(name string) string { runtimeOS := runtime.GOOS @@ -97,16 +86,13 @@ func GetTestNamespace(name string) string { } else { runtimeOS = runtimeOS[:3] } - name = reduceName(strings.ToLower(name)) + // To avoid namespace name conflicts, we hash the test name, and add a timestamp and the OS as prefix + sha := fmt.Sprintf("%x", sha256.Sum256([]byte(name))) + finalName := fmt.Sprintf("%d-%s-%s", time.Now().Unix(), runtimeOS, sha[:8]) if prefix := os.Getenv("OKTETO_NAMESPACE_PREFIX"); prefix != "" { - name = fmt.Sprintf("%s-%s", prefix, name) + finalName = fmt.Sprintf("%s-%s", prefix, finalName) } - return strings.ToLower(fmt.Sprintf("%s-%s-%d", name, runtimeOS, time.Now().Unix())) -} - -// GetCurrentNamespace returns the current namespace of the kubeconfig path -func GetCurrentNamespace() string { - return kubeconfig.CurrentNamespace(config.GetKubeconfigPath()) + return finalName } // GetContentFromURL returns the content of the url