Skip to content

Commit

Permalink
lint final
Browse files Browse the repository at this point in the history
  • Loading branch information
skonto committed Jul 12, 2024
1 parent 5de813d commit 12ca280
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 50 deletions.
12 changes: 6 additions & 6 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@ run:
build-tags:
- e2e

skip-dirs:
- pkg/client

skip-files:
- "^prom.png$"

linters:
enable:
- asciicheck
Expand Down Expand Up @@ -56,3 +50,9 @@ issues:
- text: "ST1000: at least one file in a package should have a package comment"
linters:
- stylecheck

exclude-dirs:
- pkg/client

exclude-files:
- "^prom.png$"

Check failure on line 58 in .golangci.yaml

View workflow job for this annotation

GitHub Actions / style / Golang / Lint

[EOF Newline] reported by reviewdog 🐶 Missing newline Raw Output: .golangci.yaml:58: Missing newline
34 changes: 15 additions & 19 deletions pkg/reconciler/autoscaling/hpa/keda_hpa_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ import (

_ "knative.dev/autoscaler-keda/pkg/client/injection/informers/keda/v1alpha1/scaledobject/fake"

. "knative.dev/pkg/reconciler/testing"
. "knative.dev/serving/pkg/reconciler/testing/v1"
. "knative.dev/serving/pkg/testing"
reconcilertesting "knative.dev/pkg/reconciler/testing"
testingv1 "knative.dev/serving/pkg/reconciler/testing/v1"
. "knative.dev/serving/pkg/testing" //nolint:all

kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1"
)
Expand All @@ -82,7 +82,7 @@ const (
)

