diff --git a/.gitignore b/.gitignore index d9cfd93bd77..6334d88b1bf 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,6 @@ site/.docusaurus/ site/node_modules/ hack/tools/bin + +#vscode +.vscode/ diff --git a/go.mod b/go.mod index 100b659f47e..a00a734892c 100644 --- a/go.mod +++ b/go.mod @@ -212,7 +212,7 @@ require ( k8s.io/apiserver v0.29.3 // indirect k8s.io/component-base v0.29.3 // indirect k8s.io/cri-api v0.29.2 // indirect - oras.land/oras-go v1.2.4 // indirect + oras.land/oras-go v1.2.5 // indirect sigs.k8s.io/kustomize/api v0.14.0 // indirect sigs.k8s.io/kustomize/kyaml v0.14.3 // indirect ) diff --git a/go.sum b/go.sum index dc2e4ad00a9..4f3a16c4337 100644 --- a/go.sum +++ b/go.sum @@ -1121,8 +1121,8 @@ k8s.io/kubectl v0.29.3 h1:RuwyyIU42MAISRIePaa8Q7A3U74Q9P4MoJbDFz9o3us= k8s.io/kubectl v0.29.3/go.mod h1:yCxfY1dbwgVdEt2zkJ6d5NNLOhhWgTyrqACIoFhpdd4= k8s.io/utils v0.0.0-20231127182322-b307cd553661 h1:FepOBzJ0GXm8t0su67ln2wAZjbQ6RxQGZDnzuLcrUTI= k8s.io/utils v0.0.0-20231127182322-b307cd553661/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= -oras.land/oras-go v1.2.4 h1:djpBY2/2Cs1PV87GSJlxv4voajVOMZxqqtq9AB8YNvY= -oras.land/oras-go v1.2.4/go.mod h1:DYcGfb3YF1nKjcezfX2SNlDAeQFKSXmf+qrFmrh4324= +oras.land/oras-go v1.2.5 h1:XpYuAwAb0DfQsunIyMfeET92emK8km3W4yEzZvUbsTo= +oras.land/oras-go v1.2.5/go.mod h1:PuAwRShRZCsZb7g8Ar3jKKQR/2A/qN+pkYxIOd/FAoo= sigs.k8s.io/controller-runtime v0.13.1-0.20230315234915-a26de2d610c3 h1:fic0YtUGSr79nv8vn3ziNZJrPZsm64KT/Fd/bc7Q6xY= sigs.k8s.io/controller-runtime v0.13.1-0.20230315234915-a26de2d610c3/go.mod h1:Qox07m8Gh7skSeOfppEWllPxNMhA7+b93D8Qjj6rBlQ= sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo= diff --git a/test/e2e/framework/azure/create-cluster-with-npm.go b/test/e2e/framework/azure/create-cluster-with-npm.go index 4c2c62609d8..709ed3bfb11 100644 --- a/test/e2e/framework/azure/create-cluster-with-npm.go +++ b/test/e2e/framework/azure/create-cluster-with-npm.go @@ -18,9 +18,11 @@ var ( ) const ( - clusterTimeout = 10 * time.Minute - AgentARMSKU = "Standard_D4pls_v5" - AuxilaryNodeCount = 1 + clusterTimeout = 10 * time.Minute + clusterCreateTicker = 30 * time.Second + pollFrequency = 5 * time.Second + AgentARMSKU = "Standard_D4pls_v5" + AuxilaryNodeCount = 1 ) type CreateNPMCluster struct { @@ -49,7 +51,8 @@ func (c *CreateNPMCluster) Run() error { npmCluster.Properties.NetworkProfile.NetworkPolicy = to.Ptr(armcontainerservice.NetworkPolicyAzure) - npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ + //nolint:appendCombine // separate for verbosity + npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ //nolint:all Type: to.Ptr(armcontainerservice.AgentPoolTypeVirtualMachineScaleSets), AvailabilityZones: []*string{to.Ptr("1")}, Count: to.Ptr[int32](AuxilaryNodeCount), @@ -64,6 +67,7 @@ func (c *CreateNPMCluster) Run() error { }) /* todo: add azlinux node pool + //nolint:appendCombine // separate for verbosity npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ Type: to.Ptr(armcontainerservice.AgentPoolTypeVirtualMachineScaleSets), AvailabilityZones: []*string{to.Ptr("1")}, @@ -78,7 +82,8 @@ func (c *CreateNPMCluster) Run() error { MaxPods: to.Ptr(int32(azure.MaxPodsPerNode)), }) */ - npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ + //nolint:appendCombine // separate for verbosity + npmCluster.Properties.AgentPoolProfiles = append(npmCluster.Properties.AgentPoolProfiles, &armcontainerservice.ManagedClusterAgentPoolProfile{ //nolint:all Type: to.Ptr(armcontainerservice.AgentPoolTypeVirtualMachineScaleSets), AvailabilityZones: []*string{to.Ptr("1")}, Count: to.Ptr[int32](AuxilaryNodeCount), @@ -116,7 +121,7 @@ func (c *CreateNPMCluster) Run() error { notifychan := make(chan struct{}) go func() { _, err = poller.PollUntilDone(ctx, &runtime.PollUntilDoneOptions{ - Frequency: 5 * time.Second, + Frequency: pollFrequency, }) if err != nil { log.Printf("failed to create cluster: %v\n", err) @@ -126,7 +131,7 @@ func (c *CreateNPMCluster) Run() error { close(notifychan) }() - ticker := time.NewTicker(30 * time.Second) + ticker := time.NewTicker(clusterCreateTicker) defer ticker.Stop() for { select { @@ -135,7 +140,7 @@ func (c *CreateNPMCluster) Run() error { case <-ticker.C: log.Printf("waiting for cluster %s to be ready...\n", c.ClusterName) case <-notifychan: - return err + return fmt.Errorf("received notification, failed to create cluster: %w", err) } } } diff --git a/test/e2e/framework/generic/load-tag.go b/test/e2e/framework/generic/load-tag.go index b5ee7652c31..d3131c2829d 100644 --- a/test/e2e/framework/generic/load-tag.go +++ b/test/e2e/framework/generic/load-tag.go @@ -9,6 +9,8 @@ import ( const DefaultTagEnv = "TAG" +var ErrTagNotSet = fmt.Errorf("tag not set") + type LoadTag struct { TagEnv string } @@ -32,9 +34,8 @@ func (s *LoadTag) Prevalidate() error { log.Printf("using version \"%s\" from flag", tag) os.Setenv(s.TagEnv, tag) return nil - } else { - return fmt.Errorf("tag is not set from flag nor env %s", s.TagEnv) } + return fmt.Errorf("tag is not set from flag nor env %s: %w", s.TagEnv, ErrTagNotSet) } return nil } diff --git a/test/e2e/framework/kubernetes/get-logs.go b/test/e2e/framework/kubernetes/get-logs.go index 677eeb513bb..761a8922290 100644 --- a/test/e2e/framework/kubernetes/get-logs.go +++ b/test/e2e/framework/kubernetes/get-logs.go @@ -12,7 +12,7 @@ import ( "k8s.io/client-go/tools/clientcmd" ) -func PrintPodLogs(kubeconfigpath string, namespace string, labelSelector string) { +func PrintPodLogs(kubeconfigpath, namespace string, labelSelector string) { // Load the kubeconfig file to get the configuration to access the cluster config, err := clientcmd.BuildConfigFromFlags("", kubeconfigpath) if err != nil { @@ -34,7 +34,8 @@ func PrintPodLogs(kubeconfigpath string, namespace string, labelSelector string) } // Iterate over the pods and get the logs for each pod - for _, pod := range pods.Items { + for i := range pods.Items { + pod := pods.Items[i] fmt.Printf("############################## logs for pod %s #########################\n", pod.Name) // Get the logs for the pod @@ -43,7 +44,6 @@ func PrintPodLogs(kubeconfigpath string, namespace string, labelSelector string) if err != nil { fmt.Printf("error getting logs for pod %s: %s\n", pod.Name, err) } - defer podLogs.Close() // Read the logs buf, err := io.ReadAll(podLogs) @@ -51,6 +51,8 @@ func PrintPodLogs(kubeconfigpath string, namespace string, labelSelector string) log.Printf("error reading logs for pod %s: %s\n", pod.Name, err) } + podLogs.Close() + // Print the logs log.Println(string(buf)) } diff --git a/test/e2e/framework/kubernetes/install-retina-helm.go b/test/e2e/framework/kubernetes/install-retina-helm.go index 93798386dd1..70e74e65261 100644 --- a/test/e2e/framework/kubernetes/install-retina-helm.go +++ b/test/e2e/framework/kubernetes/install-retina-helm.go @@ -17,7 +17,10 @@ const ( deleteTimeout = 60 * time.Second ) -var errEmptyTag = fmt.Errorf("tag is empty") +var ( + errEmptyTag = fmt.Errorf("tag is empty") + errDirectoryNotFound = fmt.Errorf("directory not found") +) type InstallHelmChart struct { Namespace string @@ -99,8 +102,8 @@ func (i *InstallHelmChart) Prevalidate() error { if err != nil { return fmt.Errorf("failed to get current working directory %s: %w", cwd, err) } - fmt.Printf("the current working directory %s", cwd) - return fmt.Errorf("directory not found at %s: working directory: %s", i.ChartPath, cwd) + log.Printf("the current working directory %s", cwd) + return fmt.Errorf("directory not found at %s: working directory: %s: %w", i.ChartPath, cwd, errDirectoryNotFound) } log.Printf("found chart at %s", i.ChartPath) diff --git a/test/e2e/framework/prometheus/prometheus.go b/test/e2e/framework/prometheus/prometheus.go index 645ec2cd8f3..603f0d96acd 100644 --- a/test/e2e/framework/prometheus/prometheus.go +++ b/test/e2e/framework/prometheus/prometheus.go @@ -21,7 +21,7 @@ var ( defaultRetryAttempts = 60 ) -func CheckMetric(promAddress string, metricName string, validMetric map[string]string) error { +func CheckMetric(promAddress, metricName string, validMetric map[string]string) error { defaultRetrier := retry.Retrier{Attempts: defaultRetryAttempts, Delay: defaultRetryDelay} ctx := context.Background() diff --git a/test/retry/retry.go b/test/retry/retry.go index 7b46f9266e8..72a6b3f43c0 100644 --- a/test/retry/retry.go +++ b/test/retry/retry.go @@ -3,6 +3,7 @@ package retry import ( "context" + "fmt" "time" ) @@ -32,7 +33,11 @@ func (r Retrier) Do(ctx context.Context, f func() error) error { select { case <-ctx.Done(): - return ctx.Err() + ctxErr := ctx.Err() + if ctxErr != nil { + return fmt.Errorf("context error: %w", ctxErr) + } + return nil case <-done: return err }