Skip to content

Commit d164ef1

Browse files
[POA-3228] Add POSTMAN_INSIGHTS_DISABLE_REPRO_MODE env var at pod level (#93)
This pull request includes changes to add a new `POSTMAN_INSIGHTS_DISABLE_REPRO_MODE` environment variable to explicitly disable repro mode at the pod level. ### New ReproMode attribute at `PodArgs` level: * `cmd/internal/kube/daemonset/constants.go`: Added a new environment variable `POSTMAN_INSIGHTS_DISABLE_REPRO_MODE` to control the ReproMode feature at the pod level. * `cmd/internal/kube/daemonset/pod_args.go`: Updated the `PodArgs` struct to include a new `ReproMode` boolean field. * `cmd/internal/kube/daemonset/apidump_process.go`: Modified the `StartApiDumpProcess` method to use the new `ReproMode` field from `podArgs` instead of `d.InsightsReproModeEnabled`. ### Pod Environment Variables Inspection: * `cmd/internal/kube/daemonset/kube_events_worker.go`: * Introduced a new `containerConfig` struct to encapsulate the required container configuration and the new `disableReproMode` field. Updated the `inspectPodForEnvVars` function to populate and use this new struct. * Set the pod level `reproMode` attribute based on the daemonset repro mode and env variable from the pod ### Telemetry Logging: * `cmd/internal/kube/daemonset/telemetry.go`: Enhanced the `dumpPodsApiDumpProcessState` function to include the `ReproMode` status in the log output.
1 parent 2909f60 commit d164ef1

File tree

5 files changed

+48
-13
lines changed

5 files changed

+48
-13
lines changed

cmd/internal/kube/daemonset/apidump_process.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (d *Daemonset) StartApiDumpProcess(podUID types.UID) error {
8484
CollectTCPAndTLSReports: apispec.DefaultCollectTCPAndTLSReports,
8585
ParseTLSHandshakes: apispec.DefaultParseTLSHandshakes,
8686
MaxWitnessSize_bytes: apispec.DefaultMaxWitnessSize_bytes,
87-
ReproMode: d.InsightsReproModeEnabled,
87+
ReproMode: podArgs.ReproMode,
8888
DaemonsetArgs: optionals.Some(apidump.DaemonsetArgs{
8989
TargetNetworkNamespaceOpt: networkNamespace,
9090
StopChan: podArgs.StopChan,

cmd/internal/kube/daemonset/constants.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import "time"
44

55
const (
66
// Pod environment variables
7-
POSTMAN_INSIGHTS_PROJECT_ID = "POSTMAN_INSIGHTS_PROJECT_ID"
8-
POSTMAN_INSIGHTS_API_KEY = "POSTMAN_INSIGHTS_API_KEY"
7+
POSTMAN_INSIGHTS_PROJECT_ID = "POSTMAN_INSIGHTS_PROJECT_ID"
8+
POSTMAN_INSIGHTS_API_KEY = "POSTMAN_INSIGHTS_API_KEY"
9+
POSTMAN_INSIGHTS_DISABLE_REPRO_MODE = "POSTMAN_INSIGHTS_DISABLE_REPRO_MODE"
910

1011
// Daemonset environment variables
1112
POSTMAN_INSIGHTS_ENV = "POSTMAN_ENV" // This is same as root POSTMAN_ENV

cmd/internal/kube/daemonset/kube_events_worker.go

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package daemonset
22

33
import (
44
"fmt"
5+
"strconv"
56

67
"github.com/akitasoftware/akita-libs/akid"
78
"github.com/akitasoftware/go-utils/maps"
@@ -41,6 +42,11 @@ type requiredContainerConfig struct {
4142
apiKey string
4243
}
4344

45+
type containerConfig struct {
46+
requiredContainerConfig requiredContainerConfig
47+
disableReproMode string
48+
}
49+
4450
// handlePodAddEvent handles the event when a pod is added to the Kubernetes cluster.
4551
// It performs the following steps:
4652
// 1. Check if the pod does not have the agent sidecar container.
@@ -168,7 +174,7 @@ func (d *Daemonset) inspectPodForEnvVars(pod coreV1.Pod, podArgs *PodArgs) error
168174
return errors.New("no running containers found in the pod")
169175
}
170176

171-
containerConfigMap := maps.NewMap[string, requiredContainerConfig]()
177+
containerConfigMap := maps.NewMap[string, containerConfig]()
172178

173179
// Iterate over all containers in the pod to check for the required environment variables
174180
for _, containerUUID := range containerUUIDs {
@@ -178,23 +184,30 @@ func (d *Daemonset) inspectPodForEnvVars(pod coreV1.Pod, podArgs *PodArgs) error
178184
continue
179185
}
180186

181-
containerEnvVars := requiredContainerConfig{}
187+
containerEnvVars := containerConfig{
188+
requiredContainerConfig: requiredContainerConfig{},
189+
}
182190
if projectID, exists := envVars[POSTMAN_INSIGHTS_PROJECT_ID]; exists {
183-
containerEnvVars.projectID = projectID
191+
containerEnvVars.requiredContainerConfig.projectID = projectID
184192
}
185193
if apiKey, exists := envVars[POSTMAN_INSIGHTS_API_KEY]; exists {
186-
containerEnvVars.apiKey = apiKey
194+
containerEnvVars.requiredContainerConfig.apiKey = apiKey
195+
}
196+
if disableReproMode, exists := envVars[POSTMAN_INSIGHTS_DISABLE_REPRO_MODE]; exists {
197+
containerEnvVars.disableReproMode = disableReproMode
187198
}
188199
containerConfigMap[containerUUID] = containerEnvVars
189200
}
190201

191202
mainContainerUUID := ""
192-
mainContainerConfig := requiredContainerConfig{}
203+
mainContainerConfig := containerConfig{
204+
requiredContainerConfig: requiredContainerConfig{},
205+
}
193206
mainContainerMissingAttrs := []string{}
194207
maxSetAttrs := -1
195208

196209
for uuid, config := range containerConfigMap {
197-
attrCount, missingAttrs := countSetAttributes(config)
210+
attrCount, missingAttrs := countSetAttributes(config.requiredContainerConfig)
198211
if attrCount > maxSetAttrs {
199212
maxSetAttrs = attrCount
200213
mainContainerMissingAttrs = missingAttrs
@@ -227,15 +240,34 @@ func (d *Daemonset) inspectPodForEnvVars(pod coreV1.Pod, podArgs *PodArgs) error
227240
deployment.SetK8sTraceTags(pod, podArgs.TraceTags)
228241

229242
podArgs.ContainerUUID = mainContainerUUID
230-
err = akid.ParseIDAs(mainContainerConfig.projectID, &podArgs.InsightsProjectID)
243+
err = akid.ParseIDAs(mainContainerConfig.requiredContainerConfig.projectID, &podArgs.InsightsProjectID)
231244
if err != nil {
232245
return errors.Wrap(err, "failed to parse project ID")
233246
}
234247
podArgs.PodCreds = PodCreds{
235-
InsightsAPIKey: mainContainerConfig.apiKey,
248+
InsightsAPIKey: mainContainerConfig.requiredContainerConfig.apiKey,
236249
InsightsEnvironment: d.InsightsEnvironment,
237250
}
238251

252+
// Determine ReproMode flag for the apidump process
253+
podArgs.ReproMode = d.InsightsReproModeEnabled
254+
255+
if !d.InsightsReproModeEnabled {
256+
printer.Infof("Repro mode is disabled at the DaemonSet level for pod: %s\n", pod.Name)
257+
return nil
258+
}
259+
260+
// Check if ReproMode is explicitly disabled at the pod level
261+
if mainContainerConfig.disableReproMode != "" {
262+
reproModeDisabled, err := strconv.ParseBool(mainContainerConfig.disableReproMode)
263+
if err != nil {
264+
printer.Errorf("Invalid disableReproMode value for pod: %s, error: %v. Defaulting to DaemonSet-level setting.\n", pod.Name, err)
265+
} else if reproModeDisabled {
266+
podArgs.ReproMode = false
267+
printer.Infof("Repro mode is explicitly disabled at the pod level for pod: %s\n", pod.Name)
268+
}
269+
}
270+
239271
return nil
240272
}
241273

cmd/internal/kube/daemonset/pod_args.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type PodArgs struct {
4242
// apidump related fields
4343
InsightsProjectID akid.ServiceID
4444
TraceTags tags.SingletonTags
45+
ReproMode bool
4546

4647
// Pod related fields
4748
PodName string

cmd/internal/kube/daemonset/telemetry.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ func (d *Daemonset) dumpPodsApiDumpProcessState() {
3535
logf("Dumping pods api dump process state, time: %s\n", time.Now().UTC())
3636

3737
logf(hrBr)
38-
logf(" %-30v%-30v%-40v%-70v\n", "projectID", "currentState", "podUID", "podName")
38+
logf(" %-30v%-30v%-10v%-40v%-70v\n", "projectID", "currentState", "reproMode", "podUID", "podName")
3939
logf(hrBr)
4040

4141
d.PodArgsByNameMap.Range(func(k, v interface{}) bool {
4242
podUID := k.(types.UID)
4343
podArgs := v.(*PodArgs)
44-
logf(" %-30v%-30v%-40v%-70v\n",
44+
logf(" %-30v%-30v%-10v%-40v%-70v\n",
4545
podArgs.InsightsProjectID,
4646
podArgs.PodTrafficMonitorState,
47+
podArgs.ReproMode,
4748
podUID,
4849
podArgs.PodName,
4950
)

0 commit comments

Comments
 (0)