Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor proxy injection to use Helm charts #3195

Closed
wants to merge 4 commits into from

Conversation

alpeb
Copy link
Member

@alpeb alpeb commented Aug 5, 2019

Fixes #3128

New patch chart

A new chart /charts/patch was created, that generates the JSON patch
payload that is to be returned to the k8s API when doing the injection
through the proxy injector, and it's also leveraged by the linkerd inject --manual CLI.

Virtual File System changes

The VFS was used by linkerd install to access the old chart under
/chart. Now the proxy injection also uses the Helm charts to generate
the JSON patch (see above) so we've moved the VFS from cli/static to a
new common place under /pkg/charts/static, and the new root for the VFS is
now /charts.

linkerd install hasn't yet migrated to use the new charts (that'll
happen in #3127), so the only change in that regard was the creation of
/charts/chart which is a symlink pointing to /chart that
install.go now uses, so that the VFS contains both the old and new
charts, as a temporary measure.

You can see that /bin/Dockerfile-bin, /controller/Dockerfile and
/bin/build-cli-bin do now go generate pointing to the new location
(and the go generate annotation was moved from /cli/main.go to
pkg/charts/static/templates.go).

The symlink trick doesn't work when building the binaries through
Docker, so /bin/Dockerfile-bin replaces the symlink with an actual
copy of /chart.

Also note that in /controller/Dockerfile we now need to include the
prod tag in go install like we do in /bin/Dockerfile-bin so that
the proxy injector does use the VFS instead of the local file system.

Other changes

  • The common logic to parse a chart has been moved from install.go to
    /pkg/charts/util.go.
  • The special ENV var in the proxy for "outbound router capacity" that
    only applies to the Prometheus pod is now handled directly in the proxy
    partial and all the associated go code could be removed.
  • The patch.go lib for generating the JSON patch in go along
    with its tests patch_test.go are no longer needed.
  • Lots of functions in /pkg/inject/inject.go got removed/simplified
    with their logic being moved into the charts themselves. As a
    consequence lots of things in inject_test.go became irrelevant.
  • Moved template-values.go from /pkg/inject to pkg/charts as that
    contains the go structs representation of the chart variables that
    will be leveraged in Refactor CLI Install Command To Work With 2.5 Helm Chart #3127.

Testing

Don't forget to run /bin/helm.sh whenever you make changes to charts
;-)

Fixes #3128

