Skip to content

Commit

Permalink
engine: fix a bug in cluster connection checks
Browse files Browse the repository at this point in the history
before this change, if you were deploying
to both a DockerCompose engine and a Kube
cluster, we sometimes wouldn't correctly
synchronize the cluster connections.

this led to problems where we would try
to deploy before the connection had been
established properly.

fixes #6453

Signed-off-by: Nick Santos <[email protected]>
  • Loading branch information
nicks committed Oct 30, 2024
1 parent af69f52 commit 68c1bf1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
9 changes: 7 additions & 2 deletions internal/engine/buildcontrol/build_control.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package buildcontrol

import (
"log"
"time"

v1 "k8s.io/api/core/v1"
Expand Down Expand Up @@ -85,7 +86,11 @@ func NextTargetToBuild(state store.EngineState) (*store.ManifestTarget, HoldSet)
unbuilt := FindTargetsNeedingInitialBuild(targets)

if len(unbuilt) > 0 {
return NextUnbuiltTargetToBuild(unbuilt), holds
result := NextUnbuiltTargetToBuild(unbuilt)
if result.Manifest.Name == "ahoy0" {
log.Printf("DEPLOY AHOY %s", result.Manifest.Name)
}
return result, holds
}

// Check to see if any targets are currently being successfully reconciled,
Expand Down Expand Up @@ -254,7 +259,7 @@ func HoldTargetsWaitingOnCluster(state store.EngineState, mts []*store.ManifestT
cluster, ok := state.Clusters[clusterName]
isClusterOK := ok && cluster.Status.Error == "" && cluster.Status.Arch != ""
if isClusterOK {
return
continue
}

gvk := v1alpha1.SchemeGroupVersion.WithKind("Cluster")
Expand Down
38 changes: 38 additions & 0 deletions internal/engine/buildcontrol/build_control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,31 @@ func TestK8sDependsOnCluster(t *testing.T) {
f.assertNextTargetToBuild("k8s1")
}

func TestK8sDependsOnCluster_TwoClusters(t *testing.T) {
f := newTestFixture(t)

f.st.Clusters["default"].Status.Error = "connection error"

_ = f.upsertK8sManifest("k8s1")
dc1 := f.upsertDCManifest("dc1")
f.assertNextTargetToBuild("dc1")
dc1.State.AddCompletedBuild(model.BuildRecord{
StartTime: time.Now(),
FinishTime: time.Now(),
})
f.assertNoTargetNextToBuild()

f.assertHoldOnRefs("k8s1", store.HoldReasonCluster, v1alpha1.UIResourceStateWaitingOnRef{
Group: "tilt.dev",
APIVersion: "v1alpha1",
Kind: "Cluster",
Name: "default",
})

f.st.Clusters["default"].Status.Error = ""
f.assertNextTargetToBuild("k8s1")
}

func TestCurrentlyBuildingLocalResourceDisablesK8sScheduling(t *testing.T) {
f := newTestFixture(t)

Expand Down Expand Up @@ -679,6 +704,11 @@ type testFixture struct {
func newTestFixture(t *testing.T) testFixture {
f := tempdir.NewTempDirFixture(t)
st := store.NewState()
st.Clusters["docker"] = &v1alpha1.Cluster{
Status: v1alpha1.ClusterStatus{
Arch: "amd64",
},
}
st.Clusters["default"] = &v1alpha1.Cluster{
Status: v1alpha1.ClusterStatus{
Arch: "amd64",
Expand Down Expand Up @@ -742,6 +772,14 @@ func (f *testFixture) upsertK8sManifest(name model.ManifestName, opts ...manifes
return f.upsertManifest(b.WithK8sYAML(testyaml.SanchoYAML).Build())
}

func (f *testFixture) upsertDCManifest(name model.ManifestName, opts ...manifestOption) *store.ManifestTarget {
b := manifestbuilder.New(f, name)
for _, o := range opts {
b = o(b)
}
return f.upsertManifest(b.WithDockerCompose().Build())
}

func (f *testFixture) upsertLocalManifest(name model.ManifestName, opts ...manifestOption) *store.ManifestTarget {
b := manifestbuilder.New(f, name)
for _, o := range opts {
Expand Down

0 comments on commit 68c1bf1

Please sign in to comment.