Skip to content
This repository was archived by the owner on Jan 16, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
115 commits
Select commit Hold shift + click to select a range
bb2c1f5
DEV-39965: Allow the user to specify a parent group during installation
Oct 12, 2018
5735cb4
Merge pull request #1 in DEV/k8s-argus from DEV-39965-allow-the-user-…
Oct 15, 2018
2d53e26
DEV-39965: Allow the user to specify a parent group during installation
Oct 16, 2018
3c03f96
Merge pull request #2 in DEV/k8s-argus from DEV-39965-allow-the-user-…
Oct 16, 2018
5dfab5b
DEV-40505: Sync the k8s resource to santaba when argus launches
Nov 1, 2018
4058f07
DEV-40434: The alert status of Pods and Services are disabled
Nov 2, 2018
e43a6a7
DEV-40505: Sync the k8s resource to santaba when argus launches
Nov 2, 2018
58a9125
Merge pull request #3 in DEV/k8s-argus from DEV-40505-sync-the-k8s-re…
Nov 6, 2018
33c0a67
Merge pull request #4 in DEV/k8s-argus from bugfix/DEV-40434-the-aler…
Nov 6, 2018
b4ce488
DEV-40505: Sync the k8s resource to santaba when argus launches
Nov 9, 2018
a03490e
Merge pull request #6 in DEV/k8s-argus from DEV-40505-sync-the-k8s-re…
Nov 10, 2018
e7c90f1
DEV-40779: Enable the alert on service group when it is created by argus
Nov 14, 2018
d36f943
Merge pull request #7 in DEV/k8s-argus from DEV-40779-enable-the-aler…
Nov 15, 2018
cc8efda
DEV-41432: Use IP as hostname for argus related devices
Dec 11, 2018
eb4fffb
DEV-41432: Use IP as hostname for argus related devices
Dec 13, 2018
16000b5
DEV-41459: Add a new device type for k8s devices
Dec 13, 2018
821500c
Merge pull request #9 in DEV/k8s-argus from DEV-41459-add-a-new-devic…
Dec 14, 2018
d570b4f
Merge pull request #8 in DEV/k8s-argus from DEV-41432-use-ip-as-hostn…
Dec 14, 2018
e6152f8
DEV-41432: Use IP as hostname for argus related devices
Dec 17, 2018
4079f66
Merge pull request #10 in DEV/k8s-argus from DEV-41432-use-ip-as-host…
Dec 17, 2018
f35228a
DEV-40217: Support to set log levels and improve logs in argus relate…
Dec 18, 2018
968a0ad
DEV-40217: Support to set log levels and improve logs in argus relate…
Dec 19, 2018
a6f1cd1
Merge branch 'master' into develop
woz5999 Dec 20, 2018
e56e41e
DEV-41682: Improve the argus code for the CI failure in GitHub
Dec 21, 2018
66f8a96
Merge pull request #1 from JeremyTangCD/DEV-41682-improve-the-argus-c…
JeremyTangCD Dec 21, 2018
5a8c798
Merge pull request #12 in DEV/k8s-argus from DEV-41682-improve-the-ar…
Dec 26, 2018
f634986
Merge pull request #11 in DEV/k8s-argus from DEV-40217-support-to-set…
Dec 26, 2018
2d0e559
Merge pull request #3 from JeremyTangCD/DEV-40217-support-to-set-log-…
JeremyTangCD Jan 2, 2019
b27023b
Merge branch 'develop' into develop
JeremyTangCD Jan 2, 2019
3286dcd
Dev-40217 support to set log levels and improve
JeremyTangCD Jan 2, 2019
06bdd15
DEV-41947: Improve the initsync logic to prevent lost data after k8s …
Jan 9, 2019
c69d432
DEV-41947: Improve the initsync logic to prevent lost data after k8s …
Jan 10, 2019
fc8f4f7
Merge pull request #13 in DEV/k8s-argus from DEV-41947-improve-the-in…
Jan 11, 2019
f1a712e
DEV-42060: Don't create collector device for Kubernetes Clusters
Jan 14, 2019
1d790d0
Merge pull request #14 in DEV/k8s-argus from DEV-42060-don-t-create-c…
Jan 15, 2019
d65374e
DEV-47062 Add distinguishing property to host network pods
Jan 22, 2019
746c3d9
Merge pull request #15 in DEV/k8s-argus from DEV-47062-add-distinguis…
Jan 29, 2019
30932b0
DEV-49046 Fix the internal IP cannot found bug in argus
Feb 14, 2019
838e88b
Merge pull request #16 in DEV/k8s-argus from DEV-49046-fix-the-intern…
Feb 15, 2019
7ecbcf6
Merge pull request #4 from JeremyTangCD/DEV-49046-fix-the-internal-ip…
JeremyTangCD Feb 15, 2019
a0c3b2d
Merge branch 'develop' into develop
JeremyTangCD Feb 15, 2019
2cc8d13
DEV-49046 Fix the internal IP cannot found bug in argus
Feb 18, 2019
93e95d8
Merge pull request #17 in DEV/k8s-argus from DEV-49046-fix-the-intern…
Feb 18, 2019
6293a0a
Merge pull request #5 from JeremyTangCD/DEV-49046-fix-the-internal-ip…
JeremyTangCD Feb 18, 2019
2333cd4
Update node_test.go
JeremyTangCD Feb 18, 2019
ea10463
DEV-48974 Upgrade Argus from golang 1.9 to 1.11
Feb 18, 2019
55d703e
Merge pull request #18 in DEV/k8s-argus from DEV-48974-upgrade-argus-…
Feb 21, 2019
cf2cdf0
Merge pull request #6 from JeremyTangCD/DEV-48974-upgrade-argus-from-…
JeremyTangCD Feb 28, 2019
f9d6759
Merge pull request #7 from logicmonitor/develop
JeremyTangCD Feb 28, 2019
ffacdd6
DEV-48974 Upgrade Argus from golang 1.9 to 1.11
Feb 28, 2019
a77e88b
Merge pull request #8 from JeremyTangCD/DEV-48974-upgrade-argus-from-…
JeremyTangCD Feb 28, 2019
1a1fa4e
Merge pull request #9 from logicmonitor/develop
JeremyTangCD Apr 25, 2019
5e8f826
DEV-49251 improve panic log process
DzXiaoLMCD Apr 26, 2019
e9d8d90
DEV-50734 Support all service type, and add the logs
DzXiaoLMCD Apr 26, 2019
34a4ea2
DEV-41301 Upgrade the go sdk to v2
May 5, 2019
21527a1
DEV-41301 Upgrade the go sdk to v2
May 5, 2019
db5aaed
DEV-41301 Upgrade the go sdk to v2
May 5, 2019
12fd071
DEV-41301 Upgrade the go sdk to v2
May 6, 2019
f0997f0
DEV-50734 Support all service type, modify the UpdateFunc
DzXiaoLMCD May 6, 2019
69f8fb5
DEV-41301 Upgrade the go sdk to v2
May 6, 2019
5f8afc4
DEV-50929 Add k8s deployments monitoring by Argus
DzXiaoLMCD May 7, 2019
d45062a
DEV-49251 Add the defer to initSync and improve log output
DzXiaoLMCD May 7, 2019
fa9fe85
Merge pull request #20 in DEV/k8s-argus from DEV-50734-devts-6790-dis…
DzXiaoLMCD May 7, 2019
23f2cd3
Merge pull request #21 in DEV/k8s-argus from DEV-41301-upgrade-the-go…
May 7, 2019
8e1b0e5
DEV-41301 Upgrade the go sdk to v2
May 7, 2019
3d9407c
Merge pull request #23 in DEV/k8s-argus from DEV-41301-upgrade-the-go…
May 7, 2019
0e9d209
DEV-50929 Improve the code with comments
DzXiaoLMCD May 7, 2019
50e6b2d
Merge pull request #19 in DEV/k8s-argus from DEV-49251-improve-panic-…
DzXiaoLMCD May 8, 2019
3944266
DEV-50929 Add k8s deployments monitoring by Argus
DzXiaoLMCD May 8, 2019
17a50a0
DEV-49675 Merge from develop branch
DzXiaoLMCD May 10, 2019
8f80c6c
DEV-50734 Improve the log message
DzXiaoLMCD May 11, 2019
100a717
DEV-49251 Improve the log message
DzXiaoLMCD May 11, 2019
70702f7
Merge pull request #27 in DEV/k8s-argus from DEV-49251-improve-panic-…
DzXiaoLMCD May 12, 2019
6d1787f
Merge pull request #28 in DEV/k8s-argus from DEV-50734-devts-6790-dis…
DzXiaoLMCD May 12, 2019
58027d7
DEV-49251 Improve the comments
DzXiaoLMCD May 13, 2019
cef2c2f
DEV-49251 Merge improve-panic-log-process branch
DzXiaoLMCD May 13, 2019
5abe682
DEV-51405 Fix the argus log format
DzXiaoLMCD May 13, 2019
1e77de0
DEV-51567 Fixed the label value of k8s monitored
DzXiaoLMCD May 13, 2019
978c9a1
Merge branch 'develop' of https://stash.logicmonitor.com/scm/dev/k8s-…
DzXiaoLMCD May 14, 2019
57c574e
DEV-49675 Synchronous develop branch, add the recover panic logic for…
DzXiaoLMCD May 14, 2019
2ca8da0
Merge pull request #31 in DEV/k8s-argus from DEV-51405-improve-argus-…
DzXiaoLMCD May 14, 2019
9a4617c
Merge pull request #32 in DEV/k8s-argus from bugfix/DEV-51567-the-lab…
DzXiaoLMCD May 14, 2019
69cc809
Merge branch 'develop' of https://stash.logicmonitor.com/scm/dev/k8s-…
DzXiaoLMCD May 14, 2019
6e05ef5
Modify the format by Travis CI check
DzXiaoLMCD May 15, 2019
665b218
DEV-51677 Improve the code according to github comments
DzXiaoLMCD May 16, 2019
8c3a4e1
Merge pull request #33 in DEV/k8s-argus from DEV-51677-create-github-…
DzXiaoLMCD May 17, 2019
823f4a1
Improve the variable naming
DzXiaoLMCD May 17, 2019
32730de
DEV-51932 fix uptime widget for k8s resources
DzXiaoLMCD May 30, 2019
dfe477f
Merge pull request #34 in DEV/k8s-argus from DEV-51932-fix-uptime-wid…
DzXiaoLMCD May 31, 2019
c1b5a71
DEV-49675 Merge from develop branch
DzXiaoLMCD Jun 4, 2019
68a9e6f
DEV-49675 Restore the dockerfile
DzXiaoLMCD Jun 4, 2019
f206d06
DEV-52508 Fixed the CI check
DzXiaoLMCD Jun 12, 2019
e313748
DEV-52508 Argus deployment rbac privilege improve
DzXiaoLMCD Jun 12, 2019
87941be
DEV-52508 Argus deployment rbac privilege improve
DzXiaoLMCD Jun 12, 2019
d5f9ae0
DEV-52508 Argus deployment rbac privilege compatibility improvement
DzXiaoLMCD Jun 14, 2019
af73614
DEV-52508 Argus deployment rbac privilege compatibility improvement
DzXiaoLMCD Jun 14, 2019
7b00015
DEV-52508 Argus deployment rbac privilege compatibility improvement
DzXiaoLMCD Jun 14, 2019
0551743
DEV-52036 Allow for duplicate pod names in one LM account
DzXiaoLMCD Jun 16, 2019
d139bb7
DEV-52508 Improve by the comments
DzXiaoLMCD Jun 16, 2019
b516b2d
DEV-52036 Allow for duplicate pod names in one LM account
DzXiaoLMCD Jun 16, 2019
2686988
DEV-52508 Fix the comments
DzXiaoLMCD Jun 17, 2019
a1df27e
DEV-52508 Fix the comments
DzXiaoLMCD Jun 17, 2019
421d532
Merge pull request #35 in DEV/k8s-argus from feature/DEV-52508-argus-…
DzXiaoLMCD Jun 17, 2019
538e9b3
Merge branch 'develop' of https://github.com/logicmonitor/k8s-argus i…
DzXiaoLMCD Jun 19, 2019
ef024be
remove logo link
DzXiaoLMCD Jun 19, 2019
c828030
Merge branch 'develop' of https://stash.logicmonitor.com/scm/dev/k8s-…
DzXiaoLMCD Jun 19, 2019
a0d2ab0
DEV-52036 Allow for duplicate pod names in one LM account
DzXiaoLMCD Jun 20, 2019
9fe97da
DEV-52036 Allow for duplicate pod names in one LM account
DzXiaoLMCD Jun 20, 2019
203f978
DEV-52036 Allow for duplicate pod names in one LM account
DzXiaoLMCD Jun 20, 2019
6921bc3
Merge branch 'develop' of https://github.com/logicmonitor/k8s-argus i…
DzXiaoLMCD Jun 20, 2019
1829b56
DEV-52036 Fix the comments
DzXiaoLMCD Jun 21, 2019
41a2dc0
DEV-52036 Fix the comments
DzXiaoLMCD Jun 21, 2019
e294264
Merge branch 'DEV-52036-allow-for-duplicate-pod-names-in' of https://…
DzXiaoLMCD Jul 2, 2019
a5e616a
Merge branch 'develop' of https://github.com/DzXiaoLMCD/k8s-argus int…
DzXiaoLMCD Jul 2, 2019
72f2ee8
DEV-52991 Add UT
DzXiaoLMCD Jul 3, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ const (
const (
// K8sClusterNamePropertyKey is the key of the unique auto property kubernetes cluster name
K8sClusterNamePropertyKey = "auto.clustername"
// K8sResourceNamePropertyKey is the key of the custom property used to record resource name
K8sResourceNamePropertyKey = "auto.resourcename"
// K8sResourceCreatedOnPropertyKey is the key of the custom property used to record resource create timestamp
K8sResourceCreatedOnPropertyKey = "kubernetes.resourceCreatedOn"
// K8sDeviceType is the type value of the k8s device
Expand Down
139 changes: 111 additions & 28 deletions pkg/device/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package device
import (
"context"
"fmt"
"strings"

"github.com/logicmonitor/k8s-argus/pkg/config"
"github.com/logicmonitor/k8s-argus/pkg/constants"
Expand Down Expand Up @@ -55,40 +56,92 @@ func buildDevice(c *config.Config, client api.CollectorSetControllerClient, opti

// checkAndUpdateExistingDevice tries to find and update the devices which needs to be changed
func (m *Manager) checkAndUpdateExistingDevice(device *models.Device) (*models.Device, error) {
oldDevice, err := m.FindByDisplayName(*device.DisplayName)
displayNameWithClusterName := fmt.Sprintf("%s-%s", *device.DisplayName, m.Config().ClusterName)
existingDevices, err := m.FindByDisplayNames(*device.DisplayName, displayNameWithClusterName)
if err != nil {
return nil, err
}
if oldDevice == nil {
return nil, fmt.Errorf("can not find the device: %s", *device.DisplayName)
if len(existingDevices) == 0 {
return nil, fmt.Errorf("cannot find devices with name: %s", *device.DisplayName)
}

// the device which is not changed will be ignored
if *device.Name == *oldDevice.Name {
log.Infof("No changes to device (%s). Ignoring update", *device.DisplayName)
return device, nil
}

// the device of the other cluster will be ignored
oldClusterName := ""
if oldDevice.CustomProperties != nil && len(oldDevice.CustomProperties) > 0 {
for _, cp := range oldDevice.CustomProperties {
if *cp.Name == constants.K8sClusterNamePropertyKey {
oldClusterName = *cp.Value
for _, existingDevice := range existingDevices {
clusterName := m.GetPropertyValue(existingDevice, constants.K8sClusterNamePropertyKey)
if clusterName == m.Config().ClusterName {
// the device which is not changed will be ignored
if *existingDevice.Name == *device.Name {
log.Infof("No changes to device (%s). Ignoring update", *device.DisplayName)
return device, nil
}
// the clusterName is the same and hostName is not the same, need update
*device.DisplayName = *existingDevice.DisplayName
newDevice, err2 := m.updateAndReplace(existingDevice.ID, device)
if err2 != nil {
return nil, err2
}
log.Infof("Updating existing device (%s)", *newDevice.DisplayName)
return newDevice, nil
}
}
if oldClusterName != m.Config().ClusterName {
log.Infof("Device (%s) belongs to a different cluster (%s). Ignoring update", *device.DisplayName, oldClusterName)
return device, nil
// duplicate device exists. update displayName and re-add
renamedDevice, err := m.renameAndAddDevice(device)
if err != nil {
log.Errorf("rename device failed: %v", err)
return nil, fmt.Errorf("rename device failed")
}
return renamedDevice, nil
}

newDevice, err := m.updateAndReplace(oldDevice.ID, device)
// renameAndAddDevice rename display name and then add the device
func (m *Manager) renameAndAddDevice(device *models.Device) (*models.Device, error) {
resourceName := m.GetPropertyValue(device, constants.K8sResourceNamePropertyKey)
if resourceName == "" {
resourceName = *device.DisplayName
}
renameResourceName := fmt.Sprintf("%s-%s", resourceName, m.Config().ClusterName)
existingDevice, err := m.FindByDisplayName(renameResourceName)
if err != nil {
log.Warnf("Get device(%s) failed, err: %v", resourceName, err)
}
if existingDevice != nil {
if m.Config().ClusterName == m.GetPropertyValue(existingDevice, constants.K8sClusterNamePropertyKey) {
device.DisplayName = existingDevice.DisplayName
return m.updateAndReplace(existingDevice.ID, device)
}
return nil, fmt.Errorf("exist displayName: %s", renameResourceName)
}
log.Infof("Rename device: %s -> %s", *device.DisplayName, renameResourceName)
device.DisplayName = &renameResourceName
params := lm.NewAddDeviceParams()
addFromWizard := false
params.SetAddFromWizard(&addFromWizard)
params.SetBody(device)
restResponse, err := m.LMClient.LM.AddDevice(params)
if err != nil {
return nil, err
}
log.Infof("Finished updating the device: %s", *newDevice.DisplayName)
return newDevice, nil
return restResponse.Payload, nil
}

// GetPropertyValue get device property value by property name
func (m *Manager) GetPropertyValue(device *models.Device, propertyName string) string {
if device == nil {
return ""
}
if len(device.CustomProperties) > 0 {
for _, cp := range device.CustomProperties {
if *cp.Name == propertyName {
return *cp.Value
}
}
}
if len(device.SystemProperties) > 0 {
for _, cp := range device.SystemProperties {
if *cp.Name == propertyName {
return *cp.Value
}
}
}
return ""
}

func (m *Manager) updateAndReplace(id int32, device *models.Device) (*models.Device, error) {
Expand Down Expand Up @@ -124,6 +177,37 @@ func (m *Manager) FindByDisplayName(name string) (*models.Device, error) {
return nil, nil
}

// FindByDisplayNames implements types.DeviceManager.
func (m *Manager) FindByDisplayNames(displayNames ...string) ([]*models.Device, error) {
if len(displayNames) == 0 {
return []*models.Device{}, nil
}
filter := fmt.Sprintf("displayName:\"%s\"", strings.Join(displayNames, "\"|\""))
params := lm.NewGetDeviceListParams()
params.SetFilter(&filter)
restResponse, err := m.LMClient.LM.GetDeviceList(params)
if err != nil {
return nil, err
}
log.Debugf("%#v", restResponse)
return restResponse.Payload.Items, nil
}

// FindByDisplayNameAndClusterName implements types.DeviceManager.
func (m *Manager) FindByDisplayNameAndClusterName(displayName string) (*models.Device, error) {
displayNameWithClusterName := fmt.Sprintf("%s-%s", displayName, m.Config().ClusterName)
devices, err := m.FindByDisplayNames(displayName, displayNameWithClusterName)
if err != nil {
return nil, err
}
for _, device := range devices {
if m.Config().ClusterName == m.GetPropertyValue(device, constants.K8sClusterNamePropertyKey) {
return device, nil
}
}
return nil, nil
}

// Add implements types.DeviceManager.
func (m *Manager) Add(options ...types.DeviceOption) (*models.Device, error) {
device := buildDevice(m.Config(), m.ControllerClient, options...)
Expand Down Expand Up @@ -152,7 +236,6 @@ func (m *Manager) Add(options ...types.DeviceOption) (*models.Device, error) {
return nil, err
}
log.Debugf("%#v", restResponse)

return restResponse.Payload, nil
}

Expand All @@ -166,7 +249,7 @@ func (m *Manager) UpdateAndReplaceByID(id int32, options ...types.DeviceOption)

// UpdateAndReplaceByDisplayName implements types.DeviceManager.
func (m *Manager) UpdateAndReplaceByDisplayName(name string, options ...types.DeviceOption) (*models.Device, error) {
d, err := m.FindByDisplayName(name)
d, err := m.FindByDisplayNameAndClusterName(name)
if err != nil {
return nil, err
}
Expand All @@ -175,7 +258,7 @@ func (m *Manager) UpdateAndReplaceByDisplayName(name string, options ...types.De
log.Warnf("Could not find device %q", name)
return nil, nil
}

options = append(options, m.DisplayName(*d.DisplayName))
// Update the device.
device, err := m.UpdateAndReplaceByID(d.ID, options...)
if err != nil {
Expand Down Expand Up @@ -210,7 +293,7 @@ func (m *Manager) UpdateAndReplaceFieldByID(id int32, field string, options ...t

// UpdateAndReplaceFieldByDisplayName implements types.DeviceManager.
func (m *Manager) UpdateAndReplaceFieldByDisplayName(name string, field string, options ...types.DeviceOption) (*models.Device, error) {
d, err := m.FindByDisplayName(name)
d, err := m.FindByDisplayNameAndClusterName(name)
if err != nil {
return nil, err
}
Expand All @@ -219,7 +302,7 @@ func (m *Manager) UpdateAndReplaceFieldByDisplayName(name string, field string,
log.Infof("Could not find device %q", name)
return nil, nil
}

options = append(options, m.DisplayName(*d.DisplayName))
// Update the device.
device, err := m.UpdateAndReplaceFieldByID(d.ID, field, options...)
if err != nil {
Expand All @@ -239,7 +322,7 @@ func (m *Manager) DeleteByID(id int32) error {

// DeleteByDisplayName implements types.DeviceManager.
func (m *Manager) DeleteByDisplayName(name string) error {
d, err := m.FindByDisplayName(name)
d, err := m.FindByDisplayNameAndClusterName(name)
if err != nil {
return err
}
Expand Down
52 changes: 52 additions & 0 deletions pkg/device/device_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package device

import (
"testing"

"github.com/logicmonitor/lm-sdk-go/models"
)

func TestGetPropertyValue(t *testing.T) {
deviceName := "test-device"

customPropertiesName1 := "name1"
customPropertiesValue1 := "value1"
customPropertiesName2 := "name2"
customPropertiesValue2 := "value2"

systemPropertiesName1 := "system-name1"
systemPropertiesValue1 := "system-value1"
systemPropertiesName2 := "system-name2"
systemPropertiesValue2 := "system-value2"

device := &models.Device{
Name: &deviceName,
DisplayName: &deviceName,
CustomProperties: []*models.NameAndValue{
{
Name: &customPropertiesName1,
Value: &customPropertiesValue1,
}, {
Name: &customPropertiesName2,
Value: &customPropertiesValue2,
},
},
SystemProperties: []*models.NameAndValue{
{
Name: &systemPropertiesName1,
Value: &systemPropertiesValue1,
}, {
Name: &systemPropertiesName2,
Value: &systemPropertiesValue2,
},
},
}

manage := Manager{}
value := manage.GetPropertyValue(device, customPropertiesName1)
t.Logf("name=%s, value=%s", customPropertiesName1, value)
value = manage.GetPropertyValue(device, systemPropertiesName2)
t.Logf("name=%s, value=%s", systemPropertiesName2, value)
value = manage.GetPropertyValue(device, "non-exist-name")
t.Logf("name=%s, value=%s", "non-exist-name", value)
}
18 changes: 8 additions & 10 deletions pkg/sync/initsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,21 +158,19 @@ func (i *InitSyncer) syncDevices(resourceType string, resourcesMap map[string]st
for _, device := range devices {
// the "auto.clustername" property checking is used to prevent unexpected deletion of the normal non-k8s device
// which may be assigned to the cluster group
cps := device.CustomProperties
autoClusterName := ""
for _, cp := range cps {
if *cp.Name == constants.K8sClusterNamePropertyKey {
autoClusterName = *cp.Value
break
}
}
autoClusterName := i.DeviceManager.GetPropertyValue(device, constants.K8sClusterNamePropertyKey)
if autoClusterName != i.DeviceManager.Config().ClusterName {
log.Infof("Ignore the device (%v) which does not have property %v:%v",
*device.DisplayName, constants.K8sClusterNamePropertyKey, i.DeviceManager.Config().ClusterName)
continue
}

_, exist := resourcesMap[*device.DisplayName]
// the displayName may be renamed, we should use the constants.K8sResourceNamePropertyKey property value
resourceName := i.DeviceManager.GetPropertyValue(device, constants.K8sResourceNamePropertyKey)
// for compatibility, if resourceName is empty, use display name
if resourceName == "" {
resourceName = *device.DisplayName
}
_, exist := resourcesMap[resourceName]
if !exist {
log.Infof("Delete the non-exist %v device: %v", resourceType, *device.DisplayName)
err := i.DeviceManager.DeleteByID(device.ID)
Expand Down
4 changes: 4 additions & 0 deletions pkg/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type DeviceMapper interface {
// FindByDisplayName searches for a device by it's display name. It will return a device if and only if
// one device was found, and return nil otherwise.
FindByDisplayName(string) (*models.Device, error)
// FindByDisplayNames searches for devices by the specified string by its display name. It will return the device list.
FindByDisplayNames(...string) ([]*models.Device, error)
// FindByDisplayNameAndClusterName searches for device by the specified string by its display name and clusterName. It will return a device if and only if
FindByDisplayNameAndClusterName(string) (*models.Device, error)
// Add adds a device to a LogicMonitor account.
Add(...DeviceOption) (*models.Device, error)
// UpdateAndReplaceByID updates a device using the 'replace' OpType.
Expand Down
1 change: 1 addition & 0 deletions pkg/watch/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ func (w *Watcher) args(deployment *v1beta2.Deployment, category string) []types.
w.Auto("selflink", deployment.SelfLink),
w.Auto("uid", string(deployment.UID)),
w.Custom(constants.K8sResourceCreatedOnPropertyKey, strconv.FormatInt(deployment.CreationTimestamp.Unix(), 10)),
w.Custom(constants.K8sResourceNamePropertyKey, fmtDeploymentDisplayName(deployment)),
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/watch/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (w *Watcher) args(node *v1.Node, category string) []types.DeviceOption {
w.Auto("selflink", node.SelfLink),
w.Auto("uid", string(node.UID)),
w.Custom(constants.K8sResourceCreatedOnPropertyKey, strconv.FormatInt(node.CreationTimestamp.Unix(), 10)),
w.Custom(constants.K8sResourceNamePropertyKey, node.Name),
}
}

Expand Down
1 change: 1 addition & 0 deletions pkg/watch/pod/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ func (w *Watcher) args(pod *v1.Pod, category string) []types.DeviceOption {
w.Auto("uid", string(pod.UID)),
w.System("ips", pod.Status.PodIP),
w.Custom(constants.K8sResourceCreatedOnPropertyKey, strconv.FormatInt(pod.CreationTimestamp.Unix(), 10)),
w.Custom(constants.K8sResourceNamePropertyKey, pod.Name),
}
if pod.Spec.HostNetwork {
options = append(options, w.Custom("kubernetes.pod.hostNetwork", "true"))
Expand Down
1 change: 1 addition & 0 deletions pkg/watch/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (w *Watcher) args(service *v1.Service, category string) []types.DeviceOptio
w.Auto("selflink", service.SelfLink),
w.Auto("uid", string(service.UID)),
w.Custom(constants.K8sResourceCreatedOnPropertyKey, strconv.FormatInt(service.CreationTimestamp.Unix(), 10)),
w.Custom(constants.K8sResourceNamePropertyKey, fmtServiceDisplayName(service)),
}
}

Expand Down