-
Notifications
You must be signed in to change notification settings - Fork 995
Use host IDs instead of host names when doing generate-gitops for manual labels #34254
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
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 |
|---|---|---|
|
|
@@ -752,8 +752,8 @@ func setupLabelSpecsTest(t *testing.T, ds fleet.Datastore) []*fleet.LabelSpec { | |
| SeenTime: time.Now(), | ||
| OsqueryHostID: ptr.String(strconv.Itoa(i)), | ||
| NodeKey: ptr.String(strconv.Itoa(i)), | ||
| UUID: strconv.Itoa(i), | ||
| Hostname: strconv.Itoa(i), | ||
| UUID: fmt.Sprintf("uuid%s", strconv.Itoa(i)), | ||
| Hostname: fmt.Sprintf("host%s", strconv.Itoa(i)), | ||
|
Comment on lines
-755
to
+756
Contributor
Author
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. This test was always a bit wonky in that it used numbers for the UUID and Hostname as well. Since we added ID to the mix of things you can specify for label membership in GitOps, it led to weird results where if you said "I want hosts 1, 2, and 3" you'd get a label with hosts 1, 2, 3 and 4 because host #4 had a UUID and hostname of "3". Changing these to be strings clears up that confusion in the test. |
||
| }) | ||
| require.Nil(t, err) | ||
| } | ||
|
|
@@ -790,10 +790,7 @@ func setupLabelSpecsTest(t *testing.T, ds fleet.Datastore) []*fleet.LabelSpec { | |
| err := ds.ApplyLabelSpecs(context.Background(), expectedSpecs) | ||
| require.Nil(t, err) | ||
|
|
||
| // Because `Hosts` for manual labels matches both host name AND host ID, | ||
| // specifying "1" will match both host with ID 1 (whose name is "0") | ||
| // and host with name "1". | ||
| expectedSpecs[4].Hosts = []string{"0", "1", "2", "3", "4"} | ||
| expectedSpecs[4].Hosts = []string{"1", "2", "3", "4"} | ||
|
Contributor
Author
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. see comment above |
||
| return expectedSpecs | ||
| } | ||
|
|
||
|
|
@@ -1870,8 +1867,8 @@ func testUpdateLabelMembershipByHostIDs(t *testing.T, ds *Datastore) { | |
| require.NoError(t, err) | ||
| // label.Hosts contains hostnames | ||
| require.Len(t, labelSpec.Hosts, 2) | ||
| require.Equal(t, host1.Hostname, labelSpec.Hosts[0]) | ||
| require.Equal(t, host2.Hostname, labelSpec.Hosts[1]) | ||
| require.Equal(t, strconv.Itoa(int(host1.ID)), labelSpec.Hosts[0]) //nolint:gosec // dismiss G115 | ||
| require.Equal(t, strconv.Itoa(int(host2.ID)), labelSpec.Hosts[1]) //nolint:gosec // dismiss G115 | ||
|
|
||
| labels, err := ds.ListLabelsForHost(ctx, host1.ID) | ||
| require.NoError(t, err) | ||
|
|
@@ -1977,9 +1974,9 @@ func testUpdateLabelMembershipByHostIDs(t *testing.T, ds *Datastore) { | |
|
|
||
| // label.Hosts contains hostnames | ||
| require.Len(t, labelSpec.Hosts, 3) | ||
| require.Equal(t, host1.Hostname, labelSpec.Hosts[0]) | ||
| require.Equal(t, host2.Hostname, labelSpec.Hosts[1]) | ||
| require.Equal(t, host3.Hostname, labelSpec.Hosts[2]) | ||
| require.Equal(t, strconv.Itoa(int(host1.ID)), labelSpec.Hosts[0]) //nolint:gosec // dismiss G115 | ||
| require.Equal(t, strconv.Itoa(int(host2.ID)), labelSpec.Hosts[1]) //nolint:gosec // dismiss G115 | ||
| require.Equal(t, strconv.Itoa(int(host3.ID)), labelSpec.Hosts[2]) //nolint:gosec // dismiss G115 | ||
| } | ||
|
|
||
| func testApplyLabelSpecsForSerialUUID(t *testing.T, ds *Datastore) { | ||
|
|
||
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.
The only real functional change. This method is only used by the
/spec/labelsendpoint and byfleetctl generate-gitops. I posted about the API change in Slack to get @rachaelshaw's feedback but I don't think it should be cause for concern.