{"id":20119595,"url":"https://github.com/box/error-reporting-with-kubernetes-events","last_synced_at":"2025-05-06T14:32:34.232Z","repository":{"id":57544301,"uuid":"113617629","full_name":"box/error-reporting-with-kubernetes-events","owner":"box","description":" A demonstration of how Box utilizes Kubernetes CustomResourceDefinitions and Events","archived":false,"fork":false,"pushed_at":"2018-01-10T20:05:19.000Z","size":20453,"stargazers_count":32,"open_issues_count":0,"forks_count":11,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-09T13:46:57.577Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/box.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-12-08T21:10:29.000Z","updated_at":"2022-09-27T09:15:43.000Z","dependencies_parsed_at":"2022-09-16T23:01:22.250Z","dependency_job_id":null,"html_url":"https://github.com/box/error-reporting-with-kubernetes-events","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Ferror-reporting-with-kubernetes-events","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Ferror-reporting-with-kubernetes-events/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Ferror-reporting-with-kubernetes-events/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/box%2Ferror-reporting-with-kubernetes-events/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/box","download_url":"https://codeload.github.com/box/error-reporting-with-kubernetes-events/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252703454,"owners_count":21790887,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-13T19:16:14.777Z","updated_at":"2025-05-06T14:32:30.489Z","avatar_url":"https://github.com/box.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# error-reporting-with-kubernetes-events\n\n[![Project Status](http://opensource.box.com/badges/stable.svg)](http://opensource.box.com/badges)\n[![CircleCI](https://circleci.com/gh/box/error-reporting-with-kubernetes-events.svg?style=svg)](https://circleci.com/gh/box/error-reporting-with-kubernetes-events)\n\nThis repo serves as a demonstration of how Box utilizes\n[Kubernetes CustomResourceDefinitions](https://kubernetes.io/docs/tasks/access-kubernetes-api/extend-api-custom-resource-definitions/),\nto communicate amongst containerized services and\n[Kubernetes Events](https://v1-7.docs.kubernetes.io/docs/api-reference/v1.7/#event-v1-core)\n to report errors from one containerized service to another.\n\nAt Box, we have several services running on our clusters that make up the\n*control plane*, performing necessary processing and operational tasks on\nbehalf of the various application services running on the cluster. Application\nlevel services (being separate from the control plane), can trigger additional\nprocessing in the control plane. CustomResourceDefinitions are used for\ntriggering the processing and passing parameters to the computation. A control\nplane service does some checking of the passed parameters. If there is any\nunexpected values in the parameters, Kubernetes Events are used to relay the\nerror information back to the application container.\n\n# Prerequisites\n\nEven though the code *should* work in later versions, this example is tested\nwith Kubernetes 1.7.5. More specifically:\n\n```\n$ kubectl version\nClient Version: version.Info{Major:\"1\", Minor:\"7\", GitVersion:\"v1.7.5\", GitCommit:\"17d7182a7ccbb167074be7a87f0a68bd00d58d97\", GitTreeState:\"clean\", BuildDate:\"2017-08-31T19:32:12Z\", GoVersion:\"go1.9\", Compiler:\"gc\", Platform:\"darwin/amd64\"}\nServer Version: version.Info{Major:\"1\", Minor:\"7\", GitVersion:\"v1.7.5\", GitCommit:\"17d7182a7ccbb167074be7a87f0a68bd00d58d97\", GitTreeState:\"clean\", BuildDate:\"2017-10-04T09:07:46Z\", GoVersion:\"go1.8.3\", Compiler:\"gc\", Platform:\"linux/amd64\"}\n```\n\n\u003e NOTE: Because of the lack of availability of\n\u003e [CustomResourceDefinitions](https://kubernetes.io/docs/tasks/access-kubernetes-api/extend-api-custom-resource-definitions/),\n\u003e this example will not work with Kubernetes versions earlier than 1.7.\n\n\nUsing\n[minikube](https://kubernetes.io/docs/getting-started-guides/minikube/#specifying-the-kubernetes-version)\nyou can start a Kubernetes server at v1.7.5.\n\n```\nminikube start --kubernetes-version v1.7.5\n```\n[brew](https://brew.sh/) can be used to install an old kubectl at\n[v1.7.5](https://github.com/Homebrew/homebrew-core/blob/8e0e4c9c9b1c4154f31f3313e6b5cfce7de79109/Formula/kubernetes-cli.rb#L5).\n\nYou should use the Docker daemon in the minikube vm. Follow the instructions\n[here](https://kubernetes.io/docs/getting-started-guides/minikube/#reusing-the-docker-daemon)\n\nThe code in this example has been tested using these versions of Docker:\n```\n$ docker version\nClient:\n Version:      17.11.0-ce\n API version:  1.23\n Go version:   go1.9.2\n Git commit:   1caf76c\n Built:        unknown-buildtime\n OS/Arch:      darwin/amd64\n\nServer:\n Version:      17.06.0-ce\n API version:  1.30 (minimum version 1.12)\n Go version:   go1.8.3\n Git commit:   02c1d87\n Built:        Fri Jun 23 21:51:55 2017\n OS/Arch:      linux/amd64\n Experimental: false\n```\n\n\u003e NOTE: For older versions of Docker, we have seen problems with the `COPY`\n\u003e command in Dockerfiles while copying a large number of files.\n\n# Build\n\n## Build the Docker containers\n\nFrom project root execute:\n\n```\ndocker build  -f cmd/controlplane/Dockerfile \\\n   -t boxinc/error-reporting-with-kubernetes-events:controlplane  .\n```\n\n# Run\n\n## Start the control plane app and define the CustomResourceDefinition\n\nFrom repo root:\n```\nkubectl  apply  -f cmd/controlplane/config.yml\n```\n\nExpected output:\n```\ncustomresourcedefinition \"pkis.box.com\" configured\nnamespace \"controlplane\" configured\ndeployment \"controlplane\" configured\n```\n\n## Start the applications that trigger processing in the control plane app\n\n\nFrom repo root:\n```\nkubectl apply  -f cmd/app1/config.yml\nkubectl apply  -f cmd/app2/config.yml\n```\n\nExpected output:\n\n```\nnamespace \"app1\" configured\npki \"app1-pki\" configured\ndeployment \"app1\" configured\n\nnamespace \"app2\" configured\npki \"app2-pki\" configured\ndeployment \"app2\" created\n```\n\n\n# Expected Behavior\n\nAll [pods](https://kubernetes.io/docs/concepts/workloads/pods/pod/) except the\npod for `app1` should transition to `Running` state eventually.\n\n```\n$ kubectl get pods --all-namespaces\nNAMESPACE      NAME                            READY     STATUS              RESTARTS   AGE\napp1           app1-647877271-lrpbd            0/1       ContainerCreating   0          1d\napp2           app2-3513338968-9hf6l           1/1       Running             1          1d\ncontrolplane   controlplane-1148696967-13dgv   1/1       Running             0          1d\n....\n```\n\nThere is an error in `app1`'s `config.yml` to demonstrate the error\nhandling using [Kubernetes\nEvents](https://v1-7.docs.kubernetes.io/docs/api-reference/v1.7/#event-v1-core)\n\nThe events history in `kubectl describe` output provides diagnostic\ninformation to the application owner so that she can fix the error\neasily.\n\n```\nkubectl describe pod app1-647877271-lrpbd --namespace app1\n\nEvents:\n  FirstSeen   LastSeen   Count   From         SubObjectPath   Type      Reason         Message\n  ---------   --------   -----   ----         -------------   --------   ------         -------\n  ....\n  1d      1m      24   controlplane            Warning      pki ServiceName error   ServiceName: appp1 in pki: app1-pki is not found in allowedNames: [app1 app2]\n  ....\n\n```\n\nThe shown error line is generated by the controlplane app and placed at the\nevent stream of the problematic pod. More details about generating this\nerror event can be found at the controlplane application's implementation.\n\nThe application programmer can easily rootcause that the `serviceName` field\nin `config.yml` has a typo.\n```\nspec:\n  # This service name has a typo\n  serviceName: appp1\n```\n\n\n\n\n\n## Support\n\nNeed to contact us directly? Email oss@box.com and be sure to include the name of this project in the subject.\n\n## Copyright and License\n\nCopyright 2017 Box, Inc. All rights reserved.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n   http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbox%2Ferror-reporting-with-kubernetes-events","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbox%2Ferror-reporting-with-kubernetes-events","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbox%2Ferror-reporting-with-kubernetes-events/lists"}