Skip to content
This repository has been archived by the owner on Apr 17, 2019. It is now read-only.

[nginx-ingress-controller] Refactoring of template handling #1498

Merged
merged 4 commits into from
Aug 26, 2016

Conversation

aledbf
Copy link
Contributor

@aledbf aledbf commented Aug 7, 2016

This also watch for changes in the template

fixes #1457


This change is Reviewable

watcher: watcher,
}

go func() {

Choose a reason for hiding this comment

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

I would vastly prefer if we did this in a compsable way. Perhaps we can have a sidecar that watches the config map, notices a change, and forces a reload on the nginx controller through a /reload http endpoint ? that would make for a nice reusable component.

$ watch-configmaps --reload-url="url-in-same-netns" --file="/path/to/file"

When we upgrade to docker1.12 we will get shared pid namespaces and can consider replacing the --reload-url arg with just pkill SIGHIUP nginx.

The most reusable way to do this right now would be to avoid even the http server, and do:

$ watch-configmaps --pod-name="foopod, defaults to self" \
    --container-name="nginx, defaults to first peer container in list of own pod" \
    --file="/path/to/file" \
    --script="/reload.sh"

That would kubectl exec in the give pod and exec the the signal to the given container/process. If you're interested you can download the kubectl client from:
wget https://storage.googleapis.com/kubernetes-release/release/${KUBERNETES_VERSION}/bin/linux/amd64/kubectl

Or exec through a REST client like we do in our e2es:
https://github.com/kubernetes/kubernetes/blob/4bb5fdc47f4c409f7d290b3af348fb135d0daf0f/test/e2e/framework/util.go#L3756

Quite a few people have asked for something like the last one. I would put this under ingress/ so it doesn't get lost when we split ingress out of contrib.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would vastly prefer if we did this in a composable way

Agree. I'll start working on this.

@aledbf
Copy link
Contributor Author

aledbf commented Aug 10, 2016

@bprashanth the last commit contains a sidecar that watch changes in a file or a kubernetes resource (configmap and secrets for now).
Writing the example I realized that this requires the use of volumes (at least emptyDir, copying the template before the start of the controller) to be able to watch the file located in a different container.

Is this change acceptable just to be able to use a sidecar and not add this code in the controller?

@k8s-github-robot
Copy link

@aledbf PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 17, 2016
@aledbf aledbf force-pushed the ref-templates branch 2 times, most recently from 5cc7cf7 to 77b87d0 Compare August 18, 2016 13:55
@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 18, 2016
@k8s-github-robot
Copy link

@aledbf PR needs rebase

@k8s-github-robot k8s-github-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 22, 2016
@aledbf aledbf changed the title WIP: [nginx-ingress-controller] Refactoring of template handling [nginx-ingress-controller] Refactoring of template handling Aug 22, 2016
@aledbf
Copy link
Contributor Author

aledbf commented Aug 22, 2016

@bprashanth ping

@k8s-github-robot k8s-github-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 22, 2016
name: watch-template
command:
- /watch-resource-cmdrunner
- --command="echo 'nginx template updated'"

Choose a reason for hiding this comment

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

don't you want to reload nginx when this happens?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Right. The correct content should be curl http://localhost:10254/reload-template

@bprashanth
Copy link

Suggest simplifying the pr to just watch configmaps mounted into 2 containers, and send a signal from the first to the second through kubeClient. Then write a good example that uses a configmap, modifies it , and has an nginx reload. We can iterate on growing that out as required.

@aledbf
Copy link
Contributor Author

aledbf commented Aug 22, 2016

Suggest simplifying the pr to just watch configmaps mounted into 2 containers, and send a signal from the first to the second through kubeClient.

Just in case if an user just upgrades the current version (without a volume) the controller behaves like now (no reload if the template changes)

Then write a good example that uses a configmap, modifies it , and has an nginx reload.

I think this https://gist.github.com/aledbf/e9e669657ab00ae2f8562e89e47c3cb1 is that example

@aledbf
Copy link
Contributor Author

aledbf commented Aug 25, 2016

Suggest simplifying the pr to just watch

done

Here is the important part

Basically I watch for the template file for changes. Is not important from where the file comes (emptyDir, another volume, configmap, etc).

@aledbf
Copy link
Contributor Author

aledbf commented Aug 25, 2016

This is an example of the change

kubectl exec nginx-ingress-controller-7g2rv -- echo "" >> /etc/nginx/template/nginx.tmpl
I0825 00:21:01.317244       1 main.go:94] new NGINX template loaded
I0825 00:21:04.832265       1 command.go:81] change in configuration detected. Reloading...
kubectl exec nginx-ingress-controller-7g2rv -- echo "{{ something }}" >> /etc/nginx/template/nginx.tmpl
W0825 00:21:59.913088       1 main.go:88] invalid NGINX template: template: nginx.tmpl:370: function "something" not defined

@aledbf aledbf force-pushed the ref-templates branch 2 times, most recently from 61d00a7 to aa8fd13 Compare August 25, 2016 18:22
@aledbf
Copy link
Contributor Author

aledbf commented Aug 25, 2016

Also contains update to godeps required by #1623

// checkTemplate verifies the NGINX template exists (file /etc/nginx/template/nginx.tmpl)
// If the file does not exists it means:
// a. custom docker image
// b. standard image using watch-resource sidecar with emptyDir volume

Choose a reason for hiding this comment

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

why emptyDir volume? isn't this just like the nginx example in main repo, except this sidecar is reusable with any existing pod that mounts a config map?

@bprashanth
Copy link

LGTM

@bprashanth bprashanth added the lgtm Indicates that a PR is ready to be merged. label Aug 26, 2016
@k8s-github-robot
Copy link

Automatic merge from submit-queue

@tjliupeng
Copy link

tjliupeng commented Nov 18, 2016

@aledbf , I change the content of /etc/nginx/template/nginx.tmpl in a running container, but no new nginx.conf is generated. What do I miss?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NGINX Ingress Controller - net.core.somaxconn=128
5 participants