No description
Find a file
2021-05-27 09:08:32 +02:00
.vscode Self review: Make Kubernetes abstration a simple package 2021-05-26 12:56:08 +02:00
api Self review: Self-containe HTTP Server, change mux and add request logging 2021-05-26 13:36:13 +02:00
chart Minor fixing and add a proper README 2021-05-27 09:08:32 +02:00
cmd Self review: Self-containe HTTP Server, change mux and add request logging 2021-05-26 13:36:13 +02:00
docs Minor fixing and add a proper README 2021-05-27 09:08:32 +02:00
kubernetes Self review: Self-containe HTTP Server, change mux and add request logging 2021-05-26 13:36:13 +02:00
.dockerignore Add Docker image creation 2021-05-26 16:28:05 +02:00
.gitignore Add Docker image creation 2021-05-26 16:28:05 +02:00
challenge.go Self review: Self-containe HTTP Server, change mux and add request logging 2021-05-26 13:36:13 +02:00
Dockerfile Add Docker image creation 2021-05-26 16:28:05 +02:00
go.mod Self review: Self-containe HTTP Server, change mux and add request logging 2021-05-26 13:36:13 +02:00
go.sum Self review: Self-containe HTTP Server, change mux and add request logging 2021-05-26 13:36:13 +02:00
README.md Minor fixing and add a proper README 2021-05-27 09:08:32 +02:00

Here is my solution to the challenge requested as a test for my technical skills.

Disclaimer

I always try to test some of my skills too on this kins of tests so I try to learn a new technology or a new programming languaje on this kind of tests.

I do not know Golang, I started to learn ir about 3 years ago (and simply did the Go tour) and left it becuase I do not had time to properly had time. Since then I do not developed anything in Go until past year that a monitoring tool in Go failed and I had to do some fixing.

So here we are, trying to do this challenge in a language I do not completly domain. I hace read some easy APIs a friend of mine had on Github to try to understand Golang strange idiomatic and try to do it "The Go Way".

I failed doing it "the go Way" but had a first working example that refacterd to a better and cleaner solution.

First of all, I found all commit message with typos in the messages, these weeks have been though and had mixed challenges for other hiring processes which include Python, Shell scripting, Terraform, Drone, GitHub Actions, Jenkins, a bit of Groovy and having inteviews in English and Spanish so at some point I have not been careful enough but I would rather send this solution as-is without trying to hide anything.

Running in local

TL;DR: go run ./cmd & sleep 3; xdg-open 'http://localhost:5000/services

This project is compilable and usable and accept these flags:

  • --namespace or SERVICE_DISCOVER_NAMESPACE environment variable.

This challenge asked to discover services in the default namespace but for testing this in my personal cluster I used other namespace and other namespace can be configured. By default it uses default.

  • --log-level or SERVICE_DISCOVER_LOG_LEVEL environment variable.

About log level, I programmed if so maybe I needed some debug logging while traying to make this work in-cluster but my error handling made all errors found clear enough to not need any debug logging. There is no error level below info and info is the default.

  • --kubeconfig or SERVICE_DISCOVER_KUBECONFIG of KUBECONFIG environment variable.

In my compute I have more than one Kubeconfig file with various contexts inside of each one so I often use KUBECONFIG environment variable. Also usefull for this.

Running

Listening port is hardcoded into the server to 5000 so in order to run type go run ./cmd with your needed flags/environment variables and open in you browser http://localhost:5000/healthz, http://localhost:5000/services or http://localhost:5000/services/beta (for an example of appGroup filtering)

Running inside a cluster

  • Build the image using Docker with docker built -t your-repository/your-image:your-tag
  • Upload it: docker push your-repository/your-image:your-tag
  • Change in the helm's chart values.yaml file these values to your needs.
  • Deploy it: helm upgrade --install --wait --timeout 150s --namespace -a-namespace-where-to-deploy-it release-name ./chart

Caveats

You can deploy this discoverer in the same namespace as the services provided but will appear in the service list with the other services.

JSON output

This is reason there is a namespace in the values file. By default this discoverer will look at the namespace where it is deployed:

env:
- name: SERVICE_DISCOVER_NAMESPACE
{{- if .Values.namespace }}
    value: {{ .Values.namespace }}
{{- else }}
    valueFrom:
        fieldRef:
            fieldPath: metadata.namespace
{{- end }}

Also, to allow internamespace listing I have to use ClusterRoles so this service can list deployments at cluster level.

A live version of a deployment of the services and the discoverer will be live for a month in https://freenow-challenge.sre-202105.kangmak.es/services