k8s mode fix
diff --git a/conf/dubbo-cp.yaml b/conf/dubbo-cp.yaml
index d61487c..b1c6373 100644
--- a/conf/dubbo-cp.yaml
+++ b/conf/dubbo-cp.yaml
@@ -14,7 +14,7 @@
# limitations under the License.
# 可选 k8s half universal
-deploy_mode: k8s
+deploy_mode: universal
mode: test
runtime:
kubernetes:
diff --git a/pkg/core/managers/apis/dataplane/dataplane_manager.go b/pkg/core/managers/apis/dataplane/dataplane_manager.go
index 2f4a56b..f3feb71 100644
--- a/pkg/core/managers/apis/dataplane/dataplane_manager.go
+++ b/pkg/core/managers/apis/dataplane/dataplane_manager.go
@@ -31,7 +31,6 @@
mesh_proto "github.com/apache/dubbo-kubernetes/api/mesh/v1alpha1"
config_core "github.com/apache/dubbo-kubernetes/pkg/config/core"
"github.com/apache/dubbo-kubernetes/pkg/core"
- "github.com/apache/dubbo-kubernetes/pkg/core/logger"
core_mesh "github.com/apache/dubbo-kubernetes/pkg/core/resources/apis/mesh"
core_manager "github.com/apache/dubbo-kubernetes/pkg/core/resources/manager"
core_model "github.com/apache/dubbo-kubernetes/pkg/core/resources/model"
@@ -69,11 +68,7 @@
if err != nil {
return err
}
- options := core_store.NewGetOptions(opts...)
- if options.Labels[mesh_proto.Application] == "" || options.Labels[mesh_proto.Revision] == "" {
- logger.Sugar().Error("需要携带application和revision才能查询")
- return nil
- }
+
if err := m.store.Get(ctx, dataplane, opts...); err != nil {
return err
}
diff --git a/pkg/plugins/resources/traditional/store.go b/pkg/plugins/resources/traditional/store.go
index 56cae11..af5a03a 100644
--- a/pkg/plugins/resources/traditional/store.go
+++ b/pkg/plugins/resources/traditional/store.go
@@ -20,6 +20,7 @@
import (
"context"
"fmt"
+ "github.com/dubbogo/go-zookeeper/zk"
"sync"
)
@@ -47,7 +48,6 @@
core_model "github.com/apache/dubbo-kubernetes/pkg/core/resources/model"
"github.com/apache/dubbo-kubernetes/pkg/core/resources/store"
"github.com/apache/dubbo-kubernetes/pkg/events"
- "github.com/apache/dubbo-kubernetes/pkg/plugins/util/ccache"
)
const (
@@ -555,9 +555,7 @@
switch resource.Descriptor().Name {
case mesh.DataplaneType:
- app := opts.Labels[mesh_proto.Application]
- revision := opts.Labels[mesh_proto.Revision]
- key := ccache.GetDataplaneKey(app, revision)
+ key := opts.Name
value, ok := c.dCache.Load(key)
if !ok {
return nil
@@ -649,6 +647,9 @@
key := opts.Name
set, err := c.metadataReport.GetServiceAppMapping(key, mappingGroup, nil)
if err != nil {
+ if errors.Is(err, zk.ErrNoNode) {
+ return nil
+ }
return err
}
meta := &resourceMetaObject{
@@ -669,9 +670,9 @@
Mesh: opts.Mesh,
})
case mesh.MetaDataType:
- labels := opts.Labels
- revision := labels[mesh_proto.Revision]
- app := labels[mesh_proto.Application]
+ name := opts.Name
+ // 拆分name得到revision和app
+ app, revision := splitAppAndRevision(name)
if revision == "" {
children, err := c.regClient.GetChildren(getMetadataPath(app))
if err != nil {
diff --git a/pkg/plugins/resources/traditional/path_util.go b/pkg/plugins/resources/traditional/utils.go
similarity index 90%
rename from pkg/plugins/resources/traditional/path_util.go
rename to pkg/plugins/resources/traditional/utils.go
index 4f9cb08..999d240 100644
--- a/pkg/plugins/resources/traditional/path_util.go
+++ b/pkg/plugins/resources/traditional/utils.go
@@ -19,6 +19,7 @@
import (
"fmt"
+ "strings"
)
func GenerateCpGroupPath(resourceName string, name string) string {
@@ -66,3 +67,10 @@
}
return rootDir
}
+
+func splitAppAndRevision(name string) (app string, revision string) {
+ split := strings.Split(name, "-")
+ n := len(split)
+ app = strings.Replace(name, "-"+split[n-1], "", -1)
+ return app, split[n-1]
+}
diff --git a/pkg/plugins/resources/traditional/utils_test.go b/pkg/plugins/resources/traditional/utils_test.go
new file mode 100644
index 0000000..c5593ca
--- /dev/null
+++ b/pkg/plugins/resources/traditional/utils_test.go
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package traditional
+
+import "testing"
+
+func TestSplitAppAndRevision(t *testing.T) {
+ name := "dubbo-springboot-demo-lixinyang-bdc0958191bba7a0f050a32709ee1111"
+ app, revision := splitAppAndRevision(name)
+ if app != "dubbo-springboot-demo-lixinyang" && revision != "bdc0958191bba7a0f050a32709ee1111" {
+ t.Error("解析错误")
+ }
+}
diff --git a/pkg/test/component.go b/pkg/test/component.go
index 60769f2..d4231a1 100644
--- a/pkg/test/component.go
+++ b/pkg/test/component.go
@@ -77,11 +77,14 @@
return err
}
- // get
- if err := manager.Get(rt.AppContext(), dataplaneResource,
- store.GetByApplication("dubbo-springboot-demo-provider"),
- store.GetByRevision("bdc0958191bba7a0f050a32709ee1262")); err != nil {
- return err
+ if len(dataplaneList.Items) > 0 {
+ // get
+ if err := manager.Get(rt.AppContext(), dataplaneResource,
+ store.GetBy(core_model.ResourceKey{
+ Name: dataplaneList.Items[0].Meta.GetName(),
+ })); err != nil {
+ return err
+ }
}
return nil
@@ -105,14 +108,16 @@
return err
}
if err := manager.Create(rt.AppContext(), metadata2, store.CreateBy(core_model.ResourceKey{
- Name: metadata2.Spec.App,
+ Name: metadata2.Spec.App + "-" + metadata2.Spec.Revision,
})); err != nil {
return err
}
metadata1 := mesh.NewMetaDataResource()
// get
- if err := manager.Get(rt.AppContext(), metadata1, store.GetByApplication("dubbo-springboot-demo-provider")); err != nil {
+ if err := manager.Get(rt.AppContext(), metadata1, store.GetBy(core_model.ResourceKey{
+ Name: metadata2.Spec.App + "-" + metadata2.Spec.Revision,
+ })); err != nil {
return err
}
@@ -125,6 +130,7 @@
// update
metadata3 := mesh.NewMetaDataResource()
+ metadata3.SetMeta(metadata1.GetMeta())
err = metadata3.SetSpec(&mesh_proto.MetaData{
App: "dubbo-springboot-demo-lixinyang",
Revision: "bdc0958191bba7a0f050a32709ee1111",
@@ -183,6 +189,7 @@
}
mapping3 := mesh.NewMappingResource()
+ mapping3.SetMeta(mapping1.GetMeta())
err = mapping3.SetSpec(&mesh_proto.Mapping{
Zone: "zone2",
InterfaceName: "org.apache.dubbo.springboot.demo.DemoService1",