mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-19 04:26:39 +00:00
+6








b5a9925042
* Create testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Update testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Delete testwr Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Chore: (deps): Bump goreleaser/goreleaser-action from 5.0.0 to 6.3.0 (#6775) Bumps [goreleaser/goreleaser-action](https://github.com/goreleaser/goreleaser-action) from 5.0.0 to 6.3.0. - [Release notes](https://github.com/goreleaser/goreleaser-action/releases) - [Commits](https://github.com/goreleaser/goreleaser-action/compare/7ec5c2b0c6cdda6e8bbb49444bc797dd33d74dd8...9c156ee8a17a598857849441385a2041ef570552) --- updated-dependencies: - dependency-name: goreleaser/goreleaser-action dependency-version: 6.3.0 dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Chore: Replace the openssf badge with UI link (#6783) [optional body] [optional footer] Signed-off-by: Anoop Gopalakrishnan <anoop2811@aol.in> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * chore: moves dockerhub user name to secret section in the reusable workflow (#6778) Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Signed-off-by: Ayush <ayushshyam.official.888@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Chore: update helm repo path in tests (#6797) * chore: fixes the breaking tests with older helm chart address Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Co-authored-by: Amit Singh <singhamitch@outlook.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * tests: update the registery url Signed-off-by: semmet95 <singhamitch@outlook.com> * updates the default url Signed-off-by: semmet95 <singhamitch@outlook.com> * test: reverts the changes Signed-off-by: semmet95 <singhamitch@outlook.com> * fix: sets github repo directory as the default definition registry Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: reverts the default definition registry url Signed-off-by: Amit Singh <singhamitch@outlook.com> * test: overwrites custom definition registry url Signed-off-by: Amit Singh <singhamitch@outlook.com> * debugging test failure Signed-off-by: Amit Singh <singhamitch@outlook.com> --------- Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> Signed-off-by: Amit Singh <singhamitch@outlook.com> Co-authored-by: Amit Singh <singhamitch@outlook.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: moves resource modification inside patch block (#6791) * fix: moves resource modification inside patch block Signed-off-by: Ayush Shyam Kumar <ayushshyam.official.888@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: adds changes from make-reviewable Signed-off-by: Ayush Shyam Kumar <ayushshyam.official.888@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * debugging error Signed-off-by: Ayush Shyam Kumar <ayushshyam.official.888@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * test: updates the helm outdated path to new one Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * tests: fixes the failing helm test case Signed-off-by: semmet95 <singhamitch@outlook.com> * removes debugging printing statements Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> --------- Signed-off-by: Ayush Shyam Kumar <ayushshyam.official.888@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> Signed-off-by: Amit Singh <singhamitch@outlook.com> Co-authored-by: Ayush <ayushshyam.official.888@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Chore: switches to new oapi type field type (#6794) * chore: switches to new oapi type field type Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: updates gen_sdk to use the new schema type Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: updates gen_sdk_test to use the new schema type Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: updates schema to use the new schema type Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * fix: updates chart urls Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: changes from make reviewable Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: fixes linting errors Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * debugging test failure Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * fix: fixes schema type nil check Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: replaces literals with constants Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * debugging test failure Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * test: switches to the new addon registry url Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * chore: extra line removal Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * fix: replaces deprecated urls Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * fix: removes extra quotes form marshaljson Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> * fix: updates chart url in mock resource Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> --------- Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: semmet95 <singhamitch@outlook.com> Co-authored-by: Vishal Kumar <vishal210893@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: vela cli namespace behaviour (#6805) Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: vela up command to behave similarly with kubectl (#6809) * Fix: vela up command to behave similarly with kubectl Signed-off-by: Chaitanya Reddy Onteddu <chaitanyareddy0702@gmail.com> * Chore: Update the unit test cases and add a new test cases Signed-off-by: Chaitanya Reddy Onteddu <chaitanyareddy0702@gmail.com> --------- Signed-off-by: Chaitanya Reddy Onteddu <chaitanyareddy0702@gmail.com> Co-authored-by: Chaitanya Reddy Onteddu <co@guidewire.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: check component status after initial deployment (#6824) * fix: check component status after initial deployment Signed-off-by: Brian Kane <briankane1@gmail.com> * Fix: applications should correctly reflect component health throughout the apps lifecycle Signed-off-by: Brian Kane <briankane1@gmail.com> * Fix: check component status after initial deployment Signed-off-by: Brian Kane <briankane1@gmail.com> --------- Signed-off-by: Brian Kane <briankane1@gmail.com> Co-authored-by: Mikhail Elenskii <elenskii-mikhail@outlook.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * chore: upgrade k8s version to v0.31.10 and corresponding fixes Signed-off-by: vishal210893 <vishal210893@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * fix: remove defer from feature gate testing in multiple test files Signed-off-by: vishal210893 <vishal210893@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * fix: remove defer from feature gate testing in multiple test files Signed-off-by: vishal210893 <vishal210893@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * fix: use RunPortForwardContext for improved context handling in port forwarding Signed-off-by: vishal210893 <vishal210893@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Chore: Fix check-diff Signed-off-by: Chaitanya Reddy Onteddu <co@guidewire.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * Chore: Update ENVTEST_K8S_VERSION variable Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * fix: update feature gate testing to use GinkgoT for improved context handling Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: update Kubernetes version in e2e tests to v1.31 Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: increase timeout for application revision retrieval in multicluster tests Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> * chore: update kubevela workflow to master Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Fix: increase timeout in multicluster tests Signed-off-by: Vishal Kumar <vishal210893@gmail.com> * fix: upgrade dependencies and improve context handling in port forwarding Signed-off-by: vishal210893 <vishal210893@gmail.com> * chore: remove space to trigger pipeline Signed-off-by: vishal210893 <vishal210893@gmail.com> * chore: add space to trigger pipeline Signed-off-by: vishal210893 <vishal210893@gmail.com> * chore: updated go sum Signed-off-by: vishal210893 <vishal210893@gmail.com> * chore: updated go.mod for running github action Signed-off-by: vishal210893 <vishal210893@gmail.com> * chore: updated go.mod for running github action Signed-off-by: vishal210893 <vishal210893@gmail.com> * Fix: increase timeout and enhanced multicluster tests Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * adding a comment to re run the pipeline Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * Adding back decription removed during check-diff Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * ran make reviewable Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * replaced generate-groups.sh with kube_codegen.sh Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * API Call changes for kube_codegen Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * fixed incorrect Api package path format and output dir handling Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * resolved incompatible dependencies issue Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> * chore: update clientgen.sh to use kubevela clientgen_work_temp Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * chore: update clientgen.sh to use kubevela clientgen_work_temp Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> * test: increase timeout for application deployment and rollback verification Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> --------- Signed-off-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Signed-off-by: dependabot[bot] <support@github.com> Signed-off-by: Anoop Gopalakrishnan <anoop2811@aol.in> Signed-off-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Signed-off-by: Ayush <ayushshyam.official.888@gmail.com> Signed-off-by: semmet95 <singhamitch@outlook.com> Signed-off-by: Amit Singh <singhamitch@outlook.com> Signed-off-by: Ayush Shyam Kumar <ayushshyam.official.888@gmail.com> Signed-off-by: Chaitanya Reddy Onteddu <chaitanyareddy0702@gmail.com> Signed-off-by: Brian Kane <briankane1@gmail.com> Signed-off-by: vishal210893 <vishal210893@gmail.com> Signed-off-by: Chaitanya Reddy Onteddu <co@guidewire.com> Signed-off-by: Vishal Kumar <vishal210893@gmail.com> Signed-off-by: Reetika Malhotra <malhotra.reetika25@gmail.com> Co-authored-by: Ayush Kumar <ayushshyamkumar888@gmail.com> Co-authored-by: Vaibhav Agrawal <vaibhav.agrawal0096@gmail.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Anoop Gopalakrishnan <2038273+anoop2811@users.noreply.github.com> Co-authored-by: Ayush Kumar <65535504+roguepikachu@users.noreply.github.com> Co-authored-by: Amit Singh <singhamitch@outlook.com> Co-authored-by: Ayush <ayushshyam.official.888@gmail.com> Co-authored-by: Chaitanyareddy0702 <78363486+Chaitanyareddy0702@users.noreply.github.com> Co-authored-by: Chaitanya Reddy Onteddu <co@guidewire.com> Co-authored-by: Brian Kane <briankane1@gmail.com> Co-authored-by: Mikhail Elenskii <elenskii-mikhail@outlook.com> Co-authored-by: Chaitanya Reddy Onteddu <chaitanyareddy0702@gmail.com> Co-authored-by: Reetika Malhotra <malhotra.reetika25@gmail.com>
188 lines
6.9 KiB
Go
188 lines
6.9 KiB
Go
/*
|
|
Copyright 2022 The KubeVela Authors.
|
|
|
|
Licensed 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 policy
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
corev1 "k8s.io/api/core/v1"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"k8s.io/apimachinery/pkg/runtime"
|
|
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
|
featuregatetesting "k8s.io/component-base/featuregate/testing"
|
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
|
|
|
clusterv1alpha1 "github.com/oam-dev/cluster-gateway/pkg/apis/cluster/v1alpha1"
|
|
clustercommon "github.com/oam-dev/cluster-gateway/pkg/common"
|
|
|
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1alpha1"
|
|
"github.com/oam-dev/kubevela/apis/core.oam.dev/v1beta1"
|
|
"github.com/oam-dev/kubevela/apis/types"
|
|
"github.com/oam-dev/kubevela/pkg/features"
|
|
"github.com/oam-dev/kubevela/pkg/multicluster"
|
|
"github.com/oam-dev/kubevela/pkg/utils/common"
|
|
)
|
|
|
|
func TestGetClusterLabelSelectorInTopology(t *testing.T) {
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, features.DeprecatedPolicySpec, true)
|
|
multicluster.ClusterGatewaySecretNamespace = types.DefaultKubeVelaNS
|
|
cli := fake.NewClientBuilder().WithScheme(common.Scheme).WithObjects(&corev1.Secret{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "cluster-a",
|
|
Namespace: multicluster.ClusterGatewaySecretNamespace,
|
|
Labels: map[string]string{
|
|
clustercommon.LabelKeyClusterEndpointType: string(clusterv1alpha1.ClusterEndpointTypeConst),
|
|
clustercommon.LabelKeyClusterCredentialType: string(clusterv1alpha1.CredentialTypeX509Certificate),
|
|
"key": "value",
|
|
},
|
|
},
|
|
}, &corev1.Secret{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "cluster-b",
|
|
Namespace: multicluster.ClusterGatewaySecretNamespace,
|
|
Labels: map[string]string{
|
|
clustercommon.LabelKeyClusterEndpointType: string(clusterv1alpha1.ClusterEndpointTypeConst),
|
|
clustercommon.LabelKeyClusterCredentialType: string(clusterv1alpha1.CredentialTypeX509Certificate),
|
|
"key": "value",
|
|
},
|
|
},
|
|
}, &corev1.Secret{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: "cluster-c",
|
|
Namespace: multicluster.ClusterGatewaySecretNamespace,
|
|
Labels: map[string]string{
|
|
clustercommon.LabelKeyClusterEndpointType: string(clusterv1alpha1.ClusterEndpointTypeConst),
|
|
clustercommon.LabelKeyClusterCredentialType: string(clusterv1alpha1.CredentialTypeX509Certificate),
|
|
"key": "none",
|
|
},
|
|
},
|
|
}).Build()
|
|
appNs := "test"
|
|
testCases := map[string]struct {
|
|
Inputs []v1beta1.AppPolicy
|
|
Outputs []v1alpha1.PlacementDecision
|
|
Error string
|
|
AllowCrossNamespace bool
|
|
}{
|
|
"invalid-topology-policy": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"cluster":"x"}`)},
|
|
}},
|
|
Error: "failed to parse topology policy",
|
|
},
|
|
"cluster-not-found": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusters":["cluster-x"]}`)},
|
|
}},
|
|
Error: "failed to get cluster",
|
|
},
|
|
"topology-by-clusters": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusters":["cluster-a"]}`)},
|
|
}},
|
|
Outputs: []v1alpha1.PlacementDecision{{Cluster: "cluster-a", Namespace: ""}},
|
|
},
|
|
"topology-by-cluster-selector-404": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusterSelector":{"key":"bad-value"}}`)},
|
|
}},
|
|
Error: "failed to find any cluster matches given labels",
|
|
},
|
|
"topology-by-cluster-selector-ignore-404": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusterSelector":{"key":"bad-value"},"allowEmpty":true}`)},
|
|
}},
|
|
Outputs: []v1alpha1.PlacementDecision{},
|
|
},
|
|
"topology-by-cluster-selector": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusterSelector":{"key":"value"}}`)},
|
|
}},
|
|
Outputs: []v1alpha1.PlacementDecision{{Cluster: "cluster-a", Namespace: ""}, {Cluster: "cluster-b", Namespace: ""}},
|
|
},
|
|
"topology-by-cluster-label-selector": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusterLabelSelector":{"key":"value"}}`)},
|
|
}},
|
|
Outputs: []v1alpha1.PlacementDecision{{Cluster: "cluster-a", Namespace: ""}, {Cluster: "cluster-b", Namespace: ""}},
|
|
},
|
|
"topology-by-cluster-selector-and-namespace-invalid": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusterSelector":{"key":"value"},"namespace":"override"}`)},
|
|
}},
|
|
Error: "cannot cross namespace",
|
|
},
|
|
"topology-by-cluster-selector-and-namespace": {
|
|
Inputs: []v1beta1.AppPolicy{{
|
|
Name: "topology-policy",
|
|
Type: "topology",
|
|
Properties: &runtime.RawExtension{Raw: []byte(`{"clusterSelector":{"key":"value"},"namespace":"override"}`)},
|
|
}},
|
|
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: ""}},
|
|
},
|
|
"empty-topology-policy": {
|
|
Inputs: []v1beta1.AppPolicy{{Type: "topology", Name: "some-name", Properties: nil}},
|
|
Error: "have empty properties",
|
|
},
|
|
}
|
|
for name, tt := range testCases {
|
|
t.Run(name, func(t *testing.T) {
|
|
r := require.New(t)
|
|
pds, err := GetPlacementsFromTopologyPolicies(context.Background(), cli, appNs, tt.Inputs, tt.AllowCrossNamespace)
|
|
if tt.Error != "" {
|
|
r.NotNil(err)
|
|
r.Contains(err.Error(), tt.Error)
|
|
} else {
|
|
r.NoError(err)
|
|
r.Equal(tt.Outputs, pds)
|
|
}
|
|
})
|
|
}
|
|
}
|