Skip to content

Commit 3a8bd38

Browse files
authored
[POA-1520] Remove preStop script for Kubernetes (#24)
also includes [POA-1515] Support "-f -" to read from stdin in injector As far as I can reconstruct, the preStop problem was that pgrep only checks the process name by default, which is limited to 15 characters. While we could fix that, I concluded that the only point of the script was to send SIGINT to terminate the agent gracefully, but it now supports receiving SIGTERM directly from Kubernetes, so this is unnecessary. [POA-1515]: https://postmanlabs.atlassian.net/browse/POA-1515?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
1 parent ce93138 commit 3a8bd38

File tree

4 files changed

+11
-22
lines changed

4 files changed

+11
-22
lines changed

cmd/internal/kube/inject.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ func init() {
197197
"file",
198198
"f",
199199
"",
200-
"Path to the Kubernetes YAML file to be injected. This should contain a Deployment object.",
200+
"Path to the Kubernetes YAML file to be injected, or - for standard input. This should contain a Deployment object.",
201201
)
202202
_ = injectCmd.MarkFlagRequired("file")
203203

cmd/internal/kube/injector/injector.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,15 @@ func fromRawObject(raw []byte) (*unstructured.Unstructured, error) {
164164
}
165165

166166
func getFile(filePath string) ([]byte, error) {
167+
if filePath == "-" {
168+
// Read from stdin instead.
169+
bytes, err := io.ReadAll(os.Stdin)
170+
if err != nil {
171+
return nil, errors.Wrapf(err, "could not read from standard input")
172+
}
173+
return bytes, nil
174+
}
175+
167176
fileDir, fileName := filepath.Split(filePath)
168177

169178
absOutputDir, err := filepath.Abs(fileDir)

cmd/internal/kube/print_fragment.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -87,15 +87,6 @@ func createTerraformContainer(insightsProjectID string) *hclwrite.File {
8787
containerBody.SetAttributeValue("name", cty.StringVal("postman-insights-agent"))
8888
containerBody.SetAttributeValue("image", cty.StringVal(akitaImage))
8989

90-
containerBody.AppendNewBlock("lifecycle", []string{}).
91-
Body().AppendNewBlock("pre_stop", []string{}).
92-
Body().AppendNewBlock("exec", []string{}).
93-
Body().SetAttributeValue("command", cty.ListVal([]cty.Value{
94-
cty.StringVal("/bin/sh"),
95-
cty.StringVal("-c"),
96-
cty.StringVal("POSTMAN_INSIGHTS_AGENT_PID=$(pgrep postman-insights-agent) && kill -2 $POSTMAN_INSIGHTS_AGENT_PID && tail -f /proc/$POSTMAN_INSIGHTS_AGENT_PID/fd/1"),
97-
}))
98-
9990
containerBody.AppendNewBlock("security_context", []string{}).
10091
Body().AppendNewBlock("capabilities", []string{}).
10192
Body().SetAttributeValue("add", cty.ListVal([]cty.Value{

cmd/internal/kube/util.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -113,18 +113,7 @@ func createPostmanSidecar(insightsProjectID string, addAPIKeyAsSecret bool) v1.C
113113
Name: "postman-insights-agent",
114114
Image: akitaImage,
115115
Env: envs,
116-
Lifecycle: &v1.Lifecycle{
117-
PreStop: &v1.LifecycleHandler{
118-
Exec: &v1.ExecAction{
119-
Command: []string{
120-
"/bin/sh",
121-
"-c",
122-
"POSTMAN_INSIGHTS_AGENT_PID=$(pgrep postman-insights-agent) && kill -2 $POSTMAN_INSIGHTS_AGENT_PID && tail -f /proc/$POSTMAN_INSIGHTS_AGENT_PID/fd/1",
123-
},
124-
},
125-
},
126-
},
127-
Args: args,
116+
Args: args,
128117
SecurityContext: &v1.SecurityContext{
129118
Capabilities: &v1.Capabilities{Add: []v1.Capability{"NET_RAW"}},
130119
},

0 commit comments

Comments
 (0)