Skip to content

Commit

Permalink
fix(kds): fix resource naming
Browse files Browse the repository at this point in the history
Signed-off-by: Lukasz Dziedziak <[email protected]>
  • Loading branch information
lukidzi committed Jan 23, 2024
1 parent a7c29d9 commit 3895fcc
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
23 changes: 17 additions & 6 deletions pkg/envoy/admin/kds_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"reflect"
"strings"

"github.com/pkg/errors"

Expand Down Expand Up @@ -36,7 +37,7 @@ func (k *kdsEnvoyAdminClient) PostQuit(context.Context, *core_mesh.DataplaneReso

func (k *kdsEnvoyAdminClient) ConfigDump(ctx context.Context, proxy core_model.ResourceWithAddress) ([]byte, error) {
zone := core_model.ZoneOfResource(proxy)
nameInZone := resNameInZone(proxy)
nameInZone := resNameInZone(proxy, k.k8sStore)
reqId := core.NewUUID()
tenantZoneID := service.TenantZoneClientIDFromCtx(ctx, zone)

Expand Down Expand Up @@ -73,7 +74,7 @@ func (k *kdsEnvoyAdminClient) ConfigDump(ctx context.Context, proxy core_model.R

func (k *kdsEnvoyAdminClient) Stats(ctx context.Context, proxy core_model.ResourceWithAddress) ([]byte, error) {
zone := core_model.ZoneOfResource(proxy)
nameInZone := resNameInZone(proxy)
nameInZone := resNameInZone(proxy, k.k8sStore)
reqId := core.NewUUID()
tenantZoneId := service.TenantZoneClientIDFromCtx(ctx, zone)

Expand Down Expand Up @@ -110,7 +111,7 @@ func (k *kdsEnvoyAdminClient) Stats(ctx context.Context, proxy core_model.Resour

func (k *kdsEnvoyAdminClient) Clusters(ctx context.Context, proxy core_model.ResourceWithAddress) ([]byte, error) {
zone := core_model.ZoneOfResource(proxy)
nameInZone := resNameInZone(proxy)
nameInZone := resNameInZone(proxy, k.k8sStore)
reqId := core.NewUUID()
tenantZoneID := service.TenantZoneClientIDFromCtx(ctx, zone)

Expand Down Expand Up @@ -145,11 +146,21 @@ func (k *kdsEnvoyAdminClient) Clusters(ctx context.Context, proxy core_model.Res
}
}

func resNameInZone(r core_model.Resource) string {
func resNameInZone(r core_model.Resource, k8sStore bool) string {
name := core_model.GetDisplayName(r)
if ns := r.GetMeta().GetLabels()[mesh_proto.KubeNamespaceTag]; ns != "" {
name = k8s.K8sNamespacedNameToCoreName(name, ns)
// we need to check for the legacy name
core.Log.Info("resNameInZone namespaces", "name", name)
if strings.HasPrefix(r.GetMeta().GetName(), core_model.ZoneOfResource(r)) {
return name
}

if k8sStore {
if ns := r.GetMeta().GetLabels()[mesh_proto.KubeNamespaceTag]; ns != "" {
name = k8s.K8sNamespacedNameToCoreName(name, ns)
core.Log.Info("resNameInZone namespaces", "name", name)
}
}

return name
}

Expand Down
11 changes: 9 additions & 2 deletions pkg/kds/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
config_core "github.com/kumahq/kuma/pkg/config/core"
"github.com/kumahq/kuma/pkg/core"
config_manager "github.com/kumahq/kuma/pkg/core/config/manager"
"github.com/kumahq/kuma/pkg/core/resources/apis/mesh"
"github.com/kumahq/kuma/pkg/core/resources/apis/system"
"github.com/kumahq/kuma/pkg/core/resources/manager"
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
Expand Down Expand Up @@ -69,7 +70,10 @@ func DefaultContext(
),
MapZoneTokenSigningKeyGlobalToPublicKey),
reconcile.If(
reconcile.IsKubernetes(cfg.Store.Type),
reconcile.And(
reconcile.IsKubernetes(cfg.Store.Type),
reconcile.Not(reconcile.TypeIs(mesh.ZoneIngressType)),
),
RemoveK8sSystemNamespaceSuffixMapper(cfg.Store.Kubernetes.SystemNamespace)),
reconcile.If(
reconcile.And(
Expand All @@ -88,7 +92,10 @@ func DefaultContext(
),
MapInsightResourcesZeroGeneration,
reconcile.If(
reconcile.IsKubernetes(cfg.Store.Type),
reconcile.And(
reconcile.IsKubernetes(cfg.Store.Type),
reconcile.Not(reconcile.TypeIs(mesh.ZoneIngressType)),
),
RemoveK8sSystemNamespaceSuffixMapper(cfg.Store.Kubernetes.SystemNamespace)),
HashSuffixMapper(false, mesh_proto.ZoneTag, mesh_proto.KubeNamespaceTag),
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/plugins/resources/k8s/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

"github.com/kumahq/kuma/api/mesh/v1alpha1"
"github.com/kumahq/kuma/pkg/core"
core_model "github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/resources/registry"
"github.com/kumahq/kuma/pkg/core/resources/store"
Expand Down Expand Up @@ -273,9 +274,11 @@ func (m *KubernetesMetaAdapter) GetLabels() map[string]string {
if _, ok := labels[v1alpha1.DisplayName]; !ok {
labels[v1alpha1.DisplayName] = m.GetObjectMeta().GetName()
}
if m.Namespace != "" {
if _, ok := labels[v1alpha1.KubeNamespaceTag]; !ok {
labels[v1alpha1.KubeNamespaceTag] = m.Namespace
}

core.Log.Info("GetLabels", " m.GetObjectMeta().GetName()", labels[v1alpha1.DisplayName], "m.GetObjectMeta().GetName()", m.GetObjectMeta().GetName(), "labels[v1alpha1.KubeNamespaceTag]", labels[v1alpha1.KubeNamespaceTag])
return labels
}

Expand Down

0 comments on commit 3895fcc

Please sign in to comment.