|
| 1 | +/* |
| 2 | +Copyright (C) 2022-2025 ApeCloud Co., Ltd |
| 3 | +
|
| 4 | +This file is part of KubeBlocks project |
| 5 | +
|
| 6 | +This program is free software: you can redistribute it and/or modify |
| 7 | +it under the terms of the GNU Affero General Public License as published by |
| 8 | +the Free Software Foundation, either version 3 of the License, or |
| 9 | +(at your option) any later version. |
| 10 | +
|
| 11 | +This program is distributed in the hope that it will be useful |
| 12 | +but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +GNU Affero General Public License for more details. |
| 15 | +
|
| 16 | +You should have received a copy of the GNU Affero General Public License |
| 17 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | +*/ |
| 19 | + |
| 20 | +package instanceset2 |
| 21 | + |
| 22 | +import ( |
| 23 | + "strings" |
| 24 | + "testing" |
| 25 | + |
| 26 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 27 | + "k8s.io/utils/ptr" |
| 28 | + |
| 29 | + workloads "github.com/apecloud/kubeblocks/apis/workloads/v1" |
| 30 | + "github.com/apecloud/kubeblocks/pkg/constant" |
| 31 | + "github.com/apecloud/kubeblocks/pkg/controller/kubebuilderx" |
| 32 | +) |
| 33 | + |
| 34 | +func TestValidationRejectsNodeSelectorOnce(t *testing.T) { |
| 35 | + tree := kubebuilderx.NewObjectTree() |
| 36 | + tree.SetRoot(&workloads.InstanceSet{ |
| 37 | + ObjectMeta: metav1.ObjectMeta{ |
| 38 | + Name: "test-its", |
| 39 | + Namespace: "default", |
| 40 | + Annotations: map[string]string{ |
| 41 | + constant.NodeSelectorOnceAnnotationKey: `{"test-its-0":"node-a"}`, |
| 42 | + }, |
| 43 | + }, |
| 44 | + Spec: workloads.InstanceSetSpec{ |
| 45 | + Replicas: ptr.To[int32](1), |
| 46 | + EnableInstanceAPI: ptr.To(true), |
| 47 | + }, |
| 48 | + }) |
| 49 | + |
| 50 | + _, err := NewValidationReconciler().Reconcile(tree) |
| 51 | + if err == nil { |
| 52 | + t.Fatalf("expected validation error") |
| 53 | + } |
| 54 | + if !strings.Contains(err.Error(), constant.NodeSelectorOnceAnnotationKey) { |
| 55 | + t.Fatalf("expected error to mention %s, got: %v", constant.NodeSelectorOnceAnnotationKey, err) |
| 56 | + } |
| 57 | +} |
0 commit comments