-
Notifications
You must be signed in to change notification settings - Fork 19
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
Empty label fields in policies are ignored #150
Empty label fields in policies are ignored #150
Conversation
test/e2e/case33_empty_label_test.go
Outdated
found := false | ||
|
||
_, ok := labelMap[case33StorageLabel] | ||
if ok { | ||
found = true | ||
} | ||
|
||
return found |
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.
found := false | |
_, ok := labelMap[case33StorageLabel] | |
if ok { | |
found = true | |
} | |
return found | |
_, ok := labelMap[case33StorageLabel] | |
if ok { | |
return true | |
} | |
return false |
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.
Alternatively, this would probably be better handled by the HaveKey()
Gomega assertion rather than returning a vague boolean.
You could even use HaveKeyWithValue()
to assert both the key and the value to combine both of this and the next test.
test/e2e/case33_empty_label_test.go
Outdated
Eventually(func() interface{} { | ||
node, _ := clientManaged.CoreV1().Nodes().Get(context.TODO(), case33NodeName, metav1.GetOptions{}) | ||
labelMap := node.GetLabels() | ||
merged := labelMap[case33StorageLabel] |
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.
merged := labelMap[case33StorageLabel] | |
_, ok := labelMap[case33StorageLabel] | |
return ok |
We wanted to verify whether the label exist or not
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.
I verified it in the Eventually
block above this. This check is to make sure the value of the field is an empty string.
@@ -0,0 +1,17 @@ | |||
apiVersion: v1 |
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.
Where this file used? cannot find
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.
Oh I have no idea what this is either, I will fix up my PR to remove this.
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.
Its a kubeconfig
file. This looks to me to be the result of naming the managed cluster test-managed
instead of just managed
and apparently we don't have that in our .gitignore
. 🙂
test/e2e/case33_empty_label_test.go
Outdated
const ( | ||
case33ConfigPolicy = "../resources/case33_empty_label_handling/empty-labels-config.yaml" | ||
case33ConfigPolicyName = "case33-empty-labels" | ||
case33NodeName = "test-managed-control-plane" | ||
case33StorageLabel = "cluster.ocs.openshift.io/openshift-storage" | ||
) | ||
|
||
var _ = Describe("Test resource creation when there are empty labels in configurationPolicy", Ordered, func() { | ||
Describe("Appending empty labels to a Node", func() { | ||
Context("When the Node already exists", func() { |
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.
We shouldn't be using global variables in tests unless they truly need to be global (it was an inadvisable practice that was used previously and hadn't been cleaned up yet).
Also, it seems to me the Describe()
and Context()
nodes aren't necessary with a single test suite.
const ( | |
case33ConfigPolicy = "../resources/case33_empty_label_handling/empty-labels-config.yaml" | |
case33ConfigPolicyName = "case33-empty-labels" | |
case33NodeName = "test-managed-control-plane" | |
case33StorageLabel = "cluster.ocs.openshift.io/openshift-storage" | |
) | |
var _ = Describe("Test resource creation when there are empty labels in configurationPolicy", Ordered, func() { | |
Describe("Appending empty labels to a Node", func() { | |
Context("When the Node already exists", func() { | |
var _ = Describe("Test resource creation when there are empty labels in configurationPolicy", Ordered, func() { | |
const ( | |
configPolicy = "../resources/case33_empty_label_handling/empty-labels-config.yaml" | |
configPolicyName = "case33-empty-labels" | |
nodeName = "test-managed-control-plane" | |
storageLabel = "cluster.ocs.openshift.io/openshift-storage" | |
) |
@@ -0,0 +1,17 @@ | |||
apiVersion: v1 |
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.
Its a kubeconfig
file. This looks to me to be the result of naming the managed cluster test-managed
instead of just managed
and apparently we don't have that in our .gitignore
. 🙂
metadata: | ||
name: test-managed-control-plane | ||
labels: | ||
cluster.ocs.openshift.io/openshift-storage: "" |
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.
As a sanity check, could we also check using a policy that sets cluster.ocs.openshift.io/openshift-storage: null
to make sure the policy doesn't remove the field? (Though I'm also uncertain what the behavior would be there in terms of compliance...)
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.
It would be nice to have a test just to check what this currently does, and understand if that behavior has changed (or if we change it accidentally in the future)
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.
Currently, having an unset label/setting it to nil
results in the deletion of all the labels attached to the object. I'll probably make a separate ticket to address this issue as it's a bit more involved and possibly affect annotations as well (need to confirm this but they both use the same helper function to populate the fields).
test/e2e/case33_empty_label_test.go
Outdated
const ( | ||
case33ConfigPolicy = "../resources/case33_empty_label_handling/empty-labels-config.yaml" | ||
case33ConfigPolicyName = "case33-empty-labels" | ||
case33NodeName = "test-managed-control-plane" |
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.
I'd prefer to use a different resource for the test. This relies on using a kind cluster of a specific name. If the test creates a configmap or something, the policy could just label that.
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.
/hold
Looks good to me! Thanks for the changes to the tests, it looks great now. Just holding for any other reviewer comments.
@zyjjay could you please format your commit message title and description to match the contribution guidelines? Also, ACM shouldn't be mentioned in the commit message since this is in the upstream Open Cluster Management community. |
/lgtm |
/hold |
/hold |
@zyjjay do you need help with changing the commit message? |
Fix parsing issue when policy label fields are set to empty strings ref: https://issues.redhat.com/browse/ACM-5398 Signed-off-by: Jason Zhang <jaszhang@redhat.com>
@zyjjay the commit title should start with a verb in the imperative mood (i.e. Fix ....). Please do this next time. |
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.
/unhold
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: JustinKuli, mprahl, yiraeChristineKim, zyjjay The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
7c94409
into
open-cluster-management-io:main
/cherry-pick release-2.7 |
You have to do that on the Stolostron PR: |
@yiraeChristineKim: only open-cluster-management-io org members may request cherry picks. You can still do the cherry-pick manually. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Fix parsing issue when policy label fields are set to empty strings
ref: https://issues.redhat.com/browse/ACM-5398