-
Notifications
You must be signed in to change notification settings - Fork 312
OCPBUGS-120940: quote YAML string fields in iptables-alerter Event #3151
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,40 @@ | ||||||||
| package network | ||||||||
|
|
||||||||
| import ( | ||||||||
| "testing" | ||||||||
|
|
||||||||
| . "github.com/onsi/gomega" | ||||||||
| operv1 "github.com/openshift/api/operator/v1" | ||||||||
| uns "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||||||||
| ) | ||||||||
|
|
||||||||
| func TestRenderIPTablesAlerterQuotesYAMLStringFields(t *testing.T) { | ||||||||
| g := NewGomegaWithT(t) | ||||||||
|
|
||||||||
| bootstrapResult := fakeBootstrapResult() | ||||||||
| bootstrapResult.IPTablesAlerter.Enabled = true | ||||||||
|
|
||||||||
| objs, err := renderIPTablesAlerter(&operv1.NetworkSpec{}, bootstrapResult, manifestDir) | ||||||||
| g.Expect(err).NotTo(HaveOccurred()) | ||||||||
|
|
||||||||
| var scriptCM *uns.Unstructured | ||||||||
| for _, obj := range objs { | ||||||||
| if obj.GetKind() == "ConfigMap" && obj.GetName() == "iptables-alerter-script" { | ||||||||
| scriptCM = obj | ||||||||
| break | ||||||||
| } | ||||||||
| } | ||||||||
| g.Expect(scriptCM).NotTo(BeNil()) | ||||||||
|
|
||||||||
| script, found, err := uns.NestedString(scriptCM.Object, "data", "iptables-alerter.sh") | ||||||||
| g.Expect(err).NotTo(HaveOccurred()) | ||||||||
| g.Expect(found).To(BeTrue()) | ||||||||
|
|
||||||||
| // Unquoted YAML 1.1 booleans such as yes/no/true/false/on/off unmarshal as | ||||||||
| // bool and crash kubectl when metadata.namespace/name must be strings. | ||||||||
| g.Expect(script).To(ContainSubstring(`namespace: "${pod_namespace}"`)) | ||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win Assert both namespace fields separately. The rendered script contains both Suggested test change- g.Expect(script).To(ContainSubstring(`namespace: "${pod_namespace}"`))
+ g.Expect(script).To(ContainSubstring("metadata:\n namespace: \"${pod_namespace}\""))
+ g.Expect(script).To(ContainSubstring("regarding:\n namespace: \"${pod_namespace}\""))📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||
| g.Expect(script).To(ContainSubstring(`name: "${pod_name}"`)) | ||||||||
| g.Expect(script).To(ContainSubstring(`uid: "${pod_uid}"`)) | ||||||||
| g.Expect(script).To(ContainSubstring(`pod-uid: "${pod_uid}"`)) | ||||||||
| g.Expect(script).To(ContainSubstring(`reportingInstance: "${ALERTER_POD_NAME}"`)) | ||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not doing anything useful. It's just validating "
bindata/network/iptables-alerter/002-script.yamlcontains the strings that we put intobindata/network/iptables-alerter/002-script.yaml". Notably, if someone added a new field to the event and failed to quote it, this test would not catch that.It should probably just be removed. (
iptables-alerterwill be going away soon anyway.)