You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by bz...@apache.org on 2026/09/17 01:52:26 UTC
(apisix-ingress-controller) 01/01: feat: prepare isolate bad resource
This is an automated email from the ASF dual-hosted git repository.
bzp2010 pushed a commit to branch bzp/feat-isolation-pr1-prep
in repository https://gitbox.apache.org/repos/asf/apisix-ingress-controller.git
commit 9ac1b0ba0ceee1903e526a0e98ac0abf73fba19d
Author: bzp2010 <bz...@apache.org>
AuthorDate: Thu Sep 17 09:52:11 2026 +0800
feat: prepare isolate bad resource
---
.github/workflows/apisix-e2e-test.yml | 2 +-
Makefile | 2 +-
api/adc/types.go | 12 +++++++++++
config/manager/kustomization.yaml | 2 +-
internal/adc/translator/consumer.go | 3 +++
internal/adc/translator/consumer_test.go | 34 ++++++++++++++++++++++++++++++++
internal/adc/translator/gateway.go | 2 +-
7 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/.github/workflows/apisix-e2e-test.yml b/.github/workflows/apisix-e2e-test.yml
index 1a00f63b..ea669f54 100644
--- a/.github/workflows/apisix-e2e-test.yml
+++ b/.github/workflows/apisix-e2e-test.yml
@@ -30,7 +30,7 @@ concurrency:
cancel-in-progress: true
env:
- ADC_RUST_VERSION: "0.30.3"
+ ADC_RUST_VERSION: "0.30.5"
jobs:
e2e-test:
diff --git a/Makefile b/Makefile
index a224f6b5..2736bee9 100644
--- a/Makefile
+++ b/Makefile
@@ -29,7 +29,7 @@ KIND_NAME ?= apisix-ingress-cluster
CLOUD_PROVIDER_KIND_VERSION ?= v0.6.0
CLOUD_PROVIDER_KIND_PID ?= /tmp/cloud-provider-kind.pid
-ADC_VERSION ?= 0.29.0
+ADC_VERSION ?= 0.30.5
DIR := $(shell pwd)
diff --git a/api/adc/types.go b/api/adc/types.go
index 38fb3983..cbda8c66 100644
--- a/api/adc/types.go
+++ b/api/adc/types.go
@@ -36,6 +36,12 @@ const (
TypeSSL = "ssl"
TypeGlobalRule = "global_rule"
TypePluginMetadata = "plugin_metadata"
+ // TypeStreamRoute, TypeUpstream and TypeConsumerCredential only ever name a nested
+ // entity in an ADC event: a stream route or named upstream inside a service, a
+ // credential inside a consumer.
+ TypeStreamRoute = "stream_route"
+ TypeUpstream = "upstream"
+ TypeConsumerCredential = "consumer_credential"
)
type Object interface {
@@ -541,6 +547,12 @@ func ComposeStreamRouteName(namespace, name string, rule string, typ string) str
return buf.String()
}
+// ComposeGatewayListenerSSLName composes the name a Gateway listener's certificateRef at
+// refIndex is identified by; its SSL id is generated from it.
+func ComposeGatewayListenerSSLName(kind, namespace, name, listener string, refIndex int) string {
+ return fmt.Sprintf("%s_%s_%d", ComposeSSLName(kind, namespace, name), listener, refIndex)
+}
+
func ComposeServiceNameWithRule(namespace, name string, rule string) string {
// FIXME Use sync.Pool to reuse this buffer if the upstream
// name composing code path is hot.
diff --git a/config/manager/kustomization.yaml b/config/manager/kustomization.yaml
index 7410dcd1..a55e9a6b 100644
--- a/config/manager/kustomization.yaml
+++ b/config/manager/kustomization.yaml
@@ -17,4 +17,4 @@ images:
newTag: dev
- name: sidecar
newName: ghcr.io/api7/adc
- newTag: 0.30.3
+ newTag: 0.30.5
diff --git a/internal/adc/translator/consumer.go b/internal/adc/translator/consumer.go
index d7e638be..2f75dd86 100644
--- a/internal/adc/translator/consumer.go
+++ b/internal/adc/translator/consumer.go
@@ -19,12 +19,14 @@ package translator
import (
"encoding/json"
+ "fmt"
"k8s.io/apimachinery/pkg/types"
adctypes "github.com/apache/apisix-ingress-controller/api/adc"
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
"github.com/apache/apisix-ingress-controller/internal/controller/label"
+ "github.com/apache/apisix-ingress-controller/internal/id"
"github.com/apache/apisix-ingress-controller/internal/provider"
)
@@ -42,6 +44,7 @@ func (t *Translator) TranslateConsumerV1alpha1(tctx *provider.TranslateContext,
for _, credentialSpec := range consumerV.Spec.Credentials {
credential := adctypes.Credential{}
credential.Name = credentialSpec.Name
+ credential.ID = id.GenID(fmt.Sprintf("%s/credentials/%s", username, credentialSpec.Name))
credential.Type = credentialSpec.Type
if credentialSpec.SecretRef != nil {
ns := consumerV.Namespace
diff --git a/internal/adc/translator/consumer_test.go b/internal/adc/translator/consumer_test.go
index 6e8af842..8a07d152 100644
--- a/internal/adc/translator/consumer_test.go
+++ b/internal/adc/translator/consumer_test.go
@@ -23,6 +23,7 @@ import (
"github.com/go-logr/logr"
"github.com/stretchr/testify/require"
+ apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
@@ -59,3 +60,36 @@ func TestTranslateConsumerV1alpha1_UsesMetadataLabelsWithoutOverwritingControlle
require.Equal(t, consumer.Name, translated.Labels[label.LabelName])
require.Equal(t, "apisix-ingress-controller", translated.Labels[label.LabelManagedBy])
}
+
+// TestTranslateConsumerV1alpha1_GivesEveryCredentialAStableID covers the id a rejected
+// credential is reported under: without one of our own, ADC derives an id AIC cannot
+// match back to the credential.
+func TestTranslateConsumerV1alpha1_GivesEveryCredentialAStableID(t *testing.T) {
+ translator := NewTranslator(logr.Discard(), "")
+ consumer := &v1alpha1.Consumer{
+ ObjectMeta: metav1.ObjectMeta{Name: "demo", Namespace: "default"},
+ Spec: v1alpha1.ConsumerSpec{
+ Credentials: []v1alpha1.Credential{
+ {Name: "key", Type: "key-auth", Config: apiextensionsv1.JSON{Raw: []byte(`{"key":"k"}`)}},
+ {Name: "basic", Type: "basic-auth", Config: apiextensionsv1.JSON{Raw: []byte(`{"username":"u","password":"p"}`)}},
+ },
+ },
+ }
+
+ translate := func() []string {
+ result, err := translator.TranslateConsumerV1alpha1(provider.NewDefaultTranslateContext(context.Background()), consumer)
+ require.NoError(t, err)
+ require.Len(t, result.Consumers, 1)
+ var ids []string
+ for _, credential := range result.Consumers[0].Credentials {
+ require.NotEmpty(t, credential.ID)
+ ids = append(ids, credential.ID)
+ }
+ return ids
+ }
+
+ ids := translate()
+ require.Len(t, ids, 2)
+ require.NotEqual(t, ids[0], ids[1])
+ require.Equal(t, ids, translate())
+}
diff --git a/internal/adc/translator/gateway.go b/internal/adc/translator/gateway.go
index e4288c79..9f942faa 100644
--- a/internal/adc/translator/gateway.go
+++ b/internal/adc/translator/gateway.go
@@ -148,7 +148,7 @@ func (t *Translator) translateSecret(tctx *provider.TranslateContext, listener g
}
sslObj.Snis = sslutils.NormalizeHosts(sslObj.Snis)
sslObj.Client = client
- sslObj.ID = id.GenID(fmt.Sprintf("%s_%s_%d", adctypes.ComposeSSLName(internaltypes.KindGateway, obj.Namespace, obj.Name), listener.Name, refIndex))
+ sslObj.ID = id.GenID(adctypes.ComposeGatewayListenerSSLName(internaltypes.KindGateway, obj.Namespace, obj.Name, string(listener.Name), refIndex))
t.Log.V(1).Info("generated ssl id", "ssl id", sslObj.ID, "secret", secretNN.String())
sslObj.Labels = label.GenLabel(obj)
sslObjs = append(sslObjs, sslObj)