Skip to content

Commit 7a14eda

Browse files
author
oluwole.fadeyi
committed
Move schema version to dataReading element
Moves the schemaVersion field to reading elements rather than the agent reading post element. Signed-off-by: oluwole.fadeyi <[email protected]>
1 parent 56aa65a commit 7a14eda

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

api/datareading.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ type DataReadingsPost struct {
1111
// DataGatherTime represents the time that the data readings were gathered
1212
DataGatherTime time.Time `json:"data_gather_time"`
1313
DataReadings []*DataReading `json:"data_readings"`
14-
SchemaVersion string `json:"schema_version"`
1514
}
1615

1716
// DataReading is the output of a DataGatherer.
1817
type DataReading struct {
1918
// ClusterID is optional as it can be infered from the agent
2019
// token when using basic authentication.
21-
ClusterID string `json:"cluster_id,omitempty"`
22-
DataGatherer string `json:"data-gatherer"`
23-
Timestamp Time `json:"timestamp"`
24-
Data interface{} `json:"data"`
20+
ClusterID string `json:"cluster_id,omitempty"`
21+
DataGatherer string `json:"data-gatherer"`
22+
Timestamp Time `json:"timestamp"`
23+
Data interface{} `json:"data"`
24+
SchemaVersion string `json:"schema_version"`
2525
}
2626

2727
// GatheredResource wraps the raw k8s resource that is sent to the jetstack secure backend

pkg/agent/run.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ var BackoffMaxTime time.Duration
4747
// StrictMode flag causes the agent to fail at the first attempt
4848
var StrictMode bool
4949

50+
// schema version of the data sent by the agent.
51+
// The new default version is v2.
52+
// In v2 the agent posts data readings using api.gathereredResources
53+
// Any requests without a schema version set will be interpreted
54+
// as using v1 by the backend. In v1 the agent sends
55+
// raw resource data of unstructuredList
56+
const schemaVersion string = "v2.0.0"
57+
5058
// Run starts the agent process
5159
func Run(cmd *cobra.Command, args []string) {
5260
ctx, cancel := context.WithCancel(context.Background())
@@ -291,10 +299,11 @@ func gatherData(ctx context.Context, config Config, dataGatherers map[string]dat
291299
log.Printf("successfully gathered data from %q datagatherer", k)
292300

293301
readings = append(readings, &api.DataReading{
294-
ClusterID: config.ClusterID,
295-
DataGatherer: k,
296-
Timestamp: api.Time{Time: time.Now()},
297-
Data: dgData,
302+
ClusterID: config.ClusterID,
303+
DataGatherer: k,
304+
Timestamp: api.Time{Time: time.Now()},
305+
Data: dgData,
306+
SchemaVersion: schemaVersion,
298307
})
299308
}
300309
}

pkg/client/client.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,6 @@ var ClientID string
1616
var ClientSecret string
1717
var AuthServerDomain string
1818

19-
// schema version of the data sent by the agent.
20-
// The new default version is v2.
21-
// In v2 the agent posts data readings using api.gathereredResources
22-
// Any requests without a schema version set will be interpreted
23-
// as using v1 by the backend. In v1 the agent sends
24-
// raw resource data of unstructuredList
25-
const schemaVersion string = "v2.0.0"
26-
2719
// PreflightClient can be used to talk to the Preflight backend.
2820
type PreflightClient struct {
2921
// OAuth2
@@ -89,7 +81,6 @@ func (c *PreflightClient) PostDataReadings(orgID string, readings []*api.DataRea
8981
AgentMetadata: c.agentMetadata,
9082
DataGatherTime: time.Now().UTC(),
9183
DataReadings: readings,
92-
SchemaVersion: schemaVersion,
9384
}
9485
data, err := json.Marshal(payload)
9586
if err != nil {

0 commit comments

Comments
 (0)