Skip to content

Commit

Permalink
Revert "engine/integration: remove k8s events feature flag (#1708)" (#…
Browse files Browse the repository at this point in the history
…1745)

This reverts commit ba7f5ef.
  • Loading branch information
landism authored Jun 13, 2019
1 parent 2667f95 commit 496687c
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 15 deletions.
1 change: 1 addition & 0 deletions integration/k8s_fixture_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ func (f *k8sFixture) setupNewKubeConfig() {

f.tempDir.WriteFile("config", string(current))
f.fixture.tiltEnviron["KUBECONFIG"] = f.tempDir.JoinPath("config")
f.fixture.tiltEnviron["TILT_K8S_EVENTS"] = "true"
f.usingOverriddenConfig = true
}

Expand Down
4 changes: 4 additions & 0 deletions internal/engine/event_watch_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ func NewEventWatchManager(kClient k8s.Client) *EventWatchManager {
}

func (m *EventWatchManager) needsWatch(st store.RStore) bool {
if !k8sEventsFeatureFlagOn() {
return false
}

state := st.RLockState()
defer st.RUnlockState()

Expand Down
20 changes: 15 additions & 5 deletions internal/engine/event_watch_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package engine
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand Down Expand Up @@ -72,6 +73,10 @@ type ewmFixture struct {
cancel func()
store *store.Store
getActions func() []store.Action

// old value of k8sEventsFeatureFlag env var, for teardown
// TODO(maia): remove this when we remove the feature flag
oldFeatureFlagVal string
}

func newEWMFixture(t *testing.T) *ewmFixture {
Expand All @@ -81,13 +86,16 @@ func newEWMFixture(t *testing.T) *ewmFixture {
ctx, cancel := context.WithCancel(ctx)

ret := &ewmFixture{
kClient: kClient,
ewm: NewEventWatchManager(kClient),
ctx: ctx,
cancel: cancel,
t: t,
kClient: kClient,
ewm: NewEventWatchManager(kClient),
ctx: ctx,
cancel: cancel,
t: t,
oldFeatureFlagVal: os.Getenv(k8sEventsFeatureFlag),
}

os.Setenv(k8sEventsFeatureFlag, "true")

ret.store, ret.getActions = store.NewStoreForTesting()
go ret.store.Loop(ctx)

Expand All @@ -96,6 +104,8 @@ func newEWMFixture(t *testing.T) *ewmFixture {

func (f *ewmFixture) TearDown() {
f.kClient.TearDown()

_ = os.Setenv(k8sEventsFeatureFlag, f.oldFeatureFlagVal)
f.cancel()
}

Expand Down
12 changes: 12 additions & 0 deletions internal/engine/k8s_events_feature.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package engine

import "os"

// TODO(maia): remove this when feature is merged

const k8sEventsFeatureFlag = "TILT_K8S_EVENTS"

// TEMPORARY: check env to see if feature flag is set
func k8sEventsFeatureFlagOn() bool {
return os.Getenv(k8sEventsFeatureFlag) != ""
}
4 changes: 4 additions & 0 deletions internal/engine/uid_map_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ func NewUIDMapManager(kCli k8s.Client) *UIDMapManager {
}

func (m *UIDMapManager) needsWatch(st store.RStore) bool {
if !k8sEventsFeatureFlagOn() {
return false
}

state := st.RLockState()
defer st.RUnlockState()

Expand Down
19 changes: 14 additions & 5 deletions internal/engine/uid_map_manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package engine
import (
"context"
"fmt"
"os"
"testing"
"time"

Expand Down Expand Up @@ -173,6 +174,10 @@ type ummFixture struct {
cancel func()
store *store.Store
getActions func() []store.Action

// old value of k8sEventsFeatureFlag env var, for teardown
// TODO(maia): remove this when we remove the feature flag
oldFeatureFlagVal string
}

func newUMMFixture(t *testing.T) *ummFixture {
Expand All @@ -182,13 +187,16 @@ func newUMMFixture(t *testing.T) *ummFixture {
ctx, cancel := context.WithCancel(ctx)

ret := &ummFixture{
kClient: kClient,
umm: NewUIDMapManager(kClient),
ctx: ctx,
cancel: cancel,
t: t,
kClient: kClient,
umm: NewUIDMapManager(kClient),
ctx: ctx,
cancel: cancel,
t: t,
oldFeatureFlagVal: os.Getenv(k8sEventsFeatureFlag),
}

os.Setenv(k8sEventsFeatureFlag, "true")

ret.store, ret.getActions = store.NewStoreForTesting()
go ret.store.Loop(ctx)

Expand All @@ -197,6 +205,7 @@ func newUMMFixture(t *testing.T) *ummFixture {

func (f *ummFixture) TearDown() {
f.kClient.TearDown()
_ = os.Setenv(k8sEventsFeatureFlag, f.oldFeatureFlagVal)
f.cancel()
}

Expand Down
28 changes: 23 additions & 5 deletions internal/engine/upper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1787,7 +1787,7 @@ func TestUpper_PodLogs(t *testing.T) {
}

func TestK8sEventGlobalLogAndManifestLog(t *testing.T) {
f := newTestFixture(t)
f := newTestFixture(t).EnableK8sEvents()
defer f.TearDown()

entityUID := "someEntity"
Expand Down Expand Up @@ -1845,7 +1845,7 @@ func TestK8sEventGlobalLogAndManifestLog(t *testing.T) {
}

func TestK8sEventNotLoggedIfNoManifestForUID(t *testing.T) {
f := newTestFixture(t)
f := newTestFixture(t).EnableK8sEvents()
defer f.TearDown()

entityUID := "someEntity"
Expand All @@ -1872,7 +1872,7 @@ func TestK8sEventNotLoggedIfNoManifestForUID(t *testing.T) {
}

func TestK8sEventDoNotLogNormalEvents(t *testing.T) {
f := newTestFixture(t)
f := newTestFixture(t).EnableK8sEvents()
defer f.TearDown()

entityUID := "someEntity"
Expand Down Expand Up @@ -1916,7 +1916,7 @@ func TestK8sEventDoNotLogNormalEvents(t *testing.T) {
}

func TestK8sEventLogTimestamp(t *testing.T) {
f := newTestFixture(t)
f := newTestFixture(t).EnableK8sEvents()
defer f.TearDown()

st := f.store.LockMutableStateForTesting()
Expand Down Expand Up @@ -1970,7 +1970,7 @@ func TestK8sEventLogTimestamp(t *testing.T) {
}

func TestUIDMapDeleteUID(t *testing.T) {
f := newTestFixture(t)
f := newTestFixture(t).EnableK8sEvents()
defer f.TearDown()

st := f.store.LockMutableStateForTesting()
Expand Down Expand Up @@ -2579,6 +2579,11 @@ type testFixture struct {
opter *testOpter
tiltVersionCheckDelay time.Duration

// old value of k8sEventsFeatureFlag env var, for teardown
// if nil, no reset needed.
// TODO(maia): rm when we unflag this
oldK8sEventsFeatureFlagVal *string

onchangeCh chan bool
}

Expand Down Expand Up @@ -2676,6 +2681,15 @@ func newTestFixture(t *testing.T) *testFixture {
return ret
}

func (f *testFixture) EnableK8sEvents() *testFixture {
oldVal := os.Getenv(k8sEventsFeatureFlag)
f.oldK8sEventsFeatureFlagVal = &oldVal

_ = os.Setenv(k8sEventsFeatureFlag, "true")

return f
}

func (f *testFixture) Start(manifests []model.Manifest, watchFiles bool, initOptions ...initOption) {
f.startWithInitManifests(nil, manifests, watchFiles, initOptions...)
}
Expand Down Expand Up @@ -2958,6 +2972,10 @@ func (f *testFixture) TearDown() {
close(f.fsWatcher.events)
close(f.fsWatcher.errors)

if f.oldK8sEventsFeatureFlagVal != nil {
_ = os.Setenv(k8sEventsFeatureFlag, *f.oldK8sEventsFeatureFlagVal)
}

f.cancel()
}

Expand Down

0 comments on commit 496687c

Please sign in to comment.