Skip to content

Commit

Permalink
Send object labels with deltas
Browse files Browse the repository at this point in the history
  • Loading branch information
domust committed Jun 22, 2023
1 parent 119c6f6 commit 702a6a2
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
17 changes: 9 additions & 8 deletions castai/delta_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ type Delta struct {
}

type DeltaItem struct {
Event EventType `json:"event"`
ObjectUID string `json:"object_uid"`
ObjectName string `json:"object_name,omitempty"`
ObjectNamespace string `json:"object_namespace,omitempty"`
ObjectKind string `json:"object_kind,omitempty"`
ObjectAPIVersion string `json:"object_api_version,omitempty"`
ObjectCreatedAt time.Time `json:"object_created_at,omitempty"`
ObjectOwnerUID string `json:"object_owner_uid,omitempty"`
Event EventType `json:"event"`
ObjectUID string `json:"object_uid"`
ObjectName string `json:"object_name,omitempty"`
ObjectNamespace string `json:"object_namespace,omitempty"`
ObjectKind string `json:"object_kind,omitempty"`
ObjectAPIVersion string `json:"object_api_version,omitempty"`
ObjectCreatedAt time.Time `json:"object_created_at,omitempty"`
ObjectOwnerUID string `json:"object_owner_uid,omitempty"`
ObjectLabels map[string]string `json:"object_labels,omitempty"`

// ObjectContainers and ObjectStatus are set only for objects which could contain containers.
ObjectContainers []Container `json:"object_containers,omitempty"`
Expand Down
2 changes: 1 addition & 1 deletion cmd/imgcollector/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func main() {
addPprofHandlers(mux)
go func() {
if err := http.ListenAndServe(cfg.PprofAddr, mux); err != nil { //nolint:gosec
log.Warnf("pprof http sever failed: %v", err)
log.Warnf("pprof http server failed: %v", err)
}
}()
}
Expand Down
5 changes: 3 additions & 2 deletions controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"errors"
"fmt"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/manager"
"sync"

"sigs.k8s.io/controller-runtime/pkg/manager"

"github.com/samber/lo"
"github.com/sirupsen/logrus"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -71,7 +72,7 @@ type Controller struct {
informers map[reflect.Type]cache.SharedInformer
subscribers []ObjectSubscriber

// Due to bug in k8s we need to track if obect actually changed. See https://github.com/kubernetes/kubernetes/pull/106388
// Due to bug in k8s we need to track if object actually changed. See https://github.com/kubernetes/kubernetes/pull/106388
objectHashMu sync.Mutex
objectHashes map[string]struct{}
}
Expand Down
1 change: 1 addition & 0 deletions delta/delta.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ func (d *delta) add(event controller.Event, obj object) {
ObjectAPIVersion: gvr.GroupVersion().String(),
ObjectCreatedAt: obj.GetCreationTimestamp().UTC(),
ObjectOwnerUID: getOwnerUID(obj),
ObjectLabels: obj.GetLabels(),
}
if containers, status, ok := getContainersAndStatus(obj); ok {
deltaItem.ObjectContainers = containers
Expand Down
2 changes: 2 additions & 0 deletions delta/subscriber_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func TestSubscriber(t *testing.T) {
Name: "node1",
},
},
Labels: map[string]string{"subscriber": "test"},
},
Spec: corev1.PodSpec{
NodeName: "n1",
Expand Down Expand Up @@ -65,6 +66,7 @@ func TestSubscriber(t *testing.T) {
ObjectNamespace: "default",
ObjectKind: "Pod",
ObjectAPIVersion: "v1",
ObjectLabels: map[string]string{"subscriber": "test"},
ObjectContainers: []castai.Container{
{
Name: "nginx",
Expand Down

0 comments on commit 702a6a2

Please sign in to comment.