Feat: fix empty cluster topology and support select non-control-plane clusters (#4731)

* Feat: fix empty cluster selector topology and support select non-control-plane clusters

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

* Fix: panic bug for list clusters

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

* Fix: test

Signed-off-by: Somefive <yd219913@alibaba-inc.com>

Signed-off-by: Somefive <yd219913@alibaba-inc.com>
This commit is contained in:
Somefive
2022-09-15 17:32:07 +08:00
committed by GitHub
parent 67f1901015
commit b898cecf2f
5 changed files with 26 additions and 5 deletions
+1 -1
View File
@@ -54,7 +54,7 @@ require (
github.com/klauspost/compress v1.15.9
github.com/koding/websocketproxy v0.0.0-20181220232114-7ed82d81a28c
github.com/kubevela/pkg v0.0.0-20220913093640-a41193098f92
github.com/kubevela/prism v1.4.1-0.20220613123457-94f1190f87c2
github.com/kubevela/prism v1.5.1-0.20220915071949-6bf3ad33f84f
github.com/kubevela/workflow v0.0.0-20220905111757-ae9387b554de
github.com/kyokomi/emoji v2.2.4+incompatible
github.com/mitchellh/hashstructure/v2 v2.0.1
+2 -2
View File
@@ -1381,8 +1381,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kubevela/pkg v0.0.0-20220905083925-331e331a12e1/go.mod h1:281yP5rMV+jYzxngUtM/FeZvAbqWEIow9tSamHHcDvI=
github.com/kubevela/pkg v0.0.0-20220913093640-a41193098f92 h1:B4GkHf6rdLC4x2Clya1GKAGGo683fHgNDE4IHAOSSKQ=
github.com/kubevela/pkg v0.0.0-20220913093640-a41193098f92/go.mod h1:mGQEK3fAX9MkOGexLOm7H+h99SdqZSsUzTmVLgzpSdg=
github.com/kubevela/prism v1.4.1-0.20220613123457-94f1190f87c2 h1:TaHlO4raKI3ehVSYY8QixYMHdI0VwKHY1KPNWcUre3I=
github.com/kubevela/prism v1.4.1-0.20220613123457-94f1190f87c2/go.mod h1:RP69+bRb57Occer6BeeF5zK3hrD1IhnYf2RNRsIdh9E=
github.com/kubevela/prism v1.5.1-0.20220915071949-6bf3ad33f84f h1:1lUtU1alPThdcsn4MI6XjPb7eJLuZPpmlEdgjtnUMKw=
github.com/kubevela/prism v1.5.1-0.20220915071949-6bf3ad33f84f/go.mod h1:m724/7ANnB/iukyHW20+DicpeJMEC/JA0ZhgsHY10MA=
github.com/kubevela/workflow v0.0.0-20220905111757-ae9387b554de h1:n5vkROgxW64Jq+Or6Ku9w/PDPRNypav2Ud1vJDxukWs=
github.com/kubevela/workflow v0.0.0-20220905111757-ae9387b554de/go.mod h1:8Mb05FAcLgYgLORBDgZQOqvrSt72KAum0zP4kuUE7LU=
github.com/kulti/thelper v0.4.0/go.mod h1:vMu2Cizjy/grP+jmsvOFDx1kYP6+PD1lqg4Yu5exl2U=
+5
View File
@@ -20,6 +20,7 @@ import (
"context"
"fmt"
pkgmulticluster "github.com/kubevela/pkg/multicluster"
prismclusterv1alpha1 "github.com/kubevela/prism/pkg/apis/cluster/v1alpha1"
"github.com/pkg/errors"
utilfeature "k8s.io/apiserver/pkg/util/feature"
@@ -96,6 +97,10 @@ func GetPlacementsFromTopologyPolicies(ctx context.Context, cli client.Client, a
return nil, err
}
}
default:
if err := addCluster(pkgmulticluster.Local, topologySpec.Namespace, false); err != nil {
return nil, err
}
}
}
}
+9
View File
@@ -145,6 +145,15 @@ func TestGetClusterLabelSelectorInTopology(t *testing.T) {
Outputs: []v1alpha1.PlacementDecision{{Cluster: "cluster-a", Namespace: "override"}, {Cluster: "cluster-b", Namespace: "override"}},
AllowCrossNamespace: true,
},
"topology-no-clusters-and-cluster-label-selector": {
Inputs: []v1beta1.AppPolicy{{
Name: "topology-policy",
Type: "topology",
Properties: &runtime.RawExtension{Raw: []byte(`{"namespace":"override"}`)},
}},
Outputs: []v1alpha1.PlacementDecision{{Cluster: "local", Namespace: "override"}},
AllowCrossNamespace: true,
},
"no-topology-policy": {
Inputs: []v1beta1.AppPolicy{},
Outputs: []v1alpha1.PlacementDecision{{Cluster: "local", Namespace: ""}},
+9 -2
View File
@@ -23,6 +23,7 @@ import (
"os"
"path/filepath"
"strings"
"time"
"cuelang.org/go/cue"
"github.com/google/go-cmp/cmp"
@@ -300,9 +301,15 @@ var _ = Describe("test GetNamespacedCapabilitiesFromCluster", func() {
component1 = "cd1"
component2 = "cd2"
By("clean namespace")
_ = k8sClient.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}})
_ = k8sClient.Delete(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: defaultNS}})
By("create namespace")
Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: defaultNS}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
Eventually(func(g Gomega) {
g.Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: ns}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
g.Expect(k8sClient.Create(ctx, &corev1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: defaultNS}})).Should(SatisfyAny(BeNil(), &util.AlreadyExistMatcher{}))
}, 15*time.Second).Should(Succeed())
By("create ComponentDefinition")
data, _ := os.ReadFile("testdata/componentDef.yaml")