Skip to content

Commit eef2031

Browse files
AlinsRanCopilot
andcommitted
feat: support labels on consumer resources
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 2b1aa8b commit eef2031

2 files changed

Lines changed: 62 additions & 1 deletion

File tree

internal/adc/translator/consumer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func (t *Translator) TranslateConsumerV1alpha1(tctx *provider.TranslateContext,
7171
credentials = append(credentials, credential)
7272
}
7373
consumer.Credentials = credentials
74-
consumer.Labels = label.GenLabel(consumerV)
74+
consumer.Labels = label.GenLabelWithObjectLabels(consumerV)
7575
plugins := adctypes.Plugins{}
7676
for _, plugin := range consumerV.Spec.Plugins {
7777
pluginName := plugin.Name
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package translator
19+
20+
import (
21+
"context"
22+
"testing"
23+
24+
"github.com/go-logr/logr"
25+
"github.com/stretchr/testify/require"
26+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
27+
28+
"github.com/apache/apisix-ingress-controller/api/v1alpha1"
29+
"github.com/apache/apisix-ingress-controller/internal/controller/label"
30+
"github.com/apache/apisix-ingress-controller/internal/provider"
31+
)
32+
33+
func TestTranslateConsumerV1alpha1_UsesMetadataLabelsWithoutOverwritingControllerLabels(t *testing.T) {
34+
translator := NewTranslator(logr.Discard())
35+
tctx := provider.NewDefaultTranslateContext(context.Background())
36+
37+
consumer := &v1alpha1.Consumer{
38+
TypeMeta: metav1.TypeMeta{
39+
Kind: "Consumer",
40+
APIVersion: v1alpha1.GroupVersion.String(),
41+
},
42+
ObjectMeta: metav1.ObjectMeta{
43+
Name: "demo",
44+
Namespace: "default",
45+
Labels: map[string]string{
46+
"team": "payments",
47+
label.LabelName: "user-value",
48+
label.LabelResourceKey: "user-resource-key",
49+
},
50+
},
51+
}
52+
53+
result, err := translator.TranslateConsumerV1alpha1(tctx, consumer)
54+
require.NoError(t, err)
55+
require.Len(t, result.Consumers, 1)
56+
57+
translated := result.Consumers[0]
58+
require.Equal(t, "payments", translated.Labels["team"])
59+
require.Equal(t, consumer.Name, translated.Labels[label.LabelName])
60+
require.Equal(t, "Consumer/default/demo", translated.Labels[label.LabelResourceKey])
61+
}

0 commit comments

Comments
 (0)