11package replicatedapi
22
33import (
4- "fmt"
54 "net/http"
6- "reflect"
75
86 "github.com/replicatedhq/embedded-cluster/pkg/versions"
97)
@@ -12,40 +10,13 @@ const (
1210 DistributionEmbeddedCluster string = "embedded-cluster"
1311)
1412
15- type ReportingInfo struct {
16- EmbeddedClusterNodes * string `header:"X-Replicated-EmbeddedClusterNodes"`
17- ReplHelmInstalls * string `header:"X-Replicated-ReplHelmInstalls"`
18- NativeHelmInstalls * string `header:"X-Replicated-NativeHelmInstalls"`
19- AppStatus * string `header:"X-Replicated-AppStatus"`
20- InstallStatus * string `header:"X-Replicated-InstallStatus"`
21- PreflightStatus * string `header:"X-Replicated-PreflightStatus"`
22- DownstreamChannelSequence * string `header:"X-Replicated-DownstreamChannelSequence"`
23- DownstreamSequence * string `header:"X-Replicated-DownstreamSequence"`
24- DownstreamSource * string `header:"X-Replicated-DownstreamSource"`
25- SkipPreflights * string `header:"X-Replicated-SkipPreflights"`
26-
27- // unsupported headers
28- // X-Replicated-KotsInstallID
29- // X-Replicated-KurlInstallID
30- // X-Replicated-KurlNodeCountTotal
31- // X-Replicated-KurlNodeCountReady
32- // X-Replicated-IsGitOpsEnabled
33- // X-Replicated-GitOpsProvider
34- // X-Replicated-SnapshotProvider
35- // X-Replicated-SnapshotFullSchedule
36- // X-Replicated-SnapshotFullTTL
37- // X-Replicated-SnapshotPartialSchedule
38- // X-Replicated-SnapshotPartialTTL
39-
40- }
41-
42- func (c * client ) injectReportingInfoHeaders (header http.Header , reportingInfo * ReportingInfo ) {
43- for key , value := range c .getReportingInfoHeaders (reportingInfo ) {
13+ func (c * client ) injectReportingInfoHeaders (header http.Header ) {
14+ for key , value := range c .getReportingInfoHeaders () {
4415 header .Set (key , value )
4516 }
4617}
4718
48- func (c * client ) getReportingInfoHeaders (reportingInfo * ReportingInfo ) map [string ]string {
19+ func (c * client ) getReportingInfoHeaders () map [string ]string {
4920 headers := make (map [string ]string )
5021
5122 // add headers from client
@@ -67,45 +38,6 @@ func (c *client) getReportingInfoHeaders(reportingInfo *ReportingInfo) map[strin
6738 // Add static headers
6839 headers ["X-Replicated-IsKurl" ] = "false"
6940
70- if reportingInfo != nil {
71- // Use reflection to read struct tags and map fields to headers
72- v := reflect .ValueOf (reportingInfo ).Elem ()
73- t := v .Type ()
74-
75- for i := 0 ; i < t .NumField (); i ++ {
76- field := t .Field (i )
77- headerName := field .Tag .Get ("header" )
78- if headerName == "" {
79- continue
80- }
81-
82- fieldValue := v .Field (i )
83-
84- // Check if the pointer field is nil (not set)
85- if fieldValue .IsNil () {
86- continue
87- }
88-
89- // Dereference the pointer to get the actual value
90- actualValue := fieldValue .Elem ()
91- var strValue string
92-
93- switch actualValue .Kind () {
94- case reflect .String :
95- strValue = actualValue .String ()
96- case reflect .Int , reflect .Int8 , reflect .Int16 , reflect .Int32 , reflect .Int64 :
97- strValue = fmt .Sprintf ("%d" , actualValue .Int ())
98- case reflect .Uint , reflect .Uint8 , reflect .Uint16 , reflect .Uint32 , reflect .Uint64 :
99- strValue = fmt .Sprintf ("%d" , actualValue .Uint ())
100- case reflect .Bool :
101- strValue = fmt .Sprintf ("%t" , actualValue .Bool ())
102- default :
103- panic (fmt .Sprintf ("reporting info field %s has unsupported type: %s" , field .Name , actualValue .Kind ()))
104- }
105- headers [headerName ] = strValue
106- }
107- }
108-
10941 // remove empty headers
11042 for key , value := range headers {
11143 if value == "" {
@@ -115,3 +47,26 @@ func (c *client) getReportingInfoHeaders(reportingInfo *ReportingInfo) map[strin
11547
11648 return headers
11749}
50+
51+ // TODO: the following headers are injected by KOTS and are not yet supported by Embedded Cluster
52+ // X-Replicated-EmbeddedClusterNodes
53+ // X-Replicated-ReplHelmInstalls
54+ // X-Replicated-NativeHelmInstalls
55+ // X-Replicated-AppStatus
56+ // X-Replicated-InstallStatus
57+ // X-Replicated-PreflightStatus
58+ // X-Replicated-DownstreamChannelSequence
59+ // X-Replicated-DownstreamSequence
60+ // X-Replicated-DownstreamSource
61+ // X-Replicated-SkipPreflights
62+ // X-Replicated-KotsInstallID
63+ // X-Replicated-KurlInstallID
64+ // X-Replicated-KurlNodeCountTotal
65+ // X-Replicated-KurlNodeCountReady
66+ // X-Replicated-IsGitOpsEnabled
67+ // X-Replicated-GitOpsProvider
68+ // X-Replicated-SnapshotProvider
69+ // X-Replicated-SnapshotFullSchedule
70+ // X-Replicated-SnapshotFullTTL
71+ // X-Replicated-SnapshotPartialSchedule
72+ // X-Replicated-SnapshotPartialTTL
0 commit comments