kubernetes-sigs / cluster-api

Home for Cluster API, a subproject of sig-cluster-lifecycle
https://cluster-api.sigs.k8s.io
Apache License 2.0
3.57k stars 1.31k forks source link

Add support for multiple Tilt providers in tilt-provider.json #3299

Closed h0tbird closed 4 years ago

h0tbird commented 4 years ago

User Story

As a developer I want to be able to define multiple Tilt providers per repository. This is useful for developing CAPI providers that include multiple operators (main.go).

Detailed Description

Let’s say I am working on a new CAPA operator/controller in bootstrap/eks. My tilt-provider.json might look like this:

cat tilt-provider.json
{
  "items": [
    {
      "name": "aws",
      "config": {
        "context": "",
        "image": "gcr.io/k8s-staging-cluster-api-aws/cluster-api-aws-controller",
        "live_reload_deps": [
          "main.go",
          "go.mod",
          "go.sum",
          "api",
          "cmd",
          "controllers",
          "pkg"
        ]
      }
    },
    {
      "name": "eks-bootstrap",
      "config": {
        "context": "bootstrap/eks",
        "image": "gcr.io/k8s-staging-cluster-api-aws/eks-bootstrap-controller",
        "live_reload_deps": [
          "main.go",
          "go.mod",
          "go.sum",
          "api",
          "controllers"
        ]
      }
    }
  ]
}

Anything else you would like to add:

FWIW I have this hack right now but it has two bugs, see the TODO comments:

git diff
diff --git a/Tiltfile b/Tiltfile
index 89a8f23cf..82bedbff0 100644
--- a/Tiltfile
+++ b/Tiltfile
@@ -103,10 +103,11 @@ def load_provider_tiltfiles():
     for repo in provider_repos:
         file = repo + "/tilt-provider.json"
         provider_details = read_json(file, default = {})
-        provider_name = provider_details["name"]
-        provider_config = provider_details["config"]
-        provider_config["context"] = repo
-        providers[provider_name] = provider_config
+        for item in provider_details["items"]: # TODO: Make it backward compatible.
+            provider_name = item["name"]
+            provider_config = item["config"]
+            provider_config["context"] = repo + "/" + provider_config["context"] # TODO: context might not be defined
+            providers[provider_name] = provider_config

 tilt_helper_dockerfile_header = """
 # Tilt image

/kind feature

ncdc commented 4 years ago

Another option for the format would be to use a JSON list for the document, providing backward compatibility with the contents being a map (i.e. single entry). That only works if there's a way in the Tiltfile/Starlark to check if provider_details is an array vs a map.

vincepri commented 4 years ago

/milestone v0.3.x

CecileRobertMichon commented 4 years ago

/help

k8s-ci-robot commented 4 years ago

@CecileRobertMichon: This request has been marked as needing help from a contributor.

Please ensure the request meets the requirements listed here.

If this request no longer meets these requirements, the label can be removed by commenting with the /remove-help command.

In response to [this](https://github.com/kubernetes-sigs/cluster-api/issues/3299): >/help Instructions for interacting with me using PR comments are available [here](https://git.k8s.io/community/contributors/guide/pull-requests.md). If you have questions or suggestions related to my behavior, please file an issue against the [kubernetes/test-infra](https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:) repository.
vincepri commented 4 years ago

/priority important-soon

h0tbird commented 4 years ago

Thank you @ncdc. I have implemented a solution which I think is backwards compatible.

fabriziopandini commented 4 years ago

/lifecycle active /assign @h0tbird