New `patch` chart
==================
A new chart `/charts/patch` was created, that generates the JSON patch
payload that is to be returned to the k8s API when doing the injection
through the proxy injector, and it's also leveraged by the `linkerd
inject --manual` CLI.

Virtual File System changes
===========================
The VFS was used by `linkerd install` to access the old chart under
`/chart`. Now the proxy injection also uses the Helm charts to generate
the JSON patch (see above) so we've moved the VFS from `cli/static` to a
new common place under `/pkg/charts/static`, and the new root for the VFS is
now `/charts`.

`linkerd install` hasn't yet migrated to use the new charts (that'll
happen in #3127), so the only change in that regard was the creation of
`/charts/chart` which is a symlink pointing to `/chart` that
`install.go` now uses, so that the VFS contains both the old and new
charts, as a temporary measure.

You can see that `/bin/Dockerfile-bin`, `/controller/Dockerfile` and
`/bin/build-cli-bin` do now `go generate` pointing to the new location
(and the `go generate` annotation was moved from `/cli/main.go` to
`pkg/charts/static/templates.go`).

The symlink trick doesn't work when building the binaries through
Docker, so `/bin/Dockerfile-bin` replaces the symlink with an actual
copy of `/chart`.

Also note that in `/controller/Dockerfile` we now need to include the
`prod` tag in `go install` like we do in `/bin/Dockerfile-bin` so that
the proxy injector does use the VFS instead of the local file system.

Other changes
===============
- The common logic to parse a chart has been moved from `install.go` to
`/pkg/charts/util.go`.
- The special ENV var in the proxy for "outbound router capacity" that
only applies to the Prometheus pod is now handled directly in the proxy
partial and all the associated go code could be removed.
- The `patch.go` lib for generating the JSON patch in go along
with its tests `patch_test.go` are no longer needed.
- Lots of functions in `/pkg/inject/inject.go` got removed/simplified
with their logic being moved into the charts themselves. As a
consequence lots of things in `inject_test.go` became irrelevant.
- Moved `template-values.go` from `/pkg/inject` to `pkg/charts` as that
contains the go structs representation of the chart variables that
will be leveraged in #3127.

Testing
=========
Don't forget to run `/bin/helm.sh` whenever you make changes to charts
;-)

Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
// Skip outbound port 443 to enable Kubernetes API access without the proxy.
// Once Kubernetes supports sidecar containers, this may be removed, as that
// will guarantee the proxy is running prior to control-plane startup.
configs.Proxy.IgnoreOutboundPorts = append(configs.Proxy.IgnoreOutboundPorts, &pb.Port{Port: 443})
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now handled directly in the chart

identityAPIPort = 8080

envTapDisabled = "LINKERD2_PROXY_TAP_DISABLED"
envTapSvcName = "LINKERD2_PROXY_TAP_SVC_NAME"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All these consts are now in the charts

}{
{
filename: "pod-inject-empty.yaml",
ns: nsEnabled,
conf: confNsEnabled(),
expected: true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

expected is true in all the test cases, so I removed it.

@l5d-bot
Copy link
Collaborator

l5d-bot commented Aug 5, 2019

Integration test results for 8cf5b42: fail 😕
Log output: https://gist.github.com/e589a79b25ff8ab16b5eb39fb26ba421

Copy link
Member

@siggy siggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i'm going to dig into a more full review, but leaving this here for now as it was the first thing i encountered.

my quick remote build and install yielded an error message followed by a partial installation:

$ bin/docker-build # on a remote machine

$ bin/linkerd install | kubectl apply -f - # bin/go-run cli install yields the same issue
Error: open /patch/charts/partials-0.1.0.tgz: file does not exist
Usage:
  linkerd install [flags]
  linkerd install [command]
...
Use "linkerd install [command] --help" for more information about a command.

namespace/linkerd created
clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-identity created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-identity created
serviceaccount/linkerd-identity created
clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-controller created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-controller created
serviceaccount/linkerd-controller created
role.rbac.authorization.k8s.io/linkerd-heartbeat created
rolebinding.rbac.authorization.k8s.io/linkerd-heartbeat created
serviceaccount/linkerd-heartbeat created
serviceaccount/linkerd-web created
customresourcedefinition.apiextensions.k8s.io/serviceprofiles.linkerd.io created
customresourcedefinition.apiextensions.k8s.io/trafficsplits.split.smi-spec.io created
clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-prometheus created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-prometheus created
serviceaccount/linkerd-prometheus created
serviceaccount/linkerd-grafana created
clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-proxy-injector created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-proxy-injector created
serviceaccount/linkerd-proxy-injector created
secret/linkerd-proxy-injector-tls created
mutatingwebhookconfiguration.admissionregistration.k8s.io/linkerd-proxy-injector-webhook-config created
clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-sp-validator created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-sp-validator created
serviceaccount/linkerd-sp-validator created
secret/linkerd-sp-validator-tls created
validatingwebhookconfiguration.admissionregistration.k8s.io/linkerd-sp-validator-webhook-config created
clusterrole.rbac.authorization.k8s.io/linkerd-linkerd-tap created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-tap created
clusterrolebinding.rbac.authorization.k8s.io/linkerd-linkerd-tap-auth-delegator created
serviceaccount/linkerd-tap created
rolebinding.rbac.authorization.k8s.io/linkerd-linkerd-tap-auth-reader created
secret/linkerd-tap-tls created
apiservice.apiregistration.k8s.io/v1alpha1.tap.linkerd.io created
podsecuritypolicy.policy/linkerd-linkerd-control-plane created
role.rbac.authorization.k8s.io/linkerd-psp created
rolebinding.rbac.authorization.k8s.io/linkerd-psp created
configmap/linkerd-config created
secret/linkerd-identity-issuer created
service/linkerd-identity created

it looks like the install command errors out after outputting service/linkerd-identity:

$ bin/go-run cli install
...
kind: Service
apiVersion: v1
metadata:
  name: linkerd-identity
  namespace: linkerd
  labels:
    linkerd.io/control-plane-component: identity
    linkerd.io/control-plane-ns: linkerd
  annotations:
    linkerd.io/created-by: linkerd/cli git-8cf5b428
spec:
  type: ClusterIP
  selector:
    linkerd.io/control-plane-component: identity
  ports:
  - name: grpc
    port: 8080
    targetPort: 8080
---
Error: open /Users/sig/code/linkerd2/charts/patch/charts/partials-0.1.0.tgz: no such file or directory
Usage:
  linkerd install [flags]
  linkerd install [command]

avoid requiring the build environments to have `helm` installed.

Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
@alpeb
Copy link
Member Author

alpeb commented Aug 5, 2019

@siggy my last push fixes things so that dependencies are taken care of automatically without forcing the build environments to have helm to bring them up-to-date.

But in order to install linkerd through helm (helm install charts/linkerd2), given that doesn't go through our go code, people do need to run helm dep up charts/linkerd2 beforehand, for development. In prod that won't be necessary when the linkerd2 chart gets published in the official repo, and people would be able to just issue helm install stable/linkerd2.

@l5d-bot
Copy link
Collaborator

l5d-bot commented Aug 5, 2019

Integration test results for 41c64f1: fail 😕
Log output: https://gist.github.com/e862d4e7b82b26e38885c927f3a5c886

Copy link
Member

@siggy siggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! mostly nits and questions. 🚢 👍

mind adding a section to BUILD.md and/or TEST.md around when to use commands like bin/helm.sh and helm dep up charts/linkerd2? maybe documenting the typical dev flow of modifying templates and testing a helm install command?

cli/cmd/testdata/install_output.golden Show resolved Hide resolved
pkg/charts/util.go Outdated Show resolved Hide resolved
pkg/charts/util.go Outdated Show resolved Hide resolved
Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
@l5d-bot
Copy link
Collaborator

l5d-bot commented Aug 6, 2019

Integration test results for 4250749: fail 😕
Log output: https://gist.github.com/345af8f4d41b24d7a28764ae96b0a7c4

@alpeb
Copy link
Member Author

alpeb commented Aug 6, 2019

mind adding a section to BUILD.md and/or TEST.md around when to use commands like bin/helm.sh and helm dep up charts/linkerd2? maybe documenting the typical dev flow of modifying templates and testing a helm install command?

Thanks for the feedback! I've created #3199 in the Helm project to track Helm docs effort 👍

Copy link
Member

@siggy siggy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 🚢 :shipit:

Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
@ihcsim ihcsim closed this Aug 6, 2019
@ihcsim
Copy link
Contributor

ihcsim commented Aug 6, 2019

@alpeb Opppss... looks like GH deleted this branch after I merged #3146, because this branch is set to be merged into the other feature branch. Can you reopen this PR? (GH doesn't offer me the option to reopen this PR.)

@l5d-bot
Copy link
Collaborator

l5d-bot commented Aug 6, 2019

Integration test results for 921b2d9: fail 😕
Log output: https://gist.github.com/7cfe885c66201a3c7ddad4d94ddd6d9f

alpeb added a commit that referenced this pull request Aug 6, 2019
(This replaces #3195 that had some branch issues)

Fixes #3128

A new chart `/charts/patch` was created, that generates the JSON patch
payload that is to be returned to the k8s API when doing the injection
through the proxy injector, and it's also leveraged by the `linkerd
inject --manual` CLI.

The VFS was used by `linkerd install` to access the old chart under
`/chart`. Now the proxy injection also uses the Helm charts to generate
the JSON patch (see above) so we've moved the VFS from `cli/static` to a
new common place under `/pkg/charts/static`, and the new root for the VFS is
now `/charts`.

`linkerd install` hasn't yet migrated to use the new charts (that'll
happen in #3127), so the only change in that regard was the creation of
`/charts/chart` which is a symlink pointing to `/chart` that
`install.go` now uses, so that the VFS contains both the old and new
charts, as a temporary measure.

You can see that `/bin/Dockerfile-bin`, `/controller/Dockerfile` and
`/bin/build-cli-bin` do now `go generate` pointing to the new location
(and the `go generate` annotation was moved from `/cli/main.go` to
`pkg/charts/static/templates.go`).

The symlink trick doesn't work when building the binaries through
Docker, so `/bin/Dockerfile-bin` replaces the symlink with an actual
copy of `/chart`.

Also note that in `/controller/Dockerfile` we now need to include the
`prod` tag in `go install` like we do in `/bin/Dockerfile-bin` so that
the proxy injector does use the VFS instead of the local file system.

- The common logic to parse a chart has been moved from `install.go` to
`/pkg/charts/util.go`.
- The special ENV var in the proxy for "outbound router capacity" that
only applies to the Prometheus pod is now handled directly in the proxy
partial and all the associated go code could be removed.
- The `patch.go` lib for generating the JSON patch in go along
with its tests `patch_test.go` are no longer needed.
- Lots of functions in `/pkg/inject/inject.go` got removed/simplified
with their logic being moved into the charts themselves. As a
consequence lots of things in `inject_test.go` became irrelevant.
- Moved `template-values.go` from `/pkg/inject` to `pkg/charts` as that
contains the go structs representation of the chart variables that
will be leveraged in #3127.

Don't forget to run `/bin/helm.sh` whenever you make changes to charts
;-)

Signed-off-by: Alejandro Pedraza <alejandro@buoyant.io>
@alpeb
Copy link
Member Author

alpeb commented Aug 6, 2019

This PR has been replaced with #3200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants