Skip to content

Commit 3c66f9a

Browse files
committed
Add initial draft of flag options
1 parent be029fa commit 3c66f9a

File tree

5 files changed

+94
-14
lines changed

5 files changed

+94
-14
lines changed

cmd/gateway/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ func createStaticModeCommand() *cobra.Command {
215215
Version: version,
216216
ExperimentalFeatures: gwExperimentalFeatures,
217217
ImageSource: imageSource,
218+
Flags: cmd.Flags(),
218219
}
219220

220221
if err := static.StartManager(conf); err != nil {

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ require (
1717
github.com/prometheus/client_golang v1.18.0
1818
github.com/prometheus/common v0.48.0
1919
github.com/spf13/cobra v1.8.0
20+
github.com/spf13/pflag v1.0.5
2021
github.com/tsenart/vegeta/v12 v12.11.1
2122
go.uber.org/zap v1.27.0
2223
k8s.io/api v0.29.2
@@ -71,7 +72,6 @@ require (
7172
github.com/prometheus/client_model v0.5.0 // indirect
7273
github.com/prometheus/procfs v0.12.0 // indirect
7374
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417 // indirect
74-
github.com/spf13/pflag v1.0.5 // indirect
7575
github.com/stretchr/testify v1.8.4 // indirect
7676
go.uber.org/multierr v1.11.0 // indirect
7777
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect

internal/mode/static/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"time"
55

66
"github.com/go-logr/logr"
7+
"github.com/spf13/pflag"
78
"go.uber.org/zap"
89
"k8s.io/apimachinery/pkg/types"
910
)
@@ -15,6 +16,8 @@ type Config struct {
1516
ImageSource string
1617
// AtomicLevel is an atomically changeable, dynamic logging level.
1718
AtomicLevel zap.AtomicLevel
19+
// Flags are all the NGF flags.
20+
Flags *pflag.FlagSet
1821
// GatewayNsName is the namespaced name of a Gateway resource that the Gateway will use.
1922
// The Gateway will ignore all other Gateway resources.
2023
GatewayNsName *types.NamespacedName

internal/mode/static/manager.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ func StartManager(cfg config.Config) error {
253253
Name: cfg.GatewayPodConfig.Name,
254254
},
255255
ImageSource: cfg.ImageSource,
256+
Flags: cfg.Flags,
256257
})
257258
if err = mgr.Add(createTelemetryJob(cfg, dataCollector, nginxChecker.getReadyCh())); err != nil {
258259
return fmt.Errorf("cannot register telemetry job: %w", err)

internal/mode/static/telemetry/collector.go

Lines changed: 88 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import (
55
"errors"
66
"fmt"
77
"runtime"
8+
"strconv"
89

10+
"github.com/spf13/pflag"
911
appsv1 "k8s.io/api/apps/v1"
1012
v1 "k8s.io/api/core/v1"
1113
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -47,17 +49,49 @@ type ProjectMetadata struct {
4749
Version string
4850
}
4951

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+
5083
// Data is telemetry data.
5184
// Note: this type might change once https://github.com/nginxinc/nginx-gateway-fabric/issues/1318 is implemented.
5285
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
6195
}
6296

6397
// DataCollectorConfig holds configuration parameters for DataCollectorImpl.
@@ -68,6 +102,8 @@ type DataCollectorConfig struct {
68102
GraphGetter GraphGetter
69103
// ConfigurationGetter allows us to get the Configuration.
70104
ConfigurationGetter ConfigurationGetter
105+
// Flags are all the NGF flags.
106+
Flags *pflag.FlagSet
71107
// Version is the NGF version.
72108
Version string
73109
// PodNSName is the NamespacedName of the NGF Pod.
@@ -111,6 +147,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
111147
if err != nil {
112148
return Data{}, fmt.Errorf("failed to collect NGF replica count: %w", err)
113149
}
150+
deploymentFlagOptions := collectDeploymentFlagOptions(c.cfg.Flags)
114151

115152
deploymentID, err := getDeploymentID(replicaSet)
116153
if err != nil {
@@ -129,11 +166,12 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
129166
Name: "NGF",
130167
Version: c.cfg.Version,
131168
},
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,
137175
}
138176

139177
return data, nil
@@ -258,3 +296,40 @@ func CollectClusterID(ctx context.Context, k8sClient client.Reader) (string, err
258296
}
259297
return string(kubeNamespace.GetUID()), nil
260298
}
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

Comments
 (0)