diff --git a/.golangci.yml b/.golangci.yml index aac8a13f9..cfadc12b6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,33 +1,14 @@ +version: "2" run: - timeout: 5m allow-parallel-runners: true - -issues: - # don't skip warning about doc comments - # don't exclude the default set of lint - exclude-use-default: false - # restore some of the defaults - # (fill in the rest as needed) - exclude-rules: - - path: "api/*" - linters: - - lll - - path: "internal/*" - linters: - - dupl - - lll linters: - disable-all: true + default: none enable: - dupl - errcheck - - exportloopref - ginkgolinter - goconst - gocyclo - - gofmt - - goimports - - gosimple - govet - ineffassign - lll @@ -36,12 +17,38 @@ linters: - prealloc - revive - staticcheck - - typecheck - unconvert - unparam - unused - -linters-settings: - revive: + settings: + revive: + rules: + - name: comment-spacings + exclusions: + generated: lax rules: - - name: comment-spacings + - linters: + - lll + path: api/* + - linters: + - dupl + - lll + path: internal/* + - linters: + - staticcheck + text: "ST1001:" + path: test/.* + paths: + - third_party$ + - builtin$ + - examples$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - third_party$ + - builtin$ + - examples$ diff --git a/Makefile b/Makefile index 79104dddc..488a2843a 100644 --- a/Makefile +++ b/Makefile @@ -285,7 +285,7 @@ GOLANGCI_LINT = $(LOCALBIN)/golangci-lint KUSTOMIZE_VERSION ?= v5.4.2 CONTROLLER_TOOLS_VERSION ?= v0.15.0 ENVTEST_VERSION ?= release-0.18 -GOLANGCI_LINT_VERSION ?= v1.59.1 +GOLANGCI_LINT_VERSION ?= v2.1.5 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -305,7 +305,7 @@ $(ENVTEST): $(LOCALBIN) .PHONY: golangci-lint golangci-lint: $(GOLANGCI_LINT) ## Download golangci-lint locally if necessary. $(GOLANGCI_LINT): $(LOCALBIN) - $(call go-install-tool,$(GOLANGCI_LINT),github.com/golangci/golangci-lint/cmd/golangci-lint,$(GOLANGCI_LINT_VERSION)) + curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s $(GOLANGCI_LINT_VERSION) gofmt: ## Apply go fmt @gofmt -w -r 'interface{} -> any' . diff --git a/api/dashboard/v1/types.go b/api/dashboard/v1/types.go index df927c6d8..18a98aa65 100644 --- a/api/dashboard/v1/types.go +++ b/api/dashboard/v1/types.go @@ -730,9 +730,9 @@ func ComposeConsumerName(namespace, name string) string { buf := bytes.NewBuffer(p) // TODO If APISIX modifies the consumer name schema, we can drop this. - buf.WriteString(strings.Replace(namespace, "-", "_", -1)) + buf.WriteString(strings.ReplaceAll(namespace, "-", "_")) buf.WriteString("_") - buf.WriteString(strings.Replace(name, "-", "_", -1)) + buf.WriteString(strings.ReplaceAll(name, "-", "_")) return buf.String() } diff --git a/internal/controller/consumer_controller.go b/internal/controller/consumer_controller.go index 17f29d659..94c1c886d 100644 --- a/internal/controller/consumer_controller.go +++ b/internal/controller/consumer_controller.go @@ -307,7 +307,7 @@ func (r *ConsumerReconciler) checkGatewayRef(object client.Object) bool { return false } gatewayClass := &gatewayv1.GatewayClass{} - if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil { + if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil { r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName) return false } diff --git a/internal/controller/gateway_controller.go b/internal/controller/gateway_controller.go index f6e157d24..5900f2ef3 100644 --- a/internal/controller/gateway_controller.go +++ b/internal/controller/gateway_controller.go @@ -208,7 +208,7 @@ func (r *GatewayReconciler) listGatewayForGatewayClass(ctx context.Context, gate func (r *GatewayReconciler) checkGatewayClass(obj client.Object) bool { gateway := obj.(*gatewayv1.Gateway) gatewayClass := &gatewayv1.GatewayClass{} - if err := r.Client.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil { + if err := r.Get(context.Background(), client.ObjectKey{Name: string(gateway.Spec.GatewayClassName)}, gatewayClass); err != nil { r.Log.Error(err, "failed to get gateway class", "gateway", gateway.GetName(), "gatewayclass", gateway.Spec.GatewayClassName) return false } diff --git a/internal/controller/ingress_controller.go b/internal/controller/ingress_controller.go index 88aa5b96d..5cb356dd0 100644 --- a/internal/controller/ingress_controller.go +++ b/internal/controller/ingress_controller.go @@ -209,7 +209,7 @@ func (r *IngressReconciler) getIngressClass(obj client.Object) (*networkingv1.In // if it does not match, check if the ingress class is controlled by us ingressClass := networkingv1.IngressClass{} - if err := r.Client.Get(context.Background(), client.ObjectKey{Name: *ingress.Spec.IngressClassName}, &ingressClass); err != nil { + if err := r.Get(context.Background(), client.ObjectKey{Name: *ingress.Spec.IngressClassName}, &ingressClass); err != nil { return nil, err } diff --git a/internal/provider/adc/translator/consumer.go b/internal/provider/adc/translator/consumer.go index 8cd8f446f..b1d5ff518 100644 --- a/internal/provider/adc/translator/consumer.go +++ b/internal/provider/adc/translator/consumer.go @@ -3,7 +3,6 @@ package translator import ( "encoding/json" - "github.com/api7/api7-ingress-controller/api/adc" adctypes "github.com/api7/api7-ingress-controller/api/adc" "github.com/api7/api7-ingress-controller/api/v1alpha1" "github.com/api7/api7-ingress-controller/internal/provider" @@ -22,7 +21,7 @@ func (t *Translator) TranslateConsumerV1alpha1(tctx *provider.TranslateContext, } credentials := make([]adctypes.Credential, 0, len(consumerV.Spec.Credentials)) for _, credentialSpec := range consumerV.Spec.Credentials { - credential := adc.Credential{} + credential := adctypes.Credential{} credential.Name = credentialSpec.Name credential.Type = credentialSpec.Type if credentialSpec.SecretRef != nil { diff --git a/internal/provider/adc/translator/httproute.go b/internal/provider/adc/translator/httproute.go index f7af81bb5..eef8d848a 100644 --- a/internal/provider/adc/translator/httproute.go +++ b/internal/provider/adc/translator/httproute.go @@ -180,8 +180,8 @@ func (t *Translator) fillPluginFromHTTPRequestMirrorFilter(plugins adctypes.Plug } var ( - port int = 80 - ns string = namespace + port = 80 + ns = namespace ) if reqMirror.BackendRef.Port != nil { port = int(*reqMirror.BackendRef.Port) diff --git a/internal/provider/adc/translator/ingress.go b/internal/provider/adc/translator/ingress.go index d1f3818da..745f1573a 100644 --- a/internal/provider/adc/translator/ingress.go +++ b/internal/provider/adc/translator/ingress.go @@ -171,7 +171,8 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw uris := []string{path.Path} if path.PathType != nil { - if *path.PathType == networkingv1.PathTypePrefix { + switch *path.PathType { + case networkingv1.PathTypePrefix: // As per the specification of Ingress path matching rule: // if the last element of the path is a substring of the // last element in request path, it is not a match, e.g. /foo/bar @@ -188,7 +189,7 @@ func (t *Translator) TranslateIngress(tctx *provider.TranslateContext, obj *netw prefix += "/*" } uris = append(uris, prefix) - } else if *path.PathType == networkingv1.PathTypeImplementationSpecific { + case networkingv1.PathTypeImplementationSpecific: uris = []string{"/*"} } } diff --git a/internal/provider/adc/translator/policies.go b/internal/provider/adc/translator/policies.go index 20f0202e2..86f3eefa0 100644 --- a/internal/provider/adc/translator/policies.go +++ b/internal/provider/adc/translator/policies.go @@ -1,13 +1,11 @@ package translator import ( - "github.com/api7/api7-ingress-controller/api/adc" + adctypes "github.com/api7/api7-ingress-controller/api/adc" "github.com/api7/api7-ingress-controller/api/v1alpha1" "k8s.io/apimachinery/pkg/types" "k8s.io/utils/ptr" gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" - - adctypes "github.com/api7/api7-ingress-controller/api/adc" ) func convertBackendRef(namespace, name, kind string) gatewayv1.BackendRef { @@ -53,13 +51,13 @@ func (t *Translator) attachBackendTrafficPolicyToUpstream(policy *v1alpha1.Backe } if policy.Spec.Timeout != nil { upstream.Timeout = &adctypes.Timeout{ - Connect: int(policy.Spec.Timeout.Connect.Duration.Seconds()), - Read: int(policy.Spec.Timeout.Read.Duration.Seconds()), - Send: int(policy.Spec.Timeout.Send.Duration.Seconds()), + Connect: int(policy.Spec.Timeout.Connect.Seconds()), + Read: int(policy.Spec.Timeout.Read.Seconds()), + Send: int(policy.Spec.Timeout.Send.Seconds()), } } if policy.Spec.LoadBalancer != nil { - upstream.Type = adc.UpstreamType(policy.Spec.LoadBalancer.Type) + upstream.Type = adctypes.UpstreamType(policy.Spec.LoadBalancer.Type) upstream.HashOn = policy.Spec.LoadBalancer.HashOn upstream.Key = policy.Spec.LoadBalancer.Key } diff --git a/internal/provider/controlplane/translator/httproute.go b/internal/provider/controlplane/translator/httproute.go index 3bf56e37c..1d3b3a15d 100644 --- a/internal/provider/controlplane/translator/httproute.go +++ b/internal/provider/controlplane/translator/httproute.go @@ -167,8 +167,8 @@ func (t *Translator) fillPluginFromHTTPRequestMirrorFilter(plugins v1.Plugins, n } var ( - port int = 80 - ns string = namespace + port = 80 + ns = namespace ) if reqMirror.BackendRef.Port != nil { port = int(*reqMirror.BackendRef.Port) @@ -273,8 +273,8 @@ func (t *Translator) TranslateHTTPRoute(tctx *provider.TranslateContext, httpRou backend.Namespace = &namespace } upstream := t.translateBackendRef(tctx, backend.BackendRef) - upstream.Labels["name"] = string(backend.BackendRef.Name) - upstream.Labels["namespace"] = string(*backend.BackendRef.Namespace) + upstream.Labels["name"] = string(backend.Name) + upstream.Labels["namespace"] = string(*backend.Namespace) upstreams = append(upstreams, upstream) if len(upstream.Nodes) == 0 { upstream.Nodes = v1.UpstreamNodes{ @@ -389,7 +389,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa } } - if match.Headers != nil && len(match.Headers) > 0 { + if len(match.Headers) > 0 { for _, header := range match.Headers { name := strings.ToLower(string(header.Name)) name = strings.ReplaceAll(name, "-", "_") @@ -420,7 +420,7 @@ func (t *Translator) translateGatewayHTTPRouteMatch(match *gatewayv1.HTTPRouteMa } } - if match.QueryParams != nil && len(match.QueryParams) > 0 { + if len(match.QueryParams) > 0 { for _, query := range match.QueryParams { var this []v1.StringOrSlice this = append(this, v1.StringOrSlice{ diff --git a/internal/types/duration.go b/internal/types/duration.go index 56d6a4ef7..0e7389f44 100644 --- a/internal/types/duration.go +++ b/internal/types/duration.go @@ -31,7 +31,7 @@ type TimeDuration struct { } func (d *TimeDuration) MarshalJSON() ([]byte, error) { - return json.Marshal(d.Duration.String()) + return json.Marshal(d.String()) } func (d *TimeDuration) UnmarshalJSON(data []byte) error { @@ -55,7 +55,7 @@ func (d *TimeDuration) UnmarshalJSON(data []byte) error { } func (d *TimeDuration) MarshalYAML() (any, error) { - return d.Duration.String(), nil + return d.String(), nil } func (d *TimeDuration) UnmarshalYAML(unmarshal func(any) error) error { diff --git a/pkg/dashboard/cluster.go b/pkg/dashboard/cluster.go index ac09bfad3..9ef717ac7 100644 --- a/pkg/dashboard/cluster.go +++ b/pkg/dashboard/cluster.go @@ -63,7 +63,7 @@ var ( // ErrRouteNotFound means the [route, ssl, upstream] was not found. ErrNotFound = cache.ErrNotFound - _errReadOnClosedResBody = errors.New("http: read on closed response body") + errReadOnClosedResBody = errors.New("http: read on closed response body") ) // ClusterOptions contains parameters to customize APISIX client. @@ -128,10 +128,14 @@ func newCluster(ctx context.Context, o *ClusterOptions) (Cluster, error) { if err != nil { return nil, err } - if u.Port() == "" { - if u.Scheme == "http" { + + switch u.Scheme { + case "http": + if u.Port() == "" { u.Host = u.Host + ":80" - } else if u.Scheme == "https" { + } + case "https": + if u.Port() == "" { u.Host = u.Host + ":443" } } @@ -698,7 +702,7 @@ func (c *cluster) deleteResource(ctx context.Context, url, resource string) erro func drainBody(r io.ReadCloser, url string) { _, err := io.Copy(io.Discard, r) if err != nil { - if err.Error() != _errReadOnClosedResBody.Error() { + if err.Error() != errReadOnClosedResBody.Error() { log.Warnw("failed to drain body (read)", zap.String("url", url), zap.Error(err), diff --git a/pkg/dashboard/consumer_test.go b/pkg/dashboard/consumer_test.go index 7f15f186d..0520cf7b0 100644 --- a/pkg/dashboard/consumer_test.go +++ b/pkg/dashboard/consumer_test.go @@ -76,7 +76,7 @@ func (srv *fakeAPISIXConsumerSrv) ServeHTTP(w http.ResponseWriter, r *http.Reque Value: srv.consumer[key], }, } - resp.fakeGetCreateItem.Value = srv.consumer[key] + resp.Value = srv.consumer[key] w.WriteHeader(http.StatusOK) data, _ := json.Marshal(resp) _, _ = w.Write(data) diff --git a/test/e2e/adminapi/dashboard_api.go b/test/e2e/adminapi/dashboard_api.go index d17a57e9b..a3b241a5e 100644 --- a/test/e2e/adminapi/dashboard_api.go +++ b/test/e2e/adminapi/dashboard_api.go @@ -20,8 +20,8 @@ import ( "time" "github.com/api7/api7-ingress-controller/test/e2e/scaffold" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck v1 "github.com/api7/api7-ingress-controller/api/dashboard/v1" ) diff --git a/test/e2e/framework/dashboard.go b/test/e2e/framework/dashboard.go index a9285ec44..4a9262fb8 100644 --- a/test/e2e/framework/dashboard.go +++ b/test/e2e/framework/dashboard.go @@ -277,7 +277,7 @@ func (f *Framework) deploy() { install.Namespace = f.kubectlOpts.Namespace install.ReleaseName = "api7ee3" - chartPath, err := install.ChartPathOptions.LocateChart("api7/api7ee3", cli.New()) + chartPath, err := install.LocateChart("api7/api7ee3", cli.New()) f.GomegaT.Expect(err).ShouldNot(HaveOccurred(), "locate helm chart") chart, err := loader.Load(chartPath) diff --git a/test/e2e/framework/database.go b/test/e2e/framework/database.go index 55982cca5..b7296c003 100644 --- a/test/e2e/framework/database.go +++ b/test/e2e/framework/database.go @@ -52,6 +52,7 @@ const ( mysqlDSN = "mysql://root:changeme@tcp(mysql:3306)/api7ee" ) +//nolint:unused func getDSN() string { switch _db { case postgres: diff --git a/test/e2e/framework/framework.go b/test/e2e/framework/framework.go index 39f1a0db0..147e9774f 100644 --- a/test/e2e/framework/framework.go +++ b/test/e2e/framework/framework.go @@ -10,8 +10,8 @@ import ( "github.com/gruntwork-io/terratest/modules/k8s" "github.com/gruntwork-io/terratest/modules/logger" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck clientv3 "go.etcd.io/etcd/client/v3" "gorm.io/gorm" k8serrors "k8s.io/apimachinery/pkg/api/errors" diff --git a/test/e2e/framework/gateway.go b/test/e2e/framework/gateway.go index e5a8c27de..f5539876d 100644 --- a/test/e2e/framework/gateway.go +++ b/test/e2e/framework/gateway.go @@ -7,7 +7,7 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/gruntwork-io/terratest/modules/k8s" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:staticcheck corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/test/e2e/framework/ingress.go b/test/e2e/framework/ingress.go index b6a89218a..0f041c76f 100644 --- a/test/e2e/framework/ingress.go +++ b/test/e2e/framework/ingress.go @@ -8,7 +8,7 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/gruntwork-io/terratest/modules/k8s" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:staticcheck metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/test/e2e/framework/k8s.go b/test/e2e/framework/k8s.go index a5bba2334..45957d26e 100644 --- a/test/e2e/framework/k8s.go +++ b/test/e2e/framework/k8s.go @@ -11,10 +11,9 @@ import ( "github.com/gavv/httpexpect" "github.com/gruntwork-io/terratest/modules/k8s" "github.com/gruntwork-io/terratest/modules/testing" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:staticcheck "go.uber.org/zap" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -104,6 +103,7 @@ func (f *Framework) GetServiceEndpoints(name string) ([]string, error) { return endpoints, nil } +//nolint:unused func (f *Framework) deletePods(selector string) { podList, err := f.clientset.CoreV1().Pods(_namespace).List(f.Context, metav1.ListOptions{ LabelSelector: selector, @@ -141,7 +141,7 @@ func (f *Framework) CreateNamespaceWithTestService(name string) { Selector: map[string]string{ "app": "httpbin", }, - Type: v1.ServiceTypeClusterIP, + Type: corev1.ServiceTypeClusterIP, }, }, metav1.CreateOptions{}) if err != nil && !errors.IsAlreadyExists(err) { @@ -194,10 +194,11 @@ func (f *Framework) newDashboardTunnel() error { service := k8s.GetService(f.GinkgoT, f.kubectlOpts, "api7ee3-dashboard") for _, port := range service.Spec.Ports { - if port.Name == "http" { + switch port.Name { + case "http": httpNodePort = int(port.NodePort) httpPort = int(port.Port) - } else if port.Name == "https" { + case "https": httpsNodePort = int(port.NodePort) httpsPort = int(port.Port) } diff --git a/test/e2e/framework/nginx.go b/test/e2e/framework/nginx.go index 26d2c763d..3ffb2686a 100644 --- a/test/e2e/framework/nginx.go +++ b/test/e2e/framework/nginx.go @@ -7,7 +7,7 @@ import ( "github.com/Masterminds/sprig/v3" "github.com/gruntwork-io/terratest/modules/k8s" - . "github.com/onsi/gomega" + . "github.com/onsi/gomega" //nolint:staticcheck corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) diff --git a/test/e2e/framework/utils.go b/test/e2e/framework/utils.go index ed589de34..35683409d 100644 --- a/test/e2e/framework/utils.go +++ b/test/e2e/framework/utils.go @@ -18,7 +18,6 @@ import ( "github.com/onsi/gomega" "golang.org/x/net/html" corev1 "k8s.io/api/core/v1" - v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/tools/remotecommand" @@ -53,7 +52,7 @@ func (f *Framework) ListRunningPods(selector string) []corev1.Pod { f.GomegaT.Expect(err).ShouldNot(gomega.HaveOccurred(), "list pod: ", selector) runningPods := make([]corev1.Pod, 0) for _, p := range pods.Items { - if p.Status.Phase == corev1.PodRunning && p.ObjectMeta.DeletionTimestamp == nil { + if p.Status.Phase == corev1.PodRunning && p.DeletionTimestamp == nil { runningPods = append(runningPods, p) } } @@ -273,7 +272,7 @@ func (f *Framework) LogoutDashboardByOIDC(logoutPath string, cookies []*http.Coo func (f *Framework) GetPodLogs(name string, previous bool) string { reader, err := f.clientset.CoreV1(). Pods(_namespace). - GetLogs(name, &v1.PodLogOptions{Previous: previous}). + GetLogs(name, &corev1.PodLogOptions{Previous: previous}). Stream(context.Background()) f.GomegaT.Expect(err).ShouldNot(gomega.HaveOccurred(), "get logs") defer func() { @@ -305,7 +304,7 @@ func (f *Framework) WaitPodsLog(selector, keyword string, sinceSeconds int64, ti wg.Add(1) go func(p corev1.Pod) { defer wg.Done() - opts := v1.PodLogOptions{Follow: true} + opts := corev1.PodLogOptions{Follow: true} if sinceSeconds > 0 { opts.SinceSeconds = ptr.To(sinceSeconds) } else { diff --git a/test/e2e/scaffold/k8s.go b/test/e2e/scaffold/k8s.go index ea44e8dfa..9804f55a2 100644 --- a/test/e2e/scaffold/k8s.go +++ b/test/e2e/scaffold/k8s.go @@ -23,13 +23,12 @@ import ( "time" "github.com/api7/api7-ingress-controller/pkg/dashboard" - apisix "github.com/api7/api7-ingress-controller/pkg/dashboard" "github.com/api7/api7-ingress-controller/test/e2e/framework" "github.com/gruntwork-io/terratest/modules/k8s" "github.com/gruntwork-io/terratest/modules/retry" "github.com/gruntwork-io/terratest/modules/testing" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/client-go/kubernetes" @@ -37,12 +36,7 @@ import ( // CreateResourceFromString creates resource from a loaded yaml string. func (s *Scaffold) CreateResourceFromString(yaml string) error { - err := k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions, yaml) - // if the error raised, it may be a &shell.ErrWithCmdOutput, which is useless in debug - if err != nil { - err = fmt.Errorf(err.Error()) - } - return err + return k8s.KubectlApplyFromStringE(s.t, s.kubectlOptions, yaml) } func (s *Scaffold) DeleteResourceFromString(yaml string) error { @@ -138,7 +132,7 @@ func (s *Scaffold) NewAPISIX() (dashboard.Dashboard, error) { return dashboard.NewClient() } -func (s *Scaffold) ClusterClient() (apisix.Cluster, error) { +func (s *Scaffold) ClusterClient() (dashboard.Cluster, error) { u := url.URL{ Scheme: "http", Host: "localhost:7080", @@ -148,7 +142,7 @@ func (s *Scaffold) ClusterClient() (apisix.Cluster, error) { if err != nil { return nil, err } - err = cli.AddCluster(context.Background(), &apisix.ClusterOptions{ + err = cli.AddCluster(context.Background(), &dashboard.ClusterOptions{ BaseURL: u.String(), ControllerName: s.opts.ControllerName, Labels: map[string]string{"k8s/controller-name": s.opts.ControllerName}, diff --git a/test/e2e/scaffold/scaffold.go b/test/e2e/scaffold/scaffold.go index 82f3571b1..70a4fc483 100644 --- a/test/e2e/scaffold/scaffold.go +++ b/test/e2e/scaffold/scaffold.go @@ -32,8 +32,8 @@ import ( "github.com/gavv/httpexpect/v2" "github.com/gruntwork-io/terratest/modules/k8s" "github.com/gruntwork-io/terratest/modules/testing" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/wait" @@ -550,7 +550,7 @@ func (s *Scaffold) addFinalizers(f func()) { func (s *Scaffold) FormatRegistry(workloadTemplate string) string { customRegistry, isExist := os.LookupEnv("REGISTRY") if isExist { - return strings.Replace(workloadTemplate, "127.0.0.1:5000", customRegistry, -1) + return strings.ReplaceAll(workloadTemplate, "127.0.0.1:5000", customRegistry) } else { return workloadTemplate } @@ -682,10 +682,11 @@ func (s *Scaffold) createDataplaneTunnels( ) for _, port := range svc.Spec.Ports { - if port.Name == "http" { + switch port.Name { + case "http": httpNodePort = int(port.NodePort) httpPort = int(port.Port) - } else if port.Name == "https" { + case "https": httpsNodePort = int(port.NodePort) httpsPort = int(port.Port) } diff --git a/test/e2e/scaffold/ssl.go b/test/e2e/scaffold/ssl.go index 0389ab1f6..4a22831e6 100644 --- a/test/e2e/scaffold/ssl.go +++ b/test/e2e/scaffold/ssl.go @@ -27,8 +27,8 @@ import ( "math/big" "time" - . "github.com/onsi/ginkgo/v2" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo/v2" //nolint:staticcheck + . "github.com/onsi/gomega" //nolint:staticcheck ) const ( diff --git a/test/utils/utils.go b/test/utils/utils.go index 6b96ab5d0..3b7d787a3 100644 --- a/test/utils/utils.go +++ b/test/utils/utils.go @@ -22,7 +22,7 @@ import ( "os/exec" "strings" - . "github.com/onsi/ginkgo/v2" //nolint:golint,revive + . "github.com/onsi/ginkgo/v2" //nolint:golint,revive,staticcheck ) const ( @@ -135,6 +135,6 @@ func GetProjectDir() (string, error) { if err != nil { return wd, err } - wd = strings.Replace(wd, "/test/e2e", "", -1) + wd = strings.ReplaceAll(wd, "/test/e2e", "") return wd, nil }