func TestControllerCanReconcile(t *testing.T) {
ctx, cancel, infs := SetupFakeContextWithCancel(t)
ctx, cancel, infs := reconcilertesting.SetupFakeContextWithCancel(t)
ctl := NewController(ctx, configmap.NewStaticWatcher(
&corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Expand All @@ -108,7 +108,7 @@ func TestControllerCanReconcile(t *testing.T) {
Data: map[string]string{},
}))

waitInformers, err := RunAndSyncInformers(ctx, infs...)
waitInformers, err := reconcilertesting.RunAndSyncInformers(ctx, infs...)
if err != nil {
t.Fatal("Failed to start informers:", err)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ func TestReconcile(t *testing.T) {
deployName := testRevision + "-deployment"
privateSvc := names.PrivateService(testRevision)

table := TableTest{{
table := reconcilertesting.TableTest{{
Name: "no op",
Objects: []runtime.Object{
hpa(pa(testNamespace, testRevision, WithHPAClass, WithMetricAnnotation("cpu"))),
Expand Down Expand Up @@ -273,14 +273,14 @@ func TestReconcile(t *testing.T) {
},
Key: key(testNamespace, testRevision),
WithReactors: []ktesting.ReactionFunc{
InduceFailure("update", "serverlessservices"),
reconcilertesting.InduceFailure("update", "serverlessservices"),
},
WantErr: true,
WantUpdates: []ktesting.UpdateActionImpl{{
Object: sks(testNamespace, testRevision, WithDeployRef(deployName), WithSKSReady),
}},
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error updating SKS test-revision: inducing failure for update serverlessservices"),
reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error updating SKS test-revision: inducing failure for update serverlessservices"),
},
}, {
Name: "create sks - create fails",
Expand All @@ -291,14 +291,14 @@ func TestReconcile(t *testing.T) {
},
Key: key(testNamespace, testRevision),
WithReactors: []ktesting.ReactionFunc{
InduceFailure("create", "serverlessservices"),
reconcilertesting.InduceFailure("create", "serverlessservices"),
},
WantErr: true,
WantCreates: []runtime.Object{
sks(testNamespace, testRevision, WithDeployRef(deployName)),
},
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error creating SKS test-revision: inducing failure for create serverlessservices"),
reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", "error reconciling SKS: error creating SKS test-revision: inducing failure for create serverlessservices"),
},
}, {
Name: "sks is disowned",
Expand All @@ -314,7 +314,7 @@ func TestReconcile(t *testing.T) {
Object: pa(testNamespace, testRevision, WithHPAClass, MarkResourceNotOwnedByPA("ServerlessService", testRevision)),
}},
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "InternalError", `error reconciling SKS: PA: test-revision does not own SKS: test-revision`),
reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError", `error reconciling SKS: PA: test-revision does not own SKS: test-revision`),
},
}, {
Name: "pa is disowned",
Expand All @@ -330,7 +330,7 @@ func TestReconcile(t *testing.T) {
Object: pa(testNamespace, testRevision, WithHPAClass, MarkResourceNotOwnedByPA("ScaledObject", testRevision)),
}},
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "InternalError",
reconcilertesting.Eventf(corev1.EventTypeWarning, "InternalError",
`PodAutoscaler: "test-revision" does not own ScaledObject: "test-revision"`),
},
}, {
Expand All @@ -357,10 +357,10 @@ func TestReconcile(t *testing.T) {
Key: key(testNamespace, testRevision),
WantErr: true,
WithReactors: []ktesting.ReactionFunc{
InduceFailure("update", "podautoscalers"),
reconcilertesting.InduceFailure("update", "podautoscalers"),
},
WantEvents: []string{
Eventf(corev1.EventTypeWarning, "UpdateFailed", `Failed to update status for "test-revision": inducing failure for update podautoscalers`),
reconcilertesting.Eventf(corev1.EventTypeWarning, "UpdateFailed", `Failed to update status for "test-revision": inducing failure for update podautoscalers`),
},
}, {
Name: "invalid key",
Expand All @@ -370,7 +370,7 @@ func TestReconcile(t *testing.T) {
Key: "sandwich///",
}}

table.Test(t, MakeFactory(func(ctx context.Context, listers *Listers, cmw configmap.Watcher) controller.Reconciler {
table.Test(t, testingv1.MakeFactory(func(ctx context.Context, listers *testingv1.Listers, _ configmap.Watcher) controller.Reconciler {
retryAttempted = false
ctx = podscalable.WithDuck(ctx)
ctx, _ = fakekedaclient.With(ctx)
Expand Down Expand Up @@ -432,10 +432,6 @@ func pa(namespace, name string, options ...PodAutoscalerOption) *autoscalingv1al

type hpaOption func(*autoscalingv2.HorizontalPodAutoscaler)

func withHPAOwnersRemoved(hpa *autoscalingv2.HorizontalPodAutoscaler) {
hpa.OwnerReferences = nil
}

func withScales(d, a int32) PodAutoscalerOption {
return func(pa *autoscalingv1alpha1.PodAutoscaler) {
pa.Status.DesiredScale, pa.Status.ActualScale = ptr.Int32(d), ptr.Int32(a)
Expand Down
16 changes: 0 additions & 16 deletions test/e2e/autoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,6 @@ func newVegetaHTTPClient(ctx *TestContext, url *url.URL) *http.Client {
return spoof.Client
}

func generateTrafficAtFixedConcurrency(ctx *TestContext, concurrency int, stopChan chan struct{}) error {
pacer := vegeta.ConstantPacer{} // Sends requests as quickly as possible, capped by MaxWorkers below.

attacker := vegeta.NewAttacker(
vegeta.Timeout(0), // No timeout is enforced at all.
vegeta.Workers(uint64(concurrency)),
vegeta.MaxWorkers(uint64(concurrency)),
vegeta.Client(newVegetaHTTPClient(ctx, ctx.resources.Route.Status.URL.URL())),
)

target := getVegetaTarget(ctx.resources.Route.Status.URL.URL().Hostname(), "sleep", autoscaleSleep, test.ServingFlags.HTTPS)

ctx.t.Logf("Maintaining %d concurrent requests.", concurrency)
return generateTraffic(ctx, attacker, pacer, stopChan, target)
}

func generateTrafficAtFixedRPS(ctx *TestContext, rps int, stopChan chan struct{}) error {
pacer := vegeta.ConstantPacer{Freq: rps, Per: time.Second}
attacker := vegeta.NewAttacker(
Expand Down
16 changes: 7 additions & 9 deletions test/test_images/metrics-test/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
})
)

func hello(w http.ResponseWriter, req *http.Request) {
func hello(w http.ResponseWriter, _ *http.Request) {
defer opsProcessed.Inc()
fmt.Fprint(w, "Hello!")

Expand Down Expand Up @@ -77,14 +77,12 @@ func main() {
cancelCtx()
}()

select {
case <-ctx.Done():
if err := mainServer.Shutdown(context.Background()); err != nil {
fmt.Printf("failed to shutdown main server: %s\n", err)
}
<-ctx.Done()
if err := mainServer.Shutdown(context.Background()); err != nil {
fmt.Printf("failed to shutdown main server: %s\n", err)
}

if err := promServer.Shutdown(context.Background()); err != nil {
fmt.Printf("failed to shutdown Prometheus server: %s\n", err)
}
if err := promServer.Shutdown(context.Background()); err != nil {
fmt.Printf("failed to shutdown Prometheus server: %s\n", err)
}
}

0 comments on commit 12ca280

Please sign in to comment.