Skip to content

Commit bdc0e4f

Browse files
feat: Add NodeSelectorChaos (#99)
1 parent 6a30e2e commit bdc0e4f

31 files changed

+2183
-2
lines changed
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// Copyright 2021 Chaos Mesh Authors.PodPVCChaos
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
package v1alpha1
17+
18+
import (
19+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20+
)
21+
22+
var (
23+
_ InnerObject = (*NodeSelectorChaos)(nil)
24+
_ InnerObjectWithSelector = (*NodeSelectorChaos)(nil)
25+
)
26+
27+
// +kubebuilder:object:root=true
28+
// +chaos-mesh:experiment
29+
type NodeSelectorChaos struct {
30+
metav1.TypeMeta `json:",inline"`
31+
metav1.ObjectMeta `json:"metadata,omitempty"`
32+
33+
Spec NodeSelectorChaosSpec `json:"spec"`
34+
Status NodeSelectorChaosStatus `json:"status"`
35+
}
36+
37+
type NodeSelectorChaosSpec struct {
38+
DeploymentSelectorSpec `json:"selector"`
39+
// Key is the name of the key that will be applied to the deployment's nodeSelector field.
40+
Key string `json:"key"`
41+
// Value is the value assigned to the provided key.
42+
Value string `json:"value"`
43+
// Duration represents the duration of the chaos
44+
// +optional
45+
Duration *string `json:"duration,omitempty"`
46+
// RemoteCluster represents the remote cluster where the chaos will be deployed
47+
// +optional
48+
RemoteCluster string `json:"remoteCluster,omitempty"`
49+
}
50+
type NodeSelectorChaosStatus struct {
51+
ChaosStatus `json:",inline"`
52+
}
53+
54+
func (obj *NodeSelectorChaos) GetSelectorSpecs() map[string]interface{} {
55+
return map[string]interface{}{
56+
".": &obj.Spec.DeploymentSelector,
57+
}
58+
}

api/v1alpha1/selector.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,3 +164,12 @@ type NodeSelectorSpec struct {
164164
// +optional
165165
ExpressionSelectors LabelSelectorRequirements `json:"expressionSelectors,omitempty" swaggerignore:"true"`
166166
}
167+
168+
type DeploymentSelector struct {
169+
// Map of namespace names to a list of deployments in that namespace.
170+
Deployments map[string][]string `json:"deployments,omitempty"`
171+
}
172+
173+
type DeploymentSelectorSpec struct {
174+
DeploymentSelector `json:",inline"`
175+
}

api/v1alpha1/zz_generated.chaosmesh.go

Lines changed: 149 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/v1alpha1/zz_generated.chaosmesh_test.go

Lines changed: 63 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)