Skip to content

Commit 879c07b

Browse files
authored
[POA-3567] add common apidump flags to kube commands (#113)
Adds the common apidump flags to the `kube inject`, `kube helm-fragment`, and `kube tf-fragment` commands.
1 parent fa7348e commit 879c07b

File tree

3 files changed

+29
-8
lines changed

3 files changed

+29
-8
lines changed

cmd/internal/kube/inject.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/akitasoftware/akita-libs/akid"
88
"github.com/akitasoftware/go-utils/optionals"
99
"github.com/pkg/errors"
10+
"github.com/postmanlabs/postman-insights-agent/cmd/internal/apidump"
1011
"github.com/postmanlabs/postman-insights-agent/cmd/internal/cmderr"
1112
"github.com/postmanlabs/postman-insights-agent/cmd/internal/kube/injector"
1213
"github.com/postmanlabs/postman-insights-agent/printer"
@@ -32,6 +33,8 @@ var (
3233

3334
// Postman related flags
3435
insightsProjectID string
36+
37+
apidumpFlags *apidump.CommonApidumpFlags
3538
)
3639

3740
var injectCmd = &cobra.Command{
@@ -118,8 +121,9 @@ var injectCmd = &cobra.Command{
118121

119122
var container v1.Container
120123

124+
apidumpArgs := apidump.ConvertCommonApiDumpFlagsToArgs(apidumpFlags)
121125
// Inject the sidecar into the input file
122-
container = createPostmanSidecar(insightsProjectID, true)
126+
container = createPostmanSidecar(insightsProjectID, true, apidumpArgs)
123127

124128
rawInjected, err := injector.ToRawYAML(injectr, container)
125129
if err != nil {
@@ -219,5 +223,7 @@ func init() {
219223
// Default value is "true" when the flag is given without an argument.
220224
injectCmd.Flags().Lookup("secret").NoOptDefVal = "true"
221225

226+
apidumpFlags = apidump.AddCommonApiDumpFlags(injectCmd)
227+
222228
Cmd.AddCommand(injectCmd)
223229
}

cmd/internal/kube/print_fragment.go

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/hashicorp/hcl/v2/hclsyntax"
99
"github.com/hashicorp/hcl/v2/hclwrite"
1010
"github.com/postmanlabs/postman-insights-agent/cfg"
11+
"github.com/postmanlabs/postman-insights-agent/cmd/internal/apidump"
1112
"github.com/postmanlabs/postman-insights-agent/cmd/internal/cmderr"
1213
"github.com/postmanlabs/postman-insights-agent/rest"
1314
"github.com/spf13/cobra"
@@ -16,6 +17,11 @@ import (
1617
"sigs.k8s.io/yaml"
1718
)
1819

20+
var (
21+
printHelmApidumpFlags *apidump.CommonApidumpFlags
22+
printTFApidumpFlags *apidump.CommonApidumpFlags
23+
)
24+
1925
var printHelmChartFragmentCmd = &cobra.Command{
2026
Use: "helm-fragment",
2127
Short: "Print a Helm chart container definition for adding the Postman Insights Agent to existing kubernetes deployment.",
@@ -38,8 +44,9 @@ func printHelmChartFragment(_ *cobra.Command, _ []string) error {
3844
return err
3945
}
4046

47+
apidumpArgs := apidump.ConvertCommonApiDumpFlagsToArgs(printHelmApidumpFlags)
4148
// Create the Postman Insights Agent sidecar container
42-
container := createPostmanSidecar(insightsProjectID, false)
49+
container := createPostmanSidecar(insightsProjectID, false, apidumpArgs)
4350
// Store it in an array since the fragment will be added to a list of containers
4451
containerArray := []v1.Container{container}
4552

@@ -91,17 +98,21 @@ func createTerraformContainer(insightsProjectID string) *hclwrite.File {
9198
cty.StringVal("NET_RAW"),
9299
}))
93100

94-
// Add the args to the container
95-
args := cty.ListVal([]cty.Value{
101+
argList := []cty.Value{
96102
cty.StringVal("apidump"),
97103
cty.StringVal("--project"),
98104
cty.StringVal(insightsProjectID),
99-
})
105+
}
100106
// If a non default --domain flag was used, specify it for the container as well.
101107
if rest.Domain != rest.DefaultDomain() {
102-
args.Add(cty.StringVal("--domain"))
103-
args.Add(cty.StringVal(rest.Domain))
108+
argList = append(argList, cty.StringVal("--domain"), cty.StringVal(rest.Domain))
109+
}
110+
apidumpArgs := apidump.ConvertCommonApiDumpFlagsToArgs(printTFApidumpFlags)
111+
for _, arg := range apidumpArgs {
112+
argList = append(argList, cty.StringVal(arg))
104113
}
114+
// Add the args to the container
115+
args := cty.ListVal(argList)
105116
containerBody.SetAttributeValue("args", args)
106117

107118
// Add the environment variables to the container
@@ -133,6 +144,9 @@ func indentCodeFragment(codeFragmentInBytes []byte, indentLevel int) string {
133144
}
134145

135146
func init() {
147+
printHelmApidumpFlags = apidump.AddCommonApiDumpFlags(printHelmChartFragmentCmd)
136148
Cmd.AddCommand(printHelmChartFragmentCmd)
149+
150+
printTFApidumpFlags = apidump.AddCommonApiDumpFlags(printTerraformFragmentCmd)
137151
Cmd.AddCommand(printTerraformFragmentCmd)
138152
}

cmd/internal/kube/util.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ func createFile(path string) (*os.File, error) {
7373
return outputFile, nil
7474
}
7575

76-
func createPostmanSidecar(insightsProjectID string, addAPIKeyAsSecret bool) v1.Container {
76+
func createPostmanSidecar(insightsProjectID string, addAPIKeyAsSecret bool, apidumpArgs []string) v1.Container {
7777
args := []string{"apidump", "--project", insightsProjectID}
7878

7979
// If a non default --domain flag was used, specify it for the container as well.
8080
if rest.Domain != rest.DefaultDomain() {
8181
args = append(args, "--domain", rest.Domain)
8282
}
83+
args = append(args, apidumpArgs...)
8384

8485
pmKey, pmEnv := cfg.GetPostmanAPIKeyAndEnvironment()
8586
envs := []v1.EnvVar{}

0 commit comments

Comments
 (0)