Skip to content

Commit 89e9531

Browse files
committed
Add some review feedback
1 parent 95c4653 commit 89e9531

File tree

6 files changed

+39
-31
lines changed

6 files changed

+39
-31
lines changed

cmd/gateway/commands.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func createStaticModeCommand() *cobra.Command {
179179
}
180180
}
181181

182-
flagKeys, flagValues := parseFlagKeysAndValues(cmd.Flags())
182+
flagKeys, flagValues := parseFlags(cmd.Flags())
183183

184184
conf := config.Config{
185185
GatewayCtlrName: gatewayCtlrName.value,
@@ -218,9 +218,9 @@ func createStaticModeCommand() *cobra.Command {
218218
Version: version,
219219
ExperimentalFeatures: gwExperimentalFeatures,
220220
ImageSource: imageSource,
221-
FlagKeyValues: config.FlagKeyValues{
222-
FlagKeys: flagKeys,
223-
FlagValues: flagValues,
221+
Flags: config.Flags{
222+
Names: flagKeys,
223+
Values: flagValues,
224224
},
225225
}
226226

@@ -458,17 +458,17 @@ func createSleepCommand() *cobra.Command {
458458
return cmd
459459
}
460460

461-
func parseFlagKeysAndValues(flags *pflag.FlagSet) (flagKeys, flagValues []string) {
461+
func parseFlags(flags *pflag.FlagSet) (flagKeys, flagValues []string) {
462462
flagKeys = []string{}
463463
flagValues = []string{}
464464

465465
flags.VisitAll(
466466
func(flag *pflag.Flag) {
467467
flagKeys = append(flagKeys, flag.Name)
468-
switch flag.Value.Type() {
469-
case "bool":
468+
469+
if flag.Value.Type() == "bool" {
470470
flagValues = append(flagValues, flag.Value.String())
471-
default:
471+
} else {
472472
var val string
473473
if flag.Value.String() == flag.DefValue {
474474
val = "default"

cmd/gateway/commands_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@ func TestSleepCmdFlagValidation(t *testing.T) {
457457
}
458458
}
459459

460-
func TestParseFlagKeysAndValues(t *testing.T) {
460+
func TestParseFlags(t *testing.T) {
461461
g := NewWithT(t)
462462

463463
flagSet := pflag.NewFlagSet("flagSet", 0)
464-
// set SortFlags to false for testing purposes so when parseFlagKeysAndValues loops over the flagSet it
464+
// set SortFlags to false for testing purposes so when parseFlags loops over the flagSet it
465465
// goes off of primordial order.
466466
flagSet.SortFlags = false
467467

@@ -582,7 +582,7 @@ func TestParseFlagKeysAndValues(t *testing.T) {
582582
"user-defined",
583583
}
584584

585-
flagKeys, flagValues := parseFlagKeysAndValues(flagSet)
585+
flagKeys, flagValues := parseFlags(flagSet)
586586

587587
g.Expect(flagKeys).Should(Equal(expectedKeys))
588588
g.Expect(flagValues).Should(Equal(expectedValues))

internal/mode/static/config/config.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Config struct {
1515
ImageSource string
1616
// AtomicLevel is an atomically changeable, dynamic logging level.
1717
AtomicLevel zap.AtomicLevel
18-
// FlagKeyValues contains the parsed NGF flag keys and values.
19-
FlagKeyValues FlagKeyValues
18+
// Flags contains the NGF command-line flag names and values.
19+
Flags Flags
2020
// GatewayNsName is the namespaced name of a Gateway resource that the Gateway will use.
2121
// The Gateway will ignore all other Gateway resources.
2222
GatewayNsName *types.NamespacedName
@@ -108,12 +108,12 @@ type UsageReportConfig struct {
108108
InsecureSkipVerify bool
109109
}
110110

111-
// FlagKeyValues contains the parsed NGF flag keys and values.
112-
// Flag Key and Value are paired based off of index in slice.
113-
type FlagKeyValues struct {
114-
// FlagKeys contains the name of the flag.
115-
FlagKeys []string
116-
// FlagValues contains the value of the flag in string form.
117-
// Value will be either true or false for boolean flags and default or user-defined for non-boolean flags.
118-
FlagValues []string
111+
// Flags contains the NGF command-line flag names and values.
112+
// Flag Names and Values are paired based off of index in slice.
113+
type Flags struct {
114+
// Names contains the name of the flag.
115+
Names []string
116+
// Values contains the value of the flag in string form.
117+
// Each Value will be either true or false for boolean flags and default or user-defined for non-boolean flags.
118+
Values []string
119119
}

internal/mode/static/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,8 @@ func StartManager(cfg config.Config) error {
252252
Namespace: cfg.GatewayPodConfig.Namespace,
253253
Name: cfg.GatewayPodConfig.Name,
254254
},
255-
ImageSource: cfg.ImageSource,
256-
FlagKeyValues: cfg.FlagKeyValues,
255+
ImageSource: cfg.ImageSource,
256+
Flags: cfg.Flags,
257257
})
258258
if err = mgr.Add(createTelemetryJob(cfg, dataCollector, nginxChecker.getReadyCh())); err != nil {
259259
return fmt.Errorf("cannot register telemetry job: %w", err)

internal/mode/static/telemetry/collector.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ type Data struct {
5656
Arch string
5757
DeploymentID string
5858
ImageSource string
59-
FlagKeyValues config.FlagKeyValues
59+
Flags config.Flags
6060
NGFResourceCounts NGFResourceCounts
6161
NodeCount int
6262
NGFReplicaCount int
@@ -76,8 +76,8 @@ type DataCollectorConfig struct {
7676
PodNSName types.NamespacedName
7777
// ImageSource is the source of the NGF image.
7878
ImageSource string
79-
// FlagKeyValues contains the parsed NGF flag keys and values.
80-
FlagKeyValues config.FlagKeyValues
79+
// Flags contains the command-line NGF flag keys and values.
80+
Flags config.Flags
8181
}
8282

8383
// DataCollectorImpl is am implementation of DataCollector.
@@ -138,7 +138,7 @@ func (c DataCollectorImpl) Collect(ctx context.Context) (Data, error) {
138138
ImageSource: c.cfg.ImageSource,
139139
Arch: runtime.GOARCH,
140140
DeploymentID: deploymentID,
141-
FlagKeyValues: c.cfg.FlagKeyValues,
141+
Flags: c.cfg.Flags,
142142
}
143143

144144
return data, nil

internal/mode/static/telemetry/collector_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ var _ = Describe("Collector", Ordered, func() {
7979
ngfReplicaSet *appsv1.ReplicaSet
8080
kubeNamespace *v1.Namespace
8181
baseGetCalls getCallsFunc
82-
flagKeyValues config.FlagKeyValues
82+
flags config.Flags
8383
)
8484

8585
BeforeAll(func() {
@@ -127,9 +127,9 @@ var _ = Describe("Collector", Ordered, func() {
127127
},
128128
}
129129

130-
flagKeyValues = config.FlagKeyValues{
131-
FlagKeys: []string{"boolFlag", "intFlag", "stringFlag"},
132-
FlagValues: []string{"false", "default", "user-defined"},
130+
flags = config.Flags{
131+
Names: []string{"boolFlag", "intFlag", "stringFlag"},
132+
Values: []string{"false", "default", "user-defined"},
133133
}
134134
})
135135

@@ -140,10 +140,14 @@ var _ = Describe("Collector", Ordered, func() {
140140
NGFResourceCounts: telemetry.NGFResourceCounts{},
141141
NGFReplicaCount: 1,
142142
ClusterID: string(kubeNamespace.GetUID()),
143+
<<<<<<< HEAD
143144
ImageSource: "local",
144145
Arch: runtime.GOARCH,
145146
DeploymentID: string(ngfReplicaSet.ObjectMeta.OwnerReferences[0].UID),
146147
FlagKeyValues: flagKeyValues,
148+
=======
149+
Flags: flags,
150+
>>>>>>> 9e04b8c (Add some review feedback)
147151
}
148152

149153
k8sClientReader = &eventsfakes.FakeReader{}
@@ -159,8 +163,12 @@ var _ = Describe("Collector", Ordered, func() {
159163
ConfigurationGetter: fakeConfigurationGetter,
160164
Version: version,
161165
PodNSName: podNSName,
166+
<<<<<<< HEAD
162167
ImageSource: "local",
163168
FlagKeyValues: flagKeyValues,
169+
=======
170+
Flags: flags,
171+
>>>>>>> 9e04b8c (Add some review feedback)
164172
})
165173

166174
baseGetCalls = createGetCallsFunc(ngfPod, ngfReplicaSet, kubeNamespace)

0 commit comments

Comments
 (0)