Skip to content

Commit 4bada1b

Browse files
committed
feat: align DataGather with InsightsDataGather
This commit aligns the configuration options of the DataGather CRD with those of InsightsDataGather, making it easier to use both CRDs. Signed-off-by: Ondrej Pokorny <[email protected]>
1 parent bb4323d commit 4bada1b

File tree

11 files changed

+854
-347
lines changed

11 files changed

+854
-347
lines changed

insights/v1alpha2/tests/datagathers.insights.openshift.io/InsightsOnDemandDataGather.yaml

Lines changed: 148 additions & 60 deletions
Large diffs are not rendered by default.

insights/v1alpha2/types_insights.go

Lines changed: 98 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// +kubebuilder:object:root=true
1111
// +kubebuilder:resource:path=datagathers,scope=Cluster
1212
// +kubebuilder:subresource:status
13-
// +openshift:api-approved.openshift.io=https://github.com/openshift/api/pull/1365
13+
// +openshift:api-approved.openshift.io=https://github.com/openshift/api/pull/2248
1414
// +openshift:file-pattern=cvoRunLevel=0000_10,operatorName=insights,operatorOrdering=01
1515
// +openshift:enable:FeatureGate=InsightsOnDemandDataGather
1616
// +kubebuilder:printcolumn:name=State,type=string,JSONPath=.status.dataGatherState,description=DataGather job state
@@ -37,28 +37,71 @@ type DataGather struct {
3737

3838
// DataGatherSpec contains the configuration for the DataGather.
3939
type DataGatherSpec struct {
40-
// dataPolicy allows user to enable additional global obfuscation of the IP addresses and base domain
41-
// in the Insights archive data. Valid values are "ClearText" and "ObfuscateNetworking".
42-
// When set to ClearText the data is not obfuscated.
40+
// dataPolicy is an optional list of DataPolicyOptions that allows user to enable additional obfuscation of the Insights archive data.
41+
// It may not exceed 2 items and must not contain duplicates.
42+
// Valid values are ObfuscateNetworking and WorkloadNames.
4343
// When set to ObfuscateNetworking the IP addresses and the cluster domain name are obfuscated.
44-
// When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time.
45-
// The current default is ClearText.
44+
// When set to WorkloadNames, the gathered data about cluster resources will not contain the workload names for your deployments. Resources UIDs will be used instead.
45+
// When omitted no obfuscation is applied.
46+
// +kubebuilder:validation:MaxItems=2
47+
// +kubebuilder:validation:XValidation:rule="self.all(x, self.exists_one(y, x == y))",message="dataPolicy items must be unique"
48+
// +listType=atomic
4649
// +optional
47-
DataPolicy DataPolicy `json:"dataPolicy"`
48-
// gatherers is an optional list of gatherers configurations.
49-
// The list must not exceed 100 items.
50-
// The particular gatherers IDs can be found at https://github.com/openshift/insights-operator/blob/master/docs/gathered-data.md.
51-
// Run the following command to get the names of last active gatherers:
52-
// "oc get insightsoperators.operator.openshift.io cluster -o json | jq '.status.gatherStatus.gatherers[].name'"
53-
// +kubebuilder:validation:MaxItems=100
50+
DataPolicy []DataPolicyOption `json:"dataPolicy"`
51+
// gatherers is an optional field that specifies the configuration of the gatherers.
5452
// +optional
55-
Gatherers []GathererConfig `json:"gatherers,omitempty"`
53+
Gatherers Gatherers `json:"gatherers,omitempty"`
5654
// storage is an optional field that allows user to define persistent storage for gathering jobs to store the Insights data archive.
5755
// If omitted, the gathering job will use ephemeral storage.
5856
// +optional
5957
Storage *Storage `json:"storage,omitempty"`
6058
}
6159

60+
// Gathereres specifies the configuration of the gatherers
61+
// +kubebuilder:validation:XValidation:rule="has(self.mode) && self.mode == 'Custom' ? has(self.custom) : !has(self.custom)",message="custom is required when mode is Custom, and forbidden otherwise"
62+
type Gatherers struct {
63+
// mode is a required field that specifies the mode for gatherers. Allowed values are All, None, and Custom.
64+
// When set to All, all gatherers wil run and gather data.
65+
// When set to None, all gatherers will be disabled and no data will be gathered.
66+
// When set to Custom, the custom configuration from the custom field will be applied.
67+
// +required
68+
Mode GatheringMode `json:"mode"`
69+
// custom provides gathering configuration.
70+
// It is required when mode is Custom, and forbidden otherwise.
71+
// Custom configuration allows user to disable only a subset of gatherers.
72+
// Gatherers that are not explicitly disabled in custom configuration will run.
73+
// +optional
74+
Custom *Custom `json:"custom,omitempty"`
75+
}
76+
77+
// custom provides the custom configuration of gatherers
78+
type Custom struct {
79+
// configs is a required list of gatherers configurations that can be used to enable or disable specific gatherers.
80+
// It may not exceed 100 items and each gatherer can be present only once.
81+
// It is possible to disable an entire set of gatherers while allowing a specific function within that set.
82+
// The particular gatherers IDs can be found at https://github.com/openshift/insights-operator/blob/master/docs/gathered-data.md.
83+
// Run the following command to get the names of last active gatherers:
84+
// "oc get insightsoperators.operator.openshift.io cluster -o json | jq '.status.gatherStatus.gatherers[].name'"
85+
// +kubebuilder:validation:MaxItems=100
86+
// +listType=map
87+
// +listMapKey=name
88+
// +required
89+
Configs []GathererConfig `json:"configs"`
90+
}
91+
92+
// gatheringMode defines the valid gathering modes.
93+
// +kubebuilder:validation:Enum=All;None;Custom
94+
type GatheringMode string
95+
96+
const (
97+
// Enabled enables all gatherers
98+
GatheringModeAll GatheringMode = "All"
99+
// Disabled disables all gatherers
100+
GatheringModeNone GatheringMode = "None"
101+
// Custom applies the configuration from GatheringConfig.
102+
GatheringModeCustom GatheringMode = "Custom"
103+
)
104+
62105
// storage provides persistent storage configuration options for gathering jobs.
63106
// If the type is set to PersistentVolume, then the PersistentVolume must be defined.
64107
// If the type is set to Ephemeral, then the PersistentVolume must not be defined.
@@ -114,52 +157,49 @@ type PersistentVolumeClaimReference struct {
114157
Name string `json:"name"`
115158
}
116159

160+
// dataPolicyOption declares valid data policy types
161+
// +kubebuilder:validation:Enum=ObfuscateNetworking;WorkloadNames
162+
type DataPolicyOption string
163+
117164
const (
118-
// No data obfuscation
119-
NoPolicy DataPolicy = "ClearText"
120165
// IP addresses and cluster domain name are obfuscated
121-
ObfuscateNetworking DataPolicy = "ObfuscateNetworking"
122-
// Data gathering is running
123-
Running DataGatherState = "Running"
124-
// Data gathering is completed
125-
Completed DataGatherState = "Completed"
126-
// Data gathering failed
127-
Failed DataGatherState = "Failed"
128-
// Data gathering is pending
129-
Pending DataGatherState = "Pending"
130-
// Gatherer state marked as disabled, which means that the gatherer will not run.
131-
Disabled GathererState = "Disabled"
132-
// Gatherer state marked as enabled, which means that the gatherer will run.
133-
Enabled GathererState = "Enabled"
166+
DataPolicyOptionObfuscateNetworking DataPolicyOption = "ObfuscateNetworking"
167+
// Data from Deployment Validation Operator are obfuscated
168+
DataPolicyOptionObfuscateWorkloadNames DataPolicyOption = "WorkloadNames"
134169
)
135170

136-
// dataPolicy declares valid data policy types
137-
// +kubebuilder:validation:Enum="";ClearText;ObfuscateNetworking
138-
type DataPolicy string
139-
140-
// state declares valid gatherer state types.
141-
// +kubebuilder:validation:Enum="";Enabled;Disabled
142-
type GathererState string
143-
144171
// gathererConfig allows to configure specific gatherers
145172
type GathererConfig struct {
146-
// name is the required name of specific gatherer
147-
// It must be at most 256 characters in length.
148-
// The format for the gatherer name should be: {gatherer}/{function} where the function is optional.
173+
// name is the required name of a specific gatherer
174+
// It may not exceed 256 characters.
175+
// The format for a gatherer name is: {gatherer}/{function} where the function is optional.
149176
// Gatherer consists of a lowercase letters only that may include underscores (_).
150177
// Function consists of a lowercase letters only that may include underscores (_) and is separated from the gatherer by a forward slash (/).
151178
// The particular gatherers can be found at https://github.com/openshift/insights-operator/blob/master/docs/gathered-data.md.
179+
// Run the following command to get the names of last active gatherers:
180+
// "oc get insightsoperators.operator.openshift.io cluster -o json | jq '.status.gatherStatus.gatherers[].name'"
152181
// +kubebuilder:validation:MaxLength=256
153182
// +kubebuilder:validation:XValidation:rule=`self.matches("^[a-z]+[_a-z]*[a-z]([/a-z][_a-z]*)?[a-z]$")`,message=`gatherer name must be in the format of {gatherer}/{function} where the gatherer and function are lowercase letters only that may include underscores (_) and are separated by a forward slash (/) if the function is provided`
154183
// +required
155184
Name string `json:"name"`
156-
// state allows you to configure specific gatherer. Valid values are "Enabled", "Disabled" and omitted.
157-
// When omitted, this means no opinion and the platform is left to choose a reasonable default.
158-
// The current default is Enabled.
159-
// +optional
185+
// state is a required field that allows you to configure specific gatherer. Valid values are "Enabled" and "Disabled".
186+
// When set to Enabled the gatherer will run.
187+
// When set to Disabled the gatherer will not run.
188+
// +required
160189
State GathererState `json:"state"`
161190
}
162191

192+
// state declares valid gatherer state types.
193+
// +kubebuilder:validation:Enum=Enabled;Disabled
194+
type GathererState string
195+
196+
const (
197+
// GathererStateEnabled gatherer state, which means that the gatherer will run.
198+
GathererStateEnabled GathererState = "Enabled"
199+
// GathererStateDisabled gatherer state, which means that the gatherer will not run.
200+
GathererStateDisabled GathererState = "Disabled"
201+
)
202+
163203
// dataGatherState declares valid gathering state types
164204
// +kubebuilder:validation:Optional
165205
// +kubebuilder:validation:Enum=Running;Completed;Failed;Pending
@@ -170,6 +210,17 @@ type GathererConfig struct {
170210
// +kubebuilder:validation:XValidation:rule="!(oldSelf == 'Failed' && self == 'Running')", message="dataGatherState cannot transition from Failed to Running"
171211
type DataGatherState string
172212

213+
const (
214+
// Data gathering is running
215+
DataGatherStateRunning DataGatherState = "Running"
216+
// Data gathering is completed
217+
DataGatherStateCompleted DataGatherState = "Completed"
218+
// Data gathering failed
219+
DataGatherStateFailed DataGatherState = "Failed"
220+
// Data gathering is pending
221+
DataGatherStatePending DataGatherState = "Pending"
222+
)
223+
173224
// DataGatherStatus contains information relating to the DataGather state.
174225
// +kubebuilder:validation:XValidation:rule="(!has(oldSelf.insightsRequestID) || has(self.insightsRequestID))",message="cannot remove insightsRequestID attribute from status"
175226
// +kubebuilder:validation:XValidation:rule="(!has(oldSelf.startTime) || has(self.startTime))",message="cannot remove startTime attribute from status"
@@ -202,6 +253,7 @@ type DataGatherStatus struct {
202253
FinishTime metav1.Time `json:"finishTime,omitempty"`
203254
// relatedObjects is a list of resources which are useful when debugging or inspecting the data
204255
// gathering Pod
256+
// +listType=atomic
205257
// +kubebuilder:validation:MaxItems=100
206258
// +optional
207259
RelatedObjects []ObjectReference `json:"relatedObjects,omitempty"`
@@ -226,8 +278,8 @@ type GathererStatus struct {
226278
// +listMapKey=type
227279
// +kubebuilder:validation:MinItems=1
228280
// +kubebuilder:validation:MaxItems=100
229-
// +required
230-
Conditions []metav1.Condition `json:"conditions"`
281+
// +optional
282+
Conditions []metav1.Condition `json:"conditions,omitempty"`
231283
// name is the name of the gatherer.
232284
// +required
233285
// +kubebuilder:validation:MaxLength=256

0 commit comments

Comments
 (0)