@@ -48,6 +48,7 @@ func NewCyberArk(httpClient *http.Client) (*CyberArkClient, error) {
4848
4949// PostDataReadingsWithOptions uploads data readings to CyberArk.
5050// It converts the supplied data readings into a snapshot format expected by CyberArk.
51+ // Deleted resources are excluded from the snapshot because they are not needed by CyberArk.
5152// It then minimizes the snapshot to avoid uploading unnecessary data.
5253// It initializes a data upload client with the configured HTTP client and credentials,
5354// then uploads a snapshot.
@@ -112,6 +113,8 @@ func extractClusterIDAndServerVersionFromReading(reading *api.DataReading, targe
112113// extractResourceListFromReading converts the opaque data from a DynamicData
113114// data reading to runtime.Object resources, to allow access to the metadata and
114115// other kubernetes API fields.
116+ // Deleted resources are skipped because the CyberArk Discovery and Context service
117+ // does not need to see resources that no longer exist.
115118func extractResourceListFromReading (reading * api.DataReading , target * []runtime.Object ) error {
116119 if reading == nil {
117120 return fmt .Errorf ("programmer mistake: the DataReading must not be nil" )
@@ -122,10 +125,13 @@ func extractResourceListFromReading(reading *api.DataReading, target *[]runtime.
122125 "programmer mistake: the DataReading must have data type *api.DynamicData. " +
123126 "This DataReading (%s) has data type %T" , reading .DataGatherer , reading .Data )
124127 }
125- resources := make ([]runtime.Object , len (data .Items ))
128+ resources := make ([]runtime.Object , 0 , len (data .Items ))
126129 for i , item := range data .Items {
130+ if ! item .DeletedAt .IsZero () {
131+ continue
132+ }
127133 if resource , ok := item .Resource .(runtime.Object ); ok {
128- resources [ i ] = resource
134+ resources = append ( resources , resource )
129135 } else {
130136 return fmt .Errorf (
131137 "programmer mistake: the DynamicData items must have Resource type runtime.Object. " +
@@ -136,6 +142,11 @@ func extractResourceListFromReading(reading *api.DataReading, target *[]runtime.
136142 return nil
137143}
138144
145+ // defaultExtractorFunctions maps data gatherer names to functions that extract
146+ // their data from DataReadings into the appropriate fields of a Snapshot.
147+ // Each function takes a DataReading and a pointer to a Snapshot,
148+ // and populates the relevant field(s) of the Snapshot based on the DataReading's data.
149+ // Deleted resources are excluded from the snapshot because they are not needed by CyberArk.
139150var defaultExtractorFunctions = map [string ]func (* api.DataReading , * dataupload.Snapshot ) error {
140151 "ark/discovery" : extractClusterIDAndServerVersionFromReading ,
141152 "ark/secrets" : func (r * api.DataReading , s * dataupload.Snapshot ) error {
@@ -184,6 +195,7 @@ var defaultExtractorFunctions = map[string]func(*api.DataReading, *dataupload.Sn
184195// The extractorFunctions map should contain functions for each expected
185196// DataGatherer name, which will be called with the corresponding DataReading
186197// and the target snapshot to populate the relevant fields.
198+ // Deleted resources are excluded from the snapshot because they are not needed by CyberArk.
187199func convertDataReadings (
188200 extractorFunctions map [string ]func (* api.DataReading , * dataupload.Snapshot ) error ,
189201 readings []* api.DataReading ,
0 commit comments