You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
returnfmt.Sprintf("While the disruption is ongoing, it will send slack messages for every event of severity %s or higher, "+
142
+
"to the slack channel with the ID (not name) %s, mentioning the purpose \"%s\"",
143
+
r.MinNotificationType,
144
+
r.SlackChannel,
145
+
r.Purpose)
146
+
}
147
+
140
148
// EmbeddedChaosAPI includes the library so it can be statically exported to chaosli
141
149
//
142
150
//go:embed *.go
@@ -875,6 +883,149 @@ func (s DisruptionSpec) DisruptionCount() int {
875
883
returncount
876
884
}
877
885
886
+
// Explain returns a string explanation of this disruption spec
887
+
func (sDisruptionSpec) Explain() []string {
888
+
varexplanation []string
889
+
explanation=append(explanation, "Here's our best explanation of what this spec will do when run:")
890
+
891
+
durationExpl:=s.Duration.Duration().String()
892
+
ifs.Duration.Duration() ==0 {
893
+
durationExpl="not set, so the default duration for your cluster will be used"
894
+
}
895
+
896
+
explanation=append(explanation, fmt.Sprintf("spec.duration is %s. After that amount of time, the disruption "+
897
+
"will stop and clean itself up. If it fails to clean up, an alert will be sent. If you want the disruption to stop early, "+
898
+
"just try to delete the disruption. All chaos-injector pods will immediately try to stop the failure.",
899
+
durationExpl,
900
+
))
901
+
902
+
ifs.DryRun {
903
+
explanation=append(explanation, "spec.dryRun is set to true, meaning we will simulate a real disruption "+
904
+
"as best as possible, by creating the resource, picking targets, and creating chaos-injector pods, "+
905
+
"but we will not inject any actual failure.")
906
+
}
907
+
908
+
// s.Level can be "", which defaults to Pod
909
+
ifs.Level!=chaostypes.DisruptionLevelNode {
910
+
explanation=append(explanation, "spec.level is pod. We will pick pods as targets based on your selector, and inject the failure into the pods' containers.")
911
+
} else {
912
+
explanation=append(explanation, "spec.level is node. We will pick nodes as targets based on your selector, and inject the failure into the nodes, affecting all pods on those nodes.")
913
+
}
914
+
915
+
ifs.Selector!=nil {
916
+
explanation=append(explanation, fmt.Sprintf("This spec has the following selectors which will be used to target %ss with these labels:\n\t%s", s.Level, s.Selector.String()))
917
+
}
918
+
919
+
ifs.AdvancedSelector!=nil {
920
+
advancedSelectorExplanation:=fmt.Sprintf("This spec has the following advanced selectors which will be used to target %ss based on their labels:\n", s.Level)
explanation=append(explanation, fmt.Sprintf("This spec has the following annotation filters which will be used to target %ss with these annotations.\n\t%s\n", s.Level, s.Filter.Annotations.String()))
931
+
}
932
+
933
+
ifs.Containers!=nil {
934
+
explanation=append(explanation, fmt.Sprintf("spec.containers is set, so this disruption will only inject the failure the following containers on the target pods\n\t%s\n", strings.Join(s.Containers, ",")))
935
+
}
936
+
937
+
ifs.Pulse!=nil {
938
+
explanation=append(explanation,
939
+
fmt.Sprintf("spec.pulse is set, so rather than a constant failure injection, after an initial delay of %s"+
940
+
" the disruption will alternate between an active injected state with a duration of %s,"+
941
+
" and an inactive dormant state with a duration of %s.\n",
942
+
s.Pulse.InitialDelay.Duration().String(),
943
+
s.Pulse.ActiveDuration.Duration().String(),
944
+
s.Pulse.DormantDuration.Duration().String()))
945
+
}
946
+
947
+
ifs.OnInit {
948
+
explanation=append(explanation, fmt.Sprintf("spec.onInit is true. "+
949
+
"The disruptions will be launched during the initialization of the targeted pods."+
950
+
"This requires some extra setup on your end, please [read the full documentation](https://github.com/DataDog/chaos-controller/blob/main/docs/features.md#applying-a-disruption-on-pod-initialization)"))
951
+
}
952
+
953
+
countSuffix:=""
954
+
ifs.Count.Type==intstr.Int {
955
+
countSuffix=fmt.Sprintf("exactly %d %ss. If it can't find that many targets, it will inject into as many as it discovers. "+
956
+
"If there are more than %d eligible targets, a random %d will be chosen.",
957
+
s.Count.IntValue(),
958
+
s.Level,
959
+
s.Count.IntValue(),
960
+
s.Count.IntValue(),
961
+
)
962
+
ifs.Count.IntValue() ==100 {
963
+
countSuffix+=" Your count is \"100\", but you almost certainly meant to specify \"100%\". The former means to find exactly 100 targets, the latter means to inject into all available targets."
964
+
} else {
965
+
countSuffix+=" If it's more convenient, you can set spec.count to a % instead (just append the '%' character)."
966
+
}
967
+
} else {
968
+
countSuffix=fmt.Sprintf("%s percent of all eligible %ss found. "+
969
+
"If it's more convenient, you can set spec.count to an int intead of a percentage.",
970
+
s.Count.String(),
971
+
s.Level,
972
+
)
973
+
}
974
+
975
+
explanation=append(explanation, fmt.Sprintf("spec.count is %s, so the disruption will try to target %s",
976
+
s.Count.String(),
977
+
countSuffix,
978
+
))
979
+
980
+
ifs.StaticTargeting {
981
+
explanation=append(explanation, fmt.Sprintf("spec.staticTargeting is true, so after we pick an initial set of targets and inject, "+
982
+
"we will not attempt to inject into any new targets that appear while the disruption is ongoing."))
983
+
} else {
984
+
explanation=append(explanation, "By default we will continually compare the injected target count "+
985
+
"to your defined spec.count, and add/remove targets as needed, e.g., with a count of \"100%\", if new targets "+
986
+
"are scheduled, we will inject into them as well. "+
987
+
"If you want a different behavior, trying setting spec.staticTargeting to true.")
Copy file name to clipboardExpand all lines: api/v1beta1/dns_disruption.go
+10Lines changed: 10 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -74,3 +74,13 @@ func (s DNSDisruptionSpec) GenerateArgs() []string {
74
74
75
75
returnargs
76
76
}
77
+
78
+
func (sDNSDisruptionSpec) Explain() []string {
79
+
explanation:= []string{"", "spec.dns will intercept DNS requests from the target, replacing the specified records:"}
80
+
81
+
for_, pair:=ranges {
82
+
explanation=append(explanation, fmt.Sprintf("DNS queries for %s will return an %s record with the value %s", pair.Hostname, pair.Record.Type, pair.Record.Value))
0 commit comments