Skip to content
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

Automated cherry pick of #15621 - initial empty SET PodUpdate #17947

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions pkg/kubelet/config/config.go
Expand Up @@ -153,31 +153,33 @@ func (s *podStorage) Merge(source string, change interface{}) error {
s.updateLock.Lock()
defer s.updateLock.Unlock()

seenBefore := s.sourcesSeen.Has(source)
adds, updates, deletes := s.merge(source, change)
firstSet := !seenBefore && s.sourcesSeen.Has(source)

// deliver update notifications
switch s.mode {
case PodConfigNotificationIncremental:
if len(deletes.Pods) > 0 {
s.updates <- *deletes
}
if len(adds.Pods) > 0 {
if len(adds.Pods) > 0 || firstSet {
s.updates <- *adds
}
if len(updates.Pods) > 0 {
s.updates <- *updates
}

case PodConfigNotificationSnapshotAndUpdates:
if len(deletes.Pods) > 0 || len(adds.Pods) > 0 || firstSet {
s.updates <- kubelet.PodUpdate{Pods: s.MergedState().([]*api.Pod), Op: kubelet.SET, Source: source}
}
if len(updates.Pods) > 0 {
s.updates <- *updates
}
if len(deletes.Pods) > 0 || len(adds.Pods) > 0 {
s.updates <- kubelet.PodUpdate{Pods: s.MergedState().([]*api.Pod), Op: kubelet.SET, Source: source}
}

case PodConfigNotificationSnapshot:
if len(updates.Pods) > 0 || len(deletes.Pods) > 0 || len(adds.Pods) > 0 {
if len(updates.Pods) > 0 || len(deletes.Pods) > 0 || len(adds.Pods) > 0 || firstSet {
s.updates <- kubelet.PodUpdate{Pods: s.MergedState().([]*api.Pod), Op: kubelet.SET, Source: source}
}

Expand Down
25 changes: 25 additions & 0 deletions pkg/kubelet/config/config_test.go
Expand Up @@ -267,6 +267,31 @@ func TestNewPodAddedUpdatedSet(t *testing.T) {
CreatePodUpdate(kubelet.UPDATE, TestSource, pod))
}

func TestInitialEmptySet(t *testing.T) {
for _, test := range []struct {
mode PodConfigNotificationMode
op kubelet.PodOperation
}{
{PodConfigNotificationIncremental, kubelet.ADD},
{PodConfigNotificationSnapshot, kubelet.SET},
{PodConfigNotificationSnapshotAndUpdates, kubelet.SET},
} {
channel, ch, _ := createPodConfigTester(test.mode)

// should register an empty PodUpdate operation
podUpdate := CreatePodUpdate(kubelet.SET, TestSource)
channel <- podUpdate
expectPodUpdate(t, ch, CreatePodUpdate(test.op, TestSource))

// should ignore following empty sets
podUpdate = CreatePodUpdate(kubelet.SET, TestSource)
channel <- podUpdate
podUpdate = CreatePodUpdate(kubelet.ADD, TestSource, CreateValidPod("foo", "new"))
channel <- podUpdate
expectPodUpdate(t, ch, CreatePodUpdate(test.op, TestSource, CreateValidPod("foo", "new")))
}
}

func TestPodUpdateAnnotations(t *testing.T) {
channel, ch, _ := createPodConfigTester(PodConfigNotificationIncremental)

Expand Down