Skip to content

Commit

Permalink
feature: enable stop build buttons (#5515)
Browse files Browse the repository at this point in the history
  • Loading branch information
landism authored Feb 18, 2022
1 parent f5e2ef5 commit e541309
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 66 deletions.
4 changes: 0 additions & 4 deletions internal/controllers/core/tiltfile/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,10 +346,6 @@ func toToggleButtons(tlr *tiltfile.TiltfileLoadResult, disableSources disableSou

func toCancelButtons(tlr *tiltfile.TiltfileLoadResult) apiset.TypedObjectSet {
result := apiset.TypedObjectSet{}
if !tlr.FeatureFlags[feature.CancelBuild] {
return result
}

for _, m := range tlr.Manifests {
button := uibutton.StopBuildButton(m.Name.String())
result[button.Name] = button
Expand Down
2 changes: 0 additions & 2 deletions internal/engine/buildcontroller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1617,7 +1617,6 @@ func TestCancelButton(t *testing.T) {
f.b.completeBuildsManually = true
f.useRealTiltfileLoader()
f.WriteFile("Tiltfile", `
enable_feature('cancel_build')
local_resource('local', 'sleep 10000')
`)
f.loadAndStart()
Expand Down Expand Up @@ -1645,7 +1644,6 @@ func TestCancelButtonClickedBeforeBuild(t *testing.T) {
f.b.completeBuildsManually = true
f.useRealTiltfileLoader()
f.WriteFile("Tiltfile", `
enable_feature('cancel_build')
local_resource('local', 'sleep 10000')
`)
// grab a timestamp now to represent clicking the button before the build started
Expand Down
31 changes: 5 additions & 26 deletions internal/engine/configs/configs_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import (

"github.com/tilt-dev/tilt/internal/controllers/apis/tiltfile"
"github.com/tilt-dev/tilt/internal/controllers/apis/uibutton"
"github.com/tilt-dev/tilt/internal/feature"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/pkg/model"
)

type ConfigsController struct {
ctrlClient ctrlclient.Client
isInitialTiltfileCreated bool
isInitialTiltfileCancelButtonCreated bool
ctrlClient ctrlclient.Client
isInitialTiltfileCreated bool
}

func NewConfigsController(ctrlClient ctrlclient.Client) *ConfigsController {
Expand All @@ -36,12 +34,7 @@ func (cc *ConfigsController) OnChange(ctx context.Context, st store.RStore, summ
return err
}
}
if !cc.isInitialTiltfileCancelButtonCreated {
err := cc.maybeCreateInitialTiltfileCancelButton(ctx, st)
if err != nil {
return err
}
}

return nil
}

Expand All @@ -56,25 +49,11 @@ func (cc *ConfigsController) maybeCreateInitialTiltfile(ctx context.Context, st
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}

cc.isInitialTiltfileCreated = true
return nil
}

func (cc *ConfigsController) maybeCreateInitialTiltfileCancelButton(ctx context.Context, st store.RStore) error {
state := st.RLockState()
// TODO(matt) - once we enable the feature and remove the flag, just merge this into maybeCreateInitialTiltfile
cancelEnabled := state.Features[feature.CancelBuild]
st.RUnlockState()
if !cancelEnabled {
return nil
}
err := cc.ctrlClient.Create(ctx, uibutton.StopBuildButton(model.MainTiltfileManifestName.String()))
err = cc.ctrlClient.Create(ctx, uibutton.StopBuildButton(model.MainTiltfileManifestName.String()))
if err != nil && !apierrors.IsAlreadyExists(err) {
return err
}

cc.isInitialTiltfileCancelButtonCreated = true

cc.isInitialTiltfileCreated = true
return nil
}
28 changes: 0 additions & 28 deletions internal/engine/configs/configs_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/tilt-dev/tilt/internal/controllers/apis/tiltfile"
"github.com/tilt-dev/tilt/internal/controllers/apis/uibutton"
"github.com/tilt-dev/tilt/internal/controllers/fake"
"github.com/tilt-dev/tilt/internal/feature"
"github.com/tilt-dev/tilt/internal/store"
"github.com/tilt-dev/tilt/pkg/apis/core/v1alpha1"
"github.com/tilt-dev/tilt/pkg/model"
Expand All @@ -28,33 +27,6 @@ func TestCreateTiltfile(t *testing.T) {
cc := NewConfigsController(client)
require.NoError(t, cc.OnChange(ctx, st, store.ChangeSummary{}))

var tf v1alpha1.Tiltfile
require.NoError(t, client.Get(ctx, types.NamespacedName{Name: model.MainTiltfileManifestName.String()}, &tf))
assert.Equal(t, tf.Spec, v1alpha1.TiltfileSpec{
Path: tiltfile.ResolveFilename("fake-tiltfile-path"),
Args: []string{"arg1", "arg2"},
RestartOn: &v1alpha1.RestartOnSpec{
FileWatches: []string{"configs:(Tiltfile)"},
},
StopOn: &v1alpha1.StopOnSpec{
UIButtons: []string{uibutton.StopBuildButtonName("(Tiltfile)")},
},
})
}

// TODO(matt) - replace TestCreateTiltfile above with this when removing feature.CancelBuild
func TestCreateTiltfileCancelEnabled(t *testing.T) {
st := store.NewTestingStore()
st.WithState(func(s *store.EngineState) {
s.DesiredTiltfilePath = "./fake-tiltfile-path"
s.UserConfigState = model.NewUserConfigState([]string{"arg1", "arg2"})
s.Features = map[string]bool{feature.CancelBuild: true}
})
ctx := context.Background()
client := fake.NewFakeTiltClient()
cc := NewConfigsController(client)
require.NoError(t, cc.OnChange(ctx, st, store.ChangeSummary{}))

var tf v1alpha1.Tiltfile
require.NoError(t, client.Get(ctx, types.NamespacedName{Name: model.MainTiltfileManifestName.String()}, &tf))
expectedTfSpec := v1alpha1.TiltfileSpec{
Expand Down
6 changes: 0 additions & 6 deletions internal/feature/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ const Labels = "labels"
const LiveUpdateV2 = "live_update_v2"
const DisableResources = "disable_resources"
const BulkDisableResources = "bulk_disable_resources"
const CancelBuild = "cancel_build"

// The Value a flag can have. Status should never be changed.
type Value struct {
Expand Down Expand Up @@ -79,11 +78,6 @@ var MainDefaults = Defaults{
Enabled: false,
Status: Obsolete,
},
// TODO(matt) - remove once the frontend styling is in place
CancelBuild: Value{
Enabled: false,
Status: Active,
},
}

// FeatureSet is a mutable set of Features.
Expand Down

0 comments on commit e541309

Please sign in to comment.