From f12960e8ff020e7989410258a324f0ddd7f41291 Mon Sep 17 00:00:00 2001 From: Peter Kelly Date: Thu, 6 Sep 2018 14:25:22 +0100 Subject: [PATCH] Address PR feedback - lint, doc updates, dockerfiles and moving files. - Addresses all `golint` warnings including ones not caused by this PR - Moves install files to correct place - Updates docs with old references before structure - Fixes broken links (not caused by this PR) - Updates COPY command in other Dockerfiles --- .gitignore | 2 +- CONTRIBUTING.md | 2 +- README.md | 2 +- build/DockerfileForAlpine | 2 +- build/DockerfileForPlus | 2 +- build/README.md | 7 +--- cmd/nginx-ingress/main.go | 2 +- .../nginx-ingress-with-prometheus.yaml | 1 - .../nginx-ingress-with-prometheus.yaml | 1 - deployments/helm-chart/Chart.yaml | 2 +- deployments/helm-chart/README.md | 8 ++--- docs/installation.md | 2 +- examples/customization/README.md | 4 +-- internal/controller/controller.go | 14 +++++++- internal/controller/controller_test.go | 4 +-- internal/handlers/configMap.go | 1 + internal/handlers/endpoint.go | 1 + internal/handlers/ingress.go | 1 + internal/handlers/leader.go | 1 + internal/handlers/secret.go | 1 + internal/handlers/service.go | 1 + internal/nginx/configurator.go | 14 ++++---- internal/nginx/ingress.go | 1 + internal/nginx/nginx.go | 34 +++++++++---------- internal/nginx/plus/nginx_api.go | 4 +++ internal/nginx/plus/nginx_client.go | 1 + internal/nginx/template_executor.go | 2 +- internal/nginx/templates/templates_test.go | 2 +- internal/queue/queue.go | 7 ++-- internal/utils/utils.go | 3 ++ 30 files changed, 74 insertions(+), 55 deletions(-) rename {install => deployments}/daemon-set/nginx-ingress-with-prometheus.yaml (99%) rename {install => deployments}/deployment/nginx-ingress-with-prometheus.yaml (99%) diff --git a/.gitignore b/.gitignore index 820e61d81b..bf36da9b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -27,7 +27,7 @@ nginx-ingress !nginx-ingress/ osx-nginx-plus-ingress nginx-plus-ingress -cmd/nginx-ic/nginx-ic +cmd/nginx-ingress/nginx-ingress # NGINX Plus license files *.crt diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 67580f866b..7a43e2303e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -31,7 +31,7 @@ Read the [documentation](https://github.com/nginxinc/kubernetes-ingress/tree/mas * This Ingress Controller is written in Go and supports both the open source NGINX software and NGINX Plus. * The project follows a standard Go project layout - * The main code is found at `cmd/nginx-ic/` + * The main code is found at `cmd/nginx-ingress/` * The internal code is found at `internal/` * Build files for Docker and CI are found under `build/` * Deployment yaml files, and Helm files are found at `deployments/` diff --git a/README.md b/README.md index 2163120961..c8b70722dd 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ The table below summarizes the options regarding the images, manifests, helm cha | Version | Description | Image for NGINX | Image for NGINX Plus | Installation Manifests and Helm Chart | Documentation and Examples | | ------- | ----------- | --------------- | -------------------- | ---------------------------------------| -------------------------- | | Latest stable release | For production use | `nginx/nginx-ingress:1.3.0`, `nginx/nginx-ingress:1.3.0-alpine` from [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress/) or [build your own image](https://github.com/nginxinc/kubernetes-ingress/tree/v1.3.0/nginx-controller). | [Build your own image](https://github.com/nginxinc/kubernetes-ingress/tree/v1.3.0/nginx-controller). | [Manifests](https://github.com/nginxinc/kubernetes-ingress/tree/v1.3.0/install). [Helm chart](https://github.com/nginxinc/kubernetes-ingress/tree/v1.3.0/helm-chart). | [Documentation](https://github.com/nginxinc/kubernetes-ingress/tree/v1.3.0/docs). [Examples](https://github.com/nginxinc/kubernetes-ingress/tree/v1.3.0/examples). | -| Edge | For testing and experimenting | `nginx/nginx-ingress:edge`, `nginx/nginx-ingress:edge-alpine` from [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress/) or [build your own image](https://github.com/nginxinc/kubernetes-ingress/tree/master/nginx-controller). | [Build your own image](https://github.com/nginxinc/kubernetes-ingress/tree/master/nginx-controller). | [Manifests](https://github.com/nginxinc/kubernetes-ingress/tree/master/install). [Helm chart](https://github.com/nginxinc/kubernetes-ingress/tree/master/helm-chart). | [Documentation](https://github.com/nginxinc/kubernetes-ingress/tree/master/docs). [Examples](https://github.com/nginxinc/kubernetes-ingress/tree/master/examples). | +| Edge | For testing and experimenting | `nginx/nginx-ingress:edge`, `nginx/nginx-ingress:edge-alpine` from [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress/) or [build your own image](https://github.com/nginxinc/kubernetes-ingress/tree/master/build). | [Build your own image](https://github.com/nginxinc/kubernetes-ingress/tree/master/build). | [Manifests](https://github.com/nginxinc/kubernetes-ingress/tree/master/deployments). [Helm chart](https://github.com/nginxinc/kubernetes-ingress/tree/master/deployments/helm-chart). | [Documentation](https://github.com/nginxinc/kubernetes-ingress/tree/master/docs). [Examples](https://github.com/nginxinc/kubernetes-ingress/tree/master/examples). | ## Benefits of Using the Ingress Controller with NGINX Plus diff --git a/build/DockerfileForAlpine b/build/DockerfileForAlpine index 08e44b88c7..9f8a5be296 100644 --- a/build/DockerfileForAlpine +++ b/build/DockerfileForAlpine @@ -6,7 +6,7 @@ RUN ln -sf /proc/1/fd/1 /var/log/nginx/access.log \ && ln -sf /proc/1/fd/1 /var/log/nginx/stream-access.log \ && ln -sf /proc/1/fd/2 /var/log/nginx/error.log -COPY nginx-ingress nginx/templates/nginx.ingress.tmpl nginx/templates/nginx.tmpl / +COPY nginx-ingress internal/nginx/templates/nginx.ingress.tmpl internal/nginx/templates/nginx.tmpl / RUN rm /etc/nginx/conf.d/* diff --git a/build/DockerfileForPlus b/build/DockerfileForPlus index 3e8530bdce..aed325e074 100644 --- a/build/DockerfileForPlus +++ b/build/DockerfileForPlus @@ -50,7 +50,7 @@ RUN ln -sf /proc/1/fd/1 /var/log/nginx/access.log \ EXPOSE 80 443 -COPY nginx-ingress nginx/templates/nginx-plus.ingress.tmpl nginx/templates/nginx-plus.tmpl / +COPY nginx-ingress internal/nginx/templates/nginx-plus.ingress.tmpl internal/nginx/templates/nginx-plus.tmpl / RUN rm /etc/nginx/conf.d/* \ && mkdir -p /etc/nginx/secrets diff --git a/build/README.md b/build/README.md index 82b3c3efc2..907cd522ae 100644 --- a/build/README.md +++ b/build/README.md @@ -32,11 +32,6 @@ We build the image using the make utility and the provided `Makefile`. Let’s c $ git clone https://github.com/nginxinc/kubernetes-ingress/ ``` -1. If you're using a stable release, check out the corresponding tag. For release 1.3.0, run: - ``` - $ git checkout v1.3.0 - ``` - 1. Build the image: * For NGINX: ``` @@ -47,7 +42,7 @@ We build the image using the make utility and the provided `Makefile`. Let’s c As the result, the image **myregistry.example.com/nginx-ingress:edge** is built and pushed to the registry. Note that the tag `edge` comes from the `VERSION` variable, defined in the Makefile. - * For NGINX Plus, first, make sure that the certificate (`nginx-repo.crt`) and the key (`nginx-repo.key`) of your license are located in the `nginx-controller` folder: + * For NGINX Plus, first, make sure that the certificate (`nginx-repo.crt`) and the key (`nginx-repo.key`) of your license are located in the root of the project: ``` $ ls nginx-repo.* nginx-repo.crt nginx-repo.key diff --git a/cmd/nginx-ingress/main.go b/cmd/nginx-ingress/main.go index b8545c0f29..5bbbafa191 100644 --- a/cmd/nginx-ingress/main.go +++ b/cmd/nginx-ingress/main.go @@ -284,7 +284,7 @@ func main() { } } -func handleTermination(lbc *controller.LoadBalancerController, ngxc *nginx.NginxController, nginxDone chan error) { +func handleTermination(lbc *controller.LoadBalancerController, ngxc *nginx.Controller, nginxDone chan error) { signalChan := make(chan os.Signal, 1) signal.Notify(signalChan, syscall.SIGTERM) diff --git a/install/daemon-set/nginx-ingress-with-prometheus.yaml b/deployments/daemon-set/nginx-ingress-with-prometheus.yaml similarity index 99% rename from install/daemon-set/nginx-ingress-with-prometheus.yaml rename to deployments/daemon-set/nginx-ingress-with-prometheus.yaml index eabaf93a0a..92398cc9ff 100644 --- a/install/daemon-set/nginx-ingress-with-prometheus.yaml +++ b/deployments/daemon-set/nginx-ingress-with-prometheus.yaml @@ -52,4 +52,3 @@ spec: - :9113 - -nginx.scrape-uri - http://127.0.0.1:8080/stub_status - diff --git a/install/deployment/nginx-ingress-with-prometheus.yaml b/deployments/deployment/nginx-ingress-with-prometheus.yaml similarity index 99% rename from install/deployment/nginx-ingress-with-prometheus.yaml rename to deployments/deployment/nginx-ingress-with-prometheus.yaml index 051d5b660c..a77d0d6ee9 100644 --- a/install/deployment/nginx-ingress-with-prometheus.yaml +++ b/deployments/deployment/nginx-ingress-with-prometheus.yaml @@ -51,4 +51,3 @@ spec: - :9113 - nginx.scrape-uri - http://127.0.0.1:8080/stub_status - diff --git a/deployments/helm-chart/Chart.yaml b/deployments/helm-chart/Chart.yaml index 05f8be4cfc..f62e788fed 100644 --- a/deployments/helm-chart/Chart.yaml +++ b/deployments/helm-chart/Chart.yaml @@ -3,7 +3,7 @@ version: 0.1.2 appVersion: edge description: NGINX Ingress Controller sources: - - https://github.com/nginxinc/kubernetes-ingress/tree/master/helm-chart + - https://github.com/nginxinc/kubernetes-ingress/tree/master/deployment/helm-chart keywords: - ingress - nginx diff --git a/deployments/helm-chart/README.md b/deployments/helm-chart/README.md index fdf82847c3..3baa696460 100644 --- a/deployments/helm-chart/README.md +++ b/deployments/helm-chart/README.md @@ -19,13 +19,9 @@ This chart deploys the NGINX Ingress controller in your Kubernetes cluster. ``` $ git clone https://github.com/nginxinc/kubernetes-ingress/ ``` -1. If you're using a stable release, check out the corresponding tag. For release 1.3.0, run: +2. Change your working directory to /deployments/helm-chart: ``` - $ git checkout v1.3.0 - ``` -2. Change your working directory to /helm-chart: - ``` - $ cd kubernetes-ingress/helm-chart + $ cd kubernetes-ingress/deployments/helm-chart ``` 3. To install the chart with the release name my-release (my-release is the name that you choose): diff --git a/docs/installation.md b/docs/installation.md index 7058e0e099..9df112bee0 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -7,7 +7,7 @@ Make sure you have access to the Ingress controller image: * For NGINX Ingress controller, use the image `nginx/nginx-ingress` from [DockerHub](https://hub.docker.com/r/nginx/nginx-ingress/). * For NGINX Plus Ingress controller, build your own image and push it to your private Docker registry by following the instructions from [here](../build/README.md). -The installation manifests are located in the [install](../install) folder. In the steps below we assume that you will be running the commands from that folder. +The installation manifests are located in the [deployments](../deployments) folder. In the steps below we assume that you will be running the commands from that folder. ## 1. Create a Namespace, a SA and the Default Secret. diff --git a/examples/customization/README.md b/examples/customization/README.md index f204f9846c..e38a046389 100644 --- a/examples/customization/README.md +++ b/examples/customization/README.md @@ -24,7 +24,7 @@ The table below summarizes all of the options. For some of them, there are examp | `nginx.org/redirect-to-https` | `redirect-to-https` | Sets the 301 redirect rule based on the value of the `http_x_forwarded_proto` header on the server block to force incoming traffic to be over HTTPS. Useful when terminating SSL in a load balancer in front of the Ingress controller — see [115](https://github.com/nginxinc/kubernetes-ingress/issues/115) | `False` | | | `ingress.kubernetes.io/ssl-redirect` | `ssl-redirect` | Sets an unconditional 301 redirect rule for all incoming HTTP traffic to force incoming traffic over HTTPS. | `True` | | | N/A | `error-log-level` | Sets the global [error log level](http://nginx.org/en/docs/ngx_core_module.html#error_log) for NGINX. | `notice` | | -| N/A | `log-format` | Sets the custom [log format](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format). | See the [template file](../../nginx-controller/nginx/nginx.conf.tmpl). | | +| N/A | `log-format` | Sets the custom [log format](http://nginx.org/en/docs/http/ngx_http_log_module.html#log_format). | See the [template file](../../internal/nginx/templates/nginx.tmpl). | | | `nginx.org/hsts` | `hsts` | Enables [HTTP Strict Transport Security (HSTS)](https://www.nginx.com/blog/http-strict-transport-security-hsts-and-nginx/): the HSTS header is added to the responses from backends. The `preload` directive is included in the header. | `False` | | | `nginx.org/hsts-max-age` | `hsts-max-age` | Sets the value of the `max-age` directive of the HSTS header. | `2592000` (1 month) | | `nginx.org/hsts-include-subdomains` | `hsts-include-subdomains` | Adds the `includeSubDomains` directive to the HSTS header. | `False`| | @@ -69,7 +69,7 @@ The table below summarizes all of the options. For some of them, there are examp | `nginx.com/slow-start` | N/A | Sets the upstream server [slow-start period](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-load-balancer/#server-slow-start). By default, slow-start is activated after a server becomes [available](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/#passive-health-checks) or [healthy](https://docs.nginx.com/nginx/admin-guide/load-balancer/http-health-check/#active-health-checks). To enable slow-start for newly added servers, configure [mandatory active health checks](../health-checks). | `"0s"` | | | N/A | `external-status-address` | Sets the address to be reported in the status of Ingress resources. Requires the `-report-status` command-line argument. Overrides the `-external-service` argument. | N/A | [Report Ingress Status](../../docs/report-ingress-status.md). | | N/A | `stream-snippets` | Sets a custom snippet in stream context. | N/A | [Support for TCP/UDP Load Balancing](../tcp-udp). | -| N/A | `stream-log-format` | Sets the custom [log format](http://nginx.org/en/docs/stream/ngx_stream_log_module.html#log_format) for TCP/UDP load balancing. | See the [template file](../../nginx-controller/nginx/nginx.conf.tmpl). | | +| N/A | `stream-log-format` | Sets the custom [log format](http://nginx.org/en/docs/stream/ngx_stream_log_module.html#log_format) for TCP/UDP load balancing. | See the [template file](../../internal/nginx/templates/nginx.tmpl). | | ## Using ConfigMaps diff --git a/internal/controller/controller.go b/internal/controller/controller.go index 0f77f40c08..8882679380 100644 --- a/internal/controller/controller.go +++ b/internal/controller/controller.go @@ -137,10 +137,12 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc return &lbc } +// UpdateManagedAndMergeableIngresses invokes the UpdateManagedAndMergeableIngresses method on the Status Updater func (lbc *LoadBalancerController) UpdateManagedAndMergeableIngresses(ingresses []v1beta1.Ingress, mergeableIngresses map[string]*nginx.MergeableIngresses) error { return lbc.statusUpdater.UpdateManagedAndMergeableIngresses(ingresses, mergeableIngresses) } +// AddLeaderHandler adds the handler for leader election to the controller func (lbc *LoadBalancerController) AddLeaderHandler(leaderHandler leaderelection.LeaderCallbacks) { var err error lbc.leaderElector, err = NewLeaderElector(lbc.client, leaderHandler, lbc.controllerNamespace) @@ -149,18 +151,22 @@ func (lbc *LoadBalancerController) AddLeaderHandler(leaderHandler leaderelection } } +// GetIngressClassKey returns the ingress class key func (lbc *LoadBalancerController) GetIngressClassKey() string { return ingressClassKey } +// AddSyncQueue enqueues the provided item on the sync queue func (lbc *LoadBalancerController) AddSyncQueue(item interface{}) { lbc.syncQueue.Enqueue(item) } +// WatchNginxConfigMaps sets the controller to watch config map changes func (lbc *LoadBalancerController) WatchNginxConfigMaps() { lbc.watchNginxConfigMaps = true } +// AddSecretHandler adds the handler for secrets to the controller func (lbc *LoadBalancerController) AddSecretHandler(handlers cache.ResourceEventHandlerFuncs) { lbc.secretLister.Store, lbc.secretController = cache.NewInformer( cache.NewListWatchFromClient( @@ -174,6 +180,7 @@ func (lbc *LoadBalancerController) AddSecretHandler(handlers cache.ResourceEvent ) } +// AddServiceHandler adds the handler for services to the controller func (lbc *LoadBalancerController) AddServiceHandler(handlers cache.ResourceEventHandlerFuncs) { lbc.svcLister, lbc.svcController = cache.NewInformer( cache.NewListWatchFromClient( @@ -187,6 +194,7 @@ func (lbc *LoadBalancerController) AddServiceHandler(handlers cache.ResourceEven ) } +// AddIngressHandler adds the handler for ingresses to the controller func (lbc *LoadBalancerController) AddIngressHandler(handlers cache.ResourceEventHandlerFuncs) { lbc.ingressLister.Store, lbc.ingressController = cache.NewInformer( cache.NewListWatchFromClient( @@ -200,6 +208,7 @@ func (lbc *LoadBalancerController) AddIngressHandler(handlers cache.ResourceEven ) } +// AddEndpointHandler adds the handler for endpoints to the controller func (lbc *LoadBalancerController) AddEndpointHandler(handlers cache.ResourceEventHandlerFuncs) { lbc.endpointLister.Store, lbc.endpointController = cache.NewInformer( cache.NewListWatchFromClient( @@ -213,6 +222,7 @@ func (lbc *LoadBalancerController) AddEndpointHandler(handlers cache.ResourceEve ) } +// AddConfigMapHandler adds the handler for config maps to the controller func (lbc *LoadBalancerController) AddConfigMapHandler(handlers cache.ResourceEventHandlerFuncs, namespace string) { lbc.configMapLister.Store, lbc.configMapController = cache.NewInformer( cache.NewListWatchFromClient( @@ -226,6 +236,7 @@ func (lbc *LoadBalancerController) AddConfigMapHandler(handlers cache.ResourceEv ) } +// GetDefaultServerSecret returns the default server secret func (lbc *LoadBalancerController) GetDefaultServerSecret() string { return lbc.defaultServerSecret } @@ -579,7 +590,7 @@ func (lbc *LoadBalancerController) syncExternalService(task queue.Task) { } } -// isExternalServiceForStatus matches the service specified by the external-service arg +// IsExternalServiceForStatus matches the service specified by the external-service arg func (lbc *LoadBalancerController) IsExternalServiceForStatus(svc *api_v1.Service) bool { return lbc.statusUpdater.namespace == svc.Namespace && lbc.statusUpdater.externalServiceName == svc.Name } @@ -805,6 +816,7 @@ items: return nonMinions, minions, nil } +// EnqueueIngressForService enqueues the ingress for the given service func (lbc *LoadBalancerController) EnqueueIngressForService(svc *api_v1.Service) { ings := lbc.getIngressesForService(svc) for _, ing := range ings { diff --git a/internal/controller/controller_test.go b/internal/controller/controller_test.go index ecb282a8b2..e406af7a19 100644 --- a/internal/controller/controller_test.go +++ b/internal/controller/controller_test.go @@ -549,7 +549,7 @@ func getMergableDefaults() (cafeMaster, coffeeMinion, teaMinion extensions.Ingre cafeMasterIngEx, _ := lbc.createIngress(&cafeMaster) ingExMap["default-cafe-master"] = cafeMasterIngEx - cnf := nginx.NewConfigurator(&nginx.NginxController{}, &nginx.Config{}, &plus.NginxAPIController{}, &nginx.TemplateExecutor{}) + cnf := nginx.NewConfigurator(&nginx.Controller{}, &nginx.Config{}, &plus.NginxAPIController{}, &nginx.TemplateExecutor{}) // edit private field ingresses to use in testing pointerVal := reflect.ValueOf(cnf) @@ -782,7 +782,7 @@ func TestFindProbeForPods(t *testing.T) { func TestGetServicePortForIngressPort(t *testing.T) { fakeClient := fake.NewSimpleClientset() - cnf := nginx.NewConfigurator(&nginx.NginxController{}, &nginx.Config{}, &plus.NginxAPIController{}, &nginx.TemplateExecutor{}) + cnf := nginx.NewConfigurator(&nginx.Controller{}, &nginx.Config{}, &plus.NginxAPIController{}, &nginx.TemplateExecutor{}) lbc := LoadBalancerController{ client: fakeClient, ingressClass: "nginx", diff --git a/internal/handlers/configMap.go b/internal/handlers/configMap.go index 93cbc077a8..9a61672848 100644 --- a/internal/handlers/configMap.go +++ b/internal/handlers/configMap.go @@ -9,6 +9,7 @@ import ( "k8s.io/client-go/tools/cache" ) +// CreateConfigMapHandlers builds the handler funcs for config maps func CreateConfigMapHandlers(lbc *controller.LoadBalancerController, name string) cache.ResourceEventHandlerFuncs { return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { diff --git a/internal/handlers/endpoint.go b/internal/handlers/endpoint.go index 8186613204..12e8d5aa18 100644 --- a/internal/handlers/endpoint.go +++ b/internal/handlers/endpoint.go @@ -9,6 +9,7 @@ import ( "k8s.io/client-go/tools/cache" ) +// CreateEndpointHandlers builds the handler funcs for endpoints func CreateEndpointHandlers(lbc *controller.LoadBalancerController) cache.ResourceEventHandlerFuncs { return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { diff --git a/internal/handlers/ingress.go b/internal/handlers/ingress.go index 50fe681128..6c2ec394e7 100644 --- a/internal/handlers/ingress.go +++ b/internal/handlers/ingress.go @@ -8,6 +8,7 @@ import ( "k8s.io/client-go/tools/cache" ) +// CreateIngressHandlers builds the handler funcs for ingresses func CreateIngressHandlers(lbc *controller.LoadBalancerController) cache.ResourceEventHandlerFuncs { return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { diff --git a/internal/handlers/leader.go b/internal/handlers/leader.go index 7f58fc9628..b60e1ba5ea 100644 --- a/internal/handlers/leader.go +++ b/internal/handlers/leader.go @@ -6,6 +6,7 @@ import ( "k8s.io/client-go/tools/leaderelection" ) +// CreateLeaderHandler builds the handler funcs for leader handling func CreateLeaderHandler(lbc *controller.LoadBalancerController) leaderelection.LeaderCallbacks { return leaderelection.LeaderCallbacks{ OnStartedLeading: func(stop <-chan struct{}) { diff --git a/internal/handlers/secret.go b/internal/handlers/secret.go index 4233c564fe..b0972ff727 100644 --- a/internal/handlers/secret.go +++ b/internal/handlers/secret.go @@ -9,6 +9,7 @@ import ( "k8s.io/client-go/tools/cache" ) +// CreateSecretHandlers builds the handler funcs for secrets func CreateSecretHandlers(lbc *controller.LoadBalancerController) cache.ResourceEventHandlerFuncs { return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { diff --git a/internal/handlers/service.go b/internal/handlers/service.go index f371ce0c27..1e43e9890e 100644 --- a/internal/handlers/service.go +++ b/internal/handlers/service.go @@ -10,6 +10,7 @@ import ( api_v1 "k8s.io/api/core/v1" ) +// CreateServiceHandlers builds the handler funcs for services func CreateServiceHandlers(lbc *controller.LoadBalancerController) cache.ResourceEventHandlerFuncs { return cache.ResourceEventHandlerFuncs{ AddFunc: func(obj interface{}) { diff --git a/internal/nginx/configurator.go b/internal/nginx/configurator.go index 8a72d79822..c53fe18002 100644 --- a/internal/nginx/configurator.go +++ b/internal/nginx/configurator.go @@ -28,7 +28,7 @@ const JWTKeyAnnotation = "nginx.com/jwt-key" // Configurator transforms an Ingress resource into NGINX Configuration type Configurator struct { - nginx *NginxController + nginx *Controller config *Config nginxAPI *plus.NginxAPIController templateExecutor *TemplateExecutor @@ -37,7 +37,7 @@ type Configurator struct { } // NewConfigurator creates a new Configurator -func NewConfigurator(nginx *NginxController, config *Config, nginxAPI *plus.NginxAPIController, templateExecutor *TemplateExecutor) *Configurator { +func NewConfigurator(nginx *Controller, config *Config, nginxAPI *plus.NginxAPIController, templateExecutor *TemplateExecutor) *Configurator { cnf := Configurator{ nginx: nginx, config: config, @@ -738,7 +738,7 @@ func parsePort(value string) (int, error) { port, err := strconv.ParseInt(value, 10, 16) if err != nil { return 0, fmt.Errorf( - "Unable to parse port as integer: %s\n", + "Unable to parse port as integer: %s", err, ) } @@ -1051,7 +1051,7 @@ func (cnf *Configurator) updatePlusEndpoints(ingEx *IngressEx) error { func filterMasterAnnotations(annotations map[string]string) []string { var removedAnnotations []string - for key, _ := range annotations { + for key := range annotations { if _, notAllowed := masterBlacklist[key]; notAllowed { removedAnnotations = append(removedAnnotations, key) delete(annotations, key) @@ -1064,7 +1064,7 @@ func filterMasterAnnotations(annotations map[string]string) []string { func filterMinionAnnotations(annotations map[string]string) []string { var removedAnnotations []string - for key, _ := range annotations { + for key := range annotations { if _, notAllowed := minionBlacklist[key]; notAllowed { removedAnnotations = append(removedAnnotations, key) delete(annotations, key) @@ -1085,8 +1085,8 @@ func mergeMasterAnnotationsIntoMinion(minionAnnotations map[string]string, maste } // GenerateNginxMainConfig generate NginxMainConfig from Config -func GenerateNginxMainConfig(config *Config) *NginxMainConfig { - nginxCfg := &NginxMainConfig{ +func GenerateNginxMainConfig(config *Config) *MainConfig { + nginxCfg := &MainConfig{ MainSnippets: config.MainMainSnippets, HTTPSnippets: config.MainHTTPSnippets, StreamSnippets: config.MainStreamSnippets, diff --git a/internal/nginx/ingress.go b/internal/nginx/ingress.go index 1df62bcc7b..12c4bb2c8e 100644 --- a/internal/nginx/ingress.go +++ b/internal/nginx/ingress.go @@ -15,6 +15,7 @@ type IngressEx struct { HealthChecks map[string]*api_v1.Probe } +// MergeableIngresses is a mergeable ingress of a master and minions type MergeableIngresses struct { Master *IngressEx Minions []*IngressEx diff --git a/internal/nginx/nginx.go b/internal/nginx/nginx.go index 4fd6a2af08..8bc642c722 100644 --- a/internal/nginx/nginx.go +++ b/internal/nginx/nginx.go @@ -17,8 +17,8 @@ const dhparamFilename = "dhparam.pem" const TLSSecretFileMode = 0600 const jwkSecretFileMode = 0644 -// NginxController updates NGINX configuration, starts and reloads NGINX -type NginxController struct { +// Controller updates NGINX configuration, starts and reloads NGINX +type Controller struct { nginxConfdPath string nginxSecretsPath string local bool @@ -137,8 +137,8 @@ type Location struct { IngressResource string } -// NginxMainConfig describe the main NGINX configuration file -type NginxMainConfig struct { +// MainConfig describe the main NGINX configuration file +type MainConfig struct { ServerNamesHashBucketSize string ServerNamesHashMaxSize string LogFormat string @@ -182,8 +182,8 @@ func NewUpstreamWithDefaultServer(name string) Upstream { } // NewNginxController creates a NGINX controller -func NewNginxController(nginxConfPath string, local bool) *NginxController { - ngxc := NginxController{ +func NewNginxController(nginxConfPath string, local bool) *Controller { + ngxc := Controller{ nginxConfdPath: path.Join(nginxConfPath, "conf.d"), nginxSecretsPath: path.Join(nginxConfPath, "secrets"), local: local, @@ -194,7 +194,7 @@ func NewNginxController(nginxConfPath string, local bool) *NginxController { // DeleteIngress deletes the configuration file, which corresponds for the // specified ingress from NGINX conf directory -func (nginx *NginxController) DeleteIngress(name string) { +func (nginx *Controller) DeleteIngress(name string) { filename := nginx.getIngressNginxConfigFileName(name) glog.V(3).Infof("deleting %v", filename) @@ -206,7 +206,7 @@ func (nginx *NginxController) DeleteIngress(name string) { } // AddOrUpdateDHParam creates the servers dhparam.pem file -func (nginx *NginxController) AddOrUpdateDHParam(dhparam string) (string, error) { +func (nginx *Controller) AddOrUpdateDHParam(dhparam string) (string, error) { fileName := nginx.nginxSecretsPath + "/" + dhparamFilename if !nginx.local { pem, err := os.Create(fileName) @@ -224,7 +224,7 @@ func (nginx *NginxController) AddOrUpdateDHParam(dhparam string) (string, error) } // AddOrUpdateSecretFile creates a file with the specified name, content and mode. -func (nginx *NginxController) AddOrUpdateSecretFile(name string, content []byte, mode os.FileMode) string { +func (nginx *Controller) AddOrUpdateSecretFile(name string, content []byte, mode os.FileMode) string { filename := nginx.getSecretFileName(name) if !nginx.local { @@ -258,7 +258,7 @@ func (nginx *NginxController) AddOrUpdateSecretFile(name string, content []byte, } // DeleteSecretFile the file with a Secret -func (nginx *NginxController) DeleteSecretFile(name string) { +func (nginx *Controller) DeleteSecretFile(name string) { filename := nginx.getSecretFileName(name) glog.V(3).Infof("deleting %v", filename) @@ -270,16 +270,16 @@ func (nginx *NginxController) DeleteSecretFile(name string) { } -func (nginx *NginxController) getIngressNginxConfigFileName(name string) string { +func (nginx *Controller) getIngressNginxConfigFileName(name string) string { return path.Join(nginx.nginxConfdPath, name+".conf") } -func (nginx *NginxController) getSecretFileName(name string) string { +func (nginx *Controller) getSecretFileName(name string) string { return path.Join(nginx.nginxSecretsPath, name) } // Reload reloads NGINX -func (nginx *NginxController) Reload() error { +func (nginx *Controller) Reload() error { if !nginx.local { if err := shellOut("nginx -t"); err != nil { return fmt.Errorf("Invalid nginx configuration detected, not reloading: %s", err) @@ -294,7 +294,7 @@ func (nginx *NginxController) Reload() error { } // Start starts NGINX -func (nginx *NginxController) Start(done chan error) { +func (nginx *Controller) Start(done chan error) { if !nginx.local { cmd := exec.Command("nginx") cmd.Stdout = os.Stdout @@ -311,7 +311,7 @@ func (nginx *NginxController) Start(done chan error) { } // Quit shutdowns NGINX gracefully -func (nginx *NginxController) Quit() { +func (nginx *Controller) Quit() { if !nginx.local { if err := shellOut("nginx -s quit"); err != nil { glog.Fatalf("Failed to quit nginx: %v", err) @@ -351,7 +351,7 @@ func shellOut(cmd string) (err error) { } // UpdateMainConfigFile writes the main NGINX configuration file to the filesystem -func (nginx *NginxController) UpdateMainConfigFile(cfg []byte) { +func (nginx *Controller) UpdateMainConfigFile(cfg []byte) { filename := "/etc/nginx/nginx.conf" glog.V(3).Infof("Writing NGINX conf to %v", filename) @@ -374,7 +374,7 @@ func (nginx *NginxController) UpdateMainConfigFile(cfg []byte) { } // UpdateIngressConfigFile writes the Ingress configuration file to the filesystem -func (nginx *NginxController) UpdateIngressConfigFile(name string, cfg []byte) { +func (nginx *Controller) UpdateIngressConfigFile(name string, cfg []byte) { filename := nginx.getIngressNginxConfigFileName(name) glog.V(3).Infof("Writing Ingress conf to %v", filename) diff --git a/internal/nginx/plus/nginx_api.go b/internal/nginx/plus/nginx_api.go index a887e5e7e8..69c7d7119d 100644 --- a/internal/nginx/plus/nginx_api.go +++ b/internal/nginx/plus/nginx_api.go @@ -6,17 +6,20 @@ import ( "github.com/golang/glog" ) +// NginxAPIController works with the NGINX API type NginxAPIController struct { client *NginxClient local bool } +// ServerConfig holds the config data type ServerConfig struct { MaxFails int64 FailTimeout string SlowStart string } +// NewNginxAPIController creates an instance of NginxAPIController func NewNginxAPIController(httpClient *http.Client, endpoint string, local bool) (*NginxAPIController, error) { client, err := NewNginxClient(httpClient, endpoint) if !local && err != nil { @@ -26,6 +29,7 @@ func NewNginxAPIController(httpClient *http.Client, endpoint string, local bool) return nginx, nil } +// UpdateServers updates upstream servers func (nginx *NginxAPIController) UpdateServers(upstream string, servers []string, config ServerConfig) error { if nginx.local { glog.V(3).Infof("Updating endpoints of %v: %v\n", upstream, servers) diff --git a/internal/nginx/plus/nginx_client.go b/internal/nginx/plus/nginx_client.go index bde2a0fb5d..d902d8eaa5 100644 --- a/internal/nginx/plus/nginx_client.go +++ b/internal/nginx/plus/nginx_client.go @@ -20,6 +20,7 @@ type NginxClient struct { type versions []int +// UpstreamServer holds the fields for an upstream server type UpstreamServer struct { ID int64 `json:"id,omitempty"` Server string `json:"server"` diff --git a/internal/nginx/template_executor.go b/internal/nginx/template_executor.go index 66055c2d32..306f5a05a1 100644 --- a/internal/nginx/template_executor.go +++ b/internal/nginx/template_executor.go @@ -60,7 +60,7 @@ func (te *TemplateExecutor) UpdateIngressTemplate(templateString *string) error } // ExecuteMainConfigTemplate generates the content of the main NGINX configuration file -func (te *TemplateExecutor) ExecuteMainConfigTemplate(cfg *NginxMainConfig) ([]byte, error) { +func (te *TemplateExecutor) ExecuteMainConfigTemplate(cfg *MainConfig) ([]byte, error) { cfg.HealthStatus = te.HealthStatus cfg.NginxStatus = te.NginxStatus cfg.NginxStatusPort = te.NginxStatusPort diff --git a/internal/nginx/templates/templates_test.go b/internal/nginx/templates/templates_test.go index db02b9faad..221b64040f 100644 --- a/internal/nginx/templates/templates_test.go +++ b/internal/nginx/templates/templates_test.go @@ -80,7 +80,7 @@ var ingCfg = nginx.IngressNginxConfig{ Keepalive: "16", } -var mainCfg = nginx.NginxMainConfig{ +var mainCfg = nginx.MainConfig{ ServerNamesHashMaxSize: "512", ServerTokens: "off", WorkerProcesses: "auto", diff --git a/internal/queue/queue.go b/internal/queue/queue.go index 68f08ea461..d7013a5ff8 100644 --- a/internal/queue/queue.go +++ b/internal/queue/queue.go @@ -32,6 +32,7 @@ func NewTaskQueue(syncFn func(Task)) *TaskQueue { } } +// Run begins running the worker for the given duration func (t *TaskQueue) Run(period time.Duration, stopCh <-chan struct{}) { wait.Until(t.worker, period, stopCh) } @@ -55,11 +56,13 @@ func (t *TaskQueue) Enqueue(obj interface{}) { t.queue.Add(task) } +// Requeue adds the task to the queue again and logs the given error func (t *TaskQueue) Requeue(task Task, err error) { glog.Errorf("Requeuing %v, err %v", task.Key, err) t.queue.Add(task) } +// RequeueAfter adds the task to the queue after the given duration func (t *TaskQueue) RequeueAfter(task Task, err error, after time.Duration) { glog.Errorf("Requeuing %v after %s, err %v", task.Key, after.String(), err) go func(task Task, after time.Duration) { @@ -68,7 +71,7 @@ func (t *TaskQueue) RequeueAfter(task Task, err error, after time.Duration) { }(task, after) } -// worker processes work in the queue through sync. +// Worker processes work in the queue through sync. func (t *TaskQueue) worker() { for { task, quit := t.queue.Get() @@ -82,7 +85,7 @@ func (t *TaskQueue) worker() { } } -// shutdown shuts down the work queue and waits for the worker to ACK +// Shutdown shuts down the work queue and waits for the worker to ACK func (t *TaskQueue) Shutdown() { t.queue.ShutDown() <-t.workerDone diff --git a/internal/utils/utils.go b/internal/utils/utils.go index 6c3965382d..a85eb23b1d 100644 --- a/internal/utils/utils.go +++ b/internal/utils/utils.go @@ -147,6 +147,7 @@ type StoreToSecretLister struct { cache.Store } +// IsMinion determines is an ingress is a minion or not func IsMinion(ing *extensions.Ingress) bool { if ing.Annotations["nginx.org/mergeable-ingress-type"] == "minion" { return true @@ -154,6 +155,7 @@ func IsMinion(ing *extensions.Ingress) bool { return false } +// IsMaster determines is an ingress is a master or not func IsMaster(ing *extensions.Ingress) bool { if ing.Annotations["nginx.org/mergeable-ingress-type"] == "master" { return true @@ -161,6 +163,7 @@ func IsMaster(ing *extensions.Ingress) bool { return false } +// HasChanges determines if current ingress has changes compared to old ingress func HasChanges(old *extensions.Ingress, current *extensions.Ingress) bool { old.Status.LoadBalancer.Ingress = current.Status.LoadBalancer.Ingress old.ResourceVersion = current.ResourceVersion