diff --git a/.golangci.yml b/.golangci.yml index 70ede479..2093c261 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -49,7 +49,6 @@ issues: exclude-rules: - path: _test\.go linters: - - gomnd - dupl - unparam # Exclude gci check for //+kubebuilder:scaffold:imports comments. Waiting to @@ -60,6 +59,11 @@ issues: - path: operator/main.go linters: - gci + # Exlude httpso.Spec.ScaleTargetRef.Deployment until we remove it in v0.9.0 + - linters: + - staticcheck + text: "SA1019: httpso.Spec.ScaleTargetRef.Deployment" + linters-settings: funlen: lines: 80 diff --git a/examples/xkcd/templates/ingress.yaml b/examples/xkcd/templates/ingress.yaml index 4d2aeb3b..d0c5123c 100644 --- a/examples/xkcd/templates/ingress.yaml +++ b/examples/xkcd/templates/ingress.yaml @@ -1,7 +1,7 @@ apiVersion: networking.k8s.io/v1 kind: Ingress metadata: - name: {{ include "xkcd.fullname" . }} + name: {{ include "xkcd.fullname" . }} annotations: nginx.ingress.kubernetes.io/rewrite-target: / kubernetes.io/ingress.class: nginx diff --git a/interceptor/config/serving.go b/interceptor/config/serving.go index 74ee822f..50267f51 100644 --- a/interceptor/config/serving.go +++ b/interceptor/config/serving.go @@ -24,12 +24,12 @@ type Serving struct { // ConfigMapCacheRsyncPeriod is the time interval // for the configmap informer to rsync the local cache. ConfigMapCacheRsyncPeriod time.Duration `envconfig:"KEDA_HTTP_SCALER_CONFIG_MAP_INFORMER_RSYNC_PERIOD" default:"60m"` - // DEPRECATED: The interceptor has an internal process that periodically fetches the state + // Deprecated: The interceptor has an internal process that periodically fetches the state // of deployment that is running the servers it forwards to. // // This is the interval (in milliseconds) representing how often to do a fetch DeploymentCachePollIntervalMS int `envconfig:"KEDA_HTTP_DEPLOYMENT_CACHE_POLLING_INTERVAL_MS" default:"250"` - //The interceptor has an internal process that periodically fetches the state + // The interceptor has an internal process that periodically fetches the state // of endpoints that is running the servers it forwards to. // // This is the interval (in milliseconds) representing how often to do a fetch diff --git a/interceptor/forward_wait_func_test.go b/interceptor/forward_wait_func_test.go index 11c63c7c..3a5f0f09 100644 --- a/interceptor/forward_wait_func_test.go +++ b/interceptor/forward_wait_func_test.go @@ -27,7 +27,7 @@ func TestForwardWaitFuncOneReplica(t *testing.T) { endpoints := *newEndpoint(ns, endpointsName) cache := k8s.NewFakeEndpointsCache() cache.Set(endpoints) - cache.SetSubsets(ns, endpointsName, 1) + r.NoError(cache.SetSubsets(ns, endpointsName, 1)) ctx, done := context.WithTimeout(ctx, waitFuncWait) defer done() diff --git a/interceptor/proxy_handlers_integration_test.go b/interceptor/proxy_handlers_integration_test.go index d927d7c7..61b9a012 100644 --- a/interceptor/proxy_handlers_integration_test.go +++ b/interceptor/proxy_handlers_integration_test.go @@ -59,7 +59,7 @@ func TestIntegrationHappyPath(t *testing.T) { Namespace: target.GetNamespace(), }, }) - h.endpCache.SetSubsets(target.GetNamespace(), serviceName, 1) + r.NoError(h.endpCache.SetSubsets(target.GetNamespace(), serviceName, 1)) // happy path res, err := doRequest( @@ -341,10 +341,6 @@ func (h *harness) String() string { ) } -func i32Ptr(i int32) *int32 { - return &i -} - func hostForTest(t *testing.T) string { t.Helper() return fmt.Sprintf("%s.integrationtest.interceptor.kedahttp.dev", t.Name()) diff --git a/interceptor/proxy_handlers_test.go b/interceptor/proxy_handlers_test.go index 42f50aae..b282e09f 100644 --- a/interceptor/proxy_handlers_test.go +++ b/interceptor/proxy_handlers_test.go @@ -364,7 +364,7 @@ func notifyingFunc() (forwardWaitFunc, <-chan struct{}, func()) { func targetFromURL( u *url.URL, port int, - deployment string, + workload string, service string, ) *httpv1alpha1.HTTPScaledObject { host := strings.Split(u.Host, ":")[0] @@ -374,6 +374,7 @@ func targetFromURL( }, Spec: httpv1alpha1.HTTPScaledObjectSpec{ ScaleTargetRef: httpv1alpha1.ScaleTargetRef{ + Name: workload, Service: service, Port: int32(port), }, diff --git a/operator/apis/http/v1alpha1/httpscaledobject_types.go b/operator/apis/http/v1alpha1/httpscaledobject_types.go index e4e117f5..0ff66399 100644 --- a/operator/apis/http/v1alpha1/httpscaledobject_types.go +++ b/operator/apis/http/v1alpha1/httpscaledobject_types.go @@ -22,7 +22,7 @@ import ( // ScaleTargetRef contains all the details about an HTTP application to scale and route to type ScaleTargetRef struct { - // DEPRECATED: The name of the deployment to scale according to HTTP traffic + // Deprecated: The name of the deployment to scale according to HTTP traffic // +optional Deployment string `json:"deployment"` // +optional diff --git a/pkg/k8s/scaledobject.go b/pkg/k8s/scaledobject.go index 249506c6..b5b61d6d 100644 --- a/pkg/k8s/scaledobject.go +++ b/pkg/k8s/scaledobject.go @@ -3,10 +3,11 @@ package k8s import ( "strings" - "github.com/kedacore/http-add-on/operator/apis/http/v1alpha1" kedav1alpha1 "github.com/kedacore/keda/v2/apis/keda/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/utils/ptr" + + "github.com/kedacore/http-add-on/operator/apis/http/v1alpha1" ) const ( diff --git a/tests/checks/scaling_phase_custom_resource/scaling_phase_custom_resource_test.go b/tests/checks/scaling_phase_custom_resource/scaling_phase_custom_resource_test.go index c68be328..e2c98961 100644 --- a/tests/checks/scaling_phase_custom_resource/scaling_phase_custom_resource_test.go +++ b/tests/checks/scaling_phase_custom_resource/scaling_phase_custom_resource_test.go @@ -11,7 +11,6 @@ import ( "time" "github.com/stretchr/testify/assert" - "k8s.io/client-go/kubernetes" . "github.com/kedacore/http-add-on/tests/helper" ) @@ -154,30 +153,30 @@ func TestCheck(t *testing.T) { data, templates := getTemplateData() CreateKubernetesResources(t, kc, testNamespace, data, templates) - assert.True(t, waitForArgoRolloutReplicaCount(t, kc, rolloutName, testNamespace, minReplicaCount, 6, 10), + assert.True(t, waitForArgoRolloutReplicaCount(t, rolloutName, testNamespace, minReplicaCount, 6, 10), "replica count should be %d after 1 minutes", minReplicaCount) - testScaleOut(t, kc, data) - testScaleIn(t, kc) + testScaleOut(t, data) + testScaleIn(t) // cleanup DeleteKubernetesResources(t, testNamespace, data, templates) } -func testScaleOut(t *testing.T, kc *kubernetes.Clientset, data templateData) { +func testScaleOut(t *testing.T, data templateData) { t.Log("--- testing scale out ---") KubectlApplyWithTemplate(t, data, "loadJobTemplate", loadJobTemplate) - assert.True(t, waitForArgoRolloutReplicaCount(t, kc, rolloutName, testNamespace, maxReplicaCount, 18, 10), + assert.True(t, waitForArgoRolloutReplicaCount(t, rolloutName, testNamespace, maxReplicaCount, 18, 10), "replica count should be %d after 3 minutes", maxReplicaCount) KubectlDeleteWithTemplate(t, data, "loadJobTemplate", loadJobTemplate) } -func testScaleIn(t *testing.T, kc *kubernetes.Clientset) { +func testScaleIn(t *testing.T) { t.Log("--- testing scale out ---") - assert.True(t, waitForArgoRolloutReplicaCount(t, kc, rolloutName, testNamespace, minReplicaCount, 12, 10), + assert.True(t, waitForArgoRolloutReplicaCount(t, rolloutName, testNamespace, minReplicaCount, 12, 10), "replica count should be %d after 2 minutes", minReplicaCount) } @@ -197,7 +196,7 @@ func getTemplateData() (templateData, []Template) { } } -func waitForArgoRolloutReplicaCount(t *testing.T, kc *kubernetes.Clientset, name, namespace string, +func waitForArgoRolloutReplicaCount(t *testing.T, name, namespace string, target, iterations, intervalSeconds int) bool { for i := 0; i < iterations; i++ { kctlGetCmd := fmt.Sprintf(`kubectl get rollouts.argoproj.io/%s -n %s -o jsonpath="{.spec.replicas}"`, name, namespace)