Skip to content

Commit

Permalink
fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
matmerr committed Dec 2, 2024
1 parent a442646 commit 76b5798
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 47 deletions.
2 changes: 1 addition & 1 deletion test/e2e/framework/kubernetes/validateHttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (v *ValidateHTTPResponse) Run() error {
defer resp.Body.Close()

if resp.StatusCode != v.ExpectedStatus {
return fmt.Errorf("unexpected status code: got %d, want %d", resp.StatusCode, v.ExpectedStatus)
return fmt.Errorf("unexpected status code: got %d, want %d", resp.StatusCode, v.ExpectedStatus) //nolint:goerr113 no formatting needed
}
log.Printf("HTTP validation succeeded for URL: %s with status code %d\n", v.URL, resp.StatusCode)

Expand Down
1 change: 0 additions & 1 deletion test/e2e/framework/scaletest/add-shared-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func (a *AddSharedLabelsToAllPods) Prevalidate() error {
// Primary step where test logic is executed
// Returning an error will cause the test to fail
func (a *AddSharedLabelsToAllPods) Run() error {

if a.NumSharedLabelsPerPod < 1 {
return nil
}
Expand Down
1 change: 0 additions & 1 deletion test/e2e/framework/scaletest/add-unique-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ func (a *AddUniqueLabelsToAllPods) Prevalidate() error {
// Primary step where test logic is executed
// Returning an error will cause the test to fail
func (a *AddUniqueLabelsToAllPods) Run() error {

if a.NumUniqueLabelsPerPod < 1 {
return nil
}
Expand Down
1 change: 0 additions & 1 deletion test/e2e/framework/scaletest/create-network-policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ func (c *CreateNetworkPolicies) Prevalidate() error {
// Primary step where test logic is executed
// Returning an error will cause the test to fail
func (c *CreateNetworkPolicies) Run() error {

config, err := clientcmd.BuildConfigFromFlags("", c.KubeConfigFilePath)
if err != nil {
return fmt.Errorf("error building kubeconfig: %w", err)
Expand Down
3 changes: 0 additions & 3 deletions test/e2e/framework/scaletest/delete-and-re-add-labels.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (d *DeleteAndReAddLabels) Prevalidate() error {
// Primary step where test logic is executed
// Returning an error will cause the test to fail
func (d *DeleteAndReAddLabels) Run() error {

if d.NumSharedLabelsPerPod <= 2 || !d.DeleteLabels {
return nil
}
Expand Down Expand Up @@ -89,7 +88,6 @@ func (d *DeleteAndReAddLabels) Run() error {
}

func (d *DeleteAndReAddLabels) addLabels(ctx context.Context, clientset *kubernetes.Clientset, pods *corev1.PodList, patch string) error {

for _, pod := range pods.Items {
_, err := clientset.CoreV1().Pods(d.Namespace).Patch(ctx, pod.Name, types.StrategicMergePatchType, []byte(patch), metav1.PatchOptions{})
if err != nil {
Expand All @@ -101,7 +99,6 @@ func (d *DeleteAndReAddLabels) addLabels(ctx context.Context, clientset *kuberne
}

func (d *DeleteAndReAddLabels) deleteLabels(ctx context.Context, clientset *kubernetes.Clientset, pods *corev1.PodList, patch string) error {

for _, pod := range pods.Items {
_, err := clientset.CoreV1().Pods(d.Namespace).Patch(ctx, pod.Name, types.StrategicMergePatchType, []byte(patch), metav1.PatchOptions{})
if err != nil {
Expand Down
7 changes: 1 addition & 6 deletions test/e2e/framework/scaletest/get-publish-metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ func (g *GetAndPublishMetrics) Run() error {
g.wg.Add(1)

go func() {

t := time.NewTicker(5 * time.Minute)

for {
Expand All @@ -66,7 +65,6 @@ func (g *GetAndPublishMetrics) Run() error {

}
}

}()

return nil
Expand All @@ -92,7 +90,6 @@ func (g *GetAndPublishMetrics) Prevalidate() error {
}

func (g *GetAndPublishMetrics) getAndPublishMetrics() error {

config, err := clientcmd.BuildConfigFromFlags("", g.KubeConfigFilePath)
if err != nil {
return fmt.Errorf("error building kubeconfig: %w", err)
Expand Down Expand Up @@ -121,14 +118,13 @@ func (g *GetAndPublishMetrics) getAndPublishMetrics() error {
log.Println("Publishing metrics to AppInsights")
for _, metric := range metrics {
g.telemetryClient.TrackEvent("scale-test", metric)

}
}

// Write metrics to file
if g.OutputFilePath != "" {
log.Println("Writing metrics to file ", g.OutputFilePath)
file, err := os.OpenFile(g.OutputFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
file, err := os.OpenFile(g.OutputFilePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
return fmt.Errorf("error writing to csv file: %w", err)
}
Expand All @@ -151,7 +147,6 @@ func (g *GetAndPublishMetrics) getAndPublishMetrics() error {
type metric map[string]string

func (g *GetAndPublishMetrics) getMetrics(ctx context.Context, k8sClient *kubernetes.Clientset, metricsClient *metrics.Clientset) ([]metric, error) {

labelSelector := labels.Set(g.Labels).String()

pods, err := k8sClient.CoreV1().Pods(common.KubeSystemNamespace).List(ctx, metav1.ListOptions{LabelSelector: labelSelector})
Expand Down
34 changes: 16 additions & 18 deletions test/e2e/framework/scaletest/templates/networkpolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,21 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
NetworkPolicy = netv1.NetworkPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "NetworkPolicy",
APIVersion: "networking.k8s.io/v1",
var NetworkPolicy = netv1.NetworkPolicy{
TypeMeta: metav1.TypeMeta{
Kind: "NetworkPolicy",
APIVersion: "networking.k8s.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: "template-network-policy",
},
Spec: netv1.NetworkPolicySpec{
PolicyTypes: []netv1.PolicyType{
"Ingress",
"Egress",
},
ObjectMeta: metav1.ObjectMeta{
Name: "template-network-policy",
PodSelector: metav1.LabelSelector{
MatchLabels: map[string]string{},
},
Spec: netv1.NetworkPolicySpec{
PolicyTypes: []netv1.PolicyType{
"Ingress",
"Egress",
},
PodSelector: metav1.LabelSelector{
MatchLabels: map[string]string{},
},
},
}
)
},
}
3 changes: 1 addition & 2 deletions test/e2e/framework/scaletest/validate-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ func (po *ValidateAndPrintOptions) Prevalidate() error {

// Returning an error will cause the test to fail
func (po *ValidateAndPrintOptions) Run() error {

log.Printf("Starting to scale with folowing options: %+v", po.Options)
log.Printf("Starting to scale with following options: %+v", po.Options)

return nil
}
Expand Down
1 change: 0 additions & 1 deletion test/e2e/jobs/jobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,4 +365,3 @@ func RunPerfTest(kubeConfigFilePath string, chartPath string) *types.Job {

return job
}

2 changes: 1 addition & 1 deletion test/e2e/jobs/scale.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func ScaleTest(opt *scaletest.Options) *types.Job {
job.AddStep(&scaletest.GetAndPublishMetrics{
Labels: opt.LabelsToGetMetrics,
AdditionalTelemetryProperty: opt.AdditionalTelemetryProperty,
OutputFilePath: os.Getenv("OUTPUT_FILEPATH"),
OutputFilePath: os.Getenv("OUTPUT_FILEPATH"),
}, &types.StepOptions{
SkipSavingParametersToJob: true,
RunInBackgroundWithID: "get-metrics",
Expand Down
12 changes: 8 additions & 4 deletions test/e2e/retina_longrunning_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@ package retina
import (
"testing"

"github.com/microsoft/retina/test/e2e/framework/helpers"
"github.com/microsoft/retina/test/e2e/framework/types"
jobs "github.com/microsoft/retina/test/e2e/jobs"
"github.com/stretchr/testify/require"
)

// Scrape PProf over a long running datapath tests
func TestLongRunningRetina(t *testing.T) {
ctx, cancel := helpers.Context(t)
defer cancel()

settings, err := LoadInfraSettings()
require.NoError(t, err)

// CreateTestInfra
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, clusterName, location, settings.KubeConfigFilePath, settings.CreateInfra))
createTestInfra.Run()
createTestInfra := types.NewRunner(t, jobs.CreateTestInfra(subID, resourceGroup, clusterName, location, settings.KubeConfigFilePath, settings.CreateInfra))
createTestInfra.Run(ctx)
t.Cleanup(func() {
if settings.DeleteInfra {
_ = jobs.DeleteTestInfra(subID, clusterName, location).Run()
_ = jobs.DeleteTestInfra(subID, resourceGroup, clusterName, location).Run()
}
})

longrunning := types.NewRunner(t, jobs.CreateLongRunningTest(subID, clusterName, location, settings.KubeConfigFilePath, settings.CreateInfra))
longrunning.Run()
longrunning.Run(ctx)
}
2 changes: 1 addition & 1 deletion test/e2e/scenarios/perf/publish-perf-results.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (v *PublishPerfResults) Run() error {
return nil
}

resultsFile, err := os.OpenFile(v.ResultsFile, os.O_RDONLY, 0644)
resultsFile, err := os.OpenFile(v.ResultsFile, os.O_RDONLY, 0o644)
if err != nil {
return errors.Wrap(err, "failed to open results file")
}
Expand Down
23 changes: 16 additions & 7 deletions test/e2e/settings_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package retina

import (
"crypto/rand"
"errors"
"flag"
"fmt"
"log"
Expand All @@ -16,9 +17,12 @@ import (
)

var (
clusterName = os.Getenv("CLUSTER_NAME")
subID = os.Getenv("AZURE_SUBSCRIPTION_ID")
location = os.Getenv("AZURE_LOCATION")
clusterName = os.Getenv("CLUSTER_NAME")
subID = os.Getenv("AZURE_SUBSCRIPTION_ID")
location = os.Getenv("AZURE_LOCATION")
resourceGroup = os.Getenv("AZURE_RESOURCE_GROUP")

errAzureSubscriptionIDNotSet = errors.New("AZURE_SUBSCRIPTION_ID is not set")
)

var (
Expand All @@ -38,7 +42,7 @@ type TestInfraSettings struct {
func LoadInfraSettings() (*TestInfraSettings, error) {
curuser, err := user.Current()
if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to get current user: %w", err)
}

flag.Parse()
Expand All @@ -49,21 +53,26 @@ func LoadInfraSettings() (*TestInfraSettings, error) {
}

if subID == "" {
return nil, fmt.Errorf("AZURE_SUBSCRIPTION_ID is not set")
return nil, errAzureSubscriptionIDNotSet
}

if location == "" {
var nBig *big.Int
nBig, err = rand.Int(rand.Reader, big.NewInt(int64(len(locations))))
if err != nil {
return nil, fmt.Errorf("Failed to generate a secure random index: %v", err)
return nil, fmt.Errorf("Failed to generate a secure random index: %w", err)
}
location = locations[nBig.Int64()]
}

if resourceGroup == "" {
log.Printf("AZURE_RESOURCE_GROUP is not set, using the cluster name as the resource group name by default")
resourceGroup = clusterName
}

cwd, err := os.Getwd()
if err != nil {
return nil, err
return nil, fmt.Errorf("Failed to get current working directory: %w", err)
}

// Get to root of the repo by going up two directories
Expand Down

0 comments on commit 76b5798

Please sign in to comment.