Skip to content

Commit

Permalink
k8s: use shared clusterid for determining the current cluster (#5609)
Browse files Browse the repository at this point in the history
this is mostly just search-and-replace
  • Loading branch information
nicks authored Mar 23, 2022
1 parent 52071d1 commit 296ab00
Show file tree
Hide file tree
Showing 40 changed files with 752 additions and 535 deletions.
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ require (
github.com/spf13/cobra v1.3.0
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.7.0
github.com/tilt-dev/clusterid v0.1.2
github.com/tilt-dev/dockerignore v0.1.1
github.com/tilt-dev/fsevents v0.0.0-20200515134857-2efe37af20de
github.com/tilt-dev/fsnotify v1.4.8-0.20210701141043-dd524499d3fe
Expand Down Expand Up @@ -72,7 +73,7 @@ require (
gopkg.in/yaml.v2 v2.4.0
helm.sh/helm/v3 v3.6.2
k8s.io/api v0.23.0
k8s.io/apimachinery v0.23.0
k8s.io/apimachinery v0.23.5
k8s.io/apiserver v0.23.0
k8s.io/cli-runtime v0.23.0
k8s.io/client-go v0.23.0
Expand Down Expand Up @@ -234,7 +235,7 @@ require (
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.25 // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/kustomize/kyaml v0.13.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)

replace (
Expand Down
5 changes: 4 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1576,6 +1576,8 @@ github.com/tilt-dev/apiserver v0.23.0-tilt-20220118 h1:WRYE20MS3RsKiWlkBdRkOiGLo
github.com/tilt-dev/apiserver v0.23.0-tilt-20220118/go.mod h1:Cec35u/9zAepDPPFyT+UMrgqOCjgJ5qtfVJDxjZYmt4=
github.com/tilt-dev/browser v0.0.1 h1:e+mFToX6A7pkMlGFrXW5VLvS7qS0HVbcXqmR0uPrWUA=
github.com/tilt-dev/browser v0.0.1/go.mod h1:2DaMt8P8xEqDFzxaAbraOig5iUmQdd1wtO1Tb6tODHA=
github.com/tilt-dev/clusterid v0.1.2 h1:ch+qLP6y3n6KvuIyovSa030hJuWJ//G8gXqvouxpRSc=
github.com/tilt-dev/clusterid v0.1.2/go.mod h1:QeDTv8HzwdCk6P1WzQXA+wpPSYAniAWipqbTLEF9ets=
github.com/tilt-dev/dockerignore v0.1.1 h1:/MPYqcD8qMCMyh3yiHuQdzbMQi9NL4vVopo6/9D/XvE=
github.com/tilt-dev/dockerignore v0.1.1/go.mod h1:2ooUDj8B9FNWYvHadA4EKG0JDaeAOjiq5P+mvEzS2eY=
github.com/tilt-dev/fsevents v0.0.0-20200515134857-2efe37af20de h1:tG+nJMUUxV7MJm/MeU1Mw7rvmwN9GWyHMMg+wtf9HS4=
Expand Down Expand Up @@ -2612,8 +2614,9 @@ sigs.k8s.io/structured-merge-diff v0.0.0-20190525122527-15d366b2352e/go.mod h1:w
sigs.k8s.io/structured-merge-diff/v4 v4.0.2/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.1.0/go.mod h1:bJZC9H9iH24zzfZ/41RGcq60oK1F7G282QMXDPYydCw=
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 h1:kDvPBbnPk+qYmkHmSo8vKGp438IASWofnbbUKDE/bv0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.0/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 h1:bKCqE9GvQ5tiVHn5rfn1r+yao3aLQEaLzkkmAkf+A6Y=
sigs.k8s.io/structured-merge-diff/v4 v4.2.1/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
sigs.k8s.io/yaml v1.3.0 h1:a2VclLzOGrwOHDiV8EfBGhvjHvP46CtW5j6POvhYGGo=
Expand Down
3 changes: 2 additions & 1 deletion internal/build/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/container"
"github.com/stretchr/testify/assert"

"github.com/tilt-dev/clusterid"
wmcontainer "github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/docker"
"github.com/tilt-dev/tilt/internal/dockerfile"
Expand Down Expand Up @@ -46,7 +47,7 @@ func (c fakeClock) Now() time.Time { return c.now }

func newDockerBuildFixture(t testing.TB) *dockerBuildFixture {
ctx, _, _ := testutils.CtxAndAnalyticsForTest()
env := k8s.EnvGKE
env := clusterid.ProductGKE

dEnv := docker.ProvideClusterEnv(ctx, "gke", env, wmcontainer.RuntimeDocker, k8s.FakeMinikube{})
dCli := docker.NewDockerClient(ctx, docker.Env(dEnv))
Expand Down
5 changes: 3 additions & 2 deletions internal/cli/wire.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"context"
"time"

"github.com/tilt-dev/clusterid"
cliclient "github.com/tilt-dev/tilt/internal/cli/client"
"github.com/tilt-dev/tilt/internal/controllers/core/filewatch/fsevent"

Expand Down Expand Up @@ -62,7 +63,7 @@ import (
)

var K8sWireSet = wire.NewSet(
k8s.ProvideEnv,
k8s.ProvideClusterProduct,
k8s.ProvideClusterName,
k8s.ProvideKubeContext,
k8s.ProvideKubeConfig,
Expand Down Expand Up @@ -238,7 +239,7 @@ func wireKubeConfig(ctx context.Context) (*api.Config, error) {
return nil, nil
}

func wireEnv(ctx context.Context) (k8s.Env, error) {
func wireEnv(ctx context.Context) (clusterid.Product, error) {
wire.Build(K8sWireSet)
return "", nil
}
Expand Down
31 changes: 16 additions & 15 deletions internal/cli/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion internal/controllers/core/cluster/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func KubernetesClientFromEnv(ctx context.Context, contextOverride k8s.KubeContex
if err != nil {
return nil, err
}
env := k8s.ProvideEnv(ctx, apiConfig)
env := k8s.ProvideClusterProduct(ctx, apiConfig)
restConfigOrError := k8s.ProvideRESTConfig(clientConfig)

clientsetOrError := k8s.ProvideClientset(restConfigOrError)
Expand Down
3 changes: 2 additions & 1 deletion internal/docker/client_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@ import (
"github.com/docker/distribution/reference"
"github.com/stretchr/testify/require"

"github.com/tilt-dev/clusterid"
wmcontainer "github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/k8s"
"github.com/tilt-dev/tilt/internal/testutils"
)

func TestCli_Run(t *testing.T) {
ctx, _, _ := testutils.CtxAndAnalyticsForTest()
dEnv := ProvideClusterEnv(ctx, "gke", k8s.EnvGKE, wmcontainer.RuntimeDocker, k8s.FakeMinikube{})
dEnv := ProvideClusterEnv(ctx, "gke", clusterid.ProductGKE, wmcontainer.RuntimeDocker, k8s.FakeMinikube{})
cli := NewDockerClient(ctx, Env(dEnv))
defer func() {
// release any idle connections to avoid out of file errors if running test many times
Expand Down
23 changes: 12 additions & 11 deletions internal/docker/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/docker/docker/api/types"
"github.com/stretchr/testify/assert"

"github.com/tilt-dev/clusterid"
"github.com/tilt-dev/tilt/internal/container"
"github.com/tilt-dev/tilt/internal/k8s"
)
Expand Down Expand Up @@ -91,7 +92,7 @@ func TestSupported(t *testing.T) {
}

type provideEnvTestCase struct {
env k8s.Env
env clusterid.Product
runtime container.Runtime
minikubeV string
osEnv map[string]string
Expand All @@ -100,7 +101,7 @@ type provideEnvTestCase struct {
expectedLocal Env
}

func TestProvideEnv(t *testing.T) {
func TestProvideClusterProduct(t *testing.T) {
envVars := []string{
"DOCKER_TLS_VERIFY",
"DOCKER_HOST",
Expand All @@ -111,7 +112,7 @@ func TestProvideEnv(t *testing.T) {
cases := []provideEnvTestCase{
{},
{
env: k8s.EnvUnknown,
env: clusterid.ProductUnknown,
osEnv: map[string]string{
"DOCKER_TLS_VERIFY": "1",
"DOCKER_HOST": "tcp://192.168.99.100:2376",
Expand All @@ -132,7 +133,7 @@ func TestProvideEnv(t *testing.T) {
},
},
{
env: k8s.EnvMicroK8s,
env: clusterid.ProductMicroK8s,
runtime: container.RuntimeDocker,
expectedCluster: Env{
Host: microK8sDockerHost,
Expand All @@ -141,11 +142,11 @@ func TestProvideEnv(t *testing.T) {
expectedLocal: Env{},
},
{
env: k8s.EnvMicroK8s,
env: clusterid.ProductMicroK8s,
runtime: container.RuntimeCrio,
},
{
env: k8s.EnvMinikube,
env: clusterid.ProductMinikube,
runtime: container.RuntimeDocker,
mkEnv: map[string]string{
"DOCKER_TLS_VERIFY": "1",
Expand All @@ -163,7 +164,7 @@ func TestProvideEnv(t *testing.T) {
},
},
{
env: k8s.EnvMinikube,
env: clusterid.ProductMinikube,
runtime: container.RuntimeDocker,
minikubeV: "1.8.2",
mkEnv: map[string]string{
Expand All @@ -181,7 +182,7 @@ func TestProvideEnv(t *testing.T) {
},
},
{
env: k8s.EnvMinikube,
env: clusterid.ProductMinikube,
runtime: container.RuntimeDocker,
mkEnv: map[string]string{
"DOCKER_TLS_VERIFY": "1",
Expand All @@ -202,7 +203,7 @@ func TestProvideEnv(t *testing.T) {
{
// Test the case where the user has already run
// eval $(minikube docker-env)
env: k8s.EnvMinikube,
env: clusterid.ProductMinikube,
runtime: container.RuntimeDocker,
mkEnv: map[string]string{
"DOCKER_TLS_VERIFY": "1",
Expand Down Expand Up @@ -230,7 +231,7 @@ func TestProvideEnv(t *testing.T) {
},
},
{
env: k8s.EnvMinikube,
env: clusterid.ProductMinikube,
runtime: container.RuntimeCrio,
mkEnv: map[string]string{
"DOCKER_TLS_VERIFY": "1",
Expand All @@ -240,7 +241,7 @@ func TestProvideEnv(t *testing.T) {
},
},
{
env: k8s.EnvUnknown,
env: clusterid.ProductUnknown,
osEnv: map[string]string{
"DOCKER_TLS_VERIFY": "1",
"DOCKER_HOST": "localhost:2376",
Expand Down
Loading

0 comments on commit 296ab00

Please sign in to comment.