Skip to content

Commit 01a76ca

Browse files
authored
feat: add LabelMatchMode field to Workload struct (#510)
* feat: add LabelMatchMode field to Workload struct Signed-off-by: XploY04 <2004agarwalyash@gmail.com> * feat: add LabelMatchMode to ApplicationParams and update target formatting Signed-off-by: XploY04 <2004agarwalyash@gmail.com> * chore: add modern Kubebuilder config structure with labelMatchMode support - Generated by controller-gen v0.16.5 - Includes CRDs with labelMatchMode field in OpenAPI schema - Follows Kubebuilder v3+ project layout Signed-off-by: XploY04 <2004agarwalyash@gmail.com> * update: bump controller-tools version to v0.16.5 and clean up build tags Signed-off-by: XploY04 <2004agarwalyash@gmail.com> * gofmt chaosengine_types.go Signed-off-by: XploY04 <2004agarwalyash@gmail.com> --------- Signed-off-by: XploY04 <2004agarwalyash@gmail.com>
1 parent af8244e commit 01a76ca

File tree

8 files changed

+4035
-8
lines changed

8 files changed

+4035
-8
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ LOCALBIN ?= $(shell pwd)/bin
9595
$(LOCALBIN):
9696
mkdir -p $(LOCALBIN)
9797
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
98-
CONTROLLER_TOOLS_VERSION ?= v0.9.0
98+
CONTROLLER_TOOLS_VERSION ?= v0.16.5
9999

100100
.PHONY: controller-gen
101101
controller-gen: $(CONTROLLER_GEN) ## Download controller-gen locally if necessary.

api/litmuschaos/v1alpha1/chaosengine_types.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ type ApplicationParams struct {
117117
Applabel string `json:"applabel,omitempty"`
118118
//kind of application
119119
AppKind string `json:"appkind,omitempty"`
120+
//LabelMatchMode specifies how to match labels (union or intersection)
121+
LabelMatchMode string `json:"labelMatchMode,omitempty"`
120122
}
121123

122124
type Selector struct {
@@ -135,10 +137,11 @@ const (
135137
)
136138

137139
type Workload struct {
138-
Kind WorkloadKind `json:"kind"`
139-
Namespace string `json:"namespace"`
140-
Names string `json:"names,omitempty"`
141-
Labels string `json:"labels,omitempty"`
140+
Kind WorkloadKind `json:"kind"`
141+
Namespace string `json:"namespace"`
142+
Names string `json:"names,omitempty"`
143+
Labels string `json:"labels,omitempty"`
144+
LabelMatchMode string `json:"labelMatchMode,omitempty"`
142145
}
143146

144147
type Pod struct {

api/litmuschaos/v1alpha1/zz_generated.deepcopy.go

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

config/crd/bases/litmuschaos.io_chaosengines.yaml

Lines changed: 3163 additions & 0 deletions
Large diffs are not rendered by default.

config/crd/bases/litmuschaos.io_chaosexperiments.yaml

Lines changed: 664 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.16.5
7+
name: chaosresults.litmuschaos.io
8+
spec:
9+
group: litmuschaos.io
10+
names:
11+
kind: ChaosResult
12+
listKind: ChaosResultList
13+
plural: chaosresults
14+
singular: chaosresult
15+
scope: Namespaced
16+
versions:
17+
- name: v1alpha1
18+
schema:
19+
openAPIV3Schema:
20+
description: ChaosResult is the Schema for the chaosresults API
21+
properties:
22+
apiVersion:
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
28+
type: string
29+
kind:
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
36+
type: string
37+
metadata:
38+
type: object
39+
spec:
40+
description: |-
41+
ChaosResultSpec defines the desired state of ChaosResult
42+
The chaosresult holds the status of a chaos experiment that is listed as an item
43+
in the chaos engine to be run against a given app.
44+
properties:
45+
engine:
46+
description: EngineName defines the name of chaosEngine
47+
type: string
48+
experiment:
49+
description: ExperimentName defines the name of chaosexperiment
50+
type: string
51+
instance:
52+
description: InstanceID defines the instance id
53+
type: string
54+
required:
55+
- experiment
56+
type: object
57+
status:
58+
description: ChaosResultStatus defines the observed state of ChaosResult
59+
properties:
60+
experimentStatus:
61+
description: ExperimentStatus contains the status,verdict of the experiment
62+
properties:
63+
errorOutput:
64+
description: ErrorOutput defines error message and error code
65+
properties:
66+
errorCode:
67+
description: ErrorCode defines error code of the experiment
68+
type: string
69+
reason:
70+
description: Reason contains the error reason
71+
type: string
72+
type: object
73+
phase:
74+
description: Phase defines whether an experiment is running or
75+
completed
76+
type: string
77+
probeSuccessPercentage:
78+
description: ProbeSuccessPercentage defines the score of the probes
79+
type: string
80+
verdict:
81+
description: Verdict defines whether an experiment result is pass
82+
or fail
83+
type: string
84+
required:
85+
- phase
86+
- verdict
87+
type: object
88+
history:
89+
description: History contains cumulative values of verdicts
90+
properties:
91+
failedRuns:
92+
type: integer
93+
passedRuns:
94+
type: integer
95+
stoppedRuns:
96+
type: integer
97+
targets:
98+
items:
99+
description: TargetDetails contains target details for the experiment
100+
and the chaos status
101+
properties:
102+
chaosStatus:
103+
type: string
104+
kind:
105+
type: string
106+
name:
107+
type: string
108+
type: object
109+
type: array
110+
required:
111+
- failedRuns
112+
- passedRuns
113+
- stoppedRuns
114+
type: object
115+
probeStatuses:
116+
description: ProbeStatus contains the status of the probe
117+
items:
118+
description: ProbeStatus defines information about the status and
119+
result of the probes
120+
properties:
121+
mode:
122+
description: 'Mode defined the mode of probe, supported values:
123+
SOT, EOT, Edge, OnChaos, Continuous'
124+
type: string
125+
name:
126+
description: Name defines the name of probe
127+
type: string
128+
status:
129+
description: Status defines whether a probe is pass or fail
130+
properties:
131+
description:
132+
description: Description defines the description of probe
133+
status
134+
type: string
135+
verdict:
136+
description: 'Verdict defines the verdict of the probe,
137+
range: Passed, Failed, N/A'
138+
type: string
139+
type: object
140+
type:
141+
description: 'Type defined the type of probe, supported values:
142+
K8sProbe, HttpProbe, CmdProbe'
143+
type: string
144+
type: object
145+
type: array
146+
required:
147+
- experimentStatus
148+
type: object
149+
type: object
150+
served: true
151+
storage: true
152+
subresources:
153+
status: {}

config/rbac/role.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
apiVersion: rbac.authorization.k8s.io/v1
3+
kind: ClusterRole
4+
metadata:
5+
name: manager-role
6+
rules:
7+
- apiGroups:
8+
- litmuschaos.io
9+
resources:
10+
- chaosengines
11+
verbs:
12+
- create
13+
- delete
14+
- get
15+
- list
16+
- patch
17+
- update
18+
- watch
19+
- apiGroups:
20+
- litmuschaos.io
21+
resources:
22+
- chaosengines/finalizers
23+
verbs:
24+
- update
25+
- apiGroups:
26+
- litmuschaos.io
27+
resources:
28+
- chaosengines/status
29+
verbs:
30+
- get
31+
- patch
32+
- update

controllers/chaosengine_controller.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -646,7 +646,13 @@ func getTargets(engine *chaosTypes.EngineInfo) string {
646646
filter = w.Labels
647647
}
648648

649-
target := strings.Join([]string{string(w.Kind), w.Namespace, fmt.Sprintf("[%v]", filter)}, ":")
649+
// Set label match mode, default to "union" if not specified
650+
labelMatchMode := "union"
651+
if w.LabelMatchMode != "" {
652+
labelMatchMode = w.LabelMatchMode
653+
}
654+
655+
target := strings.Join([]string{string(w.Kind), w.Namespace, fmt.Sprintf("[%v]", filter), labelMatchMode}, ":")
650656
targets = append(targets, target)
651657
}
652658
return strings.Join(targets, ";")
@@ -666,7 +672,14 @@ func getTargets(engine *chaosTypes.EngineInfo) string {
666672
if engine.AppInfo.AppKind == "" {
667673
engine.AppInfo.AppKind = "KIND"
668674
}
669-
return strings.Join([]string{engine.AppInfo.AppKind, engine.AppInfo.Appns, fmt.Sprintf("[%v]", engine.AppInfo.Applabel)}, ":")
675+
676+
// Set label match mode for AppInfo, default to "union" if not specified
677+
labelMatchMode := "union"
678+
if engine.AppInfo.LabelMatchMode != "" {
679+
labelMatchMode = engine.AppInfo.LabelMatchMode
680+
}
681+
682+
return strings.Join([]string{engine.AppInfo.AppKind, engine.AppInfo.Appns, fmt.Sprintf("[%v]", engine.AppInfo.Applabel), labelMatchMode}, ":")
670683
}
671684

672685
// updateExperimentStatusesForStop updates ChaosEngine.Status.Experiment with Abort Status.

0 commit comments

Comments
 (0)