5
5
"errors"
6
6
"fmt"
7
7
"runtime"
8
+ "strconv"
8
9
10
+ "github.com/spf13/pflag"
9
11
appsv1 "k8s.io/api/apps/v1"
10
12
v1 "k8s.io/api/core/v1"
11
13
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -47,17 +49,49 @@ type ProjectMetadata struct {
47
49
Version string
48
50
}
49
51
52
+ //type DeploymentFlagOptions struct {
53
+ // GatewayClass string
54
+ // GatewayCtlrName string
55
+ // Gateway string
56
+ // Config string
57
+ // Service string
58
+ // UpdateGCStatus bool
59
+ // MetricsDisable bool
60
+ // MetricsSecure bool
61
+ // MetricsPort string
62
+ // HealthDisable bool
63
+ // HealthPort string
64
+ // LeaderElectionDisable bool
65
+ // LeaderElectionLockName string
66
+ // Plus bool
67
+ //}
68
+
69
+ type DeploymentFlagOptions struct {
70
+ NonBooleanFlags []NonBooleanFlag
71
+ BooleanFlags []BooleanFlag
72
+ }
73
+
74
+ type BooleanFlag struct {
75
+ Name string
76
+ Value bool
77
+ }
78
+ type NonBooleanFlag struct {
79
+ Name string
80
+ Value string
81
+ }
82
+
50
83
// Data is telemetry data.
51
84
// Note: this type might change once https://github.com/nginxinc/nginx-gateway-fabric/issues/1318 is implemented.
52
85
type Data struct {
53
- ProjectMetadata ProjectMetadata
54
- ClusterID string
55
- Arch string
56
- DeploymentID string
57
- ImageSource string
58
- NGFResourceCounts NGFResourceCounts
59
- NodeCount int
60
- NGFReplicaCount int
86
+ ProjectMetadata ProjectMetadata
87
+ ClusterID string
88
+ Arch string
89
+ DeploymentID string
90
+ ImageSource string
91
+ NGFResourceCounts NGFResourceCounts
92
+ NodeCount int
93
+ NGFReplicaCount int
94
+ DeploymentFlagOptions DeploymentFlagOptions
61
95
}
62
96
63
97
// DataCollectorConfig holds configuration parameters for DataCollectorImpl.
@@ -68,6 +102,8 @@ type DataCollectorConfig struct {
68
102
GraphGetter GraphGetter
69
103
// ConfigurationGetter allows us to get the Configuration.
70
104
ConfigurationGetter ConfigurationGetter
105
+ // Flags are all the NGF flags.
106
+ Flags * pflag.FlagSet
71
107
// Version is the NGF version.
72
108
Version string
73
109
// PodNSName is the NamespacedName of the NGF Pod.
@@ -111,6 +147,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
111
147
if err != nil {
112
148
return Data {}, fmt .Errorf ("failed to collect NGF replica count: %w" , err )
113
149
}
150
+ deploymentFlagOptions := collectDeploymentFlagOptions (c .cfg .Flags )
114
151
115
152
deploymentID , err := getDeploymentID (replicaSet )
116
153
if err != nil {
@@ -129,11 +166,12 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
129
166
Name : "NGF" ,
130
167
Version : c .cfg .Version ,
131
168
},
132
- NGFReplicaCount : replicaCount ,
133
- ClusterID : clusterID ,
134
- ImageSource : c .cfg .ImageSource ,
135
- Arch : runtime .GOARCH ,
136
- DeploymentID : deploymentID ,
169
+ NGFReplicaCount : replicaCount ,
170
+ ClusterID : clusterID ,
171
+ ImageSource : c .cfg .ImageSource ,
172
+ Arch : runtime .GOARCH ,
173
+ DeploymentID : deploymentID ,
174
+ DeploymentFlagOptions : deploymentFlagOptions ,
137
175
}
138
176
139
177
return data , nil
@@ -258,3 +296,40 @@ func CollectClusterID(ctx context.Context, k8sClient client.Reader) (string, err
258
296
}
259
297
return string (kubeNamespace .GetUID ()), nil
260
298
}
299
+
300
+ func collectDeploymentFlagOptions (flags * pflag.FlagSet ) DeploymentFlagOptions {
301
+ deploymentFlagOptions := DeploymentFlagOptions {
302
+ NonBooleanFlags : []NonBooleanFlag {},
303
+ BooleanFlags : []BooleanFlag {},
304
+ }
305
+ flags .Visit (
306
+ func (flag * pflag.Flag ) {
307
+ switch flag .Value .Type () {
308
+ case "bool" :
309
+ val , err := strconv .ParseBool (flag .Value .String ())
310
+ if err != nil {
311
+ return
312
+ }
313
+ deploymentFlagOptions .BooleanFlags = append (deploymentFlagOptions .BooleanFlags , BooleanFlag {
314
+ Name : flag .Name ,
315
+ Value : val ,
316
+ })
317
+
318
+ default :
319
+ var val string
320
+ if flag .Value .String () == flag .DefValue {
321
+ val = "default"
322
+ } else {
323
+ val = "user-defined"
324
+ }
325
+
326
+ deploymentFlagOptions .NonBooleanFlags = append (deploymentFlagOptions .NonBooleanFlags , NonBooleanFlag {
327
+ Name : flag .Name ,
328
+ Value : val ,
329
+ })
330
+ }
331
+ },
332
+ )
333
+
334
+ return deploymentFlagOptions
335
+ }
0 commit comments