Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
Milestone 3.0.1 Changes (#136)
Browse files Browse the repository at this point in the history
* Milestone 3.0.1 Changes (#135)

* Merge pull request #49 in DEV/k8s-argus from bugfix/DEV-59446-deleted-namespaces-are-still-present-on-the-portal to develop

* commit 'd0fb53894f1475979f48653c6438318faa3085b0':
  DEV-59446 delete namespace code refactored
  DEV-59446 delete namespace code refactored
  DEV-59446 fixed deleted namespaces present on portal issue

* Merge pull request #47 in DEV/k8s-argus from DEV-59276-argus-dev-prof to develop

* commit 'e1c57b89b13dd22fa949f1ca7db2672f9e29874e':
  DEV-59276: Created dev profile dockerfile and updated makefile with dev profile
  • Loading branch information
vkumbhar94 authored Jun 4, 2020
1 parent a13a3dd commit 5ed97d4
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
15 changes: 15 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM golang:1.14 as build
WORKDIR $GOPATH/src/github.com/logicmonitor/k8s-argus
ARG VERSION
COPY ./ ./
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /argus -ldflags "-X \"github.com/logicmonitor/k8s-argus/pkg/constants.Version=${VERSION}\""

FROM alpine:3.6
LABEL maintainer="LogicMonitor <[email protected]>"
RUN apk --update add ca-certificates \
&& rm -rf /var/cache/apk/* \
&& rm -rf /var/lib/apk/*
WORKDIR /app
COPY --from=build /argus /bin

ENTRYPOINT ["argus"]
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ all:
docker build --build-arg VERSION=$(VERSION) -t $(NAMESPACE)/$(REPOSITORY):v2latest .
docker tag $(NAMESPACE)/$(REPOSITORY):v2latest $(NAMESPACE)/$(REPOSITORY):$(VERSION)

dev:
docker build --build-arg VERSION=$(VERSION) -t $(NAMESPACE)/$(REPOSITORY):v2latest -f Dockerfile.dev .
docker tag $(NAMESPACE)/$(REPOSITORY):v2latest $(NAMESPACE)/$(REPOSITORY):$(VERSION)

.PHONY: docs
docs:
cd docs/source && hugo
33 changes: 33 additions & 0 deletions pkg/devicegroup/devicegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,26 @@ func Find(parentID int32, name string, client *client.LMSdkGo) (*models.DeviceGr
return deviceGroup, nil
}

// FindDeviceGroupsByName searches for a device group by name.
func FindDeviceGroupsByName(name string, client *client.LMSdkGo) ([]*models.DeviceGroup, error) {
params := lm.NewGetDeviceGroupListParams()
fields := "name,id,parentId,subGroups"
params.SetFields(&fields)
filter := fmt.Sprintf("name:\"%s\"", name)
params.SetFilter(&filter)
restResponse, err := client.LM.GetDeviceGroupList(params)
if err != nil {
return nil, err
}

var deviceGroups []*models.DeviceGroup
if restResponse != nil && restResponse.Payload != nil {
deviceGroups = restResponse.Payload.Items
}

return deviceGroups, nil
}

// Exists returns true if the specified device group exists in the account
func Exists(parentID int32, name string, client *client.LMSdkGo) bool {
deviceGroup, err := Find(parentID, name, client)
Expand Down Expand Up @@ -185,6 +205,19 @@ func DeleteSubGroup(deviceGroup *models.DeviceGroup, name string, client *client
return nil
}

// DeleteGroup deletes a device group with the specified deviceGroupID.
func DeleteGroup(deviceGroup *models.DeviceGroup, client *client.LMSdkGo) error {
params := lm.NewDeleteDeviceGroupByIDParams()
params.ID = deviceGroup.ID
deleteChildren := true
params.SetDeleteChildren(&deleteChildren)
deleteHard := true
params.SetDeleteHard(&deleteHard)
log.Infof("Deleting deviceGroup:\"%s\" ID:\"%d\" ParentID:\"%d\"", *deviceGroup.Name, deviceGroup.ID, deviceGroup.ParentID)
_, err := client.LM.DeleteDeviceGroupByID(params)
return err
}

func create(name, appliesTo string, disableAlerting bool, parentID int32, client *client.LMSdkGo) (*models.DeviceGroup, error) {
params := lm.NewAddDeviceGroupParams()
params.SetBody(&models.DeviceGroup{
Expand Down
34 changes: 20 additions & 14 deletions pkg/watch/namespace/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,28 @@ func (w *Watcher) DeleteFunc() func(obj interface{}) {
namespace := obj.(*v1.Namespace)
log.Debugf("Handle deleting namespace event: %s", namespace.Name)

for name, parentID := range w.DeviceGroups {
deviceGroup, err := devicegroup.Find(parentID, name, w.LMClient)
if err != nil {
log.Warnf("Failed to find namespace %s: %v", name, err)
return
}
// We should only be returned a device group if it is namespaced.
if deviceGroup == nil {
continue
}
err = devicegroup.DeleteSubGroup(deviceGroup, namespace.Name, w.LMClient)
if err != nil {
log.Errorf("Failed to delete namespace %q: %v", namespace.Name, err)
return
deviceGroups, err := devicegroup.FindDeviceGroupsByName(namespace.Name, w.LMClient)
if err != nil {
log.Errorf("Failed to get device group for namespace:\"%s\" with error: %v", namespace.Name, err)
return
}

reversedDeviceGroups := getReversedDeviceGroups(w.DeviceGroups)
for _, d := range deviceGroups {
if _, ok := reversedDeviceGroups[d.ParentID]; ok {
err = devicegroup.DeleteGroup(d, w.LMClient)
if err != nil {
log.Errorf("Failed to delete device group of namespace:\"%s\" having ID:\"%d\" with error: %v", namespace.Name, d.ID, err)
}
}
}
}
}

func getReversedDeviceGroups(deviceGroups map[string]int32) map[int32]string {
reversedDeviceGroups := make(map[int32]string)
for key, value := range deviceGroups {
reversedDeviceGroups[value] = key
}
return reversedDeviceGroups
}

0 comments on commit 5ed97d4

Please sign in to comment.